![将首字母缩略词的首字母大写?](https://linux22.com/image/257836/%E5%B0%86%E9%A6%96%E5%AD%97%E6%AF%8D%E7%BC%A9%E7%95%A5%E8%AF%8D%E7%9A%84%E9%A6%96%E5%AD%97%E6%AF%8D%E5%A4%A7%E5%86%99%EF%BC%9F.png)
acronym
我在文档中使用该包,在很多情况下,我想用扩展的首字母缩写词开始一个句子。有什么方法可以让包将首字母大写吗?
例如:
\acrodef{TLA}{three-letter acronym}
\acrodefplural{TLA}{three-letter acronyms}
...end of one sentence. \aclp{TLA} are acronyms with three letters...
这将产生:
...一个句子的结束。三个字母的缩写词是带有三个字母的缩写词...
答案1
这是 Egreg 回答的后续内容,基本上是完整的\Ac??
命令集。首先要注意两点:
某处
\Acfp
是一个影响(和第一次使用)的杂散尾随空格\Acp
- 在结束括号之前有一个空格。奇怪的是,它还破坏了原来的\acfp
和\acp
,我相信比我更聪明的人会大致指出它位于重新定义的位置。我只是用 % 终止了几乎所有的行,而没有注意它们做了什么。请注意使用
\robustify
(frometoolbox
),如果您想在标题中使用首字母缩略词,则必须使用 (from)(现在它们可以以大写字母开头)
我并不假装理解代码,只是在完成了 Egreg 的“读者练习”并发现了一些额外的复杂性之后,我想与大家分享。
% Extend acronym package with first letter caps
\makeatletter
\newif\ifAC@uppercase@first%
\def\Aclp#1{\AC@uppercase@firsttrue\aclp{#1}\AC@uppercase@firstfalse}%
\def\AC@aclp#1{%
\ifcsname fn@#1@PL\endcsname%
\ifAC@uppercase@first%
\expandafter\expandafter\expandafter\MakeUppercase\csname fn@#1@PL\endcsname%
\else%
\csname fn@#1@PL\endcsname%
\fi%
\else%
\AC@acl{#1}s%
\fi%
}%
\def\Acp#1{\AC@uppercase@firsttrue\acp{#1}\AC@uppercase@firstfalse}%
\def\AC@acp#1{%
\ifcsname fn@#1@PL\endcsname%
\ifAC@uppercase@first%
\expandafter\expandafter\expandafter\MakeUppercase\csname fn@#1@PL\endcsname%
\else%
\csname fn@#1@PL\endcsname%
\fi%
\else%
\AC@ac{#1}s%
\fi%
}%
\def\Acfp#1{\AC@uppercase@firsttrue\acfp{#1}\AC@uppercase@firstfalse}%
\def\AC@acfp#1{%
\ifcsname fn@#1@PL\endcsname%
\ifAC@uppercase@first%
\expandafter\expandafter\expandafter\MakeUppercase\csname fn@#1@PL\endcsname%
\else%
\csname fn@#1@PL\endcsname%
\fi%
\else%
\AC@acf{#1}s%
\fi%
}%
\def\Acsp#1{\AC@uppercase@firsttrue\acsp{#1}\AC@uppercase@firstfalse}%
\def\AC@acsp#1{%
\ifcsname fn@#1@PL\endcsname%
\ifAC@uppercase@first%
\expandafter\expandafter\expandafter\MakeUppercase\csname fn@#1@PL\endcsname%
\else%
\csname fn@#1@PL\endcsname%
\fi%
\else%
\AC@acs{#1}s%
\fi%
}%
\edef\AC@uppercase@write{\string\ifAC@uppercase@first\string\expandafter\string\MakeUppercase\string\fi\space}%
\def\AC@acrodef#1[#2]#3{%
\@bsphack%
\protected@write\@auxout{}{%
\string\newacro{#1}[#2]{\AC@uppercase@write #3}%
}\@esphack%
}%
\def\Acl#1{\AC@uppercase@firsttrue\acl{#1}\AC@uppercase@firstfalse}
\def\Acf#1{\AC@uppercase@firsttrue\acf{#1}\AC@uppercase@firstfalse}
\def\Ac#1{\AC@uppercase@firsttrue\ac{#1}\AC@uppercase@firstfalse}
\def\Acs#1{\AC@uppercase@firsttrue\acs{#1}\AC@uppercase@firstfalse}
\robustify\Aclp
\robustify\Acfp
\robustify\Acp
\robustify\Acsp
\robustify\Acl
\robustify\Acf
\robustify\Ac
\robustify\Acs
\makeatother
编辑:如果您想\acro
在acronym
环境中定义您的首字母缩略词,上述代码不会为您提供大写字母,因为存储首字母缩略词的行位于不同的宏中,并且不会被 Egreg 提出的相当简洁的定义所取代。
解决方案也是修补(好吧,覆盖)acro
:
\def\AC@@acro#1[#2]#3{%
\ifAC@nolist%
\else%
\ifAC@printonlyused%
\expandafter\ifx\csname acused@#1\endcsname\AC@used%
\item[\protect\AC@hypertarget{#1}{\acsfont{#2}}] #3%
\ifAC@withpage%
\expandafter\ifx\csname r@acro:#1\endcsname\relax%
\PackageInfo{acronym}{%
Acronym #1 used in text but not spelled out in
full in text}%
\else%
\dotfill\pageref{acro:#1}%
\fi\\%
\fi%
\fi%
\else%
\item[\protect\AC@hypertarget{#1}{\acsfont{#2}}] #3%
\fi%
\fi%
\begingroup
\def\acroextra##1{}%
\@bsphack
\protected@write\@auxout{}%
{\string\newacro{#1}[\string\AC@hyperlink{#1}{#2}]{\AC@uppercase@write #3}}%
\@esphack
\endgroup}
编辑2:请注意,第二个块需要插入到第一个块中前最后(\makeatother
)行。
答案2
Acronym 1.42 添加了\Ac{p,f,fp,fi,l,lp,lu}
命令。它们的工作方式与命令完全相同\ac
,但会打印全名,以大写字母开头(以防用小写字母定义)。感谢 Oz Davidi!
\Ac{TLA} at the beginning of a sentence instead of \ac{TLA} as normal.
答案3
仅几个宏,不尝试提供完整的集合:
\documentclass{article}
\usepackage{acronym}
\makeatletter
\newif\ifAC@uppercase@first
\def\Aclp#1{\AC@uppercase@firsttrue\aclp{#1}\AC@uppercase@firstfalse}
\def\AC@aclp#1{%
\ifcsname fn@#1@PL\endcsname
\ifAC@uppercase@first
\expandafter\expandafter\expandafter\MakeUppercase\csname fn@#1@PL\endcsname
\else
\csname fn@#1@PL\endcsname
\fi
\else
\AC@acl{#1}s
\fi
}
\edef\AC@uppercase@write{\string\ifAC@uppercase@first\string\expandafter\string\MakeUppercase\string\fi\space}
\def\AC@acrodef#1[#2]#3{%
\@bsphack
\protected@write\@auxout{}{%
\string\newacro{#1}[#2]{\AC@uppercase@write #3}%
}\@esphack
}
\def\Acl#1{\AC@uppercase@firsttrue\acl{#1}\AC@uppercase@firstfalse}
\makeatother
\acrodef{TLA}{three-letter acronym}
\acrodefplural{TLA}{three-letter acronyms}
\begin{document}
\Aclp{TLA} are acronyms with three letters.
\Acl{TLA} at the start of another sentence.
\end{document}
答案4
如果您愿意切换包,可以采用另一种方法:
\documentclass{article}
\usepackage[shortcuts,acronyms]{glossaries-extra}
\newacronym{TLA}{TLA}{three-letter acronym}
\begin{document}
...end of one sentence. \Aclp{TLA} are acronyms with three
letters...
\printunsrtglossary[type=\acronymtype]
\end{document}
生成:
...一个句子的结尾。三字母缩写词是带有三个字母的缩写词...
缩略词
TLA 三个字母的缩写