# Page order in list of acronyms with roman numbering

I have a document with three parts and different numbering: small roman numbers, arabic numbers and capital roman numbers. When printing the list of acronyms, the page order of an entry is always small roman number, capital roman number, arabic number, although the capital-roman-numbered pages are the last ones. How can I fix this?

\glshyperlinkis not an option since I still want the page numbers to appear.

\documentclass{article}
\usepackage[acronym,shortcuts,toc,hyperfirst=true,numberedsection=nolabel]{glossaries}
\setacronymstyle{long-short}
\makeglossaries
\newacronym{ABC}{ABC}{a blue cherry}
\newacronym{DEF}{DEF}{dry eggplant fruit}
\newacronym{GHI}{GHI}{green humongous iceberg lettuce}
\newacronym{JKL}{JKL}{jelly kiwi lentils}
\begin{document}
\pagenumbering{roman}
Today, I ate not only \ac{ABC}, but also \acp{DEF}.
\clearpage
\pagenumbering{arabic}
\Ac{ABC} is sweeter than a \ac{DEF}. And I ate a bit of \ac{GHI}.
The only thing I did not eat were \ac{JKL}.
\clearpage
\pagenumbering{Roman}
~
\clearpage
\ac{JKL} are even worse than \acp{DEF}.
\clearpage
\printglossary[type=\acronymtype,title={List of Abbreviations}]
\end{document}


EDIT: As was pointed out, the question boils down to "how do I teach makeindex to behave differently, or is there an alternative for makeindex?" with answers for both cases.

• As far as I know, the page ordering is something that is done by makeindex which is underlying glossaries – user31729 Mar 29 '16 at 19:00
• I think, you need something like page_precedence = "rnRAa" in a makeindex style file – user31729 Mar 29 '16 at 19:10
• thanks for the hint, apparently, adding the option xindy to it solves the problem. I didn't know thatmakeindexwas also responsible for the page numbers – riddleculous Mar 29 '16 at 19:10
• I don't know about makeindex style files. But xindy apparently does the job for me – riddleculous Mar 29 '16 at 19:15

If makeindex is used and not xindy, there's a little bit more to do.

makeindex uses .ist (index style files) in which the precise setup for glossaries is written by glossaries on-the-fly, unless an explicit different file is given.

Here is the file that is generated for the jobname glossariespageorder.tex:

% makeindex style file created by the glossaries package
% for document 'glossariespageorder' on 2016-3-29
actual '?'
encap '|'
level '!'
quote '"'
keyword "\\glossaryentry"
postamble "\%\n\\end{theglossary}\\glossarypostamble\n"
group_skip "\\glsgroupskip\n"
item_0 "\%\n"
item_1 "\%\n"
item_2 "\%\n"
item_01 "\%\n"
item_x1 "\\relax \\glsresetentrylist\n"
item_12 "\%\n"
item_x2 "\\relax \\glsresetentrylist\n"
delim_0 "\{\\glossaryentrynumbers\{\\relax "
delim_1 "\{\\glossaryentrynumbers\{\\relax "
delim_2 "\{\\glossaryentrynumbers\{\\relax "
delim_t "\}\}"
delim_n "\\delimN "
delim_r "\\delimR "
page_compositor "."
suffix_2p ""
suffix_3p ""


The crucial point for this issue about the page order is the page_precedence key which is by default "rRnaA", not "rnR" as requested by the O.P.

As far as I know there's no easy way to use glossaries to write user-defined settings into this \jobname.ist file.

Here's a hack that sets the page_precedence to "rnRAa", i.e. lower case Roman numbers, arabic numbers, upper case Roman numbers, uppercase letters and lower case lettersby writing into the\glswrite file.

Improved version

\documentclass{article}
\usepackage{xpatch}

\usepackage[nomain,acronym,shortcuts,toc,hyperfirst=true,numberedsection=nolabel]{glossaries}

\newcommand{\glspageprecedence}{rnRaA}

\newcommand{\glswritehookextra}{%
\write\glswrite{page_precedence \string"\glspageprecedence\string"}
}

\xpatchcmd{\writeist}{%
\fi
\closeout\glswrite
\let\writeist\relax
}{%
\fi
\glswritehookextra
\closeout\glswrite
\let\writeist\relax
}{}{\typeout{Error: patching \string\writeist failed}}

