TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using the method recommended in List of symbols/abbreviations and macros to automatically generate an entry to the nomenclature (nomencl package) when I first use a command, i.e.

the first occurance $\Rn$ generates an orrurance in the nomenclature,
the second occurance $\Rn$ does not.

This works nicely, and as in the second version described in List of symbols/abbreviations and macros it also works for \section{\Rn} and in figure captions, however it fails when used in subfigures \subfigure[\Rn]{} if that is the first occurrence of the macro.

A minimum example to demonstrate the error:


\defsym{\MeshMacro}{{\cal M}^{\rm mac}}
% $\MeshMacro$ works nicely
\subfigure[$\MeshMacro$ goes to hell]{ }

and the error message is

! TeX capacity exceeded, sorry [input stack size=15000].
\nomenclature ->\protect \@nomenclature 

\MeshMacro ...cal M}^{\rm mac}\else \nomenclature 
                                                  {${\cal M}^{\rm mac}$}{}\g...

\MeshMacro ...al M}^{\rm mac}$}{}\gdef \MeshMacro 
                                                  {{\cal M}^{\rm mac}}{\cal ...
l.20 \subfigure[$\MeshMacro$ goes to hell]{ }

How can I avoid this problem?

share|improve this question
up vote 2 down vote accepted

The problem has two faces. First of all the command \MeshMacro is fragile, so it should be protected. Hence

\subfigure[$\protect\MeshMacro$ goes to hell]{ }

will do; but, since the object is typeset in a box inside a box, the usage of \MeshMacro will not be recorded in the nomenclature file.

However, the problem with the first appearance of \MeshMacro in the subfloat caption can't be solved, because it's a standard TeX feature.

On the other hand, with floating objects one is never sure where they'll fall and the first appearance might end up after the object is used in the text. My suggestion is to avoid such macros in captions.

Note that \cal and \rm are obsolete commands and you should write


using the "officially supported" commands. Also subfigure is obsolete, use subfig or subcaption (they have different syntax, though).

share|improve this answer
switching from the subfigure package to subcaption solved my problem without the need to add protect. Thanks a lot. – H. Brandsmeier Feb 17 '13 at 1:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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