\todonotes 中的 AUTOREF 错误

\todonotes 中的 AUTOREF 错误

一直\autoref写的是“sezione”(部分)而不是“Teorema”(定理),我尝试了不同的解决方案(甚至是“ %”解决方案),但它们对我来说根本不起作用... 这是我的代码的一段简短摘录。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{amssymb}
\usepackage{amsmath}       
\usepackage{todonotes}
\usepackage{amsthm}
\usepackage{hyperref}

\theoremstyle{definition}\newtheorem{definition}{\todo[inline, inlinewidth=2.3cm, noinlinepar, color=green!40]{Definizione}}[section]

\newtheorem{theorem}[definition]{\todo[inline, inlinewidth=1.9cm, noinlinepar, color=red!40]{Teorema}}
%\providecommand*{\theoremautorefname}{Teorema}
%\addto\extrasitalian{\renewcommand{\theoremautorefname}{Teorema}}

\begin{document}
\begin{theorem}\label{bla}
    Bla bla bla
\end{theorem}
%\begin{proposition}
    Blu blu blu $\implies$ \autoref{bla}.
%\end{proposition}
\end{document}

答案1

我建议您按此顺序加载amsthmhyperref和(新)cleveref包,然后才执行\theoremstyle\newtheorem指令。接下来,在文档正文中,我建议您使用\cref而不是\autoref来生成交叉引用,而不必担心todohyperref包之间的(明显)交互。

如果您cleveref使用选项加载包italian,则会自动获得标签“定理”和“定义”的意大利语对应词(“teorema”和“definizione”)以及意大利语版本的语言连词(例如,“e”而不是“and”等)。[附言:我发现意大利语设置命令中有一个错误,它与环境中使用的标签有关definition。在下面的代码中,我建议插入指令\crefname{definition}{definizione}{definizioni}作为先发制人的错误修复。]

在此处输入图片描述

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{amssymb,amsmath,todonotes}

\usepackage{amsthm}
\usepackage[colorlinks,allcolors=blue]{hyperref}
\usepackage[nameinlink,italian]{cleveref} % <-- option 'italian'
\crefname{definition}{definizione}{definizioni} % preemptive bug fix

\theoremstyle{definition}
\newtheorem{definition}{\todo[inline, inlinewidth=2.3cm, 
   noinlinepar, color=green!40]{Definizione}}[section]
\newtheorem{theorem}[definition]{\todo[inline, inlinewidth=1.9cm, 
   noinlinepar, color=red!40]{Teorema}}


\begin{document}
\setcounter{section}{3} 
\begin{theorem}\label{bla} Bla bla bla \end{theorem}
\begin{definition}\label{ble} Ble ble ble \end{definition}

\autoref{bla}   % <-- still incorrect

\cref{bla,ble}  % <-- but \cref is correct
\end{document}

答案2

有两个问题。一个是它\todo在某种程度上与\autoref机制冲突;另一个是你需要使用aliascnt

\todotcolorbox功能替换了:这是一个专门的包,而不是类似的黑客包\todo

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[italian]{babel}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{tcolorbox}
\usepackage{aliascnt}
\usepackage{hyperref}

\newtcbox{\thmtcbox}[1]{
  colback=#1,
  tcbox raise base,
  left=0.4pt,
  top=0.4pt,
  right=0.4pt,
  bottom=0.4pt,
  boxrule=0.4pt,
}

\theoremstyle{definition}

\newtheorem{definition}{\thmtcbox{green!40}{Definizione}}[section]

\newaliascnt{theorem}{definition}
\newtheorem{theorem}[theorem]{\thmtcbox{red!40}{Teorema}}
\aliascntresetthe{theorem}

\providecommand*{\definitionautorefname}{Definizione}

\begin{document}

\begin{theorem}\label{bla}
Bla bla bla
\end{theorem}

\begin{definition}\label{blu}
Blu blu blu $\implies$ \autoref{bla}.
\end{definition}

\autoref{blu}

\end{document}

在此处输入图片描述

不过,cleveref更好。

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[italian]{babel}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{tcolorbox}
\usepackage{hyperref}
\usepackage{cleveref}

\newtcbox{\thmtcbox}[1]{
  colback=#1,
  tcbox raise base,
  left=0.4pt,
  top=0.4pt,
  right=0.4pt,
  bottom=0.4pt,
  boxrule=0.4pt,
}

\theoremstyle{definition}

\newtheorem{definition}{\thmtcbox{green!40}{Definizione}}[section]
\newtheorem{theorem}[definition]{\thmtcbox{red!40}{Teorema}}
\crefname{definition}{definizione}{definizioni}
\Crefname{definition}{Definizione}{Definizioni}
\crefname{theorem}{teorema}{teoremi}
\Crefname{theorem}{Teorema}{Teoremi}

\begin{document}

\begin{theorem}\label{bla}
Bla bla bla
\end{theorem}

\begin{definition}\label{blu}
Blu blu blu $\implies$ \cref{bla}.
\end{definition}

\Cref{blu}

\end{document}

在此处输入图片描述

如果你打电话

\usepackage[nameinlink]{cleveref}

链接将包含名称。

在此处输入图片描述

相关内容