![MacTeX 2020:章节中的报告 + hyperref + mathbf 错误](https://linux22.com/image/428875/MacTeX%202020%EF%BC%9A%E7%AB%A0%E8%8A%82%E4%B8%AD%E7%9A%84%E6%8A%A5%E5%91%8A%20%2B%20hyperref%20%2B%20mathbf%20%E9%94%99%E8%AF%AF.png)
我收到以下错误:
\documentclass{report}
\usepackage{hyperref}
\begin{document}
\chapter{This raises an error: \(\mathbf{x}=y\)}
test
\chapter{Using this instead works: \({\bf x}=y\)}
test
\end{document}
错误:
Chapter 1.
! TeX capacity exceeded, sorry [input stack size=5000].
\non@alpherr #1->\@latex@error {\string #1
allowed only in math mode}\@ehd
l.5 ...ter{This raises an error: \(\mathbf{x}=y\)}
! ==> Fatal error occurred, no output PDF file produced!
我尝试在 、 和 之前添加语句,\protect
但没有任何效果。如果我碰巧调换了两个章节的顺序(即一个章节标题在使用 之前使用),则不会出现错误。我完全困惑了。如果我不包含 ,错误也会消失。\(
\)
\mathbf
\bf
\mathbf
hyperref
我在两台运行 OS X 的不同机器上都看到了这个问题(一台是 Catalina,一台是 Big Sur,两台机器都最近都运行了“TeX Live Utility”来更新软件包)。在第三台机器上,直到我升级到 MacTex 2020 并运行 TeX Live Utility 时才发现这个问题。我试过使用 Ubuntu 虚拟机,但没有发现问题。正如我所说,我很困惑。有什么建议吗?
答案1
进一步退两步...
ltfssdcl.dtx 格式具有:
% \changes{v3.0u}{2020/03/19}{fix for (gnats/3357)}
% \begin{macrocode}
\expandafter#1\ifx\math@bgroup\bgroup{#4}\else#4\fi
latex/3357 有一个有趣的讨论,表明这是一个棘手的领域......
不过我认为在这里添加两个\expandafter
是正确的解决方法
\documentclass{report}
\usepackage{hyperref}
\makeatletter
\def\document@select@group#1#2#3#4{%
\ifx\math@bgroup\bgroup\else\relax\expandafter\@firstofone\fi
{%
\ifmmode
\ifnum\csname c@mv@\math@version\endcsname<\e@mathgroup@top
\begingroup
\escapechar\m@ne
\getanddefine@fonts{\csname c@mv@\math@version\endcsname}#3%
\globaldefs\@ne \math@fonts
\endgroup
\expandafter\extract@alph@from@version
\csname mv@\math@version\expandafter\endcsname
\expandafter{\number\csname
c@mv@\math@version\endcsname}%
#1%
\global\advance\csname c@mv@\math@version\endcsname\@ne
\else
\let#1\relax
\@latex@error{Too many math alphabets used
in version \math@version}%
\@eha
\fi
\else \expandafter\expandafter\expandafter\non@alpherr\fi
% \end{macrocode}
% If the legacy interface is used, e.g., \verb=$\sf -1$= the math
% alphabet \verb=#1= does not take an argument so we better do not
% surround \verb=#4= with braces, because then we get
% \verb={\relax}= into the formula and introduce an extra Ord
% atom. The two different cases can be distinguished by looking at
% the current value of \cs{math@bgroup}.
% \changes{v3.0u}{2020/03/19}{fix for (gnats/3357)}
% \begin{macrocode}
\expandafter#1\ifx\math@bgroup\bgroup{#4}\else#4\fi
}%
}
\makeatother
\begin{document}
\chapter{This raises an error: \(\mathbf{x}=y\)}
test
\chapter{Using this instead works: \({\bf x}=y\)}
test
\end{document}
我将在 latex github 上提出一个问题
答案2
您可以通过提供以下替代方案来避免错误\mathbf
:
\documentclass{report}
\usepackage{hyperref}
\makeatletter
\pdfstringdefDisableCommands{%
\let\mathbf\@firstofone
}
\makeatother
\begin{document}
\chapter{This works \(\mathbf{x}=y\)}
test
\end{document}
另一方面,在书签中使用数学无论如何都行不通,所以也许最好使用\texorpdfstring
:
\documentclass{report}
\usepackage{hyperref}
\begin{document}
\chapter{This works better \texorpdfstring{\(\mathbf{x}=y\)}{x=y}}
test
\end{document}