# Glossaries - how to define newacronym that refers to a glossary entry

I have a number of acronyms in my document, some of which have a more complex meaning than others, and I would like to have an accompanying linked entry for them in the glossary. I found that in order to define these cross-referenced acronyms, I was unable use the normal \newacronym command and had to use newglossaryentry instead with the type=\acronymtype key-value pair defined.

Things seemed fine until I noticed that some of my acronyms were showing up in my document even though I had not referenced them. So, after some tweaking/testing I've worked out that the see key is the source of the problem. I do like the functionality of the see key-value, so I'm looking for a solution to the problem I'm reporting rather than abandoning the idea.

Where an acronym references the glossary, I use the see key-value pair to tell it which glossary entry to point to. It appears that a side-effect of this key-value is that it forces the acronym to be displayed in the Acronyms list in the document even though it wasn't reference in the document body. In my case, something I do not want.

Below is a sample document that demonstrates how I've approached my cross-referencing need and also demonstrates the problem. Simply (un)comment the lines see=[Glossary:]{apig}, and \gls{api} then rebuild.

With see commented out, the behaviour is correct. Acronym and Glossary both have an API entry when \gls{api} is active, and neither do when not. Uncomment see, and you will now have the Acronym entry regardless of the state of \gls{api} (including a Glossary: API link that points to nothing), and when \gls{api} is active there will be a Glossary entry as expected and the link is correct. The TCP and IP acronyms work fine.

Is there a way of fixing this behaviour?

Updates Seems this may require bib2gls, which needs to be installed and it appears I don't have it because I'm unable to run the example in the glossaries-user.pdf (p25). As a result, I cannot see what the outcome would be.

At this point I don't know how to install bib2gls though it's available from CTAN and I have the necessary Java (v8+) installed.

I'm using MacOS Catalina 10.15.6 with Homebrew. I have mactex-20170524.pkg installed and use TexStudio 3.0.1.

        \documentclass{article}
\usepackage{hyperref}
\usepackage[acronym]{glossaries}
%\usepackage[nonumberlist,acronym]{glossaries} %% nonumberlist also turns off 'see' .
%\usepackage{glossaries-extra}
%\usepackage{glossaries-prefix}

\makeglossaries
%% Set flag to include Glossary in the ToC
%\glstoctrue
% Set acronyms such that on first use, the whole phrase is shown along with the acronym.
\setacronymstyle{long-short}
%
\newglossaryentry{api}{
type=\acronymtype,
name={API},
description={Application Programming Interface},
see=[Glossary:]{apig},
%% 'see' adds a note at the end of the acronym description
%% 'see' is turned off by global or local 'nonumberlist'
%% Using the example above it writes 'Glossary: API' with Glossary: in italics.
}

\newglossaryentry{apig}{
name={API},
description={An Application Programming Interface (API) is a particular set of rules and specifications that a software program can follow to access and    make use of the services and resources provided by another particular software program that implements that API}
}

\newacronym{ip}{IP}{Internet Protocol}
\newacronym{lan}{LAN}{Local Area Network}
\newacronym{smp}{SMP}{Symmetric Multi-Processing}
\newacronym{tcp}{TCP}{Transmission Control Protocol}

\begin{document}

\printglossary[type=\acronymtype]
%%% \newpage just to demonstrate that links are correct
\newpage
\printglossary[type=main]
\newpage

\noindent
\gls{tcp}
sits on top of
\gls{ip}
, and you need an
%\gls{api}
. \\
\\
\noindent
Just to repeat,
\gls{tcp}
sits on top of
\gls{ip}
, and you need an
%\gls{api}
.

\end{document}

