# LaTeX - How to write a mathematics symbol in caption

I'm trying to put a mathematics symbols in the caption of my figure with this:

\begin{figure}[!ht]
\centering
\includegraphics[scale=0.2]{vect_CM.png}
\caption{Vecteur $\overrightarrow{CM}$ à un moment donné}
\label{vect_CM}
\end{figure}


And LaTeX show an error:

Illegal parameter number in definition of \reserved@a.
\crcr
l.76 ...$\overrightarrow{CM}$ à un moment donné}


Do I have to use any package to do this?

## migrated from stackoverflow.comJun 27 '14 at 13:32

This question came from our site for professional and enthusiast programmers.

Figure captions are considered a "movable argument" as they could end up in the List of Figures (a Table of Contents of sorts). And, such things that move end up being written to file (the .aux, .toc, .lof, ...) for use later on. This writing requires care so that certain fragile commands don't expand prematurely. \protection helps here:
\documentclass{article}
\caption{Vecteur $\protect\overrightarrow{CM}$ à un moment donné}

• Surely there is an easier way? A \captionmath that avoids having to protect everything? – AbstractDissonance Nov 27 '18 at 13:24