Take the 2-minute tour ×
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.

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.

\defsym{\Rn}{\mathbb{R}^n}
[...]
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:

\errorcontextlines2
\documentclass[paper=a4,11pt]{scrbook}
\usepackage[refpage,noprefix]{nomencl}
\usepackage{subfigure}

\makeatletter
\newcommand*{\defsym}[3][]{\def#2{%
  \ifx\protect\@unexpandable@protect
    #3%
  \else
    \nomenclature{$#3$}{#1}\gdef#2{#3}#3%
  \fi}
}
\makeatother
\makenomenclature
\begin{document}
\defsym{\MeshMacro}{{\cal M}^{\rm mac}}
% $\MeshMacro$ works nicely
\begin{figure}
\subfigure[$\MeshMacro$ goes to hell]{ }
\end{figure}
\printnomenclature
\end{document}

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
add comment

1 Answer

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

\defsym{\MeshMacro}{\mathcal{M}^\mathrm{mac}}

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
add comment

Your Answer

 
discard

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.