有很多关于如何使用词汇表将首字母更改为大写的示例(打印首字母缩略词列表时,将每个单词的首字母大写,大写字母和缩写列表,词汇表 每个首字母大写)
就我而言,文本中必须使用一些同时具有小写和大写版本的首字母缩略词,同时在长格式的首字母缩略词列表中使用大写首字母。另一方面,我有一些条目没有大写版本,因此在\Glsentrylong
重新定义样式时我不能简单地使用 ,。
到目前为止,如果长格式为小写,更改文本中的外观没有问题。但是,更改列表中的外观对我来说太难了。我尝试使用 来检查用户条目,但没有成功(即使使用和 和样式\ifglshasfield
也没有成功)。我尝试增加类别和检查的数量(已经为long-short-user
long-short-user-desc
描述)彻底失败了。
在原始版本(注释部分)中,当长格式为小写时,我无法更改首字母缩略词列表中长格式的外观。如果长格式为大写,则我无法在文本中使用小写长格式。使用 withtext={lowcaseupcase}
作为{Lowcaseupcase}
长格式也会在文本中给出长格式。
在当前版本中,我在列表中获得以下输出:
- 给出长格式:打印长格式(好的,参见WOD,xyz)用户输入和
- 给出长格式:打印用户输入(好的,看哈哈)
- 给出描述和长格式:仅打印描述(缺少长格式,请参阅 ANY、MAKRO、tbd)
- 给出了描述、长格式和用户输入:给出了长格式和描述(缺少用户输入,参见 HOHO、LCUC)
有没有办法在文本中使用小写的长形式,而在列表中使用大写形式,而无需将每个条目大写?
一种可能的解决方案是明确将文本中的第一个字母转换为小写(而不是\acl{label}
vs \Acl{label}
),但我担心这意味着要定义很多新命令。也许我错过了一个简单的解决方案......
\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}
答案1
我将集中回答您问题的关键部分(至少我是这么认为的 ^^#)。下面的代码应该可以帮助您指定要为词汇表中的每个条目显示的文本 - 而不考虑是否有大写形式或其他内容。这对您有帮助吗?
PS:您也可以使用user1
,但必须在样式定义中切换\glsglostext{##1}
到。\glsuseri{##1}
\documentclass{scrartcl}
\usepackage[nomain,acronym]{glossaries-extra}
\glsaddkey
{glostext} % new key
{\glsentrytext{TODO}} % default value
{\glsentryglostext} % analogous to \glsentrytext
{\Glsentryglostext} % analogous to \Glsentrytext
{\glsglostext} % analogous to \glstext
{\Glsglostext} % analogous to \Glstext
{\GLSglostext} % analogous to \GLStext
% Define the glossary entries
\newacronym[
glostext={HoHo},
user1={HoHO},
description={long form instead of user entry},
]{HOHO}{HOHO}{hoho}
% Set the new glossary style
\newglossarystyle{yourAcronyms}{%
\setglossarystyle{list}%
\renewcommand*{\glossentry}[2]{%
\item[\glsentryitem{##1}%
\glstarget{##1}{\glossentryname{##1}}]
\glsglostext{##1}\glspostdescription\space ##2}%
}
\makeglossaries
\begin{document}
\glsaddall
\printacronyms[style=yourAcronyms]
\end{document}