9

I am using glossaries package with the acronym option \usepackage[acronym,toc,shortcuts]{glossaries}. When my Index is generated, the acronyms are not listed alphabetically but rather as a "Symbol" entry within the index (image below). I am writing a thesis and have a separate list of Acronyms so this "Symbol" entry in the Index is rather useless for me. Is there a way that the acronyms can be sorted alphabetically in the Index just like the rest of the entries?

MWE:

\documentclass[11pt]{article}
\usepackage{makeidx} 
\makeindex
\usepackage[acronym,toc,shortcuts]{glossaries}
\makeglossaries

\newacronym{cd}{CD}{compact disk}


\begin{document}
\noindent
First\index{first} use of \gls{cd}\\
subsequent\index{subsequent} use of \gls{cd}\index{\glsfirst{cd}}

\printglossaries
\printindex

\end{document}

Index

3
  • Just don't use the \index after running \gls. You should get a Acronyms chapter with all your \gls entries and an Index chapter with "fist" and "subsequent. Is that what you want?
    – LaRiFaRi
    Aug 23, 2013 at 9:11
  • Sorry, I missed the last sentence, that you want to have it in both lists. You may try \index{compact@\glsfirst{cd}}. Haven't tried it. Maybe with space after @ or curly brackets around the \glsfirst{cd}. Give it a try.
    – LaRiFaRi
    Aug 23, 2013 at 9:16
  • @larifari As a mather of fact, besides from the answer given, I indeed found an alternate solution using sorting by @, adding the following:\let\oldgls\gls \renewcommand*{\gls}[1]{\oldgls{#1}\index{#1@\glsfirst{#1}}}
    – PMG870505
    Aug 23, 2013 at 10:28

1 Answer 1

9

The argument of \index doesn't get expanded when written to the .idx file, so makeindex is trying to sort \glsfirst{cd}. Since makeindex doesn't interpret TeX commands, it views this as a string starting with the backslash character, which is why the entry is considered a symbol. Here's a way of automatically indexing subsequent uses of the acronyms that expands the indexed term before writing it to the .idx file:

\documentclass[11pt]{article}
\usepackage{makeidx}
\makeindex
\usepackage[acronym,toc,shortcuts]{glossaries}
\makeglossaries

\renewcommand*{\CustomAcronymFields}{%
  name={\the\glsshorttok},%
  symbol={\the\glsshorttok},%
  text={\the\glsshorttok\protect\index{\the\glslongtok\space(\the\glsshorttok)}},%
  plural={\the\glsshorttok\noexpand\acrpluralsuffix\protect\index{\the\glslongtok\space(\the\glsshorttok)}},%
  first={\the\glslongtok\space(\the\glsshorttok)},%
  firstplural={\the\glslongtok\noexpand\acrpluralsuffix\space(\the\glsshorttok)},%
  description={\the\glslongtok}%
}

\SetCustomStyle

\newacronym{cd}{CD}{compact disk}


\begin{document}
\noindent
First\index{first} use of \gls{cd}\\
subsequent\index{subsequent} use of \gls{cd}.

\printglossaries
\printindex

\end{document}

Assuming I have the makeindex headings flag set (via headings_flag 1 in a .ist file) I get the following index:

Image of index page

If you only want to index some subsequent entries rather than all of them, here's another approach that saves the index command with expanded argument in the user1 field:

\documentclass[11pt]{article}
\usepackage{makeidx}
\makeindex
\usepackage[acronym,toc,shortcuts]{glossaries}
\makeglossaries

\renewcommand*{\CustomAcronymFields}{%
  name={\the\glsshorttok},%
  symbol={\the\glsshorttok},%
  text={\the\glsshorttok},%
  plural={\the\glsshorttok\noexpand\acrpluralsuffix},%
  first={\the\glslongtok\space(\the\glsshorttok)},%
  firstplural={\the\glslongtok\noexpand\acrpluralsuffix\space(\the\glsshorttok)},%
  description={\the\glslongtok},%
  user1={\protect\index{\the\glslongtok\space(\the\glsshorttok)}}%
}

\SetCustomStyle

\newacronym{cd}{CD}{compact disk}


\begin{document}
\noindent
First\index{first} use of \gls{cd}\\
subsequent\index{subsequent} use of \gls{cd}.

\newpage

Another use of \gls{cd}\glsuseri{cd}.

\printglossaries
\printindex

\end{document}

The index now looks like:

Image of index

2
  • This is exactly what I needed. I found another solution redefining the \gls{} command: \let\oldgls\gls \renewcommand*{\gls}[1]{\oldgls{#1}\index{#1@\glsfirst{#1}}}. As I understand, it asks to sort each entry as stated itself by \gls{}.
    – PMG870505
    Aug 23, 2013 at 10:22
  • I have a question: the acronyms are only displayed when used twice, any ideas on how to modify the code so all of them are listed, even if \gls{} is only mentioned once? I posted a question here: [tex.stackexchange.com/questions/130322/…
    – PMG870505
    Aug 27, 2013 at 14:51

You must log in to answer this question.

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