Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
  \glsadd[format=hyperit]{test}
  \glsadd{test}
  \printglossary[style=index]
\end{document}

The result of this MWE is

result of MWE

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}
\GlsAddXdyCounters{fakepage}
\newglossaryentry{test}{name={Test},description={\nopostdesc}}
\makeglossaries

\begin{document}
  \setcounter{fakepage}{\thepage}
  \glsadd[format=hyperit,counter=fakepage]{test}
  \glsadd{test}
  \printglossary[style=index]
\end{document}

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

share|improve this question

1 Answer 1

up vote 6 down vote accepted
+50

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:

Resulting image

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:

Resulting image

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}
  \glsadd[format=hyperit]{test}
  \glsadd{test}
  \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
\renewcommand*{\@gls@addpredefinedattributes}{%
  \GlsAddXdyAttribute{hyperit}
  \GlsAddXdyAttribute{glsnumberformat}
}
\makeatother

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

\begin{document}
  \glsadd[format=hyperit]{test}
  \glsadd{test}
  \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
\renewcommand*{\@gls@addpredefinedattributes}{%
  \GlsAddXdyAttribute{hyperit}
  \GlsAddXdyAttribute{glsnumberformat}
}

\renewcommand*\@glsaddxdyattribute[2]{%
  \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}
  \glsadd[format=hyperit]{test}
  \glsadd{test}
  \printglossary[style=index]
\end{document}
share|improve this answer
    
Is this possible to do without manually editing the .xdy file? –  You Jan 8 '13 at 13:00
    
This works really well, thanks. –  You Jan 9 '13 at 13:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.