21

I'm using the acronym package in my document and in several instances I want to start a sentence with the expanded acronym. Is there any way of telling the package to capitalise the first letter?

For example:

\acrodef{TLA}{three-letter acronym}
\acrodefplural{TLA}{three-letter acronyms}
...end of one sentence. \aclp{TLA} are acronyms with three letters...

This will yield:

...end of one sentence. three-letter acronyms are acronyms with three letters...

2
  • @Stefan That seems to be asking how to capitalise the first letter in the acronym list; I want a way to optionally capitalise the first letter of the expanded acronym when used in text (and I'm not sure how to adapt what was suggested in the answers for my purposes). I was hoping there'd be a family of commands like \Acl, \Acf, etc. that would do this, but it seems there isn't. (Maybe the author should introduce these?) Nov 1, 2012 at 16:47
  • Maybe you can use this: latex-community.org/forum/viewtopic.php?f=5&t=9966 Nov 2, 2012 at 23:56

5 Answers 5

7

This is a follow-up to Egreg's answer, basically the full set of \Ac?? commands. Two points to note first:

  1. 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.

  2. Note the use of \robustify (from etoolbox), 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.

18
  • This is ideal, thanks. Do you mind if I point one of the maintainers to this post so that it might be integrated into the package? Dec 20, 2013 at 15:40
  • @WillVousden Of course not, go ahead - but they may have a better way of building it in rather than patching.
    – Chris H
    Dec 20, 2013 at 15:50
  • Of course, it would be nice to have a version that capitalises all first letters, or even some cleverer title case version, maybe even configurable. And it would be a good learning exercise for me. When I wouldn't be using it as an excuse for neglecting my thesis.
    – Chris H
    Jan 6, 2014 at 9:02
  • This does not work for me. Mar 1, 2015 at 19:48
  • @alpha-beta-soup, what happens? I suggest a new question to give you room to post an MWE. I haven't looked at this for a year now but should stitch together all my acronym mods into one file at some point.
    – Chris H
    Mar 1, 2015 at 19:55
9

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}

enter image description here

9

Acronym 1.42 adds the \Ac{p,f,fp,fi,l,lp,lu} commands. They work exactly the same way as the \ac commands, but prints the full name, starting with an upper case letter (in case it was defined with a lower case letter). Thanks to Oz Davidi!

\Ac{TLA} at the beginning of a sentence instead of \ac{TLA} as normal.
4

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.

2

An alternative approach if you're happy to switch packages:

\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}

Produces:

...end of one sentence. Three-letter acronyms are acronyms with three letters...

Acronyms

TLA three-letter acronym

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .