[Tex/LaTex] Meaning of “\advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip”

macros

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

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

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!

Best Answer

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

\def\@dottedtocline#1#2#3#4#5{%

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

     \@afterindenttrue

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

     \interlinepenalty\@M

prevent page breaks between lines

     \leavevmode

start a paragraph

     \@tempdima #3 \relax

set this temporary register to #3

     \advance\leftskip \@tempdima

Increase the left skip by the value just stored

      \null

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

     {#4}

typeset or otherwise do whatever is in #4

     \nobreak

prevent a break at this point

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

make a row of dots

     \nobreak

prevent a break

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

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

     \par}%

end the paragraph and the group

  \fi}

end the if test