3
\documentclass{article}
\usepackage{index}
\makeindex
\begin{document}
\begin{figure}
  \centering
  \fbox{Diagram placeholder}
  \caption{\index{quote (\verb|""|)}ok}
\end{figure}
\printindex
\end{document}

LaTeX said ERROR: Argument of \@caption has an extra }. What is wrong?

3
  • From the makeindex manual: "Recall that special characters like \ may appear in the argument of an \index command only if that command is not itself contained in the argument of another command. This is most likely to be a problem when indexing items in a footnote. Even in this case, robust commands can be placed in the “@” part of an entry, as in \index{gnu@{\it gnu}}, and fragile commands can be used if protected with the \protect command." – jon Dec 6 '15 at 3:24
  • 1
    Do you need \verb here? That is, is this just an example? Because it would probably be easier to produce the marks in another way. (Why are there 2?) – cfr Dec 6 '15 at 3:46
  • It seems \verb and \index don't mix well, out of the box. I could just use "" for " in \index. – crocket Dec 6 '15 at 3:47
6

You definitely don't want \verb there:

\documentclass{article}
\usepackage{makeidx}

\makeindex

\begin{document}

Text\index{quote (\texttt{""})}

\begin{figure}
\centering

\fbox{Diagram placeholder}

\caption[ok]{\index{quote (\string\texttt{""})}ok}

\end{figure}

\printindex

\end{document}

Why \string? Because \index is not able to read verbatim its argument when it is in the argument to another command.

Note also that the “short caption” argument is needed, or the entry would be indexed also when the caption appears in the list of figures.

Why not \protect\verb? Because \verb can never go in the argument to another command.


Actually, \verb could work:

\documentclass{article}
\usepackage{makeidx}
\makeindex
\begin{document}

\index{quote (\verb+""+)}

\begin{figure}
\centering

\fbox{Diagram placeholder}

\caption{\index{quote (\string\verb+""+)}ok}

\end{figure}

\printindex

\end{document}

gives the same result, but it's wrong to begin with.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.