Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
    
@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?) –  Will Vousden Nov 1 '12 at 16:47
    
Maybe you can use this: latex-community.org/forum/viewtopic.php?f=5&t=9966 –  Hans-Peter E. Kristiansen Nov 2 '12 at 23:56

2 Answers 2

up vote 2 down vote accepted

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}
share|improve this answer
    
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? –  Will Vousden Dec 20 '13 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 '13 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 at 9:02

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.