8

I created a supposedly robust command through \DeclareRobustCommand{\plusplus}{\relsize{-3}{++}} that modifies some ++ sign, and I use it in the document. However, when I use the \relsize and the hyperref package with the tocdepth counter set, I obtain a cryptic error (at least for me)

Runaway argument? {\@tempcnta >\z@ \relax \advance \@tempcnta \m@ne \@tempdimb ! TeX capacity exceeded, sorry [main memory size=10000000]. ...\@tempcnta \m@ne \@tempdimb \@tempa \@tempdimb \relax l.15 \subsubsection{test\plusplus}

I even try to increase the memory size, as you can see, up to 10000000. And, in my full document the error changes to

Runaway definition? ->\protect 5.3.4 test\protect \<>-\kernel@ifnextchar [4]\<>-\@ifnextchar \ETC . ! TeX capacity exceeded, sorry [main memory size=10000000]. \new@ifnex tchar l.108 \subsection{test\plusplus}

I don't understand why the error changes. However, the code below is the shortest code I get before removing the error. However, I need to use the hyperref package and the table of contents. How can I solve this problem?

\documentclass{book}

\usepackage{relsize}
\DeclareRobustCommand{\plusplus}{\relsize{-3}{++}}

\usepackage{hyperref}%remove hyperref and it compiles

\begin{document}

\setcounter{tocdepth}{3}%or remove teh tocdepth and it compiles
%but use both and it doesn't

\tableofcontents

\subsubsection{test\plusplus}

\end{document}
7

The problem is with hyperref that tries to expand \plusplus and finds itself in an infinite loop.

Solution: provide a special definition of \plusplus for the bookmarks.

\documentclass{book}

\usepackage{relsize}
\usepackage{hyperref}

\DeclareRobustCommand{\plusplus}{\relsize{-3}{++}}
\pdfstringdefDisableCommands{%
  \def\plusplus{++}%
}

\begin{document}

\tableofcontents

%%% the following would work also without \pdfstringdefDisableCommands
\section{test\texorpdfstring{\plusplus}{++}}

\section{test\plusplus}

\end{document}

For a "one shot" occurrence, using \texorpdfstring{\plusplus}{++} is simpler. The \pdfstringDisableCommands way is better as it doesn't require thinking whether a command is safe for the bookmarks or not.


You can define \plusplus differently, without relsize:

\documentclass{book}

\usepackage{hyperref}

\makeatletter
\DeclareRobustCommand{\plusplus}{%
  {\check@mathfonts\fontsize{\ssf@size}{\f@baselineskip}\selectfont++}%
}
\pdfstringdefDisableCommands{%
  \def\plusplus{++}%
}
\makeatother

\begin{document}

\tableofcontents

%%% the following would work also without \pdfstringdefDisableCommands
\section{test\texorpdfstring{\plusplus}{++}}

\section{test\plusplus}

\end{document}

enter image description here

If you want to raise the two + symbols, you can change the definition into

\makeatletter
\DeclareRobustCommand{\plusplus}{%
  \raisebox{.25ex}{\check@mathfonts\fontsize{\ssf@size}{\f@baselineskip}\selectfont++}%
}
\pdfstringdefDisableCommands{%
  \def\plusplus{++}%
}
\makeatother

enter image description here

  • However, if I use the string it would put the ++ sign as is. The whole idea of the macro is to resize and shift the ++. However, for the sake of being MWE I removed that part. Hence, how can I ensure the command being called (or at least getting the desired effect) and not getting into an infinite loop? – adn Apr 1 '13 at 13:13
  • 1
    @adn I've added also a different definition without \relsize and an easy way for shifting the + up. There's really no way to cope with complicated constructions and the bookmarks without resorting to \pdfstringdefDisableCommands. Having smaller and raised + symbols in the bookmarks is impossible (unless you find a suitable Unicode character), because those are simply strings, not typeset boxes. – egreg Apr 1 '13 at 13:20

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.