thmtools 与 hyperref/autoref 之间的冲突

thmtools 与 hyperref/autoref 之间的冲突

我想\autoref在 PDF 目录中的条目中使用(目的是作为带有证明的附录)。但不幸的是,这三个成分\addcontentsline\autorefthmtools冲突并出现神秘的错误消息。

最小(不)工作示例:

\documentclass[final]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{hyperref}

\declaretheorem{definition}

\begin{document}
\section{Main document}
\label{mysec}
\begin{definition} \label{mydef}
    The definition.
\end{definition}

\section{Additional Details}
In the following line, autoref works:
\subsection*{About \autoref{mydef}}
% the following lines work:
\addcontentsline{toc}{subsection}{Details for~\autoref{mysec}}%
\addcontentsline{toc}{subsection}{Details for~\ref{mydef}}%
% but this here breaks:
\addcontentsline{toc}{subsection}{Details for~\autoref{mydef}}%
What causes autoref to break?
\end{document}

错误信息是:

./thmtools-vs-autoref.tex:27: Use of \reserved@a doesn't match its definition.
\@uclclist ->\oe 
                 \OE \o \O \ae \AE \dh \DH \dj \DJ \l \L \ng \NG \ss \SS \th...
l.27 ...}{subsection}{Details for~\autoref{mydef}}
                                                  %
? 

我使用的是 texlive 2021 (arch linux `texlive-core 2021.58710-2)

是我做错了什么还是有一个错误?

答案1

thmtools 定义\definitionautorefname

 \protect \MakeUppercase  {d}efinition

而这个定义并不安全。

您可以重新定义它:

\documentclass[final]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{hyperref}

\declaretheorem{definition}

\renewcommand\definitionautorefname{Definition}%

\begin{document}
\tableofcontents
\section{Main document}
\label{mysec}
\begin{definition} \label{mydef}
    The definition.
\end{definition}

\section{Additional Details}
In the following line, autoref works:
\subsection*{About \autoref{mydef}}
% the following lines work:
\addcontentsline{toc}{subsection}{Details for~\autoref{mysec}}%
\addcontentsline{toc}{subsection}{Details for~\ref{mydef}}%
% but this here breaks:
\addcontentsline{toc}{subsection}{Details for~\autoref{mydef}}%
What causes autoref to break?
\end{document}

我删除了 inputenc。在当前的 latex 中,utf8 是默认设置。

相关内容