\setacronymstyle{long-short}
\makeglossaries
\newacronym{ABC}{ABC}{a blue cherry}
\newacronym{DEF}{DEF}{dry eggplant fruit}
\newacronym{GHI}{GHI}{green humongous iceberg lettuce}
\newacronym{JKL}{JKL}{jelly kiwi lentils}
\begin{document}
\pagenumbering{roman}
Today, I ate not only \ac{ABC}, but also \acp{DEF}.
\clearpage
\pagenumbering{arabic}
\Ac{ABC} is sweeter than a \ac{DEF}. And I ate a bit of \ac{GHI}.
The only thing I did not eat were \ac{JKL}.
\clearpage
\pagenumbering{Roman}
~
\clearpage
\ac{JKL} are even worse than \acp{DEF}.
\clearpage
\printglossary[type=\acronymtype,title={List of Abbreviations}]
\end{document}

• I like that here I can play around with the precedence (should be possible with xindy, too). As noted in the comment to my answer, the best would be to automatically detect the order that was actually used in the document but that is not really necessary as this can be done by hand normally. – riddleculous Mar 29 '16 at 21:23
• @riddleculous: well, this is difficult to track actually, in my point of view. – user31729 Mar 30 '16 at 2:38
• @riddleculous: I see another problem with your request: What if you have a very strange partition in, say, 8 parts, each one has a different page numbering style, e.g. arabic, roman, Alpha, Roman, Greek, lower case greek, alpha, Klingon letters, or mixing styles, occuring again ;-) How should this be tracked? – user31729 Mar 30 '16 at 22:33
• please don't understand it as a request, it would be nice but I have actually no particular use for that myself. It all depends how the text is scanned for the acronyms. If you just go from top to bottom and note down the appearances, then you should get something like "i, ii, 5, 39, III, XIV, H, f" for a certain acronym and nobody should have to care about which pagenumber style has been used when – riddleculous Mar 30 '16 at 22:38

Changing from the default makeindexto xindy solves the problem: add the package option xindy:

\documentclass{article}
\usepackage[xindy,acronym,shortcuts,toc,hyperfirst=true,numberedsection=nolabel]{glossaries}
\setacronymstyle{long-short}
\makeglossaries
\newacronym{ABC}{ABC}{a blue cherry}
\newacronym{DEF}{DEF}{dry eggplant fruit}
\newacronym{GHI}{GHI}{green humongous iceberg lettuce}
\newacronym{JKL}{JKL}{jelly kiwi lentils}
\begin{document}
\pagenumbering{roman}
Today, I ate not only \ac{ABC}, but also \acp{DEF}.
\clearpage
\pagenumbering{arabic}
\Ac{ABC} is sweeter than a \ac{DEF}. And I ate a bit of \ac{GHI}.
The only thing I did not eat were \ac{JKL}.
\clearpage
\pagenumbering{Roman}
~
\clearpage
\ac{JKL} are even worse than \acp{DEF}.
\clearpage
\printglossary[type=\acronymtype,title={List of Abbreviations}]
\end{document}


• the problem with this solution is that it will still use roman, arabic, Roman as an order, even if first the page numbering is changed to arabic first, then Roman and finally roman. I don't need this but if anyone knows how to recognize the page numbering order and adjusting xindy automatically, it might be interesting for someone in the future. – riddleculous Mar 29 '16 at 21:12

As from glossaries v4.24 (2016-05-27), you can use

\GlsSetWriteIstHook{\write\glswrite{page_precedence "rnR"}}


before \makeglossaries:

\documentclass{article}
\usepackage[acronym,shortcuts,toc,hyperfirst=true,numberedsection=nolabel]{glossaries}
\setacronymstyle{long-short}

\GlsSetWriteIstHook{\write\glswrite{page_precedence "rnR"}}

\makeglossaries

\newacronym{ABC}{ABC}{a blue cherry}
\newacronym{DEF}{DEF}{dry eggplant fruit}
\newacronym{GHI}{GHI}{green humongous iceberg lettuce}
\newacronym{JKL}{JKL}{jelly kiwi lentils}
\begin{document}
\pagenumbering{roman}
Today, I ate not only \ac{ABC}, but also \acp{DEF}.
\clearpage
\pagenumbering{arabic}
\Ac{ABC} is sweeter than a \ac{DEF}. And I ate a bit of \ac{GHI}.
The only thing I did not eat were \ac{JKL}.
\clearpage
\pagenumbering{Roman}
~
\clearpage
\ac{JKL} are even worse than \acp{DEF}.
\clearpage
\printglossary[type=\acronymtype,title={List of Abbreviations}]
\end{document}


