TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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 have defined a conditional using the ifthen package as:

\newcommand{\Switch}[1] { \ifthenelse{\equal{#1}{1}}{Test1}{Test2} }

Running this command works without problem. However, if I try to place it within a Figure Caption, it produces an error (i.e., \Switch{1} and \caption{Example text} work fine, but \caption{\Switch{1}} does not).

Is this expected behavior? How do I work around it to produce a conditional caption?

share|improve this question

The \ifthenelse command appears to be fragile? \caption{\protect\Switch{1}} works.

share|improve this answer

As a modern alternative, you can use the commands from the etoolbox package:


Or the xparse package:

\NewDocumentCommand \Switch { m } {
  \int_compare:nNnTF { #1 } = { \c_one } {
  } {
share|improve this answer
You don't like \int_compare:nTF { #1=1 }? No need for using the constant here (in fact, we shouldn't be promoting their use much, really). – Will Robertson Jan 3 '11 at 16:31

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.