# Distinct formatted page numbers with glossaries and Xindy

This is somewhat related to this question, but using Xindy as a backend, not makeindex.

I am attempting to create an index using glossaries, and in this index some page numbers have a special meaning. These are therefore typeset in italic. Unfortunately, when the same item is referenced both with its special meaning and as a regular item, in that order, the page number in the index is not italic. The following MWE illustrates the problem:

\documentclass{article}
\usepackage{hyperref}
\usepackage[xindy]{glossaries}

\newglossaryentry{test}{name={Test},description={\nopostdesc}}
\makeglossaries

\begin{document}
\printglossary[style=index]
\end{document}


The result of this MWE is

while I would like the page number to be either italic (i.e., the formatted page number always has priority) or displayed once for each formatting. Is this possible using Xindy as a backend?

I did try a method in which I defined a fake counter for the special entries, thinking that this would result in separate entries:

\documentclass{article}
\usepackage{hyperref}
\usepackage[xindy]{glossaries}

\newcounter{fakepage}
\newglossaryentry{test}{name={Test},description={\nopostdesc}}
\makeglossaries

\begin{document}
\setcounter{fakepage}{\thepage}
\printglossary[style=index]
\end{document}


Unfortunately, this resulted in wierd errors from Xindy and a result identical to that of the first MWE.

-

You'll need to manually change the ordering of the defined attributes. If you look in the .glo file for your MWE, you should see the location attributes are pageglsnumberformat (the default format) and pagehyperit (the format used when you combine format=hyperit and counter=page):

(indexentry :tkey (("Test" "\\glossaryentryfield{test}{\\glsnamefont{Test}}{\\nopostdesc }{\\relax }") ) :locref "{}{1}" :attr "pagehyperit" )
(indexentry :tkey (("Test" "\\glossaryentryfield{test}{\\glsnamefont{Test}}{\\nopostdesc }{\\relax }") ) :locref "{}{1}" :attr "pageglsnumberformat" )


The default .xdy file created by glossaries lists the pageglsnumberformat attribute before the pagehyperit attribute. This order needs to be swapped. There are two possibilities:

(define-attributes ( ("pagehyperit" "pageglsnumberformat")))


This will result in just one location using the hyperit format:

The second option is:

(define-attributes ( ("pagehyperit") ("pageglsnumberformat")))


This will result in two locations. The first using the hyperit format and the second location using the default pageglsnumberformat format:

Either way, if you manually edit the .xdy file you must add \noist to your document to prevent the .xdy file from being overridden:

\documentclass{article}
\usepackage{hyperref}
\usepackage[xindy]{glossaries}

\newglossaryentry{test}{name={Test},description={\nopostdesc}}
\noist
\makeglossaries

\begin{document}
\printglossary[style=index]
\end{document}


Edit: If you don't want to manually edit the .xdy file, you'll need to redefine some of glossaries internal commands.

First case: redefine \@gls@addpredefinedattributes to list the attributes in your desired order:

\documentclass{article}
\usepackage{hyperref}
\usepackage[xindy]{glossaries}

\makeatletter
}
\makeatother

\newglossaryentry{test}{name={Test},description={\nopostdesc}}
\makeglossaries

\begin{document}
\printglossary[style=index]
\end{document}


The second case is more complicated (\string" is used in case the double quote has been made active, e.g. via ngerman):

\documentclass{article}
\usepackage{hyperref}
\usepackage[xindy]{glossaries}

\makeatletter
}

\edef\@xdyattributes{\@xdyattributes) ^^J (\string"#1\string") ^^J
(\string"#2#1\string"}%
\expandafter\toks@\expandafter{\@xdylocref}%
\edef\@xdylocref{\the\toks@ ^^J%
(markup-locref
:open \string"\string~n%
\expandafter\string\csname glsX#2X#1\endcsname
\string" ^^J
:close \string"\string" ^^J
:attr \string"#2#1\string")}%
\expandafter\gdef\csname glsX#2X#1\endcsname##1##2{%
\setentrycounter[##1]{#2}\csname #1\endcsname{##2}%
}%
}
\makeatother

\newglossaryentry{test}{name={Test},description={\nopostdesc}}
\makeglossaries

\begin{document}

Is this possible to do without manually editing the .xdy file? – You Jan 8 '13 at 13:00