# Why does leftidx not work in a figure caption?

I use the leftidx package to get left subscripts typeset acceptably, however, when I tried to use the \leftidx command within a figure caption (\caption) command I get errors compiling. Here is a MWE:

\documentclass[12pt,letterpaper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{leftidx}
\usepackage{mathrsfs}
\usepackage{bm}
\usepackage{graphicx}

\begin{document}

I want $\leftidx{^i}{c}{_{l,m}^{n}}$ in a caption.

\begin{figure}
\caption{$\leftidx{^i}{c}{_{l,m}^{n}}$}
%\caption{$2+2=4$}
\end{figure}

\end{document}


If you comment out the \caption line with \leftidx, and uncomment the line below it you'll see that it compiles fine, including the call to \leftidx that is outside of the caption. The error I get with \leftidx inside of the caption is:

! Incomplete \iffalse; all text was ignored after line 17.
<inserted text>
\fi
<*> MWE.tex

The file ended while I was skipping conditional text.
This kind of error happens when you say \if...' and forget
the matching \fi'. I've inserted a \fi'; this might work.

! Emergency stop.
<*> MWE.tex

*** (job aborted, no legal \end found)


You need to insert \protect immediately before \leftidx.
• Yes, it's a fragile command because it starts with \vphantom`. – egreg Jul 2 '13 at 15:52