I have the following listing:

   \begin{lstlisting}[float=h,caption={Description\footnotemark.}, label={listing2},
        keywordstyle=\color{blue}\bfseries, ndkeywordstyle=\color{black}\bfseries, commentstyle=\color{red}\ttfamily,
        stringstyle=\color{green}\ttfamily, identifierstyle=\color{black},backgroundcolor=`\color{white},frame=single, frameround=ffff,captionpos=b,basicstyle=\scriptsize]`




When I compile, there is a fatal error: latex Text Capacity exceeded, sorry [input stack size=5000]

Problem is at \footnotemark, how I can solve this problem?

  • 1
    Have you tried \protect\footnotemark? – Daniel Dec 8 '13 at 15:19
  • No, thanks, it working. Can you pleas me give some explanation? because in image captions it is not needed. – rbrisuda Dec 8 '13 at 15:22

The \footnotemark command is a fragile so it needs to be protected with \protect when used as a "moving argument":

\begin{lstlisting}[float=h,caption={Description\protect\footnotemark.}, label={listing2}, ...]



In essence, "moving arguments" are macros that are passed to some other macro that eventually write them to an external file (like the ToC or list of listings). This typically involves complete expansion of their content. The \protect basically postpones this expansion until content is read back by LaTeX.

The complete topic is quite LaTeXnical: When and if \protect is needed depends not only on the implementation of the macro passed as argument (\footnotemark in this case), but also the macro that processes it in its argument (which is \lst@MakeCaption in this case). Hence, it might well be the case that for some specific caption-like commands it is not necessary. The rule of thumb is: If it breaks with a weird error message, try \protect.

The glory details of fragile and robust commands are very well explained in What is the difference between Fragile and Robust commands?, the protection mechanism itself in Minimal \protected@edef example.

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.