I'm writing some macros that need to behave differently after first occurrence. I decided to use the etoolbox package's toggle. My MWE is as follows:



  \toggletrue{SL}% switches to true after first occurrence!

A footnote.\footnote{\SL}\par
\SL \par
\SL \par

As an output I get the following:


The problem, as you can see, is that when using the command in a footnote, the toggle does not occur. (Should the image not be clear enough, the footnote reads "1 SL first".)

What is going on in here? (I tried TeX's \newif with the same result, by the way.)


The solution is hidden in the package documentation:

This command [...] may be prefixed with \global.

The meaning of this is that usually \toggletrue will work locally, that is the setting is undone by the enclosing group. \footnote here defines a group. So you need to use

\global\toggletrue{SL}% switches to true after first occurrence!

in your macro to make sure the switch is always set globally.

enter image description here

  • Just for curiosity---is there another way to accomplish this without toggles or booleans?
    – NVaughan
    Jun 11 '12 at 19:00
  • 1
    Another trick which is common with TeX is something like \newcommand{\SL}{\textit{SL}~first\renewcommand\SL{\textit{SL}~second}}. ...although a global version is easier with plain TeX than with basic LaTeX: \gdef\SL{\textit{SL}~first\gdef\SL{\textit{SL}~second}}. Jun 11 '12 at 20:00
  • Thanks! That's cool. I wasn't aware that one could redefine a command from within the very command!
    – NVaughan
    Jun 11 '12 at 20: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.