3

I am trying to use the acronym package together with subcaption. However, even in figures where I am not using subcaptions, the acronyms don't work correctly.

MWE:

\documentclass[11pt]{report}
\usepackage[withpage, printonlyused]{acronym}
\usepackage{subcaption}

\begin{document}

    \ac{FYI}.

    \begin{figure}
        \caption{\ac{TLA}}
    \end{figure}

    \begin{acronym}[TLA]
        \acro{FYI}{for your information}
        \acro{TLA}{three-letter acronym}
    \end{acronym}

\end{document}

mwe

As you can see,

  1. TLA is not expanded in the caption despite that being the first use
  2. TLA is included in the list, but there is no page number (this is the one I care about more)

I have discovered a workaround for (2):

        \caption{\ac{TLA}\protect\label{acro:TLA}}

However, I tried adding this \protect in the expansion of \ac itself (on this line), and that had no effect, which is quite strange.

By tracing the compilation, I can see \protected@write\@auxout... being expanded, but it doesn't actually write to the aux file. Does subcaption redefine things to swallow aux output somehow?

  • Try \caption[TLA]{\ac{TLA}} – Nicola Talbot Apr 27 '18 at 10:43
  • @NicolaTalbot neither \caption[TLA]{\ac{TLA}} nor \caption[\ac{TLA}]{\ac{TLA}} show any difference. – durka42 Apr 29 '18 at 23:59
1

Without caption/subcaption package, the caption text will be evaluated one time if it fits into a single line and twice if it does not. When using the caption/subcaption package the caption text will always be evaluated twice.

The problem here is that \ac will be evaluated twice but only the 2nd evaluation is actually typeset. One can force this problem without caption/subcaption package simply by using a longer caption:

\documentclass[11pt]{report}
\usepackage[withpage, printonlyused]{acronym}

\begin{document}

    \ac{FYI}.

    \begin{figure}
        \caption{\ac{TLA} -- And some more text so the caption text will be evaluated twice.}
    \end{figure}

    \begin{acronym}[TLA]
        \acro{FYI}{for your information}
        \acro{TLA}{three-letter acronym}
    \end{acronym}

\end{document}

A dirty workaround would be suppressing the 1st evaluation of \ac, for example:

\documentclass[11pt]{report}
\usepackage[withpage, printonlyused]{acronym}

\usepackage{caption}
\makeatletter
\g@addto@macro\caption@prepareslc{%
  \let\ac\@firstofone}
\makeatother

\begin{document}

    \ac{FYI}.

    \begin{figure}
        \caption{\ac{TLA} -- And some more text so the caption text will be evaluated twice.}
    \end{figure}

    \begin{acronym}[TLA]
        \acro{FYI}{for your information}
        \acro{TLA}{three-letter acronym}
    \end{acronym}

\end{document}

While this seems to work fine it solves one problem but creates a new one: The single-line-check is now not working correctly if \ac is used for the 1st time - this could lead to incorrect aligned captions. For example:

\documentclass[11pt]{report}
\usepackage[withpage, printonlyused]{acronym}

\usepackage{caption}
\makeatletter
\g@addto@macro\caption@prepareslc{%
  \let\ac\@gobble}
\makeatother

\begin{document}

    \ac{FYI}.

    \begin{figure}
        \caption{\ac{TLA} -- And some more text and some more text.}
    \end{figure}

    \begin{acronym}[TLA]
        \acro{FYI}{for your information}
        \acro{TLA}{three-letter acronym}
    \end{acronym}

\end{document}

Since a proper solution would be adapting the caption package to the acronym package I just filled a bug report here:

https://github.com/axelsommerfeldt/caption/issues/10

Addendum

I just found some time to take a look at the source of acronym and found out that re-defining \acused and the internal command \AC@placelabel for the single-line-check seems to be a proper solution. For example this document gives proper caption justification now:

\documentclass[11pt]{report}
\usepackage[withpage, printonlyused]{acronym}

\usepackage{caption}
\makeatletter
\g@addto@macro\caption@prepareslc{%
  \let\acused\@gobble
  \let\AC@placelabel\@gobble}
\makeatother

\begin{document}

    \ac{FYI}.

    \begin{figure}
        \caption{\ac{TLA} -- And some more text and some more text.}
    \end{figure}

    \begin{acronym}[TLA]
        \acro{FYI}{for your information}
        \acro{TLA}{three-letter acronym}
    \end{acronym}

\end{document}

Please let me know if everything is fine using this solution -- If yes I would like to put this patch into the caption package. (If not, I would like to improve the patch.) Thanks!

  • Well, you certainly seem like the one best positioned to answer this. Thanks! This seems like a slightly more general problem though (any command that relies on aux output, not just acronym), so it's a shame that the best solution is to add acronym-specific hacks. – durka42 May 15 '18 at 16:30
  • The dirty workaround is working fine for now. – durka42 May 15 '18 at 17:31
  • 1
    @durka42 Yes, the double evaluation of longer caption texts is a general problem which the command \ac from acronym has in common with \footnotemark, \endnotemark, \pagenote, the command \ac from the glossaries package, and many more which set flags or increase counters globally. So I try to re-define them all during the 1st evaluation of the caption text within my caption package, so the double evaluation does not make any harm. BTW: I just added a better solution to my answer, please try it out, feedback would make me happy ;-) – user2574 May 15 '18 at 20:01
  • Seems to work as well! – durka42 May 16 '18 at 0:20
  • @durka42 Thanks for testing and feedback! I'll push this patch to CTAN as soon as I have fixed tex.stackexchange.com/questions/430317 as well. – user2574 May 16 '18 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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