3

I want to define a new abbreviation style in glossaries-extra that fits the binomial nomenclature of species like this:
First use (only the long version): Escherichia coli
Second use (only the short version): E. coli

Here is an example with the abbreviation style long-em-short-em:

\documentclass{scrartcl}  
\usepackage{glossaries-extra}  
\setabbreviationstyle[species]{long-em-short-em}  
\newabbreviation[category={species}]{ecoli}{E.~coli}{Escherichia coli}  
\begin{document}  
First use: \gls{ecoli}\par  
Second use: \gls{ecoli}  
\end{document}   

enter image description here

Which works fine except of the repetition of the short version in parentheses after the first reference. I've tried to find a solution in the User Manual (chapter: 13.1.2), but i don't understand exactly how these commands work. The example in the Beginners Guide (p. 4ff.) doesn't work in my document.

1 Answer 1

3

New abbreviation styles are defined with \newabbreviationstyle, as mentioned in the glossaries-extra manual (Section 3.5, page 112, unfortunately without many details).

There are a few aspects to consider. Formatting abbreviations is done by redefining \CustomAbbreviationFields. The first use of an abbreviation is formatted with the key first that is set within \CustomAbbreviationFields. Starting from the long-short example the short form can be removed by deleting \glsxtrparen{\protect\glsfirstabbrvfont{\the\glsshorttok}} (the short form in parentheses) as well as \protect\glsxtrfullsep{\the\glslabeltok} (the separation between the long and short form).

Secondly, the abbreviation style needs to be set to regular for the changes to take effect, using the following code within the second argument of \newabbreviationstyle (the first argument is the style name):

\renewcommand*{\GlsXtrPostNewAbbreviation}{%
    \glssetattribute{\the\glslabeltok}{regular}{true}}%
}%

Third, the fonts can be defined in the third argument of \newabbreviationstyle, by defining \glsfirstlongdefaultfont for the first use and \glsabbrvfont for the subsequent uses.

MWE:

\documentclass{scrartcl}  
\usepackage{glossaries-extra}
\newabbreviationstyle{custom-firstnoshort}% label
{% setup
\renewcommand*{\CustomAbbreviationFields}{%
name={\protect\glsabbrvfont{\the\glsshorttok}},
sort={\the\glsshorttok},
first={\protect\glsfirstlongfont{\the\glslongtok}},%
firstplural={\protect\glsfirstlongfont{\the\glslongpltok}},%
plural={\protect\glsabbrvfont{\the\glsshortpltok}},%
description={\the\glslongtok}}%
\renewcommand*{\GlsXtrPostNewAbbreviation}{%
    \glssetattribute{\the\glslabeltok}{regular}{true}}%
}%
{% fmts
\renewcommand*{\glsfirstlongdefaultfont}[1]{\textit{##1}}%
\renewcommand*{\glsabbrvfont}[1]{\textit{##1}}%
}
\setabbreviationstyle[species]{custom-firstnoshort}  
\newabbreviation[category={species}]{ecoli}{E.~coli}{Escherichia coli}
\begin{document}
First use: \gls{ecoli}\par 
Second use: \gls{ecoli}
\end{document}

Result:

enter image description here

2
  • The command \renewcommand*{\glsfirstlongdefaultfont}[1]{\textit{##1}}% turns also my other abbreviations outside the category "species" in italic. Is there an option, which only sets the one category in italic?
    – Niklas
    Commented Oct 26, 2019 at 10:59
  • Maybe \glsfirstlongfont would work, or \glsabbrvemfont. For the 2nd one you need to change also the font specification in first= and firstplural=. Or define a custom command, or maybe \textit inside first= would also work (I don't have time to test it now but I'm sure it is possible).
    – Marijn
    Commented Oct 27, 2019 at 8:22

You must log in to answer this question.

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