Help on improving the Index dot fill

indexingmacrosspacingtex-core

I'm working on (re-)typesetting a classical French math book on algebraic number theory. The main part has been finished, but the appearance of the index is not very satisfying. The MWE below contains the directly copied content of the .ind file. To get the dots fill in light gray, I defined the following:

\newcommand*{\IndexDotfill}
  {
    \null\nobreak
    \leaders \hbox to .67em {\hss \textcolor{gray!55}{.} \hss} \hskip 1em plus1fill
  }

I found the original version on this site, for example as in this answer, and made some modifications. The \null\nobreak is my attempt to improve the situations described in this previous question, and \hskip 1em plus1fill comes from this answer as an attempt to make the page numbers appear on the same line (the result is not quite satisfying though, see the point 2 below).

There are several problems with my current version of \IndexDotfull:

  1. For long text, if there is an automatic line break, then the dots are not always vertically aligned (even if \leaders is used) ; below is an example appeared in the MWE:
    enter image description here
  2. The page numbers are not always placed on the right side, for example:
    enter image description here
  3. When the text takes up most of the space, sometimes the dots won't show up; same example as the previous point;
  4. The text is coming out of the page boundary, for example:
    enter image description here

In short, a desired behavior would be that all page numbers are shown on the right (push the page number to the next line if necessary), and to always have at least two dots before the page numbers (by breaking the text if necessary).

In order to achieve this, how should one modifying the \IndexDotfill?


Below is the MWE.

\documentclass[11pt]{article}
\usepackage[french]{babel}
\usepackage{hyperref}
\usepackage{xcolor}
\usepackage{amssymb}

\ExplSyntaxOn
\makeatletter

