10

When using the acronym package I would like to capitalize the first letter in the acronym description (e.g., Direct current). But when used in text I would like to have the word in lower letters.

\documentclass{article}
\usepackage{acronym}

\begin{document}
\begin{acronym}
\acro{DC}{direct current}
\end{acronym}

Batteries run on \ac{DC}.
\end{document}

Output:

DC direct current

Batteries run on direct current (DC).

lockstep
  • 250,273
Torstein I. Bø
  • 253
  • 3
  • 7

2 Answers2

8

You can patch the \AC@@acro macro that's responsible for printing the list of acronyms:

\documentclass{article}
\usepackage{acronym}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\AC@@acro}{] #3}{] \MakeUppercase #3}{}{}
\patchcmd{\AC@@acro}{] #3}{] \MakeUppercase #3}{}{}
\makeatother

%%% Alternative way (commented out because you may not have the package) % \usepackage{regexpatch} % \makeatletter % \xpatchcmd*{\AC@@acro}{] #3}{] \MakeUppercase #3}{}{} % \makeatother

\begin{document} \begin{acronym} \acro{DC}{direct current} \end{acronym}

Batteries run on \ac{DC}. \end{document}

Update

With the most recent (2020) release of acronym things have changed (and may also change in the future). The right patch, current as of December 2020 is

\documentclass{article}
\usepackage{acronym}
\usepackage{etoolbox}
\makeatletter
\expandafter\patchcmd\csname AC@\AC@prefix{}@acro\endcsname{{#3}}{{\MakeUppercase #3}}{}{}
\expandafter\patchcmd\csname AC@\AC@prefix{}@acro\endcsname{{#3}}{{\MakeUppercase #3}}{}{}
\makeatother

\begin{document} \begin{acronym} \acro{DC}{direct current} \end{acronym}

Batteries run on \ac{DC}. \end{document}

enter image description here

egreg
  • 1,121,712
  • How to capitalize the first letter of each word when printing the list of acronyms using glossaries package? But need to have lower case when used in text. – Sndn Mar 24 '19 at 09:21
  • @Sndn That's a whole new question. – egreg Mar 24 '19 at 09:52
  • https://tex.stackexchange.com/questions/481302/capitalize-first-letter-of-each-word-when-printing-list-of-acronyms – Sndn Mar 25 '19 at 06:31
  • Note: As of TexLive 2020, this appears to no longer work. It seems that \AC@@acro is not patchable anymore? (\ifpatchable*{\AC@@acro}{yes}{no} prints "no" and I don't know enough to work around it). – Disenchanted Lurker Dec 18 '20 at 10:30
  • @DisenchantedLurker Thanks for the call for action! – egreg Dec 18 '20 at 10:56
  • @egreg Wow, thank you, that was fast! – Disenchanted Lurker Dec 18 '20 at 11:07
  • Thanks a lot for your solution, that was really useful. As a side note, using \expandafter\patchcmd\csname AC@\AC@prefix{}@acro\endcsname{{#3}}{\capitalisewords{#3}}{}{} with the mfirstuc package allows you to capitalise all the first letters of each word in the list of acronyms. – DavideM Oct 06 '21 at 13:34
4

A suggestion can be to define a new Command:

\documentclass{article}
\usepackage{acronym}

\begin{document}
\newcommand*\FirstLetter[2]{#1}
\begin{acronym}
\acro{DC}{\protect\FirstLetter{D}{d}irect current}
\end{acronym}
\renewcommand*\FirstLetter[2]{#2}

Batteries run on \ac{DC}.
\end{document}

Result:

DC Direct current

Batteries run on direct current (DC).

Do work without \protect inside \acronym you can make the definition with expl3:

\ExplSyntaxOn
\cs_new_protected:Npn \FirstLetter #1#2 { #1 }
\ExplSyntaxOff

\ExplSyntaxOn
\cs_set_protected:Npn \FirstLetter #1#2 { #2 }
\ExplSyntaxOff
Marco Daniel
  • 95,681