5

Recently the package glossaries-extra was released to supplement glossaries

Among the first couple pages of the documentation is the following example:

\documentclass{article}

\usepackage{glossaries-extra}

This is like:

\documentclass{article}

\usepackage[toc,nopostdot]{glossaries}

\usepackage{glossaries-extra}

But I have noticed that when trying to make use of \glsenableentrycount the following two lines are not equivalent.

%\usepackage[savewrites=true,nogroupskip,toc,nopostdot]{glossaries} % ====> THIS WORKS FINE
\usepackage[savewrites=true,nogroupskip,acronym]{glossaries-extra}  % ====> THIS DOESN'T WORK BUT I EXPECTED IT TO BE EQUIVALENT

Using one of these lines in the MWE below, I have observed that I can't use the usepackage call on glossaries-extra (with or without glossaries as shown the quoted documentation example) and have \glsenableentrycount work.

\documentclass{article}

%\usepackage[savewrites=true,nogroupskip,toc,nopostdot]{glossaries} % ====> THIS WORKS FINE
\usepackage[savewrites=true,nogroupskip,acronym]{glossaries-extra}  % ====> THIS DOESN'T WORK

\usepackage{scrwfile}%http://www.dickimaw-books.com/cgi-bin/faq.cgi?action=view&categorylabel=glossaries#glsnewwriteexceeded

\ifdefined\HCode    \usepackage{morewrites} \else   \fi

\makeindex % activate index-making
\makeglossaries

\glsenableentrycount % enable \cgls, \cglspl, \cGls, \cGlspl

% UPDATE:  TRY ENABLING ENTRYCOUNT ATTRIBUTE
% http://mirror.its.dal.ca/ctan/macros/latex/contrib/glossaries-extra/glossaries-extra-manual.html#sec:entrycountmods
%\glssetcategoryattribute{acronym}{entrycount}{1} 
\glssetcategoryattribute{abbreviation}{entrycount}{1} 

%%%%% define synonyms to use counts by default
%%%%% http://tex.stackexchange.com/questions/98494/glossaries-dont-print-single-occurences
    \let\gls\cgls
    \let\glspl\cglspl
    \let\Gls\cGls
    \let\Glspl\cGlspl

\glssetnoexpandfield{first}
\glssetnoexpandfield{firstpl}

\newglossaryentry{SRS}{ type={acronym}, sort={stimulated Raman scattering},  name={SRS}, short={SRS}, long={stimulated Raman scattering}, first={stimulated Raman scattering (SRS)}, description={stimulated Raman scattering  } }

\newglossaryentry{CARS}{ type={acronym}, sort={coherent anti-Stokes Raman scattering},  name={CARS}, short={CARS}, long={coherent anti-Stokes Raman scattering}, first={coherent anti-Stokes Raman scattering (CARS)}, description={coherent anti-Stokes Raman scattering  } }

\glssetexpandfield{first}
\glssetexpandfield{firstpl}

%=============================================================================
%   END GLOSSARY SETUP
%=============================================================================

\begin{document}\noindent\begin{sloppypar}

\gls{CARS} -- I shouldn't see the abbreviation

\cgls{SRS} -- I shouldn't see the abbreviation

\clearpage\end{sloppypar}\end{document}
6
  • You also need to set the entrycount category attribute. – Nicola Talbot Jul 19 '16 at 19:04
  • @NicolaTalbot. Thanks, I just tried \glssetcategoryattribute{abbreviation}{entrycount}{1} and \glssetcategoryattribute{acronym}{entrycount}{1} but no change. I will update my question to reflect where I inserted this. – EngBIRD Jul 19 '16 at 19:41
  • Okay. I think your comment came while I was answering. – Nicola Talbot Jul 19 '16 at 19:46
  • @NicolaTalbot Indeed. Your answer is very complete, I am sure I will resolve my issue with it. Although, switching from \newglossaryentry to \newacronym is not ideal. – EngBIRD Jul 19 '16 at 19:49
  • @NicolaTalbot Sorry, I don't seem to get the desired output with that. I have tried the 6 different possible combinations of the three lines \glssetcategoryattribute{acronym}{regular}{false} \glssetcategoryattribute{acronym}{entrycount}{1} and \glsenableentrycount. My log file still includes the Package glossaries-extra Warning: Entry counting has been enabled that you describe below in your answer. Is there anything else from my log file I can quote that would be helpful? – EngBIRD Jul 19 '16 at 20:11
4

From 2.3 Entry Counting Modifications:

