Using the glossaries-extra package, it is possible to define the used terms and their abbreviation for convenient and consistent use within the document.
But handling inflections within a sentence becomes unexpectedly difficult, as I write in German and the plural forms are not sufficient.
A simple solution is to use \glslink and \glsdisp to show a custom text, but this has several shortcomings shown in the example below.
My understanding of LaTeX hacking is insufficient to grasp the internals of the glossaries packages and I cannot estimate whether creating a custom command to handle this is feasible.
Example
To compile this, execute pdflatex test, bib2gls --record-count test, pdflatex test in this order.
Also, to show why \gsldisp is insufficient, the example only shows the abbreviation at all, when the term is used at least twice.
File test.tex:
\documentclass{article}
\usepackage{xcolor}
\usepackage{hyperref}
\hypersetup{linkbordercolor=blue!30!white}
\usepackage[record,abbreviations,nomain]{glossaries-extra}
\setabbreviationstyle[abbreviation]{long-short-desc}
\glssetcategoryattribute{abbreviation}{nohyperfirst}{true}
\renewcommand{\glsfirstlongdefaultfont}[1]{\emph{#1}}
\GlsXtrLoadResources[src={glossary},selection=all]
\GlsXtrEnableEntryCounting{abbreviation}{1}
% Show only terms that are used more than once:
\renewcommand{\printunsrtglossaryhandler}[1]{%
\ifthenelse{\GlsXtrTotalRecordCount{#1}>1}%
{\glsxtrunsrtdo{#1}}%
{}%
}
\begin{document}
% Good; No abbreviation shown:
The first mention with a different inflection ``des \glsdisp{Vektorraum}{Vektorraums}''.
% Bad; Should show choose abbreviation here and italicize the long part:
The first mention with a different inflection ``des \glsdisp{Körper}{Körpers}''.
And here the second use ``der \gls{Körper}''.
The first mention of ``der \gls{Vektor}''.
% Bad; Should choose abbreviation here:
And here with a different inflection ``des \glsdisp{Vektor}{Vektors}''.
\printunsrtglossary[type=\acronymtype,title=Abkürzungen]
\end{document}
File glossary.bib:
@abbreviation{Vektorraum,
short={VR},
long={Vektorraum},
description={Menge von Vektoren mit Vektoraddition und Skalarmultiplikation über einen Körper.},
}
@abbreviation{Vektor,
short={VEC},
long={Vektor},
description={Ein Vektor ist ein Element eines Vektorraums.},
}
@abbreviation{Körper,
short={K},
long={Körper},
description={Zwei kompatible zweistellige Verknüfungen über eine gemeinsame Menge.},
}
Question
Given the requirements, can a gls like command be easily created to handle all the above cases, while also respecting the abbreviation style selected and also handle regular glossary terms analogously?
Existing Solutions
A similar question was posted here, but the solution sought, was to specify the inflection on usage, whereas I want to call gls with a replacement text for the long part of the abbreviation on usage to be more practical.
Thanks in advance, even if there is no solution.
EDIT: Working Example
With the code examples given by Nicola Talbot, the following achieves all requirements (at least, that I can see):
\documentclass{article}
\usepackage{xcolor}
\usepackage{hyperref}
\hypersetup{linkbordercolor=blue!30!white}
\usepackage[record,abbreviations,nomain]{glossaries-extra}
\setabbreviationstyle[abbreviation]{long-postshort-user-desc}
\glssetcategoryattribute{abbreviation}{nohyperfirst}{true}
\renewcommand{\glsfirstlonguserfont}[1]{\emph{#1}}
\GlsXtrLoadResources[src={glossary},selection=all]
\GlsXtrEnableEntryCounting{abbreviation}{1}
% Show only terms that are used more than once:
\renewcommand{\printunsrtglossaryhandler}[1]{%
\ifthenelse{\GlsXtrTotalRecordCount{#1}>1}%
{\glsxtrunsrtdo{#1}}%
{}%
}
\newcommand{\disp}[3][]{%
\ifglsentryexists{#2}%
{\glsifregular{#2}%
{\glsdisp[#1]{#2}{#3}}%
{\ifglshasshort{#2}%
{\glsxtrifcounttrigger{#2}%
{\glsifattribute{#2}{nohyperfirst}{true}%
{\glslink[hyper=false,#1]{#2}{#3}}%
{\glslink[#1]{#2}{#3}}%
\glsunset{#2} }%
{\ifglsused{#2}%
{\gls[#1]{#2}}%
{\glsdisp[textformat=glsfirstlongfont,#1]{#2}{#3}} } }%
{\glsdisp[#1]{#2}{#3}} } }%
{\glsdisp[#1]{#2}{3}}%
}
\begin{document}
% The following assertions show the required behavour:
\begin{figure}
\begin{tabular}{cc}
\disp{Vektorraum}{Vektorraums} & Vektorraums \\ % <- Without link
\disp{Vektor}{Vektors} & \emph{Vektors} (VEC) \\ % <- Without link
\disp{Vektor}{Vektors} & VEC \\ % <- With link
\end{tabular}
\end{figure}
\printunsrtglossary[type=\acronymtype,title=Abkürzungen]
\end{document}
Some things that came up during testing:
- Changing the style from
long-postshort-user-desctolong-postshort-userhas the side-effect of removing the long form from the printed glossary listing for some reason. - Using
\glslike commands within$\text{...\gls{Vektor}...}$behaves weirdly, since each use is counted as 4 occurences with regards to the use counter (\glsentryprevcountis 4 times as high).
Otherwise this seems like a splendid solution.




long-postshort-user-descstyle puts the long and short form in thenamefield, leaving the user to supply thedescriptionfield. Thelong-postshort-userstyle puts the short form in thenamefield and thelongform in thedescriptionfield. If you set the description it will override this, so the long form won't appear in the glossary. That's the basic difference between those two styles. For your second point, is$\text{...\gls{Vektor}...}$inside an environment that parses its contents (such astabularx)? That might require a separate question. – Nicola Talbot Apr 13 '19 at 12:31