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'm using the abbrevs package to provide nicer formatting of BC/AD in dates, but when I use one of the commands in a caption I get an error. Example document:

\documentclass{article}
\usepackage{abbrevs}

\begin{document}

\begin{figure}
\caption{1500--1000 \BC.}
\end{figure}

\end{document}

The error is:

! Argument of \@caption has an extra }.

Removing the \BC eliminates the error, which leads me to think the problem is in the combination of the two... so how can I use an abbreviation in a caption? Alternatively, is there a better package for formatting BC/AD in dates?

share|improve this question
1  
Such an error almost always means: "you have a fragile command in a moving argument", in this case the argument to \caption. Use \protect\BC. –  egreg Mar 4 '13 at 9:09

1 Answer 1

up vote 5 down vote accepted

Many of the commands defined by abbrevs are fragile; for example, \BC expands to \DateMark {b.c} and, in turn, the definition of \DateMark is

\newcommand\DateMark [1] {%
  \hspace{.2em}{\DateMarkSize\scshape #1}%
  \@ifnextchar. {%
      \spacefactor\@m
    }{% ELSE
    .\maybe@ic@space
  }%
}

Any command with \@ifnextchar in its definition is fragile, so it needs to be "protected" when in a moving argument.

Solutions:

  1. Easy, if you don't have too many of these commands in moving arguments

    \caption{1500--1000 \protect\BC.}
    
  2. Safer, if you don't want to bother with all these \protect

    \usepackage{abbrevs}
    \usepackage{etoolbox}
    
    \robustify{\DateMark} % after having loaded abbrevs
    

    It's better to robustify \DateMark rather than \BC, as this covers all date abbreviations.

share|improve this answer
    
Fantastic, many thanks. I went with option 2 as that seemed cleaner. –  stusmith Mar 4 '13 at 9:34

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.