1

I am trying to add dots between the sections and the pages in my table of contents without using the package tocloft, since it moved my title from its original position. Right now it looks like this:

current toc

I have found that if I comment the following line from my .cls file, I get the desired output.

\let\@dottedtocline\@plaintocline

Here's what the desired ouytput looks like:

toc target

I would like to leave the .cls file untouched, as I understand it is best practice.

So how can I suppress the effect of that line from my .tex file, instead of modifying the class?

Here is the \@plaintocline command definition:

\def\@plaintocline#1#2#3#4#5{%
  \ifnum #1>\c@tocdepth \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 \@dotsep mu\hbox{}\mkern \@dotsep
        mu$}\hfill
     \nobreak
     \hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor #5}%
     \par}%
  \fi}
gpedrosa
  • 143
  • 2
    If you use \usepackage[titles]{tocloft} then your titles are spared. –  Oct 23 '15 at 15:10
  • You can use a \renewcommand{\@dottedtocline}{} with the correct number of arguments, being gobbled. Unless \edef is used, the \@dottedtocline is used when the outer macro is in action, not already on definition, so the redefined command comes into effect. –  Oct 23 '15 at 15:10
  • Thanks Harish Kumar for the tip, that worked! @Christian, what do you mean by using that line in my preamble too? I'd still love to see a solution which did not involved tocloft by allowing me just to supress the effect of that line (and not have to load another package) – gpedrosa Oct 23 '15 at 15:18
  • 1
    @gpedrosa: This depends on the class you are using. I don't know a class which has \@plaintocline so I don't know what you want to achieve! –  Oct 23 '15 at 15:19
  • Thanks for the input @Christian. I did not realize it was a custom defined command. I have just found its definition and will add to the question. Adding \renewcommand{\@dottedtocline}{} to the preamble gave me a "missing \begin{document}" error. Adding the same line after \begin{document} gave me an unformatted TOC with numbers (such as 11em 37em) all over – gpedrosa Oct 23 '15 at 15:43
  • @gpedrosa: That definition is exactly the usual \@dottedtocline being define in the LaTeX core file latex.ltx. So your class does actually use the traditional \@dottedtocline but you want to switch it off? I can't give some advise on \renewcommand{\@dottedtocline} because I don't know what you want to achieve! –  Oct 23 '15 at 15:48
  • Sorry @Christian I forgot to adress this part of your last comment. I hope it is clear by now with my latest edit – gpedrosa Oct 23 '15 at 15:58
  • (For reference, a minimal working example (MWE) would avoid this confusion in the future.) – Sean Allred Oct 23 '15 at 16:11
  • 2
    Add thi9s to your preamble: \usepackage{etoolbox} \makeatletter \patchcmd{\@plaintocline}{\hbox{}}{\hbox{.}}{}{} \let\@dottedtocline\@plaintocline \makeatother – Gonzalo Medina Oct 23 '15 at 16:15
  • 1
    @ChristianHupfer No; the definition of \@plaintocline is not the same as the kernel's \@dottedtocline; a dot is missing (see my comment above). – Gonzalo Medina Oct 23 '15 at 16:16
  • @GonzaloMedina: Ok, the dot is important –  Oct 23 '15 at 17:09
  • @gpedrosa: It would have been nice to provide this information right from the start and not one small piece after another one. Now the question is answered with something I could have told you right from the start if the question would have been clear! :-( –  Oct 23 '15 at 17:13
  • Sorry you found it unclear @ChristianHupfer! I will deffinetly try to make new questions if they arise more clear. I did try to keep it as minimum as possible, and I disagree to Johannes_B edit and change the title. This is not what I asked. In fact I already had added the dots to the toc (even in my rustic way). I just wanted to preserve the cls file and know if I could supress the line I provided from the clsfile from the tex. And I've learned I cannot simply supress it, I have to redefine the command (in this particular case). Thank you for your effort and help! – gpedrosa Oct 23 '15 at 17:30
  • You can rollback the edit to its original state if you want, but that title was a bit unclear to me. How about: Revert classfile changes without changing the class? – Johannes_B Oct 23 '15 at 19:02
  • @Johannes_B I do agree it was a bit unclear, otherwise you wouldn't have felt the need to change it. The title your proposed is a much more suitable imo (for what I had in mind and tried to express) – gpedrosa Oct 23 '15 at 19:09
  • Go ahead, change it ;-) Maybe substitute revert with undo? – Johannes_B Oct 23 '15 at 19:11
  • Thanks for the tips and feedback! Changed it with your suggestion – gpedrosa Oct 23 '15 at 19:20

1 Answers1

2

I guess just adding:

