[Tex/LaTex] What the first argument for `\l@subsection` actually is

latex-basesectioning

Consider for example the code

  \makeatletter 
     \renewcommand{\l@subsection}[2]{\@dottedtocline{2}{1.6em}{1.6em}{\S#1}{#2}}
  \makeatother

It allows me to obtain in my table of contents records with paragraph (section) sign before the number of subsection. But I want also to have a point after the number of subsection without modification of \thesubsection command.

Looking at second and third arguments for \@dottedtocline I think that first argument for \l@subsection is actually something that behaves like encapsulated pair of number of subsection and of title of subsection (because we can control the distance between these two elements of argument #1 by third argument of \@dottedtocline).

My question is what actually the first argument to \l@subsection is and if it is possible to get from this argument the number of subsection and its title as separated values?

Best Answer

In the LaTeX kernel, \@dottedtocline is implemented with the following syntax:

\@dottedtocline{<level>}{<indent>}{<numwidth>}{<title>}{<page>}
  • <level> is an integer number that controls if the entry is typeset; if <level> is greater than \c@tocdepth (the internal form of the tocdepth counter), then no line will be produced.

  • <indent> is the total indentation from the left margin.

  • <numwidth> is the width of box for number if the <title> has a \numberline command.

  • <title> is the actual contents of entry.

  • <page> is the page number.

The second argument for \l@subsection corresponds to the page; the first argument, to the number (if any) and the text.

To get the desires result, one easy possibility would be to use the tocloft package which offers appropriate hooks:

\documentclass{article}
\usepackage{tocloft}

\renewcommand\cftsubsecaftersnum{.}
\renewcommand\cftsubsecpresnum{\S}

\begin{document}

\tableofcontents
\section{Test Section}
\subsection{Test Subsection}

\end{document}

enter image description here

Related Question