There are a lot of examples of how to change first letters to upper case using glossaries (Capitalize first letter of each word when printing list of acronyms, capitalisation and list of acronyms, Glossaries Capitalize Every First Letter)
In my case, have to use some acronyms with both a lower case and an upper case version in the text, while at the same time having an upper case first letter in the list of acronyms in the long form. On the other hand, I have some entries that do not have an upper case version, so I can't simply use \Glsentrylong
, when redefining the style.
So far, changing the appearance in the text is no problem, if the long form is given in lower case. Changing the appearance in the list, however, proved to be too difficult for me. I tried checking for a user entry, using \ifglshasfield
, without success (not even with long-short-user
and and long-short-user-desc
styles).
My attempts to increase the number of categories and checks (that are already done for the description) utterly failed.
In the original version (commented part) I was not able to change the appearance of the long form in the list of acronyms when the long form was lower case. If the long form was upper case, I was not able to use a lower case long form in text. Using text={lowcaseupcase}
with {Lowcaseupcase}
as the long form also gave the long form in the text.
In the current version I get the following outputs in the list:
- long form given: long form printed (ok, see WOD, xyz) user entry and
- long form given: user entry printed (ok, see HAHA)
- description and long form given: just the description is printed (long form missing, see ANY, MAKRO, tbd)
- desription, long form and user entry given: the long form and the description are given (user entry missing, see HOHO, LCUC)
Is there a way to use lower case long forms in text while having the upper case form in the list without capitalizing every entry?
A possible solution might be to explicitly convert the first letter in text to lower case (as opposed to \acl{label}
vs \Acl{label}
) but I fear that would mean to define a lot of new commands. Maybe I missed a simple solution to this...
\documentclass{scrartcl}
\usepackage[ngerman]{babel}
\usepackage{calc}
\usepackage[xindy,shortcuts=ac,nomain,acronym,nogroupskip,toc,shortcuts,numberedsection=nameref]{glossaries-extra}
\setlength{\glslistdottedwidth}{.5\hsize}
% discriminate between entries with and without descriptions: based on https://tex.stackexchange.com/questions/355455/style-acronyms-long-forms-and-avoid-description-fields-for-those-that-dont-have
\makeatletter
\define@key{mynewabbrv}{description}{\def\mydesc{#1}}
\makeatother
\renewcommand*{\newacronym}[4][]{%
\def\mydesc{}%
\setkeys*{mynewabbrv}{#1}%
\ifdefempty{\mydesc}%
{\newabbreviation[category=withoutdesc,#1]{#2}{#3}{#4}}%
{\newabbreviation[category=withdesc,#1]{#2}{#3}{#4}}%
}
\newglossarystyle{finallistdotted}%
{%
\setglossarystyle{list}%
\renewenvironment{theglossary}%
{%
\begin{description}%
\labelsep=0pt%
}%
{\end{description}}%
\renewcommand*{\glossaryheader}{}
\renewcommand*{\glsgroupheading}[1]{\item[\glsnavhypertarget{##1}{\glsgetgrouptitle{##1}}]%
\mbox{}\par\nobreak\csuse{@afterheading}%
}%
\renewcommand*{\glsgroupskip}{\indexspace}%
\renewcommand{\glossentry}[2]{%
\item[]\makebox[\glslistdottedwidth][l]{%
\glsentryitem{##1}%
\glstarget{##1}{\glsentryshort{##1}%
}%
\unskip\leaders\hbox to 2.9mm{\hss. }\hfill\strut}%
% previous output that worked except for capitalizing the first letters of defined entries
% \glsifcategory{##1}{withoutdesc}%
% {\glsentrylong{##1}}% \Glsentrylong{##1} gives the entry with the first letter capitalized
% {%
% \parbox[t]{\textwidth-\glslistdottedwidth}{\glsentrylong{##1}\space (\glossentrydesc{##1})}% \Glsentrylong{##1} gives the entry with the first letter capitalized
% }%
% my check for user1 -- prints user1 does not print \glsentrylong when user1 is not given and the entry has a description
\glsifcategory{##1}{withoutdesc}%
{\ifglshasfield{useri}{##1}%
{\glsentryuseri{##1}}%
{\glsentrylong{##1}}% \Glsentrylong{##1} gives the entry with the first letter capitalized
}%
{%
\ifglshasfield{useri}{##1}%
{\parbox[t]{\textwidth-\glslistdottedwidth}{\glsentrylong{##1}\space (\glossentrydesc{##1})}}% \Glsentrylong{##1} gives the entry with the first letter capitalized
{\parbox[t]{\textwidth-\glslistdottedwidth}{\glsentryuseri{##1}\space (\glossentrydesc{##1})}}%
}%
}%
}
\makeglossaries
\setabbreviationstyle[withoutdesc]{long-short}
\setabbreviationstyle[withdesc]{long-short-desc}
\renewcommand*{\glsxtrlongshortdescsort}{\the\glsshorttok} % sort by short form
\newcommand{\mymacro}{\textit{my~macro}}
% some stupid examples
\newacronym[]{WOD}{WOD}{Without Description}
\newacronym[]{xyz}{xyz}{xyz}
\newacronym[user1={Haha}]{HAHA}{HAHA}{haha}
\newacronym[description={long form missing}]{ANY}{ANY}{Anything}
\newacronym[description={long form missing}]{macro}{MAKRO}{\mymacro}
\newacronym[description={long form missing -- here I need the lower case in the list of acronyms even for the first letter of the long form, so I can't seem to use \emph{Glsentrylong} in the definition of \emph{finallistdotted} -- that would be too easy!}]{tbd}{tbd}{to be done}
\newacronym[user1={Hoho},description={long form instead of user entry given -- similar to HAHA but with description}]{HOHO}{HOHO}{hoho}
\newacronym[user1={Lowcaseupcase},description={long form instead of user entry given -- \textbf{this should allow lower case (lowcaseupcase) and upper case (Lowcaseupcase) versions in text but print "Lowcaseupcase" in the list of acronyms}}]{LCUC}{LCUC}{lowcaseupcase}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\glssetcategoryattribute{acronym}{glossname}{title}
\begin{document}
\ac{ANY} -- \ac{ANY}
\ac{WOD} -- \ac{WOD}
Pre\acl{LCUC} -- \Acl{LCUC} -- \Ac{LCUC} -- \Acf{LCUC} -- Pre\acl{LCUC} -- Pre-\acs{LCUC}
Pre\acl{HAHA} -- \Acl{HAHA} -- \Ac{HAHA} -- \Acf{HAHA} -- Pre\acl{HAHA} -- Pre-\acs{HAHA}
\Acl{HOHO}
\ac{tbd} -- \acs{tbd} -- \Acl{tbd}. -- \ACS{tbd}! -- \ACL{tbd}!!!
\ac{macro}
\ac{xyz}
\printglossary[type=\acronymtype,style=finallistdotted,title=Abkürzungsverzeichnis,toctitle=Abkürzungsverzeichnis]
\end{document}
user1
) for every entry, which you will use for the glossarystyle?\newacronym
. An entry "lower case" should be printed "lower case", an entry "Upper case" should be printed "Upper case" in the list of acronyms. In the text I also have to use "upper case" in some context, where I have some kind of prefix, like "noupper case". Trying to use theuser1
key is exactly what I was trying in my example. However, it did not work with the styles in the example or if I used styles with "user".