[Tex/LaTex] Error: Illegal parameter number in definition of \reserved@a

captionserrorstables

When I am using \caption{$\E_\A(D)$ where $\ora{UF}\!_n$} inside a table environment there shows some errors.

Error :

Only one # is allowed per tab. ...crcr }}}_n$\relax }}{95}{table.caption.41}

Error :

Illegal parameter number in definition of \reserved@a. \caption{$\E_\A(D)$ where $\ora{UF}\!_n$}

Here \E stands for \mathscr{E}, \A stands for \text{\k{A}}, \ora for \overrightarrow.

Please help resolving this problem.

Best Answer

\overrightarrow is not robust and breaks in moving arguments. Protect it with \protect:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{caption}
\usepackage[mathscr]{euscript}
\usepackage[T1]{fontenc}
\usepackage{hyperref}
\newcommand*{\A}{\text{\k{A}}}
\newcommand*{\E}{\mathscr{E}}
\newcommand*{\ora}{\overrightarrow}
\begin{document}
\listoffigures
\begin{figure}
\caption{$\E_\A(D)$ where $\protect\ora{UF}\!_n$}
\end{figure}
\end{document}

Result

Alternative:

\DeclareRobustCommand*{\ora}{\overrightarrow}

Then \ora is robust and \protect is not needed.