Capitalising the first letter of an acronym?
Just a couple of macros, with no attempt to give the complete set:
\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}
This is a follow-up to Egreg's answer, basically the full set of \Ac??
commands. Two points to note first:
Somewhere was a stray trailing space that affected
\Acfp
(and the first use of\Acp
) - There was a space before the closing bracket. Oddly, it broke the original\acfp
and\acp
as well, which I'm sure to a finer mind than mine would indicate roughly where in the redefinitions it is. I just terminated pretty much all the lines with a % without paying any attention to what they did.Note the use of
\robustify
(frometoolbox
), which is required if you want to use acronyms in headings (perhaps more likely now they can start with caps)
I don't pretend to understand the code, just that having done Egreg's "exercise for the reader" and found a couple of extra complexities along the way I thought I'd share.
% 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
EDIT: If you want to define your acronyms using \acro
in an acronym
environment, the above code doesn't give you the caps, because the line that stores the acronym is in a different macro and doesn't get replaced with the rather neat definition that Egreg came up with.
The solution is to also patch (well, overwrite) 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}
Edit 2: Note that this 2nd block needs to be inserted into the first block before the last (\makeatother
) line.
An easier approach is simply writing the desired output of the acronym in full, not using any of the acronym
commands to output it, and follow this by \acused{TLA}
.
\acused
Marks an acronym as used, as if it had been called with\ac
, but without printing anything. This means that in the future only the short form of the acronym will be printed.
Although a drawback here is the occurrence of the acronym at this position won't be updated based on earlier/later occurances, other occurances will still be updated based on the current occurance. For shorter texts the overhead of having to track these 'custom' occurances manually might not be severe.