# Different abbreviation options for the same acronym in glossary

I want to be able to have an acronym in glossary, which when referred to with \gls{} would appear in the main text in a standard form, unless specified otherwise.

I.e. i have the following acronyms:

\newacronym{a1}{A1}{Apples 1}
\newacronym{a2}{A2}{Apples 2}


I am writing about two types of apples, A1 and A2. But i am mostly interested in A1, so i just want them to be abbreviated as A from now on. So i guess i'm looking whether something like the following exists:

\newacronym{a1}{A}{A1}{Apples 1}
\gls{a1}


(abbreviation appears as A)

\gls{a1}[version2]


(abbreviation appears as A1).

Are there any standard options in glossary for this?

There are several methods that I can think of.

## 1. Just the base glossaries package.

\documentclass{article}

\usepackage[style=tree]{glossaries}

\makeglossaries

\setacronymstyle{long-short}
\newacronym{a}{A}{Apples}
\newacronym[parent=a]{a1}{A1}{Apples 1}
\newacronym[parent=a]{a2}{A2}{Apples 2}

\begin{document}
First use: \gls{a1}, \gls{a2}, \gls{a}.

Next use: \gls{a1}, \gls{a2}, \gls{a}.

\printglossaries
\end{document}


This establishes a hierarchical set of abbreviations:

The \gls{a} reference links to the parent entry in the list.

## 2. The glossaries-extra extension package.

\documentclass{article}

\usepackage[style=tree]{glossaries-extra}

\makeglossaries

\setabbreviationstyle[acronym]{long-short}

\newacronym{a1}{A1}{Apples 1}
\newacronym{a2}{A2}{Apples 2}

\newglossaryentry{a}{name={A},description={Apples},alias={a1}}

\begin{document}
First use: \gls{a1}, \gls{a2}, \gls{a}.

Next use: \gls{a1}, \gls{a2}, \gls{a}.

\printglossaries
\end{document}


This uses the alias key that makes the hyperlink for \gls{a} go to the target for a1. The aliased entry is listed in the glossary with a cross-reference:

The first use of \gls{a} doesn't show the full form as it's not an abbreviation. It can be an abbreviation if you prefer:

\newacronym[alias=a1]{a}{A}{Apples}


If you don't want the aliased term to appear at all in the list, you can create an ignored glossary and assign it to that:

\documentclass{article}

\usepackage[style=tree]{glossaries-extra}

\makeglossaries

\setabbreviationstyle[acronym]{long-short}

\newacronym{a1}{A1}{Apples 1}
\newacronym{a2}{A2}{Apples 2}

\newignoredglossary*{ignored}
\newglossaryentry{a}{name={A},description={Apples},alias={a1},type=ignored}

\begin{document}
First use: \gls{a1}, \gls{a2}, \gls{a}.

Next use: \gls{a1}, \gls{a2}, \gls{a}.

\printglossaries
\end{document}


The \gls{a} reference links to the main glossary even though a is in an ignored glossary that doesn't show up with \printglossaries.

## 3. The glossaries-extra extension package and bib2gls.

This assigns a post-link hook for the aliased entry (which now has the category label aliased) so that on first use it will show both terms.

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@acronym{a1,
short={A1},
long={Apples 1}
}
@acronym{a2,
short={A2},
long={Apples 2}
}
@index{a,
name={A},
alias={a1},
seealso={a1,a2},
category={aliased}
}
\end{filecontents*}

\usepackage[style=tree,record]{glossaries-extra}

\setabbreviationstyle[acronym]{long-short}

src={\jobname}% entries in \jobname.bib
]

\glsxtrifwasfirstuse
{%
\glsxtrifhasfield{seealso}{\glslabel}%
{%
\let\DTLlistformatitem\glsxtrlong
\space(\DTLformatlist{\glscurrentfieldvalue})%
}%
{}%
}%
{}%
}

\begin{document}
First use: \gls{a1}, \gls{a2}, \gls{a}.

Next use: \gls{a1}, \gls{a2}, \gls{a}.

\renewcommand{\printunsrtglossaryentryprocesshook}[1]{%
\glsxtrifhasfield*{alias}{#1}{\printunsrtglossaryskipentry}{}%
}
\printunsrtglossaries
\end{document}


Instead of creating an ignored glossary, I've redefined the hook used by \printunsrtglossary to skip any entry that has the alias field set.

The command \glsdefpostlink was new to glossaries-extra v1.31. If you have an older version you can change:

\glsdefpostlink{aliased}{%


to:

\newcommand{\glsxtrpostlinkaliased}{%


Here's a minor variation that includes a description for the aliased entry:

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@acronym{a1,
short={A1},
long={Apples 1}
}
@acronym{a2,
short={A2},
long={Apples 2}
}
@entry{a,
name={A},
description={Apples},
alias={a1},
seealso={a1,a2},
category={aliased}
}
\end{filecontents*}

\usepackage[style=tree,record]{glossaries-extra}

\setabbreviationstyle[acronym]{long-short}

src={\jobname}% entries in \jobname.bib
]

\glsxtrifwasfirstuse
{%
\space(\glsentrydesc{\glslabel}%
\glsxtrifhasfield{seealso}{\glslabel}%
{%
\let\DTLlistformatitem\glsxtrlong
:\space\DTLformatlist{\glscurrentfieldvalue}%
}%
{}%
)%
}%
{}%
}

\begin{document}
First use: \gls{a1}, \gls{a2}, \gls{a}.

Next use: \gls{a1}, \gls{a2}, \gls{a}.

\renewcommand{\printunsrtglossaryentryprocesshook}[1]{%
\glsxtrifhasfield*{alias}{#1}{\printunsrtglossaryskipentry}{}%
}
\printunsrtglossaries
\end{document}


• Thanks for the detailed answer, Nicola! I don't want A to appear in the Glossary and your option 2 seemed the easiest one to implement, but your code does not seem to work for me: ! LaTeX Error: Missing \begin{document}. l.13 \newignoredglossary*{i gnored} ! Package xkeyval Error: alias' undefined in families glossentry'. l.14 ...cription={Apples},alias={a1},type=ignored}  – InternazionalIV Dec 13 '18 at 14:02
• @InternazionalIV The alias key was added to glossaries-extra version 1.12 (2017-02-03) so I suspect your version is too old. – Nicola Talbot Dec 13 '18 at 14:12
• Right you are! Thanks!! Ready to submit my dissertation about the apples now.. – InternazionalIV Dec 16 '18 at 17:53
• @InternazionalIV Good luck with it :-) – Nicola Talbot Dec 16 '18 at 22:33