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.

I know, there are similar questions around, but I couldn't find a solution to what I want. E.g. here, all acronyms in the document are set to the index. I think, indexing should be done manually so that every index reference shows just 1 or 2 pages in the document. If the work of a glossary is done, I think this list should also appear in the index. This way, using the index will guide the lector at least to the short glossary explanation.


In detail: I am using imakeidx and glossaries. When I write \gls{} somewhere to set an entry in the main glossary, I don't want an index link to this place, but to the page where the glossary entry is written. Therefore the command \newglossaryentry{glo:AD}{name=Active Directory, description={Active Directory is an...}} should somehow automatically contain an \index{name} resp. \index{Active Directory}.

When I think, the appearance in the text is important enough, I will add manually \gls{glo:AD}\index{Active Directory} and obtain an index entry with two referenced page numbers.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Quick solution

Here is a shorter solution, it struggles with the issue that it writes the first occurence text to the glossary.

 \defglsdisplayfirst[\acronymtype]{#1#4\index{#1}}

It redefines the first display of the term to include a call to index using the \defglsdisplayfirst command and restricts this change to the acronym glossary. Right now the issue with this is that #1 is already defined to long term (acronym), but for normal glossary entries it should be just fine.

A workarround might be to redefine the new acronym command to set the description differently. But in the long run it would be nice to simply have access to the label in the \defglsdisplay(first) command to access the other keys as needed. I wrote a feature request to nicola.

From Nicloas response to the feature request: If one uses \glslabel one can access all the other information. Thus for acronyms use \index{\glsWhatKeyDoYouWantForTheIndex{\glslabel}} instead.

Primitive solution

I had a similar problem and deduce the awnser from that. I redefine the glossary command to call index as some of the awnsers in the related questions suggest, however the call to ìndex`is only made when its the first use.

\documentclass{article}    
\usepackage{makeidx}
\makeindex
\usepackage[acronym]{glossaries}    
 \makeglossaries
 \newacronym{gpu}{GPU}{graphics processing unit}    
 \let\oldGls\gls
 \renewcommand{\gls}[1]{%
    \ifglsused{#1}{ %
        \oldGls{#1}%
    }{%
        \oldGls{#1}%
        \index{\glsentryfirst{#1}}%
    }%
 }
\begin{document}
  %\gls{gpu}
  First use \gls{gpu}-computing\\
  subsequent \gls{gpu}-computing and \gls{gpu}
    \clearpage
    \gls{gpu}

  \printindex
\end{document}

I only covered the \gls-command, and did not check for the glossary the entries are in, this could cause trouble if you have multipleglossaries.

Indexing the entries inside printglossary

By using a custom style for printglossary one can add the index commands.

\documentclass{article} 
\usepackage{makeidx}
\makeindex   
\usepackage{hyperref}
\usepackage{glossaries}    
 \makeglossaries
 \newglossaryentry{gpu}{name=graphics processing unit, description={bla blup}}    

% \defglsdisplayfirst[acronym]{#1#4\index{#1}}
\newglossarystyle{myList}{%
  \glossarystyle{list}%
  \renewcommand*{\glossaryentryfield}[5]{%
    \item[\glsentryitem{##1}\glstarget{##1}{##2}\index{\glsentrytext{##1}}]
       ##3\glspostdescription\space ##5}%
  \renewcommand*{\glossarysubentryfield}[6]{%
    \glssubentryitem{##2}\index{\glsentrytext{##1}%
    \glstarget{##2}{\strut}##4\glspostdescription\space ##6.}%
}}
\begin{document}
  First use \gls{gpu}-computing
  \clearpage
    \printglossary[type=main, style=myList]
  \printindex
\end{document}

Simply go to your texmf tree, take a look at the style you want to use, and copy its definitions of \glossaryentryfield and \glossarysubentryfield out. create your own style be writing (place the index call at a reasonable point, otherwise you could use patch \appendto):

\newglossarystyle{yourStyle}{%
  \glossarystyle{originalStyle}%
  \renewcommand*{\glossaryentryfield}[5]{originalDef+\index{\glsentrytext{##1}}}%
  \renewcommand*{\glossarysubentryfield}[6]{originalDef+\index{\glsentrytext{##1}}}%
}
share|improve this answer
    
I think @LaRiFaRi wants index items to point to the entry in the glossary and not to the entry in the document... –  karlkoeller Aug 11 '13 at 8:57
    
@karlkoeller: i will wait for LaRiFaRi to respond to this. But that is not so hard either. He has to define his own glossary-style (simply copy inherit an existing one and overwrite the display witht the display wiht an additional \index). If you need an example let me know. –  ted Aug 11 '13 at 9:05
    
Hello, thank you @ted but @karlkoeller is right. I want to index the glossary entrys. Even if appearing in multiple glossaries. I think something like \newglossaryentry{#1}{name=#2, description={#3\index{#2}}} would work. I would be glad to see an example on this. –  LaRiFaRi Aug 11 '13 at 9:42
1  
@LaRiFaRi: Take a look at the last solution. It should do as you asked. It does not take your approach but I think in the end it does not matter to mcuh where you redefine, the \newglossaryentry or the style. –  ted Aug 11 '13 at 10:28
1  
@LaRiFaRi: thanks for the brace fix, I edited in the new part –  ted Aug 11 '13 at 10:58

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.