13

I've been using the abbreviation macros for i.e., e.g., and etc. that are provided in this post. However, I just discovered that the etc. macro, and a similar one I made for et al. both cause errors when used inside a caption. When I compile the code below, I get an error Argument of \@caption has an extra }. Is there a way to modify the macro to fix this? Thanks.

\documentclass{article}
\usepackage{caption}

\usepackage{xspace}
\newcommand*{\eg}{e.g.\@\xspace}
\newcommand*{\ie}{i.e.\@\xspace}

\makeatletter
\newcommand*{\etc}{%
    \@ifnextchar{.}%
        {etc}%
        {etc.\@\xspace}%
}
\makeatother

\begin{document}

\begin{figure}
\caption{Me \etc} % This causes problems
\label{}
\end{figure}

\end{document}
14

You should use \DeclareRobustCommand instead of \newcommand in order for the macro to work in headings and captions:

\documentclass{article}
\usepackage{caption}

\usepackage{xspace}
\DeclareRobustCommand{\eg}{e.g.\@\xspace}
\DeclareRobustCommand{\ie}{i.e.\@\xspace}

\makeatletter
\DeclareRobustCommand{\etc}{%
    \@ifnextchar{.}%
        {etc}%
        {etc.\@\xspace}%
}
\makeatother

\begin{document}
\begin{figure}
\caption{Me \etc \ie \eg} % Would cause problems if abbreviations were defined with \newcommand
\label{}
\end{figure}

\end{document}
  • Works great. Changed a comment in your code example. Thanks! – SSilk Aug 14 '11 at 17:30

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.