2

In general the glossaries interface seems straightforward with it's default settings for acronyms, however, I came across some cornercases, where I would like to change the way glossaries displays a specific term differently.

Examples would be the following:

The acronym FUSE, while in general I like the default representation of the form My Long Acronym (MLA), it feels unnatural for Filesystem in Userspace (FUSE). I would more likely write ... implemented with FUSE (Filesystem in Userspace) ... than the other way round.

Another example for a corner case would be PCIe which stands for Peripheral Component Interconnect Express, which however I would only like to see as PCI Express (PCIe) in the first use place, but in the glossary I would like to see the longer description of Peripheral Component Interconnect Express.

Question

  1. How can I achieve a different order (\glsname (\glsdesc)) for specific entries of a glossary (the acronym glossary)? (Preferably without retyping the data in name and description, Would it be possible to define a macro, that calculates first correctly?)
2

If you have a mixture of styles like this, I think it's better to use glossaries-extra rather than just glossaries. This extension to the glossaries package reimplements abbreviations to make it easier to have multiple styles.

Instead of using \setacronymstyle{style-name}, you need to use \setabbreviationstyle[category]{style-name} where the optional argument is a category label. (If omitted, abbreviation is used.) So if the majority of your abbreviations should have a long (short) style, then you'd use

\setabbreviationstyle{long-short}

(before defining the abbreviations). This is actually the default.

