[OS X TeX] "Runaway argument?" error in figure caption

Manfred Braun manfred.braun at uni-due.de
Tue Jul 17 16:52:59 CEST 2012


On 17.07.2012, at 16:38, John B. Thoo wrote:

> Hi, everyone.  I apologize that this is not a Mac-specific question, but rather a general LaTeX question; however, I don't know whom else to ask.
> 
> This code
> 
> \begin{figure}
> \begin{tikzpicture}
> \pgftransformscale{0.75}
> %% axes
>  \draw[help lines,lightgray] (-1,-1) grid (5,5);
>  \draw[thin] (-1,0) -- (5,0) node[anchor=north]{$x$};
>  \draw[thin] (0,-1) -- (0,5) node[anchor=west]{$y$};
> %% u and (u1,u2)
>  \draw[thick,-latex] (0,0) -- (3,4);
>    \draw (1.6,2) node[anchor=west]{$\vec{u} = \left[\begin{array}{c} 3 \\ 4 \end{array}\right]$};
>  \fill (3,4) circle (0.08) node[anchor=west]{$(3,4)$};
> \end{tikzpicture}
>  \caption{It is useful to picture vectors as arrows, although this may not be a literal representation of vectors.  Here we identify the vector $\vec{u} = \left[\begin{smallmatrix} 3 \\ 4 \end{smallmatrix}\right]$ in $\R{2}$ represented as an arrow with the point $(3,4)$ in the $xy$ plane.}
>  \label{fig.syslineqns:vectorasarrow}
> \end{figure}
> 
> produces this error
> 
> [5]
> ! Argument of \@caption has an extra }.
> <inserted text> 
>                \par 
> l.177 ...ith the point $(3,4)$ in the $xy$ plane.}

Within a caption the use of commands and environments is restricted.  Commands must be "protected".  A possible solution is as follows:  Define, for instance,

\newcommand\mymatrix{ \left[ \begin{smallmatrix} 3 \\ 4 \end{smallmatrix} \right] }

in the preamble.  Then replace your caption by

 \caption{It is useful to picture vectors as arrows, although this may not be a literal representation of vectors.  Here we identify the vector $\vec{u} = \protect\mymatrix$ in $\R{2}$ represented as an arrow with the point $(3,4)$ in the $xy$ plane.}

This should work.  Important is to include the \protect command.  It prevents the immediate expansion of the subsequent \mymatrix command, the expansion is postponed until the caption is typeset.

Manfred






More information about the macostex-archives mailing list