Here is a general kernel question. I am wondering why the leader dots are typeset in math mode.

While experimenting with my own sectioning commands, I had alignment issues with the dots. Does it have something to do with alignment?

\leaders\hbox{$\m@th \mkern \@dotsep mu\hbox{.}\mkern \@dotsep mu$}\hfill


Anyway, I tried it like

\leaders\hbox{
\kern .8em\hbox{.}\kern .8em}\hfill


and it seems pretty decent.

From the kernel latex.ltx:

\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
{#4}\nobreak
\leaders\hbox{$\m@th \mkern \@dotsep mu\hbox{.}\mkern \@dotsep mu$}\hfill
\nobreak
\hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor #5}%
\par}%
\fi}


Note that tocloft keeps this

\providecommand{\cftdotfill}[1]{%
\def\@tempa{#1}%
\def\@tempb{\cftnodots}%
\ifx\@tempa\@tempb
\hfill
\else
\leaders\hbox{$\m@th\mkern #1 mu\hbox{\cftdot}\mkern #1 mu$}\hfill
\fi
}

• The leader dots are not really typeset in math mode, since the \hbox escapes it to text mode (in the current font). – Werner May 8 '18 at 22:03
• Read p 371 of source2e.pdf. – Werner May 8 '18 at 22:04

This goes back to plain TeX and \dotfill which is defined as

\def\dotfill{\cleaders\hbox{$\m@th \mkern1.5mu.\mkern1.5mu$}\hfill}


LaTeX2.09 used the same definition, as did the first couple of releases of 2e. Then:

% \changes{v1.1u}{1996/10/28}{Removed math mode}


The current 2e definition is

\def\dotfill{%
\leavevmode

In LaTeX \@dottedtocline is a kind of extended \dotfill the 2.09 defintion used math mode as in the original \dotfill. In 2e though here we removed the math setting of the actual . but left the muskip spacing, probably so that the existing \@dotsep parameter still worked.
%  \item[|\@dotsep|] Separation between dots, in mu units.

The removal of math mode . was even earlier than in \dotfill:
% \changes{v1.0k}{1995/04/25}{Added \cs{hbox} around dots.}