For your short (long) abbreviations, you just need to decide on an appropriate category label (let's say reverse) and set the style for that category:

\setabbreviationstyle[reverse]{short-long}

The abbreviations are defined using \newabbreviation, which has a similar syntax to \newacronym from glossaries but the optional argument has an extra key category which is set to abbreviation by default. (This key is also available in \newglossaryentry with glossaries-extra, but defaults to general in that case.)

So for your first two examples:

\setabbreviationstyle{long-short}
\setabbreviationstyle[reverse]{short-long}

\newabbreviation{mla}{MLA}{my long abbreviation}
\newabbreviation[category=reverse]{fuse}{FUSE}{Filesystem in Userspace}

There's a predefined category label called acronym and glossaries-extra redefines

\newacronym[options]{label}{short}{long}

to

\newabbreviation[category=acronym,options]{label}{short}{long}

The style for the acronym category is automatically set to just short, but you can set it explicitly. For example:

\setabbreviationstyle[acronym]{short}

\newacronym[description={device that produces an intense narrow
beam of light}]
 {laser}% label
 {laser}% short
 {light amplification by stimulated emission of radiation}% long

This style won't actually show the long form unless the entry is used with commands like \glsxtrlong or \glsentrylong. However, with glossaries-extra you can adjust the post description hook for a particular category. For example:

\renewcommand*{\glsxtrpostdescacronym}{%
 \space(\textsc{acronym:} \glsentrylong{\glscurrententrylabel})%
}

This saves creating a custom glossary style. (Note that in this case \glsxtrpostdescacronym needs redefining, but for a custom category, such as the reverse one above, the hook won't be predefined.)

Another variation is to set attributes for a particular category to adjust the style. For example, you can make \newabbreviation automatically insert dots between each letter of the short form by setting the insertdots attribute for a particular category. For example:

\setabbreviationstyle[dottedsc]{short-sc-long}
\glssetcategoryattribute{dottedsc}{insertdots}{true}

If you set the insertdots attribute, it's a good idea to also set the discardperiod attribute which will discard a period immediately following commands like \gls to prevent a double-dot.

You can also define a "tagging" command for a particular category (or categories):

\GlsXtrEnableInitialTagging{dottedsc}{\itag}

The first argument may be a comma-separated list of category labels rather than just a single label. The second argument is a command name of your choosing that you can use to tag the initial letters. (This should not be an existing command.) For example:

\newabbreviation
 [category=dottedsc]
 {html}% identifying label
 {html}% short form
 {\itag{h}yper\itag{t}ext \itag{m}arkup \itag{l}anguage}% long form

\newabbreviation
 [category=dottedsc]
 {xml}% identifying label
 {xml}% short form
 {e\itag{x}tensible \itag{m}arkup \itag{l}anguage}% long form

In the glossary, the tagged letters will by default be underlined but not in the rest of the document.

I've left your third example until last as it's a tricky one. Even though you don't want to use the description key, I think it's necessary in this case. Either:

\newabbreviation
 [description={Peripheral Component Interconnect Express}]
 {pcie}{PCIe}{PCI Express}

or, if you also want pci indexed:

\newabbreviation{pci}{PCI}{Peripheral Component Interconnect}

\newabbreviation[description={\glsxtrlong{pci} Express}]{pcie}{PCIe}{PCI Express}

or, if you don't want pci indexed:

\newabbreviation{pci}{PCI}{Peripheral Component Interconnect}

\newabbreviation[description={\glsentrylong{pci} Express}]{pcie}{PCIe}{PCI Express}

Nested use of commands like \gls within the long (or short) form can cause all kinds of problems, although glossaries-extra tries to eliminate some of them. This is discussed in more detail in the section "Nested Links" of the glossaries-extra manual.

Complete example:

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage
 [
   %abbreviations, % for separate list of abbreviations
   %nopostdot=false % auto-insert full-stop after descriptions
 ]
 {glossaries-extra}

\makeglossaries

% Regular entry (category automatically set to "general")
\newglossaryentry{sample}{name={sample},description={an example}}

% Standard long (short) abbreviations
% This is already the default, but set it explicitly for this
% example.
\setabbreviationstyle{long-short}

% Category automatically set to "abbreviation" if not explicitly set
\newabbreviation{mla}{MLA}{my long abbreviation}

\newabbreviation
 [description={Peripheral Component Interconnect Express}]
 {pcie}{PCIe}{PCI Express}

% Reverse short (long) abbreviations.
% Let's call this category "reverse". This is just a label you can change
% but make sure it doesn't contain special characters.

\setabbreviationstyle[reverse]{short-long}

\newabbreviation[category=reverse]{fuse}{FUSE}{Filesystem in Userspace}

% There's already a predefined category called "acronym" that
% has the abbreviation style set to "short", but let's set it explicitly 
% in this example.

\setabbreviationstyle[acronym]{short}

\newacronym[description={device that produces an intense narrow
beam of light}]
 {laser}% label
 {laser}% short
 {light amplification by stimulated emission of radiation}% long

% The "short" style won't show the long form in the glossary,
% so let's adjust the post description hook just for the "acronym"
% category so that the long form is automatically inserted after the
% description. This saves defining a new custom glossary style.

\renewcommand*{\glsxtrpostdescacronym}{%
 \space(\textsc{acronym:} \glsentrylong{\glscurrententrylabel})%
}

% Let's make a dotted small-caps category called "dottedsc":
\setabbreviationstyle[dottedsc]{long-short-sc}

% provide a tagging command for the "dottedsc" category:
\GlsXtrEnableInitialTagging{dottedsc}{\itag}

% auto insert dots between letters in the short form for the
% "dottedsc" category:
\glssetcategoryattribute{dottedsc}{insertdots}{true}

% Discard trailing periods following commands like \gls:
\glssetcategoryattribute{dottedsc}{discardperiod}{true}

\newabbreviation
 [category=dottedsc]
 {html}% identifying label
 {html}% short form
 {\itag{h}yper\itag{t}ext \itag{m}arkup \itag{l}anguage}% long form

\newabbreviation
 [category=dottedsc]
 {xml}% identifying label
 {xml}% short form
 {e\itag{x}tensible \itag{m}arkup \itag{l}anguage}% long form


\begin{document}

\section{First}
First use:

\gls{sample}.

\gls{mla}.

\gls{fuse}.

\gls{laser}.

\gls{html}.

\gls{xml}.

\gls{pcie}.

\section{Next}

Next use:

\gls{sample}.

\gls{mla}.

\gls{fuse}.

\gls{laser}.

\gls{html}.

\gls{xml}.

\gls{pcie}.

\printglossaries

\end{document}

This produces:

image of document

0

In your FUSE example, if you can't redefine your first use for these terms in general because you are using \arc{} you may be able to define a new command to accomplish this when you know in advance you are using a term that requires this special treatment.

A starting point might be:
\newcommand{\acrinverse}[1]{{\acrshort{#1}}\xspace{\acrlong{#1}}}

I think you may find it easier to use \gls{} and \newglossaryentry commands rather than the faster \acr{} because you will be able define each

  • label
  • name
  • sort
  • short
  • long
  • description
  • first

all manually to conform to entry specific formatting.

With regards to your formatting, I don't think any special macro would be needed to sort, you can just define the sorting term logic within the sort field. This term will not be visible, so modify it as you need to.

Continuing your PCI example if you want to build a more dynamic solution, you could consider nesting your terms? I did something like this and I sought help in these two questions:

Nested conditional glossary terms using Glossaries \ifglsused in \newglossaryentry

and

Create new fields in glossaries newglossaryentry

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.