\newcommand*{\IndexHeading}[1]{\centerline{\textbf{#1}}}
\newcommand*{\IndexDotfill}
  {
    \null\nobreak
    \leaders \hbox to .67em {\hss \textcolor{gray!55}{.} \hss} \hskip 1em plus1fill
  }

\makeatother
\ExplSyntaxOff


\begin{document}

\begin{theindex}
\IndexHeading{A}

  \item abélienne (extension)\IndexDotfill \hyperpage{88}
  \item algébrique (élément algébrique sur un corps)\IndexDotfill 
        \hyperpage{21}
  \item algébrique (extension)\IndexDotfill \hyperpage{21}
  \item algébriquement clos (corps)\IndexDotfill \hyperpage{23}
  \item anneau
    \subitem de Dedekind\IndexDotfill \hyperpage{45}
    \subitem nœthérien\IndexDotfill \hyperpage{41}
    \subitem réduit\IndexDotfill \hyperpage{64}
  \item anneau de fractions\IndexDotfill \hyperpage{67}
  \item associés (éléments)\IndexDotfill \hyperpage{1}
  \item automorphisme de Frobenius\IndexDotfill \hyperpage{90}, 
        \hyperpage{93}

  \indexspace
\IndexHeading{B}

  \item base canonique\IndexDotfill \hyperpage{8}
  \item base d'un module\IndexDotfill \hyperpage{9}
  \item bases duales (pour la trace)\IndexDotfill \hyperpage{32}
  \item Bézout (identité de)\IndexDotfill \hyperpage{2}

  \indexspace
\IndexHeading{C}

  \item caractéristique (d'un corps)\IndexDotfill \hyperpage{13}
  \item caractéristique (polynôme)\IndexDotfill \hyperpage{27}
  \item classes d'idéaux\IndexDotfill \hyperpage{47}
  \item clôture intégrale\IndexDotfill \hyperpage{19}
  \item conjugués (corps)\IndexDotfill \hyperpage{23}
  \item conjugués (éléments)\IndexDotfill \hyperpage{23}
  \item conjugués (idéaux premiers)\IndexDotfill \hyperpage{91}
  \item corps cubique\IndexDotfill \hyperpage{34}
  \item corps cyclotomique\IndexDotfill \hyperpage{34}
  \item corps de nombres, ou corps de nombres algébriques\IndexDotfill 
        \hyperpage{21}
  \item corps parfait\IndexDotfill \hyperpage{24}
  \item corps quadratique\IndexDotfill \hyperpage{25}
    \subitem imaginaire\IndexDotfill \hyperpage{27}
    \subitem réel\IndexDotfill \hyperpage{27}
  \item cyclique (extension)\IndexDotfill \hyperpage{88}
  \item cyclotomique (corps)\IndexDotfill \hyperpage{34}
  \item cyclotomique (extension)\IndexDotfill \hyperpage{90}
  \item cyclotomique (polynôme)\IndexDotfill \hyperpage{34}

  \indexspace
\IndexHeading{D}

  \item décomposé (nombre premier)\IndexDotfill \hyperpage{76}
  \item décomposition (groupe de)\IndexDotfill \hyperpage{92}
  \item Dedekind (anneau de)\IndexDotfill \hyperpage{45}
  \item degré résiduel\IndexDotfill \hyperpage{70}
  \item dépendance intégrale (équation de)\IndexDotfill 
        \hyperpage{18}
  \item descente infinie\IndexDotfill \hyperpage{5}
  \item diophantienne (équation)\IndexDotfill \hyperpage{3}
  \item discriminant\IndexDotfill \hyperpage{30}
  \item discriminant (idéal)\IndexDotfill \hyperpage{31}, 
        \hyperpage{73}
  \item discriminant absolu (d'un corps de nombres)\IndexDotfill 
        \hyperpage{34}
  \item domaine fondamental\IndexDotfill \hyperpage{52}

  \indexspace
\IndexHeading{E}

  \item Eisenstein (critère d')\IndexDotfill \hyperpage{35}
  \item entier (anneau entier sur un autre)\IndexDotfill \hyperpage{19}
  \item entier (élément entier sur un anneau)\IndexDotfill 
        \hyperpage{18}
  \item entier (idéal)\IndexDotfill \hyperpage{44}
  \item entier d'un corps de nombres\IndexDotfill \hyperpage{34}
  \item entier de Gauss\IndexDotfill \hyperpage{80}
  \item équation de dépendance intégrale\IndexDotfill \hyperpage{18}
  \item équation de Fermat\IndexDotfill \hyperpage{3}
  \item équation de Pell-Fermat\IndexDotfill \hyperpage{62}
  \item équation diophantienne\IndexDotfill \hyperpage{3}
  \item étrangers (éléments)\IndexDotfill \hyperpage{3}
  \item Euler (critère d')\IndexDotfill \hyperpage{77}
  \item Euler (indicateur d')\IndexDotfill \hyperpage{6}
  \item extension
    \subitem abélienne\IndexDotfill \hyperpage{88}
    \subitem algébrique\IndexDotfill \hyperpage{21}
    \subitem cyclique\IndexDotfill \hyperpage{88}
    \subitem cyclotomique\IndexDotfill \hyperpage{90}
    \subitem galoisienne\IndexDotfill \hyperpage{88}
    \subitem quadratique\IndexDotfill \hyperpage{89}

  \indexspace
\IndexHeading{F}

  \item facteurs invariants\IndexDotfill \hyperpage{11}
  \item Fermat (équation de)\IndexDotfill \hyperpage{3}
  \item fermeture intégrale\IndexDotfill \hyperpage{19}
  \item fractionnaire (idéal)\IndexDotfill \hyperpage{44}
  \item fractions (anneau de)\IndexDotfill \hyperpage{67}
  \item Frobenius (automorphisme de)\IndexDotfill \hyperpage{90}, 
        \hyperpage{93}

  \indexspace
\IndexHeading{G}

  \item Galois (groupe de)\IndexDotfill \hyperpage{88}
  \item galoisienne (extension)\IndexDotfill \hyperpage{88}
  \item Gauss (entier de)\IndexDotfill \hyperpage{80}
  \item Gauss (somme de)\IndexDotfill \hyperpage{78}
  \item groupe d'inertie\IndexDotfill \hyperpage{92}
  \item groupe de décomposition\IndexDotfill \hyperpage{92}
  \item groupe de Galois\IndexDotfill \hyperpage{88}

  \indexspace
\IndexHeading{I}

  \item idéal
    \subitem maximal\IndexDotfill \hyperpage{43}
    \subitem premier\IndexDotfill \hyperpage{43}
  \item idéal discriminant\IndexDotfill \hyperpage{31}, \hyperpage{73}
  \item idéal entier\IndexDotfill \hyperpage{44}
  \item idéal fractionnaire\IndexDotfill \hyperpage{44}
  \item identité de Bézout\IndexDotfill \hyperpage{2}
  \item imaginaire (corps quadratique)\IndexDotfill \hyperpage{27}
  \item indicateur d'Euler\IndexDotfill \hyperpage{6}
  \item indice de ramification\IndexDotfill \hyperpage{70}
  \item inerte (nombre premier)\IndexDotfill \hyperpage{76}
  \item inertie (groupe d')\IndexDotfill \hyperpage{92}
  \item intégrale (fermeture, clôture)\IndexDotfill \hyperpage{19}
  \item intégralement clos (anneau)\IndexDotfill \hyperpage{20}

  \indexspace
\IndexHeading{L}

  \item Legendre (symbole de)\IndexDotfill \hyperpage{77}
  \item libre (module)\IndexDotfill \hyperpage{9}
  \item loi de réciprocité quadratique\IndexDotfill \hyperpage{78}

  \indexspace
\IndexHeading{M}

  \item maximal (idéal)\IndexDotfill \hyperpage{43}
  \item minimal (polynôme)\IndexDotfill \hyperpage{22}
  \item module
    \subitem de type fini\IndexDotfill \hyperpage{9}
    \subitem libre\IndexDotfill \hyperpage{9}
    \subitem nœthérien\IndexDotfill \hyperpage{41}
    \subitem sans torsion\IndexDotfill \hyperpage{12}
  \item monogène (extension)\IndexDotfill \hyperpage{24}

  \indexspace
\IndexHeading{N}

  \item nœthérien (anneau, module)\IndexDotfill \hyperpage{41}
  \item non-résidu\IndexDotfill \hyperpage{76}
  \item norme\IndexDotfill \hyperpage{28}
  \item norme d'un idéal\IndexDotfill \hyperpage{48}

  \indexspace
\IndexHeading{P}

  \item p.g.c.d.\IndexDotfill \hyperpage{2}
  \item p.p.c.m.\IndexDotfill \hyperpage{2}
  \item parfait (corps)\IndexDotfill \hyperpage{24}
  \item plongement canonique d'un corps de nombres\IndexDotfill 
        \hyperpage{54}
  \item polynôme caractéristique\IndexDotfill \hyperpage{28}
  \item polynôme minimal\IndexDotfill \hyperpage{22}
  \item premier (corps)\IndexDotfill \hyperpage{13}
  \item premier (idéal)\IndexDotfill \hyperpage{43}
  \item premiers entre eux\IndexDotfill \hyperpage{3}
  \item primitif (élément primitif d'une extension)\IndexDotfill 
        \hyperpage{25}
  \item primitive (racine primitive de l'unité)\IndexDotfill 
        \hyperpage{13}
  \item primitive (racine primitive modulo \( p \))\IndexDotfill 
        \hyperpage{14}
  \item principal (anneau)\IndexDotfill \hyperpage{2}
  \item principal (idéal)\IndexDotfill \hyperpage{1}
  \item produit d'idéaux\IndexDotfill \hyperpage{43}

  \indexspace
\IndexHeading{Q}

  \item quadratique (corps)\IndexDotfill \hyperpage{25}
  \item quadratique (extension)\IndexDotfill \hyperpage{89}
  \item quasi-algébriquement clos (corps)\IndexDotfill \hyperpage{14}
  \item quaternions\IndexDotfill \hyperpage{82}
  \item quaternions d'Hurwitz\IndexDotfill \hyperpage{83}

  \indexspace
\IndexHeading{R}

  \item racine primitive de l'unité\IndexDotfill \hyperpage{13}
  \item racine primitive modulo \( p \)\IndexDotfill \hyperpage{14}
  \item ramification (indice de)\IndexDotfill \hyperpage{70}
  \item ramifie (nombre premier)\IndexDotfill \hyperpage{76}
  \item ramifie (se ramifie)\IndexDotfill \hyperpage{72}
  \item rang (d'un module)\IndexDotfill \hyperpage{10}
  \item réduit (anneau)\IndexDotfill \hyperpage{64}
  \item réel (corps quadratique)\IndexDotfill \hyperpage{27}
  \item représente zéro\IndexDotfill \hyperpage{16}
  \item réseau (dans \( \mathbb{R}^n \))\IndexDotfill \hyperpage{52}
  \item résidu quadratique\IndexDotfill \hyperpage{76}
  \item résiduel (degré)\IndexDotfill \hyperpage{70}

  \indexspace
\IndexHeading{S}

  \item sans facteurs carrés (entier)\IndexDotfill \hyperpage{26}
  \item somme de Gauss\IndexDotfill \hyperpage{78}
  \item symbole de Legendre\IndexDotfill \hyperpage{77}

  \indexspace
\IndexHeading{T}

  \item torsion (module sans)\IndexDotfill \hyperpage{12}
  \item trace\IndexDotfill \hyperpage{28}
  \item transcendant (élément transcendant sur un corps)\IndexDotfill 
        \hyperpage{21}
  \item type fini (module de)\IndexDotfill \hyperpage{9}

  \indexspace
\IndexHeading{U}

  \item unités (d'un anneau)\IndexDotfill \hyperpage{1}
  \item unités (d'un corps de nombres)\IndexDotfill \hyperpage{58}
  \item unités fondamentales\IndexDotfill \hyperpage{60}, 
        \hyperpage{62}

  \indexspace
\IndexHeading{V}

  \item volume d'un réseau\IndexDotfill \hyperpage{53}

\end{theindex}
    
\end{document}

Best Answer

Here is a solution without manual intervention: Rather than break lines between two page numbers, as in

Frobenius (automorphisme de) . 90, 
           93

I would prefer to break lines between dots, as in

Frobenius (automorphisme de) . .
 . . . . . . . . . . . . .  90, 93

To this end, you must insert a line-breaking opportunity into \IndexDotfill, for example

\leaders \hbox to .67em {\hss \textcolor{gray!55}{.} \hss}\hfil
\penalty0\vadjust{}
\leaders \hbox to .67em {\hss \textcolor{gray!55}{.} \hss}\hskip1em plus1fill

The left indentation is already controlled by the \item and \subitem commands. To control right indentation (so that the page numbers end flush with the right margin, but the dots 1pc before, say), you can use

\rightskip=1pc \parfillskip=-\rightskip

Finally, the dots in the hanging lines do not line up, because the amount of hanging indentation (40pt) is not a multiple of the "dot width" .67em. You get better results with a "dot width" of 10pt:

enter image description here

Related Question