# What the first argument for \l@subsection actually is?

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?

## 2 Answers

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}


• Thank you for the answer, then I think that I can use \patchcmd to make a point after \numberline{...}. But is it possible to obtain somehow such number within \numberline parameter from <title>? In other words, can I split <title> into number (under assumption that it always starts with \numberline) and the other text? – Appliqué Apr 23 '13 at 13:52
• @Nimza I would suggest you to use the tocloft package to make the change. – Gonzalo Medina Apr 23 '13 at 13:54
• @Nimza I added such an example to my answer. – Gonzalo Medina Apr 23 '13 at 14:07
• Great thanks for this answer! I like this tocloft! Do you know if tocloft is compatible with titlesec? I.e can I define my own titleclass (instead of section, subsection, e.t.c.) with titlesec and customise its toc entries with tocloft? – Appliqué Apr 23 '13 at 14:42
• @Nimza yes, it can be done; you define your new sectional units using titlesec and then you can use \newlistentry (from titletoc) to make titletoc aware of the new sectional units; this wll allow you to use the whole family of \cft... commands for the new units. The only precaution is not to duplicate the definition of counters (each call to \newlistentry creates an associated counter). – Gonzalo Medina Apr 23 '13 at 15:30

To get the result you are asking for you can redefine \numberline locally in a group around the subsection line. You will also need to increase the space for the label. Doing it this way, you can also move the \S command into the \numberline command:

\documentclass{article}

\makeatletter
\def\dottednumberline#1{\hb@xt@\@tempdima{\S#1.\hfil}}
\renewcommand{\l@subsection}[2]{{\let\numberline\dottednumberline\@dottedtocline{2}{1.6em}{2.6em}{#1}{#2}}}
\makeatother

\begin{document}
\tableofcontents

\section{Test section}

\subsection{Test subsection}

\section{Another section}

\subsection{Another subsection}
\end{document}


This works since in the .toc we have

\contentsline {subsection}{\numberline {1.1}Test subsection}{1}


and \l@subsection will be applied to the second and third arguments, i.e.

#1 = \numberline {1.1}Test subsection
#2 = 1


the latter being the page number. You can see these arguments directly by adding \tracingmacros=1 to your document and examining the .log file.