TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In a dictionary, I have the first page of each section — corresponding to a different letter of the alphabet — marked to appear in the table of contents, using the titletoc package:


etc. This works just fine.

However, this is a dictionary of a language with a non-Roman script, and when I try to include a graphic of the letters immediately after the Roman letters in the TOC:

\addcontentsline{toc}{section}{A \includegraphics{graphic_a.png}}
\addcontentsline{toc}{section}{B \includegraphics{graphic_b.png}}

I get an error:

.tex:3412: TeX capacity exceeded, sorry [input stack size=5000].
\reserved@a ->\def \reserved@a 
                               *{\@vspacer }\reserved@a 
l.3412 ...tion}{A \includegraphics{graphic_a.png}}

The instruction \includegraphics{graphic_a.png} etc. works without problems in other contexts, but apparently it won't work in the text field of \addcontentsline{toc}{type}{text}. Perhaps only actual alphabet text is permitted there. Section 7.6. "Inserting a figure in the contents" of the Bezos documentation for titlesec and titletoc describes a way to insert a figure before a TOC line using \addtocontents with \protect, but I haven't been able to adapt that information to what I am doing.

Is there another way to accomplish my goal?

share|improve this question

closed as too localized by lockstep, Marco Daniel, Paulo Cereda, Joseph Wright Apr 16 '12 at 14:46

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

You should try adding \protect before \includegraphics. Elements being pushed into the ToC require this kind of handling. – Werner Feb 16 '12 at 19:02
@Werner: Same error. I've also tried the documentation's suggestion of segregating \includegraphics in a separate newcommand; same error. – brannerchinese Feb 16 '12 at 19:10
Would you be able to update your question to include a minimal example that duplicates your problem. Also include the versions of the packages your using (add \listfiles before \documentclass and extract the contents after **File List** in your .log). Why? Because a small MWE that loads titletoc doesn't cause any problems if I use \protect\includegraphics.... – Werner Feb 16 '12 at 19:14
@Werner: Thanks; it will take me a few days to make the time for this, but I am at work on it. Thanks for your patience and willingness to help. – brannerchinese Feb 16 '12 at 19:16
\protect should work, as @Werner says, note however you may need to remove your .toc file. If corrupted commands have been written to it earlier, it will be input at the start of the next job and generate errors even when the source file has been corrected. A new .toc should then be written and a table of contents should appear on the next run. – David Carlisle Mar 4 '12 at 1:14