\makeatletter
\def\@dottedtocline#1#2#3#4#5{%
  \ifnum #1>\c@tocdepth \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 \@dotsep mu\hbox{.}\mkern \@dotsep
        mu$}\hfill
     \nobreak
     \hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor #5}%
     \par}%
  \fi}
\makeatother

to the preamble should work. This should redefine \@dottedtocline the way it was before the \let you mention, i.e. the lay the LaTeX core latex.ltx defines it. If you tell me what class you use, I might find an option that switches off that \let. Or maybe you can try reading the documentation for it…

Addenda

  1. As you said, the manual mentions no option to reverse the change, saying instead:

    A UFPEThesis não oferece nada em particular para a produção da bibliografia ou dos índices. Esse material deve ser criado da maneira usual discutida, por exemplo, em [1].

    Or:

    UFPEThesis offers nothing in particular for the production of the bibliography or of the indices. This material must be created in the usual manner discussed, for example, in [1].

  2. As you notice, the only difference between the two tocline commands is the \hbox{.}, which is \hbox{} in the \@plaintocline macro. That is precisely what makes the dots. Basically (but I might be oversimplifying or getting things plain wrong), \leaders takes its argument and repeats it enough times to fill a line, so if it has nothing it puts nothing (\@plain), if it has a dot it puts a dot (\@dotted). You can have fun changing the contents of that \hbox and seeing strange things like:

    1. Capitulo segundo * * * * * * * * * * * * * * * <pagenumber>

    or:

    1. Capitulo segundo foo foo foo foo foo foo foo foo foo <pagenumber>

    if you like :).

A few more details about the command:

  • First it checks if the number given as #1 is greater than \c@tocdepth, so if subsubsections are not supposed to be in the toc and you start one it won't create a line. If it is not greater, then it goes into the \else branch;
  • There, it finds instructions to add vertical space, precisely a stretchable space in order to have some margin of stretchability to be able to avoid collapsing a page into the top section when the page is broken;
  • Then it opens a group;
  • Then we have some bookkeeping, more precisely some parameter changes;
  • After that bookkeeping, which goes on till \null and includes \leavevmode to start a line, we have a \nobreak forbidding a linebreak (we are at the start of the line after all), then we have a negative horizontal space (I wonder why negative), then #4 is printed, which should be the chapter title or similar;
  • After another \nobreak, we have the \leaders command, which contains \m@th, which is a spacing command I don't really know too much about, then a math space \mkern, the \hbox, and another \mkern; so the contents of the \hbox will be repeated surrounded by space; naturally, removing \mkern will reduce (or eliminate if you remove both \mkerns) the spacing around the dots/whatever is in the \hbox;
  • The \hfill strikes me as out of place, but I probably do not know how \leaders works; anyway after this a break is forbidden, and a box of the width of a \@pnumwidth (a parameter containing a width suitable for page numbers, I should think) is created and placed there, which contains precisely the page number;
  • \par, so new line, then close the group, then close the \else branch and the whole conditional with the \fi, and we are done.
MickG
  • 5,426
  • Interesting! The only difference I spot is the . in \hbox{.}. The way I see is you can't just comment that line from the tex file, you have to redefine the whole command (in my case the desired output was the default, found in the latex.ltx). Btw it works and not additional packages have to be loaded, thanks! – gpedrosa Oct 23 '15 at 17:10
  • 1
    @gpedrosa perhaps your class provides an option to revert to the default. I cannot know for sure without knowing what class it is. – MickG Oct 23 '15 at 17:13
  • 1
    The class I'm using is not on CTAN it is called ufpe thesis and I believe the manual is not in english, but I assure I've read the manual and did not find an option to do so – gpedrosa Oct 23 '15 at 17:32
  • OK, if you say so, I trust you @gpedrosa :). Out of curiosity, what language is it in? – MickG Oct 23 '15 at 17:35
  • It is in portuguese :) – gpedrosa Oct 23 '15 at 17:36
  • 1
    Uh-huh, probably wouldn't have tried then. Eu não falo Portugues :). Though Italian could have helped there :). – MickG Oct 23 '15 at 20:51
  • I took a look and concordo com você: nothing on this fix in this manual. It is surprising how easy it was to understand that Portuguese thanks to Italian :). – MickG Oct 24 '15 at 11:45
  • Added a couple details to the answer @gpedrosa. – MickG Oct 24 '15 at 12:06
  • thank you for the follow up and in-depth explanation. Also the effort to decypher the portuguese manual! This alone deserved another upvote :P I guess the ease to understand some bits due to italian relies on the root of both languages since they both are romance languages – gpedrosa Oct 25 '15 at 17:06
  • 1
    Indeed @gpedrosa. But for some reason I expected it would help me less than it did :). You're welcome. – MickG Oct 25 '15 at 19:09