TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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

Below is part of my code.

\usepackage[top=2cm, bottom=2cm, outer=1cm, inner=2.1cm,twoside, headsep=16pt]{geometry}
\usepackage{keyval}% http://ctan.org/pkg/keyval

\usepackage{etoolbox,graphicx}% http://ctan.org/pkg/{etoolbox,graphicx}
\newcommand{\addstufftotoc}[2][toc]{% \addimagetotoc[<toc>]{<stuff>}
\patchcmd{\l@section}% <cmd>
{\begingroup}% <search>
{\begingroup\normalfont\Large\bfseries}% <replace>
{}{}% <success><failure>

{ test {\ifnumcomp{\value{colnum}}{<}{#1}} }%
\noalign{\ifnum0=`}\fi\hrule \@height #1 %
\begin{mdframed}[roundcorner=0pt,leftmargin=0, rightmargin=0, linecolor=gray,outerlinewidth=.1, innerleftmargin=0, innerrightmargin=0, innertopmargin=0,innerbottommargin=0, everyline = true, splittopskip=.6cm, splitbottomskip=.3cm] 
\addstufftotoc{\nobreak\smallskip\protect\includegraphics[trim=0.6cm 4.5cm 0cm 1cm, clip=true,width=1.0\linewidth]{./tmp/AAA.pdf}\par} 


I got this error message.

Underfull \hbox (badness 10000) in paragraph at lines 295--307

Underfull \vbox (badness 10000) detected at line 323
! TeX capacity exceeded, sorry [input stack size=30000].
\par ->\@restorepar 
                \everypar {}\par \@endpefalse 
l.329 ..../tmp/image.pdf}\par}

!  ==> Fatal error occurred, no output PDF file produced!

I found many replies for the similar question but none of the answer solve my pblm.

share|improve this question
You have posted 37 questions so you should know that providing a minimal working example (MWE) increases your changes of getting an answer. – Marc van Dongen Mar 26 '13 at 6:58
Yes, I know but pblm is with my large chunk of code. I could not figure out why this pblm is. I attempted to copy a part of it but that works fine. – manish Mar 26 '13 at 7:06
@user15662 Although everyone faces the same kind problems while creating MWE and debugging LaTeX code. Building Up and Hacking Down are two valid approaches. – texenthusiast Mar 26 '13 at 7:38
@user15662 you need to take the posted code and remove all packages that are not needed. That is if you can make the error without that package, remove it. – David Carlisle Mar 26 '13 at 10:00
@DavidCarlisle I couldn't give you more than +1. – Marc van Dongen Mar 26 '13 at 10:45
up vote 6 down vote accepted

The table of contents is typeset as a list, where \par has not its primitive meaning.

Change the definition of \addstufftotoc into

\newcommand{\addstufftotoc}[2][toc]{% \addimagetotoc[<toc>]{<stuff>}

and use it as

\addstufftotoc{\includegraphics[trim=0.6cm 4.5cm 0cm 1cm,

which saves you from the burden of adding fixed formatting instructions in \addstufftotoc.

share|improve this answer
Why do we need two \unexpanded here? – cjorssen Mar 26 '13 at 14:10
@cjorssen Because \addtocontents writes to the .aux file and then the entry is written to the .toc file at the end of the job, when the .aux file is closed and read in. – egreg Mar 26 '13 at 14:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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