I am using glossaries package with the acronym option \usepackage[acronym,toc,shortcuts]{glossaries}
.
An answer provided previously (Acronyms only shown in Index when used twice) works perfectly for listing acronyms in the Index with the instruction \gls{some_acronym}
Working on a new long thesis document I noticed that when an acronym text is formatted such as:
\newacronym{ita}{ITA}{\emph{italic text} acronym}
the acronym is listed in the Index under a "Symbols" category:
I would like to have formatted acronyms listed in the Index in alphabetical order. Any ideas?
MWE:
\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)\protect\index{\the\glslongtok\space(\the\glsshorttok)}},%
firstplural={\the\glslongtok\noexpand\acrpluralsuffix\space(\the\glsshorttok)\protect\index{\the\glslongtok\space(\the\glsshorttok)}},%
description={\the\glslongtok}%
}
\SetCustomStyle
\newacronym{cd}{CD}{compact disk}
\newacronym{un}{UN}{United Nations}
\newacronym{ita}{ITA}{\emph{italic text} acronym}
\newacronym{mc}{MC}{4-methyl-compound}
\newacronym{hgh}{HGH}{human growth hormone}
\newacronym{pi}{pI}{isoelectric point}
\begin{document}
\noindent
First\index{first} use of \gls{cd}\\
subsequent\index{subsequent} use of \gls{cd}
, and
\gls{un} and
\gls{ita} and
\gls{mc} and
\gls{hgh} and again \gls{hgh} and
\gls{pi}.
\printglossaries
\printindex
\end{document}
Best Answer
The problem is that
makeindex
doesn't understand (La)TeX commands. The.idx
file created by your MWE contains:makeindex
interprets\emph {italic text} acronym (ITA)
as a string of characters\
,e
,m
,p
,h
, etc. The first character is a backslash somakeindex
puts it in the "Symbols" group. There are two options: providemakeindex
with a different sort key that doesn't contain any formatting commands or usexindy
instead (which simply ignores any LaTeX commands found in the sort key).If you want to stick with
makeindex
, it's possible to modify your definition of\CustomAcronymFields
so that it uses the same sort key that the glossary entry uses. The modified definition is:This now creates the following
.idx
file:(The sort key is the bit before the
@
character in each entry.) This now sorts according to the acronym rather than the full form. You can neaten things up a bit and reduce the chances of error by doing:However, it would be better to sort on the long form, so if you still want to stick with
makeindex
, the following modification will strip\emph
from the entry:If you have other formatting commands, for example
\textbf
, they can be stripped in the same way:The
.idx
file now contains:The resulting index now looks like: