6

Possible Duplicate:
Automatically index acronyms

I am using glossaries package for acronyms (\usepackage[acronym]{glossaries}). I have a separate .tex file for a list of \newacronym{key}{label}{description} and for a list of \newglossaryentry{key}{name=,description=,type=}. I have used the necessary command for generating index such as \usepackage{makeidx}, \makeindex, \printindex.

I want all the list of acronyms to appear in the index. But i don't want to use the command \index{} in the document every time where i use \acs or \acf or \gls or etc, which also looks ugly full of commands. Can anybody help/suggest me how to generate index automatically every time i use the command of acronyms or glossary in the document without writing the command \index{}?

Shyam
  • 61
  • Probably this can inspire you: http://tex.stackexchange.com/a/62228/10898 – azetina Jul 06 '12 at 14:58
  • Welcome to TeX.SX! Would you please be more specific about what should go in the index? Just the acronym or also its extended form? Each occurrence or just the first? – egreg Jul 06 '12 at 15:04
  • Lets say, we just put the abbreviation from the acronyms in the index. – Shyam Jul 06 '12 at 15:11
  • 2
  • In the link, \package{acronym} and \acro{NATO}{North Atlantic Treaty Organization} command is used in the acronym environment. In my case, glossaries package is used and acronym is an option (\usepackage[acronym,shortcuts,section,...]{glossaries}) and the list of acronyms is defined as \newacronym{NATO}{NATO}{North Atlantic Treaty Organization}. In the document, i use \acs{NATO} for acronyms. To generate index, i use \index{\acs{NATO}} which generate NATO in Index. But here i had to use \index{command}. I tired to change follow the link and change \ac to \acs but does not work. – Shyam Jul 06 '12 at 15:31
  • I believe that this is exactly the same question as the one @cgnieder linked, and that question contains an answer that seem to be what you are looking for. If I'm work, please explain the difference between your question and the linked one. – yo' Jul 08 '12 at 16:20
  • 2
    @tohecz The linked question is about the acronym package, not glossaries. – egreg Jul 12 '12 at 14:39
  • This is really NOT a duplicate, as egreg said. Not sure how to notify admins about this, or even if they should be notified.... – jvriesem Nov 19 '13 at 07:25
  • I agree. I've voted to reopen since the other question is specifically about the acronym package whereas this one is specifically about glossaries. – Nicola Talbot May 03 '16 at 09:11

1 Answers1

1

Here's a first attempt:

\documentclass{article}
\usepackage[acronym,shortcuts]{glossaries}

\usepackage{etoolbox}
\makeatletter
\apptocmd{\@gls@}{\shyam@index{#2}}{}{}
\def\shyam@index#1{%
  \expandafter\expandafter\expandafter\shyam@index@aux\csname glo@#1@index\endcsname\shyam@index
}
\def\shyam@index@aux#1?#2\shyam@index{\index{#1}}
\makeatother

\newacronym[longplural={diagonal matrices}]{dm}{DM}{diagonal matrix}
\newacronym{idn}{IDN}{identification number}

\makeglossaries

\usepackage{makeidx}

\makeindex

\begin{document}

\ac{dm}
\ac{idn}

\newpage

\ac{dm}
\ac{idn}


\printglossaries
\printindex

\end{document}

However, more work could be needed in case you use other commands for calling acronyms in the text. Without a minimal example covering the needs it's difficult to say more.

egreg
  • 1,121,712
  • I could really use a solution that works for the whole family of \gls macros (e.g. \gls, \glspl, \Gls, Glspl, etc.). Since I'm not a LaTeX guru (yet!), I do not understand your trick between the \makeatletter and \makeatother commands. Does your code work only for acronyms? Would it work for the \gls commands as well? Thanks in advance! – jvriesem Nov 19 '13 at 07:31