However, this requires you to know the page ordering in your document. If you want to work it out on the fly, it's possible to adjust the behaviour of \pagenumbering and build a list of the ordering. Since the ist file is generated by \makeglossaries, which is a preamble-only command, the information either has to be saved in an external file and read in on the next run or the creation of the ist file needs to be deferred until the end of the document.

Here's an example of the first approach, which creates a temporary file with the extension .tmp. (The .aux file can't be used in this case, as it's not read until the start of the document.)

% arara: pdflatex
% arara: pdflatex
% arara: makeglossaries
% arara: pdflatex
\documentclass{article}

\usepackage{etoolbox}

\usepackage[acronym,shortcuts,toc,hyperfirst=true,numberedsection=nolabel]{glossaries}
\setacronymstyle{long-short}

\def\pageordering{rnaRA}% makeindex's default

\InputIfFileExists{\jobname.tmp}
{%
\GlsSetWriteIstHook{\write\glswrite{page_precedence "\pageordering"}}
}
{%
}

\def\thispageordering{}%

\newwrite\tmpfile
\openout\tmpfile=\jobname.tmp

\AtEndDocument{%
\immediate\write\tmpfile{\string\def\string\pageordering{\thispageordering}}
\closeout\tmpfile
}

\let\orgpagenumbering\pagenumbering
\renewcommand{\pagenumbering}[1]{%
\orgpagenumbering{#1}%
\ifstrequal{#1}{arabic}%
{%
\appto\thispageordering{n}%
}%
{%
}%
}

\appto\thispageordering{#1}%
}

\makeglossaries

\newacronym{ABC}{ABC}{a blue cherry}
\newacronym{DEF}{DEF}{dry eggplant fruit}
\newacronym{GHI}{GHI}{green humongous iceberg lettuce}
\newacronym{JKL}{JKL}{jelly kiwi lentils}
\begin{document}
\pagenumbering{roman}
Today, I ate not only \ac{ABC}, but also \acp{DEF}.
\clearpage
\pagenumbering{arabic}
\Ac{ABC} is sweeter than a \ac{DEF}. And I ate a bit of \ac{GHI}.
The only thing I did not eat were \ac{JKL}.
\clearpage
\pagenumbering{Roman}
~
\clearpage
\ac{JKL} are even worse than \acp{DEF}.
\clearpage
\printglossary[type=\acronymtype,title={List of Abbreviations}]
\end{document}


This requires two LaTeX runs before makeindex can be run.

Now for the second approach. To do this, first prevent \makeglossaries from writing the ist file using \noist. Since \writeist and \GlsSetWriteIstHook are preamble only commands, their original definitions need to be saved before they're disabled.

% arara: pdflatex
% arara: makeglossaries
% arara: pdflatex
\documentclass{article}

\usepackage{etoolbox}

\usepackage[acronym,shortcuts,toc,hyperfirst=true,numberedsection=nolabel]{glossaries}
\setacronymstyle{long-short}

\newcommand\pageordering{}

\let\orgwriteist\writeist
\let\orgGlsSetWriteIstHook\GlsSetWriteIstHook
\noist

\AtEndDocument{%
\orgGlsSetWriteIstHook{\write\glswrite{page_precedence "\pageordering"}}
\orgwriteist
}

\let\orgpagenumbering\pagenumbering
\renewcommand{\pagenumbering}[1]{%
\orgpagenumbering{#1}%
\ifstrequal{#1}{arabic}%
{%
\appto\pageordering{n}%
}%
{%
}%
}

\appto\pageordering{#1}%
}

\makeglossaries

\newacronym{ABC}{ABC}{a blue cherry}
\newacronym{DEF}{DEF}{dry eggplant fruit}
\newacronym{GHI}{GHI}{green humongous iceberg lettuce}
\newacronym{JKL}{JKL}{jelly kiwi lentils}
\begin{document}
\pagenumbering{roman}
Today, I ate not only \ac{ABC}, but also \acp{DEF}.
\clearpage
\pagenumbering{arabic}
\Ac{ABC} is sweeter than a \ac{DEF}. And I ate a bit of \ac{GHI}.
The only thing I did not eat were \ac{JKL}.
\clearpage
\pagenumbering{Roman}
~
\clearpage
\ac{JKL} are even worse than \acp{DEF}.
\clearpage
\printglossary[type=\acronymtype,title={List of Abbreviations}]
\end{document}
`