0

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}

3 Answers 3

1

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

4
  • Thank you for this! Though I haven't tested it in my actual document, this seems to be exactly what I'm looking for when I posted this question. I've already chose to use a manual intervention method because 1) I don't know if a method like yours exists yesterday and 2) it seems a little bit strange as the dots on the second line seems to come out from nowhere. I will try it soon to see its behavior in my actual document :)
    – Jinwen
    Sep 3, 2022 at 14:12
  • The dots on the second line of "automorphisme de Frobenius" have the same hanging indentation as the "un corps)" line. This hanging indentation is set by the \item command. Sep 3, 2022 at 14:23
  • After comparing the automatic version and the manual intervention version, I still think that the manual version looks better for the actual document. However I shall mark your answer as accepted since this is by far the best automatic result I've seen these days. Thanks again for this wonderful solution :)
    – Jinwen
    Sep 3, 2022 at 14:33
  • If you set \rightskip=1pc plus1fil in my solution, you get line breaks like in your answer, albeit without the \raisebox{.25ex}{.}\raisebox{.05ex}{.}. Sep 4, 2022 at 10:36
2

Your dot-fill is not wrong. The problem is the index entries (\item) are not set up for decent automatic line breaking. If you check your log, you will see warnings about overfull boxes on all those lines with badly aligned page numbers. There is probably a package providing better index formatting. (Maybe try the index package; I dunno.)

For a direct patch to your document, manually insert \\ line breaks in any entries that cause overfull lines.

For a more automatic fix insert

\setlength{\rightskip}{0pt plus 100pt}

right after \begin{theindex}.

Also, prevent line breaks within the page number lists by using

\IndexDotfill \hyperpage{90},~\hyperpage{93}
3
  • Thank you for the suggestions. Two minor problems: 1) Inserting manual line break by \\ works finely in the MWE, but for unknown reason, in my real document I need \item\hspace*{\hangindent}\unskip to get the hang indent and vertically aligned dots; 2) In my workflow, the .ind file is regenerated at each compilation so I cannot actually manually change the content of it; copy the content directly into the document at the final turn would work though, but then each time the index entry is changes one has to do it again -- almost lose the automatic feature of makeindex.
    – Jinwen
    Sep 3, 2022 at 7:08
  • Is there any way you can insert the \rightskip setting into the index, or even add it to the "theindex" environment definition? Sep 3, 2022 at 9:39
  • That would not be very hard, I can add the corresponding code via environment hooks, for example. But may I ask what is this \rightskip for? (It seems to me to be a trick for fixing the out-of-margin issue, but this only happens in the MWE but not in my real document.)
    – Jinwen
    Sep 3, 2022 at 12:36
1

Following Donald Arseneau's suggestion on manual intervention, I've in particular defined the following command, which adds a manual line break inside the index entry text while keeping the dots vertical aligned (I've used \item\hspace*{\hangindent} to make sure that the dots are vertically aligned and that the \hangindent is correct, if you have them all properly configured then probably an usual line break also works here):

\newcommand*{\IndexLinebreak}
  {
    \nobreakspace\textcolor{gray}{\raisebox{.25ex}{.}\raisebox{.05ex}{.}}
    \item\hspace*{\hangindent}
    \textcolor{gray}{\raisebox{.35ex}{.}\raisebox{.15ex}{.}}\,
    \unskip
  }

It adds in addition a two-dot symbol at the end of the previous line and at the beginning of the next line, for example as the following picture shows:

enter image description here

That makes it even clearer to distinguish between sub-entry and line break: one can now tell at once that this is a usual line break, not a sub entry (without using it, though the indentation and the hang indent is not the same and can be used to distinguish them, for readers seeing the index the first time or readers not familiar with typographic rules it can still be a little bit confusing). Since this is not a standard symbol/tradition, I'm also willing to know if you have better suggestions on this.

The only problem is that the \IndexLinebreak needs to be manually added to the corresponding index entries like \index{first line\IndexLinebreak second line}. Also, since the proper breaking point is related to the page geometry, if you wish to compile your document into different page sizes, then you really need to separately work on each case. Thus this command should only be used in the final stage, when you have get the page geometry and the index text all settled and have makeindex already ran, then place \IndexLinebreak at every place in the \indexes that needs to have a line break (which should be clear from the draft version of your index -- the one without any manual intervention).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .