4

I am getting an error with the following:

\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}

The error:

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!

I've tried adding \protect statements before \(, \), and \mathbf but with no effect. If I happen to switch the order of the two chapters (so a chapter title uses \bf before one uses \mathbf), then I don't get an error. I'm completely baffled. The error also goes away if I don't include hyperref.

I saw the problem on two different machines running OS X (one Catalina, one Big Sur, both with very recent runs of the "TeX Live Utility" to update packages). On a third I did not see the problem until I upgraded to MacTex 2020 and ran TeX Live Utility. I've tried with an Ubuntu virtual machine and I don't see the problem there. As I said, I'm baffled. Any suggestions?

2

2 Answers 2

6

One step forward two steps back...

ltfssdcl.dtx in the format has:

% \changes{v3.0u}{2020/03/19}{fix for (gnats/3357)}
%    \begin{macrocode}
 \expandafter#1\ifx\math@bgroup\bgroup{#4}\else#4\fi

latex/3357 has an interesting discusssion showing this is a tricky area....

https://www.latex-project.org/cgi-bin/ltxbugs2html?category=LaTeX&responsible=anyone&state=anything&keyword=&pr=latex%2F3357&search=

However I think adding two more \expandafter is the correct fix here

\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}

I will raise an issue at the latex github

enter image description here

4

You can get away with the error by providing a substitution for \mathbf:

\documentclass{report}
\usepackage{hyperref}

\makeatletter
\pdfstringdefDisableCommands{%
  \let\mathbf\@firstofone
}
\makeatother

\begin{document}

\chapter{This works \(\mathbf{x}=y\)}

test

\end{document}

On the other hand, using math in bookmarks won't work anyhow, so maybe it's preferable to use \texorpdfstring:

\documentclass{report}
\usepackage{hyperref}

\begin{document}

\chapter{This works better \texorpdfstring{\(\mathbf{x}=y\)}{x=y}}

test

\end{document}
4
  • 1
    this used to work in tl2019 so I suspect we should take this as a bug Feb 14, 2021 at 21:08
  • @DavidCarlisle Possibly. Actually it “sort of worked”.
    – egreg
    Feb 14, 2021 at 21:29
  • sure but infinite loop isn't a kind error:-) see my answer I just posted. Feb 14, 2021 at 21:30
  • Thank you, I'll try this as a workaround. Feb 14, 2021 at 22:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.