[Tex/LaTex] Acronyms sorted alphabetically in Index

acronymsindexing

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

Best Answer

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