The \glsenableentrycount command is modified to allow for the entrycount attribute. This means that you not only need to enable entry counting with \glsenableentrycount, but you also need to set the appropriate attribute (see §5 Categories).

For example, instead of just doing:

 \glsenableentrycount

you now need to do:

 \glsenableentrycount
 \glssetcategoryattribute{abbreviation}{entrycount}{1}

This will enable the entry counting for entries in the abbreviation category, but any entries assigned to other categories will be unchanged.

This allows the entry counting to be applied to certain types of entries, and it also allows you to set a different trigger value. There should have been a warning in your transcript file:

Package glossaries-extra Warning: Entry counting has been enabled 
(glossaries-extra)                with \glsenableentrycount but the 
(glossaries-extra)                attribute `entrycount' hasn't 
(glossaries-extra)                been assigned to any of the defined 
(glossaries-extra)                entries.

This is a reminder that you need to set the entrycount attribute.

In your example, you have entry definitions like

\newglossaryentry{SRS}{ type={acronym}, sort={stimulated Raman scattering},  name={SRS}, short={SRS}, long={stimulated Raman scattering}, first={stimulated Raman scattering (SRS)}, description={stimulated Raman scattering  } }

Since this doesn't explicitly set the category, it defaults to the general category, so you'd need to add:

\glssetcategoryattribute{general}{entrycount}{1}

However, this type of explicit definition of an abbreviation using \newglossaryentry defeats the purpose of the entry counting, since first contains the abbreviation so it will always show (since it's a regular entry, \cgls internally uses the value of the first key). If you want the abbreviation suppressed with \cgls, you need to define the abbreviation using \newabbreviation (or \newacronym).

Example:

\documentclass{article}

\usepackage[savewrites=true,nogroupskip,acronym]{glossaries-extra}

\usepackage{scrwfile}

\ifdefined\HCode    \usepackage{morewrites} \else   \fi

\makeindex % activate index-making
\makeglossaries

\glsenableentrycount % enable \cgls, \cglspl, \cGls, \cGlspl
\glssetcategoryattribute{acronym}{entrycount}{1}

\let\gls\cgls
\let\glspl\cglspl
\let\Gls\cGls
\let\Glspl\cGlspl

\glssetnoexpandfield{first}
\glssetnoexpandfield{firstpl}

\setabbreviationstyle[acronym]{long-short}

\newacronym[sort={stimulated Raman scattering}]
 {SRS}{SRS}{stimulated Raman scattering}

\newacronym[sort={coherent anti-Stokes Raman scattering}]
 {CARS}{CARS}{coherent anti-Stokes Raman scattering}

\glssetexpandfield{first}
\glssetexpandfield{firstpl}

%=============================================================================
%   END GLOSSARY SETUP
%=============================================================================

\begin{document}\noindent\begin{sloppypar}

\gls{CARS} -- I shouldn't see the abbreviation

\cgls{SRS} -- I shouldn't see the abbreviation

\clearpage\end{sloppypar}\end{document}

This produces:

image showing long forms with no abbreviations

Now suppose I change the CARS entry so that it uses \newabbreviation instead of \newacronym. This sets the category to abbreviation, so it's not controlled by the entry counting mechanism (which has only been enabled for the acronym category).

\newabbreviation[sort={coherent anti-Stokes Raman scattering}]
 {CARS}{CARS}{coherent anti-Stokes Raman scattering}

Now this entry includes the abbreviation even though it's only used once:

image of result CARS entry includes abbreviation

Edit: If you really want to use \newglossaryentry instead of \newabbreviation (or \newacronym) then you'll need to redefine \cglsformat to just check for the long field (and ignore the regular atttibute). For example:

\documentclass{article}

\usepackage[savewrites=true,nogroupskip,acronym]{glossaries-extra}

\makeglossaries

\glsenableentrycount % enable \cgls, \cglspl, \cGls, \cGlspl
\glssetcategoryattribute{acronym}{entrycount}{1}

\let\gls\cgls
\let\glspl\cglspl
\let\Gls\cGls
\let\Glspl\cGlspl

\glssetnoexpandfield{first}
\glssetnoexpandfield{firstpl}

\newglossaryentry{SRS}{
  type={acronym},
  category={acronym},% <- category
  sort={stimulated Raman scattering},
  name={SRS},
  short={SRS},
  long={stimulated Raman scattering},
  first={stimulated Raman scattering (SRS)},
  description={stimulated Raman scattering}
}

\newglossaryentry{CARS}{
  type={acronym},
  category={acronym},% <- category
  sort={coherent anti-Stokes Raman scattering},
  name={CARS},
  short={CARS},
  long={coherent anti-Stokes Raman scattering},
  first={coherent anti-Stokes Raman scattering (CARS)},
  description={coherent anti-Stokes Raman scattering}
}

\glssetexpandfield{first}
\glssetexpandfield{firstpl}

% Not using \newabbreviation so redefine \cglsformat
% to just check for the long field.
\renewcommand*{\cglsformat}[2]{%
  \ifglshaslong{#1}{\glsentrylong{#1}}{\glsentryfirst{#1}}#2%
}

\begin{document}\noindent\begin{sloppypar}

\gls{CARS} -- I shouldn't see the abbreviation

\cgls{SRS} -- I shouldn't see the abbreviation

\clearpage\end{sloppypar}\end{document}

This produces:

image of result with no abbreviations

If you're still getting the above warning, first check that the category has been correctly set for your entries. For example, if you add:

Category of CARS: \glscategory{CARS}.
Category of SRS: \glscategory{SRS}.

to your document, the PDF should show

Category of CARS: acronym. Category of SRS: acronym.

If it doesn't, then check the category element in \newglossaryentry.

Next check that the entrycount attribute has been correctly set. You can do this by adding the following to your document:

entrycount attribute for CARS: \glsgetattribute{CARS}{entrycount}.
entrycount attribute for SRS: \glsgetattribute{SRS}{entrycount}.

This should show

entrycount attribute for CARS: 1. entrycount attribute for SRS: 1.

If it doesn't check the spelling of the category label and the attribute label in

\glssetcategoryattribute{acronym}{entrycount}{1}

If you need to use the plural or case-changing versions, you similarly need to redefine the analogous commands. The first letter uppercase command \cGls uses \cGlsformat:

\renewcommand*{\cGlsformat}[2]{%
  \ifglshaslong{#1}{\Glsentrylong{#1}}{\Glsentryfirst{#1}}#2%
}

(Make sure you have at least v1.14 of glossaries-extra that fixes the bug with \cGls.)

The all capitals version \cGLS uses \cGLSformat:

\renewcommand*{\cGLSformat}[2]{%
  \ifglshaslong{#1}%
  {\MakeUppercase{\glsentrylong{#1}}}
  {\MakeUppercase{\glsentryfirst{#1}}}\MakeUppercase{#2}%
}

(or you may prefer to use \mfirstucMakeUppercase to be consistent with \GLS.)

If you need to use the plural forms, remember that the long, short, longplural and shortplural keys were actually provided for \newacronym and \newabbreviation and require explicit setting if used directly in \newglossaryentry. This means that if you're not using the abbreviation interface but are explicitly uses \newglossaryentry (as in the above example), then longplural and shortplural must be explicitly set if required, otherwise they will be empty.

There isn't a plural equivalent to \ifglshaslong, although you can use \ifglshasfield instead. There are several ways of redefining \cglsplformat. The simplistic approach is:

\renewcommand*{\cglsplformat}[2]{%
  \ifglshaslong{#1}{\glsentrylongpl{#1}}{\glsentryfirstpl{#1}}#2%
}

This just checks if the long field has been set. In the above example, the long field has been set (so \ifglshaslong is true) but longplural hasn't been set, which means that \glsentrylongpl will expand to nothing for the entries in the above example. It really depends on what you want to happen in this situation. You could instead check for longplural:

\renewcommand*{\cglsplformat}[2]{%
  \ifglshasfield{longplural}{#1}{\glsentrylongpl{#1}}{\glsentryfirstpl{#1}}#2%
}

or you might want to default to the long field if long has been set but longplural hasn't:

\renewcommand*{\cglsplformat}[2]{%
  \ifglshaslong{#1}%
  {\ifglshasfield{longplural}{#1}{\glsentrylongpl{#1}}{\glsentrylong{#1}}}%
  {\glsentryfirstpl{#1}}#2%
}

Similarly for \cGlsplformat and \cGLSplformat.

2
  • This has been a really helpful answer that I keep coming back to. I've just noticed however that in the MWE of the edit that if I use\Gls instead of \gls{}, it stops working (I get the abbreviation). I've played around with trying to create a capital instance with\cGlsformat (as suggested tex.stackexchange.com/questions/98494/…) but I haven't any observable changes so my guess that the capital pattern matching may not be correct. Which format command should I try editing to get the count working on the redefined \Gls{}? – EngBIRD Apr 12 '17 at 1:06
  • 1
    @EngBIRD There's a bug in glossaries-extra's version of \glsenableentrycount. I'll get it fixed. – Nicola Talbot Apr 18 '17 at 9:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.