• well it doesn't look very logical, but it is documentated (on page 96 in my version), and it says "If you want to avoid the automatic indexing triggered by the see key, consider using Option 4" (where option 4 is using bib2gls.) May 6, 2021 at 15:05
• @UlrikeFischer: I have the same. I tried the 'example document' on page 25 (Option4 bib2gls) to see what it looks like, but I'm getting an error: Package xkeyval Error: value 'nameref' is not allowed. \RequirePackage. I'm also getting errors regarding the \gls{} invocations because the \GlsXtrLoadResources[src={entries}] failed to load my entries.bib file (though I have it in the same folder as the document). I'm not sure how to install bib2gls on MacOS yet.
– gone
May 6, 2021 at 15:50

The following should work:

\documentclass{article}
\usepackage{hyperref}
\usepackage[acronym]{glossaries}

\makeglossaries

\newglossarystyle{optgloss} {
\setglossarystyle{list}
\let\oldglossentrydesc\glossentrydesc

\renewcommand* {\glossentrydesc} [1] {%
\oldglossentrydesc{##1}%
\ifglshasfield {glossterm} {##1} {%
\glsunset{\glscurrentfieldvalue}%
\ \textit{Glossary:}~\gls[format=glsignore]{\glscurrentfieldvalue}%
}{}%
}
}

\newacronymstyle{optgloss}
{%
\GlsUseAcrEntryDispStyle{long-short}%
\ifglshasfield {glossterm} {\glslabel} {%
}%
}
{\GlsUseAcrStyleDefs{long-short}}

\setacronymstyle{optgloss}

\newglossaryentry{api}{
type=\acronymtype,
name={API},
description={Application Programming Interface},
first={Application Programming Interface (API)},
glossterm={apig}
}

\newglossaryentry{apig}{
name={API},
description={An Application Programming Interface (API) is a particular set of rules and specifications that a software program can follow to access and    make use of the services and resources provided by another particular software program that implements that API}
}

\newacronym{ip}{IP}{Internet Protocol}
\newacronym{lan}{LAN}{Local Area Network}
\newacronym{smp}{SMP}{Symmetric Multi-Processing}
\newacronym{tcp}{TCP}{Transmission Control Protocol}

\begin{document}

\printglossary[type=\acronymtype,style=optgloss]
%%% \newpage just to demonstrate that links are correct
\newpage
\printglossary[type=main]
\newpage

\noindent
\gls{tcp}
sits on top of
\gls{ip}
, and you need an
\gls{api}
. \\
\\
\noindent
Just to repeat,
\gls{tcp}
sits on top of
\gls{ip}
, and you need an
\gls{api}
.

\end{document}


You can link to a glossary entry for an acronym by including a glossterm key and setting it to the name of the glossary entry, e.g. apig (I hope it's a cute pig! 🐷).

Page numbers where the acronym appears will show up on lists for both the acronym and the glossary entry. Note that you no longer need to put \glsadd{apig} in any of the fields when defining acronyms.

The page on which the acronym appears in the acronyms list is not included in the page list for the glossary entry. If you'd prefer it did, remove the [format=glsignore] optional argument.

Use whatever style name(s) you prefer. I used optgloss for "optional glossary link". Likewise, glossterm can be changed to anything you like, provided you keep it consistent everywhere.

Finally, note that if you eliminate an acronym, you'll need to recompile the LaTeX source, then glossaries, then source, then glossaries, and finally the source again in order for the change to appear in the glossary.

• Thanks, that works exactly how I was hoping it would.
– gone
May 6, 2021 at 18:43
• Whilst the demo you put together works fine, when I use it in my document, I'm getting an error in my tex only IF I make a reference to \gls{api} (the error goes away if I remove the \gls{api}). The error is: Extra \else. \include{Introduction} and occurs on the next line after \printglossary[type=\acronymtype,style=optgloss] \printglossary[type=main]
– gone
May 6, 2021 at 20:33
• I don't understand why, but changing \include{Introduction} to \input{Introduction} fixed the problem, which is interesting because I still have a bunch more \include both before and after this line.
– gone
May 6, 2021 at 20:39
• Perhaps @UlrikeFischer can see something defective about my code that causes the error. I'm still a bit of a babe in the woods when it comes to diagnosing LaTeX errors.
– COTO
May 7, 2021 at 14:13