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'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}
share|improve this question

1 Answer 1

up vote 13 down vote accepted

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}
share|improve this answer
    
Works great. Changed a comment in your code example. Thanks! –  SSilk Aug 14 '11 at 17:30

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.