# Using \MakeUppercase on expanded macro with argument

I would like to have the first letter in an expanded macro shifted to upper case but I can not seem to manage this. In the minimal example below, I would like the two rows to produce the same output, first letter capitalized, but the second row has all letters in lower case.

\documentclass[a4paper, 10pt]{report}
\usepackage[utf8]{inputenc}
\usepackage[printonlyused]{acronym}
\usepackage{etoolbox}

%%% Begin document
\begin{document}

\begin{acronym}
\acro{rms}{root mean square}
\end{acronym}

\section{Text}
\MakeUppercase root mean square (\acs{rms})

\expandafter\MakeUppercase\expandafter\empty\ac{rms}

\end{document}


How can I solve this?

Edit:

It appears that the minimal example was to minimal. The suggested solution does not work with the rest of the document. Here is a more complete minimal example.

\documentclass[a4paper, 10pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{acronym}
\usepackage{etoolbox}

\newif\ifAcUpper
\AcUpperfalse

\makeatletter
\patchcmd{\AC@@acro}{] #3}{] \expandafter\MakeUppercase #3}{}{}
\patchcmd{\AC@@acro}{] #3}{] \expandafter\MakeUppercase #3}{}{}
\makeatother

\newif\ifACR
\ACRfalse

\makeatletter
\newcommand{\acx}{\protect\@acx}%
\newcommand{\@acx}[1]{%
\ifAC@dua
\acl{#1}%
\else
\expandafter\ifx\csname ac@#1\endcsname\AC@used
\acs{#1}%
\else
\acl{#1}%
\fi
\fi
}

\newcommand{\acy}{\protect\@acy}%
\newcommand{\@acy}[1]{%
\ifACR
\acl{#1}%
\else
\acf{#1}
\fi
}

\newcommand{\dac}{\protect\@dac}%
\newcommand{\@dac}[1]{%
\ifAC@dua
the \acl{#1}%
\else
\expandafter\ifx\csname ac@#1\endcsname\AC@used
\acs{#1}%
\else
the \acf{#1}%
\fi
\fi
}

\newcommand{\Dac}{\protect\@Dac}%
\newcommand{\@Dac}[1]{%
\ifAC@dua
The \acl{#1}%
\else
\expandafter\ifx\csname ac@#1\endcsname\AC@used
\acs{#1}%
\else
The \acf{#1}%
\fi
\fi
}

\newcommand{\Ac}{\@Ac}%
\newcommand{\@Ac}[1]{%
\ifAC@dua
\acl{#1}%
\else
\expandafter\ifx\csname ac@#1\endcsname\AC@used
\acs{#1}%
\else
\expandafter\MakeUppercase\expandafter\empty\ac{#1}
\fi
\fi
}
\makeatother

%%% Begin document
\begin{document}

\begin{acronym}
\ACRtrue
\acro{dc}[DC]{Direct Current}
\acro{pu}[p.u.]{per unit}
\acro{rms}[rms]{root-mean-square}
\acro{b}[$B$]{magnetic flux density}
\acro{hor}[$H$]{horizontal component of the \acx{b}}
\acro{d}[$D$]{electric displacement of \acx{b}}
\acro{h}[$H$]{magnetic field intensity}
\acro{rdc}[$R_{DC}$]{\acy{dc} resistance}
\acro{phi}[$\phi$]{magnetic flux}
\acro{sbase}[$S_{base}$]{\acy{pu} power base}
\acro{ubase}[$U_{base}$]{\acy{pu} voltage base}
\acro{phibase}[$\Phi_{base}$]{\acy{pu} \acx{phi} base}
\acro{udc}[$U_{DC}$]{\acy{dc} voltage}
\acro{idc}[$I_{DC}$]{\acy{dc} current}
\ACRfalse
\end{acronym}

\section{Text}
\MakeUppercase root mean square (\acs{rms})

\Ac{rms}

\end{document}


For which the output looks like this

I would like the \Ac command to produce a line starting with a capital letter and all descriptions in the list to do the same.

• What's \empty supposed to do? – egreg Aug 27 '15 at 10:14
• \ac does not work by exapnsion, and certainly would require more than one expansion step as produced by \expandafter but also you are just passing \empty as the argument to \MakeUppercase – David Carlisle Aug 27 '15 at 10:14
• I do not know if glossaries could be an option, but with this package you can define \newacronym{rms}{rms}{root mean square} and then use \gls{rms} or \Gls{rms} at the start of a sentence. – Fran Aug 27 '15 at 11:10

You need to insert the uppercasing into the result of \ac, but \ac does not work by expansion so \expandafter does not help. (If it had worked by expansion, your expression would still have been wrong as it passes \empty to \MakeUppercase)

\documentclass[a4paper, 10pt]{report}
\usepackage[utf8]{inputenc}
\usepackage[printonlyused]{acronym}
\usepackage{etoolbox}

%%% Begin document
\begin{document}
\DeclareRobustCommand\zz[1]{#1}
\begin{acronym}

\acro{rms}{\zz{r}oot mean square}

\end{acronym}

\section{Text}
\MakeUppercase root mean square (\acs{rms})

%\expandafter\MakeUppercase\expandafter\empty\ac{rms}

{\renewcommand\zz{\MakeUppercase}\ac{rms}}

\end{document}

• It seems that my minimal example was to minimal. This solution works fine on its own but not in combination with the rest of my document. I will edit the question. – Kajsa Aug 27 '15 at 12:38