# Problem with acronyms in figure caption using acro package

I'm using the acro package for manage the acronyms. I have been used the \ac{ } command in the figure captions, however, in the \appendix figures, under the following configuration (see MWE below), the acronym is not appearing in the long form even when it is called for the first time. How can I solve it?

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{acro}
\usepackage{blindtext}
\usepackage{setspace}
\DeclareAcronym{PVC}{
short=PVC,
long=Poli Vinil Chloride
}
\begin{document}
\onehalfspacing
\blindtext
\clearpage
\pagebreak
%
\appendix
\begin{center}
\vspace*{\fill}
\section*{Supplementar Files}
\vspace*{\fill}
\end{center}
\clearpage
\pagebreak
%%
\singlespacing
\section{Test}\label{sec:Esquemas-Filtros}
\acresetall
\begin{figure}[htb]
\centering
Dummy text
\caption{Some caption text to ilustrate the problem \ac{PVC}}
\label{fig:label}
\end{figure}
%
\clearpage
\pagebreak
\end{document}


• The problem is unrelated to appendices… \caption processes its argument twice – clemens Sep 22 '17 at 22:48

Edit after @clemens's comment:

If you change your \ac{PVC} to \acf{PVC} you have the same results as with my below code (for this specific example). But may be some day we will learn more from a new better answer...

You can redefine the declare acronym command to save a full name (I call it \ACROfull{} for every ACRO and use it instead of ac)

Before any declaration of acronym place this code:

\let\oldDeclareAcronym=\DeclareAcronym
\def\saveac#1{\xdef\temp{\acl{#1} (\acs{#1})}\global\expandafter\let\csname#1full\endcsname\temp}
\long\def\DeclareAcronym#1#2{\oldDeclareAcronym{#1}{#2}\saveac{#1}}


Then in your caption you can call \PVCfull{} instead of \ac{PVC} and it will print the same as \ac{PVC} out of the caption.

For some reason captions forbids the expansion of acronyms in their environment as far as I understood by trying.

Of course you could just write inside your caption: \acl{#1} (\acs{#1}) instead of all the above declarations and redeclarations.

• You know that acro already provides \acf? – clemens Sep 22 '17 at 22:39
• And of course the real “problem” is that \caption processes its contents twice for measuring the width to be able to center short captions and to align longer captions… – clemens Sep 22 '17 at 22:41
• @clemens I don't know... Just provided that solution after realized that the \ac command could not be expanded in the caption... Feel free to write a better answer and I will recommend to the OP to select yours. – koleygr Sep 22 '17 at 22:43
• I probably won't have the time for the next few days :( – clemens Sep 22 '17 at 22:45
• @clemens: It is a matter of seconds... Please... just copy paste OP's code and add an f on his \ac... I checked it and of course it works. – koleygr Sep 22 '17 at 22:48

The problem is that article typesets the caption differently depending on its length. If the caption is longer than one line it is typeset justified spanning the whole length otherwise it is centered. For this the caption is first put inside a box:

\long\def\@makecaption#1#2{%
\vskip\abovecaptionskip
\sbox\@tempboxa{#1: #2}%
\ifdim \wd\@tempboxa >\hsize
#1: #2\par
\else
\global \@minipagefalse
\hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
\fi
\vskip\belowcaptionskip}


This means if the acronym is used for the first time inside a box (\sbox\@tempboxa{#1: #2}) and its width exceeds \hsize then when the caption is typeset (#1: #2\par) the acronym is not used for the first time any more! What's worse: the caption may not even be longer than \hsize any more! The following document demonstrates this:

\documentclass[12pt,a4paper]{article}
\usepackage{acro}

\DeclareAcronym{PVC}{
short = PVC,
long = Poli Vinil Chloride
}

\usepackage{showframe}

\begin{document}

\begin{figure}[h]
\caption{Some caption text to illustrate the problem \ac{PVC}}
\end{figure}
\acresetall

\begin{figure}[h]
\caption{\ac{PVC}}
\end{figure}

\end{document}


Provided you don't use any package which redefines \@makecaption and stick with the article class we can modify the definition of \@makecaption ourselves:

\documentclass[12pt,a4paper]{article}
\usepackage{acro}

\DeclareAcronym{PVC}{
short = PVC,
long = Poli Vinil Chloride
}

\makeatletter
\renewcommand\@makecaption[2]{%
\vskip\abovecaptionskip
\sbox\@tempboxa{\acswitchoff#1: #2}% <<<<<
\ifdim \wd\@tempboxa >\hsize
#1: #2\par
\else
\global \@minipagefalse
\hb@xt@\hsize{\hfil#1: #2\hfil}% <<<<<
\fi
\vskip\belowcaptionskip}
\makeatother

\usepackage{showframe}

\begin{document}

\begin{figure}[h]
\caption{Some caption text to illustrate the problem \ac{PVC}}
\end{figure}
\acresetall

\begin{figure}[h]
\caption{\ac{PVC}}
\end{figure}

\end{document}


• +1 For the analytic explanation and the solution. But to be honset I am not in place to understand everything. Have done similar things using minipages... But this is something more than my current knowledge. – koleygr Sep 23 '17 at 14:27