# glossaries and see

I have several acronyms that I want to list using the glossaries package. Some of these are rather peculiar, so I want to edit the acronym style.

These acronyms differ from the rest in that they could be used synonymously: basically, RIVA is in Latin, to be used in the main text, and LAD is in English; it is to be used in tables and diagrams. (This is just an example, there are more of such acronym pairs. I think it's rather confusing to use different terms for the same thing in a scientific paper, but those are the requirements I've got.)

My idea was to leave the glossary entry for LAD empty and just put a link to RIVA there; while the entry for RIVA contains the long form of both RIVA and (in parentheses) LAD:

\documentclass{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage[nomain,xindy,acronym,toc,nopostdot,nogroupskip]{glossaries}

\setglossarystyle{list}
\renewcommand{\glsnumlistsep}{,}
\renewcommand{\glsnumlistlastsep}{:}

\newacronymstyle{teststyle}%
{%
\ifglshaslong{\glslabel}{\glsgenacfmt}{\glsgenentryfmt}%
}%
{%
\renewcommand*{\GenericAcronymFields}{%
first={\the\glslongtok\space\protect\paren{\the\glsshorttok}},
description={\the\glslongtok}}%
\renewcommand*{\genacrfullformat}[2]{%
\glsentrylong{##1}##2\space%
(\protect\firstacronymfont{\glsentryshort{##1}})%
}%
\renewcommand*{\acronymentry}[1]{\acronymfont{\glsentryshort{##1}}}%
\renewcommand*{\acronymsort}[2]{##1}%
\renewcommand*{\acronymfont}[1]{##1}%
\renewcommand*{\firstacronymfont}[1]{\acronymfont{##1}}%
\renewcommand*{\acrpluralsuffix}{\glspluralsuffix}%
\renewcommand*{\glossentry}[2]{%
\item[\glsentryitem{##1}%
\glstarget{##1}{\glossentryname{##1}}]
\ifglshasfield{see}{##1}
{##2}
{\glossentrydesc{##1}\glspostdescription\space ##2}%
}%
}
\setacronymstyle{teststyle}
\makeglossaries

\newacronym[%
%           description={\nopostdesc},
see={riva}]
\newacronym[%
description={Ramus interventricularis anterior (Engl.: Left Anterior Descending},
{riva}{RIVA}{Ramus interventricularis anterior}

%----------------------------------
\begin{document}
\printglossaries
\section{Test}
\clearpage
On this page, we have only \gls{riva}.
\clearpage
\gls{riva} means the same as \gls{lad} but is used in normal text, while \gls{lad} is used in tables and diagrams.

\end{document}


The interesting part of the code is the redefinition of \glossentry. I want to check whether the see field is set for an entry; if it is, print just the link, otherwise print the description and the link. However, the \ifglshasfield-directive seems to be ignored, so what I get is this:

As you can see, the definition of LAD is printed although it should have been skipped. I guess that something is wrong with my \ifglshasfield{see}{##1}…statement -- but what? Another thing I do not understand is why the numberlist of LAD looks correct (it starts with \space 1, followed by a comma) but that of RIVA not (it starts with \space ,).

Finally, I have a question that has (not yet) to do with LaTeX, but with style: Both RIVA and LAD are referenced in the document, so both will have a numberlist -- as the picture shows. In my MWE, the numberlists are pretty short, but they will be longer in the final document. I don't like to clutter up the LAD entry -- I'd just like it to have the acronym, followed by "see RIVA": First, with no definition given, the numberlist could be interpreted as the definition; second, the cross reference at the end of a potentially long line might be hard to find. Now, as both acronyms mean the same thing, do you think it might be possible to merge the numbers from the LAD numberlist into that of RIVA? It would make sense from my premise to keep the line clean, but wouldn't it be confusing if one were looking for RIVA on a page where only LAD was referenced? If merging the numberlists would, indeed, make sense: Will the combined numberlist contain double numbers, or would a package-internal equivalent to sort | uniq take care of that?

The base glossaries package doesn't actually store the value of the see key. The key, if present, automatically triggers the cross-reference when the entry is defined, so the value isn't saved. However, the glossaries-extra extension package does save it. The other advantage of glossaries-extra is that you can have different abbreviation styles for different categories.

The category is set using the new key category provided by glossaries-extra. The value is just a label of your choice (avoid special characters).

For example, you could assign the category latin for your Latin abbreviations and xr for your cross-reference abbreviations. There is an abbreviation style called long-short-user that can be used for abbreviations in the style long (short, custom text) or a similar short-long-user style for short (long, custom text). The custom text is by default obtained from the user1 field. For example:

\setabbreviationstyle[latin]{long-short-user}

\newabbreviation[category=latin,
user1={Left Anterior Descending}]
{riva}{RIVA}{Ramus interventricularis anterior}


A new abbreviation style can be created for the xr category that's similar to long-short but the description field is set to the cross-reference (through \glsxtrusesee) and the number list is automatically suppressed with nonumberlist. For example:

\newabbreviationstyle{xrstyle}%
{%
\renewcommand*{\CustomAbbreviationFields}{%
name={\protect\glsabbrvfont{\the\glsshorttok}},
sort={\the\glsshorttok},
first={\protect\glsfirstlongfont{\the\glslongtok}%
\protect\glsxtrfullsep{\the\glslabeltok}%
(\protect\glsfirstabbrvfont{\the\glsshorttok})},%
firstplural={\protect\glsfirstlongfont{\the\glslongpltok}%
\protect\glsxtrfullsep{\the\glslabeltok}%
(\protect\glsfirstabbrvfont{\the\glsshortpltok})},%
plural={\protect\glsabbvfont{\the\glsshortpltok}},%
nonumberlist,
description={ \protect\glsxtrusesee{\the\glslabeltok}}}%
\renewcommand*{\GlsXtrPostNewAbbreviation}{%
\glshasattribute{\the\glslabeltok}{regular}%
{%
\glssetattribute{\the\glslabeltok}{regular}{false}%
}%
{}%
}%
}%
{%
\GlsXtrUseAbbrStyleFmts{long-short}%
}


Abbreviation styles must always be set before defining the abbreviations that use them:

\setabbreviationstyle[xr]{xrstyle}

\newabbreviation[category=xr,see={riva}]


The category can also be used to customize the glossary appearance without defining a new glossary style. This can be done by defining \glsxtrpostdesccategory. For example,

\newcommand{\glsxtrpostdesclatin}{%
\ifglshasfield{\glsxtruserfield}{\glscurrententrylabel}%
{ (Engl.: \glscurrentfieldvalue)}%
{}%
}


This will automatically insert the translation after the description for the entries with the category set to latin.

I'm not sure whether or not it's a good idea to merge the number lists, but it can be done by automatically indexing RIVA whenever LAD is used. The glossaries-extra package provides hooks that are used after commands like \gls and \glstext in the form \glsxtrpostlinkcategory, so for the xr category, this means defining \glsxtrpostlinkxr:

\newcommand{\glsxtrpostlinkxr}{%
\glsfieldfetch{\glslabel}{see}{\xrlist}%
}


This assumes that the value of the see key is a single label, so it wouldn't work for see=[see also]lad or see={foo,bar}. More general use would require a loop over \xrlist.

Complete MWE:

\documentclass{article}

\usepackage[abbreviations,nomain,xindy,nogroupskip]{glossaries-extra}

\makeglossaries

\newabbreviationstyle{xrstyle}%
{%
\renewcommand*{\CustomAbbreviationFields}{%
name={\protect\glsabbrvfont{\the\glsshorttok}},
sort={\the\glsshorttok},
first={\protect\glsfirstlongfont{\the\glslongtok}%
\protect\glsxtrfullsep{\the\glslabeltok}%
(\protect\glsfirstabbrvfont{\the\glsshorttok})},%
firstplural={\protect\glsfirstlongfont{\the\glslongpltok}%
\protect\glsxtrfullsep{\the\glslabeltok}%
(\protect\glsfirstabbrvfont{\the\glsshortpltok})},%
plural={\protect\glsabbvfont{\the\glsshortpltok}},%
nonumberlist,
description={ \protect\glsxtrusesee{\the\glslabeltok}}}%
\renewcommand*{\GlsXtrPostNewAbbreviation}{%
\glshasattribute{\the\glslabeltok}{regular}%
{%
\glssetattribute{\the\glslabeltok}{regular}{false}%
}%
{}%
}%
}%
{%
\GlsXtrUseAbbrStyleFmts{long-short}%
}

\newcommand{\glsxtrpostdesclatin}{%
\ifglshasfield{\glsxtruserfield}{\glscurrententrylabel}%
{ (Engl.: \glscurrentfieldvalue)}%
{}%
}

\glsfieldfetch{\glslabel}{see}{\xrlist}%
}

\setabbreviationstyle[latin]{long-short-user}
\setabbreviationstyle[xr]{xrstyle}

\newabbreviation[category=latin,
user1={Left Anterior Descending}]
{riva}{RIVA}{Ramus interventricularis anterior}

\newabbreviation[category=xr,see={riva}]

\begin{document}

\printglossaries
\section{Test}
\clearpage
On this page, we have only \gls{riva}.
\clearpage
\gls{riva} means the same as \gls{lad} but is used in normal text,
while \gls{lad} is used in tables and diagrams.

\end{document}


(glossaries-extra automatically implements the package options toc and nopostdot by default.)

The first page looks like:

The second page:

This has the first use of riva displayed as:

Ramus interventricularis anterior (RIVA, Left Anterior Descending)

This is the default first-use display style for long-short-user, but the parenthetical element can be altered by redefining \glsxtruserparen. For example:

\renewcommand*{\glsxtruserparen}[2]{%
\glsxtrfullsep{#2}%
(#1\ifglshasfield{\glsxtruserfield}{#2}{, Engl.: \glscurrentfieldvalue}{})%
}