2

In the following MWE, despite having the option indexonlyfirst, the page numbers still goes to the acronym list after I reset all first use flags using \glsresetall, thus giving me

enter image description here

It there a way to turn on and off the page number to index on selected parts of the document, so I only get "page 2" in the acronym list, as shown in this MWE ?

\documentclass{report}
\usepackage[acronym,
            xindy,
            indexonlyfirst,
            ]{glossaries}
\usepackage{glossary-mcols}


\setacronymstyle{footnote-desc}

%% glossary entries

\newacronym{NMR}{NMR}{\textit{Nuclear Magnetic Resonance}}
\makeglossaries

\begin{document}
% Command to turn page numbers to index off

A glossary acronym : \gls{NMR} \gls{NMR} \gls{NMR}

\glsresetall
% Command to turn page numbers to index on
\newpage

The same acronym : \gls{NMR} \gls{NMR} \gls{NMR}

\glsresetall
% Command to turn page numbers to index off
\newpage

A third time the same acronym : \gls{NMR} \gls{NMR} \gls{NMR}

\printglossaries
\end{document}
2
  • Don't keep saying \glsresetall? Since that sets the first-use flag back to false, I think, ensuring it is added again on next use.
    – cfr
    Jan 31, 2016 at 21:24
  • If I remove all the \glsresetall, the acronym would only be mentionned in fulled on page 1, and only page 1 will be added to the index. I want to get the acronyms cited in full only once between the \glsresetall, which is what this does right now, but also that only page 2 is added to the index. Currently, it adds three occurences.
    – HcN
    Jan 31, 2016 at 21:39

1 Answer 1

3

As @cfr has mentioned, the problem is \glsresetall, which marks each entry as unused. This means that the next time it's used, it's considered "first use" and so is indexed.

I think this is a job for glossaries-extra, which extends the glossaries package. Your example can be adapted as follows:

\documentclass{report}
\usepackage[abbreviations,% "acronyms" -> "abbreviations"
            xindy,% no change from original
            nomain % don't define "main" glossary
            ]{glossaries-extra}% "glossaries" -> "glossaries-extra"
\usepackage{glossary-mcols}

% setup abbreviation style
\setabbreviationstyle{footnote}
\renewcommand*{\glsfirstlongdefaultfont}[1]{\textit{#1}}

\renewcommand*{\glossentrydesc}[1]{%
  \glsdoifexistsorwarn{#1}%
  {%
     \textit{\glsentrydesc{#1}}%
  }%
}

% switch off automatic indexing
\GlsXtrSetDefaultGlsOpts{noindex}

%% glossary entries

\newabbreviation{NMR}{NMR}{Nuclear Magnetic Resonance}

\makeglossaries

\begin{document}
\glsresetall

A glossary acronym : \gls{NMR} \gls{NMR} \gls{NMR}.

\glsresetall
\newpage

The same acronym : \gls[noindex=false]{NMR} \gls{NMR} \gls{NMR}

\glsresetall
\newpage

A third time the same acronym : \gls{NMR} \gls{NMR} \gls{NMR}

\printglossaries
\end{document}

Here, instead of trying to index first use, the automatic indexing for all entries is suppressed using

\GlsXtrSetDefaultGlsOpts{noindex}

The indexing now has to be explicitly invoked by cancelling this setting using \gls[noindex=false]{NMR}. This means you have precise control over which use of the term is actually indexed.

If you like, you can set up a modifier for commands such as \gls to provide a shortcut for [noindex=false]:

\GlsXtrSetAltModifier{!}{noindex=false}

Now you can just use \gls!{NMR} instead of \gls[noindex=false]{NMR}. (You can choose another symbol, if you prefer, but make sure it doesn't later have its category code changed. Don't use * or + as they're already modifiers.)

This produces:

image of glossary only page 2 listed in location list

You can modify the title using the optional argument of \printglossary or \printabbreviations to get it the same as with the straight glossaries example:

\printglossary[type=\glsxtrabbrvtype,title=Acronyms]

or

\printabbreviations[title=Acronyms]

or you can redefine \abbreviationsname

\renewcommand{\abbreviationsname}{Acronyms}

You can retain the original \newacronym commands, but you'll need to set the style using:

\setabbreviationstyle[acronym]{footnote}

instead of

\setacronymstyle{footnote}

This is because glossaries-extra has different categories of abbreviations and acronym is a sub-category. This allows you to have different styles for different types of abbreviations, which you can't do with glossaries. (The original commands provided by glossaries can be restored, if necessary, but they may conflict with some of the glossaries-extra styles.)

I've moved the font command \textit out of the abbreviation definition and adjusted the formatting commands using:

\renewcommand*{\glsfirstlongdefaultfont}[1]{\textit{#1}}

\renewcommand*{\glossentrydesc}[1]{%
  \glsdoifexistsorwarn{#1}%
  {%
     \textit{\glsentrydesc{#1}}%
  }%
}

This is unrelated, but is semantically better as it separates content from style. This is assuming that all your entries require italic. If that's not the case then just remove those lines.

You must log in to answer this question.

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