Take the 2-minute tour ×
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.

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!

share|improve this question
2  
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 at 15:29
1  
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 at 15:33

1 Answer 1

up vote 10 down vote accepted

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

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 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 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 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 at 7:18
4  
@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 at 9:47

Your Answer

 
discard

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.