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

I am a novice of LaTeX, and I encounter the following code which I can't understand fully.

  \ifnum #1>\c@tocdepth tt\else
    \vskip \z@ \@plus.2\p@
    {\leftskip #2 \relax \rightskip \@tocrmarg \parfillskip -\rightskip
     \parindent #2 \relax\@afterindenttrue
     \@tempdima #3 \relax
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     \leaders\hbox{$\m@th\mkern 1.5mu\cdot\mkern 1.5mu$}\hfill
     \hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor #5}%

The first is

\leftskip #2 \relax \rightskip \@tocrmarg \parfillskip -\rightskip
     \parindent #2 \relax\@afterindenttrue

Could somebody explain it to me in detail?

The second

\advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip

What's the meaning of it, why using \hskip -\leftskip and what is the meaning of \advance\leftskip \@tempdima?

Thank you in advance!

share|improve this question
Your question is likely to get more attention if you tell us why it's important to you. Can you provide a complete small document showing where you hope to use it to do some particular thing? – Ethan Bolker Aug 21 '14 at 15:29
Explaining arbitrary low-level TeX isn't really that helpful in most cases: as @EthanBolker suggests, a more profitable route is likely to be to give some indication of what you are after. If you really just want to learn what is going on here that is fine but it might be useful then to give some idea of how much (La)TeX you know. – Joseph Wright Aug 21 '14 at 15:33
up vote 10 down vote accepted

The code presumably isn't intended to be read by a novice LaTeX user but...


a macro with 5 arguments

  \ifnum #1>\c@tocdepth tt\else

If #1 is deeper than the limit for the table of contents depth typeset tt (a typo??) Otherwise

    \vskip \z@ \@plus.2\p@

add a small vertical space between 0 and .2pt

    {\leftskip #2 \relax

set \leftskip (space before left edge of paragraph) to #2

            \rightskip \@tocrmarg

set \rightskip to \@tocrmarg

           \parfillskip -\rightskip

set \parfillskip (extra space at end of paragraph) to -\rightskip so it cancels out the \rightskip, ensuring the paragraph ends flush with the right margin.

     \parindent #2 \relax

set paragraph indent to #2


set this boolean flag to true, to control indentation of first paragraph after the heading.


prevent page breaks between lines


start a paragraph

     \@tempdima #3 \relax

set this temporary register to #3

     \advance\leftskip \@tempdima

Increase the left skip by the value just stored


add an empty box to the paragraph just started

       \nobreak\hskip -\leftskip

back up by the left skip so as to make the first line not be indented by \leftskip


typeset or otherwise do whatever is in #4


prevent a break at this point

     \leaders\hbox{$\m@th\mkern 1.5mu\cdot\mkern 1.5mu$}\hfill

make a row of dots


prevent a break

     \hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor #5}%

set #5 in a box of fixed width \@pnumwidth


end the paragraph and the group


end the if test

share|improve this answer
you might mention which documentation (pdf output from dtx file) can be found. i haven't looked, but suspect the documentation there, while essentially what you've said, might have other useful information, especially if this person wants to go exploring further. – barbara beeton Aug 21 '14 at 18:12
@barbarabeeton I have no idea where the code in the question came from (is not the definition of \@dottedtocline in the latex format) the standard definition is documented in source2e.pdf but not with line by line comments. – David Carlisle Aug 21 '14 at 18:59
Thank you so much Carlisle, you are always so helpful. This class file is a Thesis and the code I posted is the toc code. I am however, still have some confusion"\advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip" why advance before then minus it again? and How could I Post the whole file, thank you again! :) – poplar Aug 22 '14 at 7:03
The whole file could be download here ctex.org/PackagePostDocRep/… In fact, I still puzzled by the command \@afterindenttrue how does it work in this thesis. the second is \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip why you first \advance \leftskip \@tempdima then you back up it by \leftskip, I couldn't find its effect after I compiling it. Could you demo it by using an obvious example. Thank you. – poplar Aug 22 '14 at 7:18
@popular You can not learn a language (any language) by jumping in to the middle of a large existing document and asking what fragments mean, you need to back up and start with easy tutorials. the \advance changes the leftskip register which changes the left margin for all following text until the end of the group, the \hskip-\leftskip is adding one negative space of that amount at one place and not changing any registers. So the two bits of code are not really comparable. – David Carlisle Aug 22 '14 at 9:47

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.