# ToC style of glossary: dots between cross-refs and page ref

I use the glossaries package for acronyms and a notation list. I'd like a ToC style for my glossaries, meaning with trailing dots up to the left side of the page and the reference of the first use page there.

I use Xindy, and I use cross-references with the see key in the notation glossary. I'd like to keep an altlist-like style, something like:

(this is an image edit of current situation)

I had a look at the glossaries manual, in particular:

So, I began investigating the style. I looked at the source of the list styles and found out that what I want to change (references, cross-references, and what comes after: those 3 are actually one big something that is given as a 2nd argument toglossentry) is not in the style definition. Hence, I simply use the style I want: \setglossarystyle{altlist}.

From the see key documentation, I understood I needed to investigate the number lists. In the xindy-dedicated part of the package documentation, I got the idea of inverting the cross-refs with the "normal" refs, using:

\GlsSetXdyLocationClassOrder{%
"see"
"arabic-page-numbers"
"arabic-section-numbers"
"roman-page-numbers"
"Roman-page-numbers"
"alpha-page-numbers"
"Alpha-page-numbers"
"Appendix-page-numbers"
}


(In the default definition, everything is identical except that the "see" field is placed last.)

Then I needed to add dots between cross-references (XRefs) and normal references. I did not find a command to modify the format of the (actual) references list (normal references only thus), so instead of adding dots before the reference, I added them after the XRefs (which leads to the first problem) using:
\renewcommand*{\glsseeformat}[3][\seename]{\emph{#1} \glsseelist{#2}\dotfill}

First problem:
I have my dots, but only for entry with cross-references.
EDIT: solved. I looked at the generated files and noticed the page numbers were printed by the \glsXpageXglsnumberformat command; command that is defined at the beginning of those files. So I used \glossarypreamble (instead of \glossaryheader to not interfere with styles) as an entry point. A few points about the solution found:

• Reading @nicola-talbot's answer here, I use the \leaders command instead of \dotfill;
• To stop the dots on "one column" like in the ToC, I place the page number in a box of fixed width;
• However, the description wraps above the number instead of wrapping where the dots stop as in the ToC. I haven't figured that out yet.

So here is the current code:

\renewcommand*\glossarypreamble{
\renewcommand*\glsXpageXglsnumberformat[2]{%
\makebox[\widthof{0000}][r]{%
\setentrycounter[##1]{page}\glsnumberformat{##2}%
}%
}%
}


Second problem:
After the dots, Xindy style adds a comma as a delimiter between the different reference types used.

These two problems are shown on the second attached figure:

Third (optional) problem:
I'd like to automatically capitalize (the first word of) the string seename. I tried with \capitalisewords from package mfirstuc, but it doesn't expand and puts the whole word in caps. Any idea?

To solve the first, maybe I could add dots after the description using \renewcommand*{\glspostdescription}{\dotfill}, but I would have to distinguish cases without XRefs, needing that re-definition, from with XRefs cases, which must not have dots between description and cross-references.

The second is due to xindy style, so I need to change that. In the number list section I found this command in an example:

\GlsAddXdyLocation{romansc}{:sep "\string\textsc\glsopenbrace"
"roman-numbers-lowercase" :sep "\glsclosebrace"}


which got me thinking of redefining \glsclosebrace with: \renewcommand*{\glsclosebrace}{} but it prompts errors of the kind "File ended while scanning for use of \glsgroupheading".


1st problem, dots between cross-ref or description and page number:
First, inverting XRef and page number display:

\GlsSetXdyLocationClassOrder{%
"see"
"arabic-page-numbers"
"arabic-section-numbers"
"roman-page-numbers"
"Roman-page-numbers"
"alpha-page-numbers"
"Alpha-page-numbers"
"Appendix-page-numbers"
}


A bunch of lengths to parametrize the display:

\newlength{\stdlinewidth} \setlength{\stdlinewidth}{\linewidth} % width for the content, including page numbers
\newlength{\glsdottedpagerefwidth} % width allocated for the page numbers
\newlength{\glsdottedpagerefwidthoffset} % optional offset between descriptions and page numbers


\glsdottedpagerefwidth: this is the width allowed for the boxes of the page numbers. It should be set to the widest number there is plus a small space (check out the formatting of the ToC). Eg, if the document is 100+ pages, but less than 1000, it should at least be the width of 000.
\glsdottedpagerefwidthoffset: Useless for acronyms. Because descriptions can be long, I find a bloc of text aligned with the end of the dots and the beginning of the page number "column" not very pretty. This is the distance between the end of line for the descriptions and the page number "column". However, after much fiddling in plain tex, I haven't found a way to have the dots printed as one bloc that does not require to totally hack glossaries (eg, saving description in a box and printing it in page number command :/), hence the dots are obtained with different skips. Not good then.

Actually parametrizing:

\setlength{\glsdottedpagerefwidth}{\widthof{0000}}
\setlength{\glsdottedpagerefwidthoffset}{2em}


% puttings dots up to the end of line, before page number
\renewcommand*\glossarypreamble{
\renewcommand*\glsXpageXglsnumberformat[2]{%
\makebox[0pt][l]{%
\makebox[\glsdottedpagerefwidth+\glsdottedpagerefwidthoffset][l]{%
\makebox[\glsdottedpagerefwidth][r]{%
\setentrycounter[##1]{page}\glsnumberformat{##2}%
}%
}%
}%
}
}
% restoring linewidth: useless, but for a clear conscience.
\renewcommand*\glossarypostamble{\setlength{\linewidth}{\stdlinewidth}}


2nd problem, commas before the dots:
For entries without cross-refs, no problem: simply redefine \glspostdescription.
For entries with cross-refs, I found a dirty(ier) hack in this answer: redefining the command preceding the comma to gobble up one more argument and dismiss it. I also need to restore a dot after the description and before the reference, which I add after taking out any skip LaTeX might have added:

\renewcommand*{\glspostdescription}{}
\renewcommand*{\glsseeformat}[4][\seename]{% % 4th "arg" (undelimited one) is the comma
\unskip. \emph{#1} \glsseelist{#2}}


3rd problem, capitalise seename macro:
A simple redefinition as a total expansion macro does the trick. However, it seems the language is attributed by printglossary, so it has to be done in preambule:

\renewcommand*\glossarypreamble{
\let\oldseename\seename
\edef\seename{\capitalisewords{\oldseename}}
[ToC style stuff]
}


As there can be several glossaries, thus several call to glossarypreamble, we restore the original definition in postamble:

\renewcommand*\glossarypostamble{%
\setlength{\linewidth}{\stdlinewidth}%
\let\seename\oldseename%
}


conclusion
All of that is pretty hacky, so if anyone has some alternative solutions I'm very much up for it!
Results:

• voluntary setting the offset to 2em, eg far from a multiple of the 2.9 mm width of the dot boxes, we can notice the difference in skips:
• more reasonably set to 6mm, eg more or less twice the width of the dot boxes:
• example with acronyms, offset to 0 as there is no description:

(the shift between notations and acronym examples is because they are on odd and even pages, respectively)