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:
