0

Using the acro package I want to use the long version of an acronym as a section title. However, as I title case them, the acronym should also be title cased while being lowercase in the normal text. Doing this with [uppercase/cmd=\ecapitalisewords] works fine for the displayed text, but hyperref complains and the resulting bookmark name in the pdf is uppercase/cmd=]MFA:

\documentclass{article}
\usepackage{acro,mwe,mfirstuc,hyperref}

\DeclareAcronym{MFA}{short=MFA, long=my fancy acronym}

\begin{document}

\section{\Aclp*{MFA}}

To title case the section title I want to use \Aclp*[uppercase/cmd=\ecapitalisewords]{MFA}. However, it results in a hyperref warning:

\begin{verbatim} Package hyperref Warning: Token not allowed in a PDF string (Unicode): (hyperref) removing `\ecapitalisewords' on input line 18. \end{verbatim}

\section{\Aclp*[uppercase/cmd=\ecapitalisewords]{MFA}} % <- This is line 18

\end{document}

I found a different answer (from the package author) but it is nearly eight years old, and the proposed solution does not work for me:

  1. The used \capitalisewords doesn't do anything for me, I have to use the expanding version of the macro.
  2. The option list-caps which seems to tell acro to capitalize all words individually does not exist anymore, and searching for something similar in the documentation does not give any results.

After some more fiddling around, I found something that works for me but is not 100% my desired outcome:

\documentclass{article}
\usepackage{acro,mwe,mfirstuc,hyperref}

\DeclareAcronym{MFA}{short=MFA, long=my fancy acronym} \AddToHook{cmd/subsection/before}{\acsetup{uppercase/cmd=\ecapitalisewords}} \AddToHook{cmd/subsectionmark/after}{\acsetup{uppercase/first}}

\begin{document}

\section{\Aclp{MFA}} \Aclp{MFA}

\subsection{\Aclp{MFA}} \Aclp{MFA}

\end{document}

What I do here is, to automatically set the uppercase/cmd to the desired command before a \section is created and set it back to the standard value after it is done (see this post telling us why we can't use the cmd/subsection/after hook and suggesting subsectionmark instead). In the example code we will see that the section renders as My fancy acronyms while the subsection renders as My Fancy Acronyms just as desired and the paragraph after the subsection is also back to normal.

The drawback: The string that ends up in the PDF table of contents is My fancy acronyms for both the section and subsection. For me this is okay, as I don't care that much about the correct capitalization in the PDF toc.

Artemis
  • 526
  • 1
    well it is hard. acro makes quite an effort to get something in the bookmarks, but if you use an optional argument this is no longer expandable and then it fails. \ecapitalisewords is not expandable either and removed by hyperref too. While it is possible to handle all this with hooks and the expandable text commands in expl3, getting all the variants right (and resetting in subsection) is not trivial, and unless you have lots of them, I would simply write \texorpdfstring{\Aclp*[uppercase/cmd=\ecapitalisewords]{MFA}}{A Fancy Acronym} – Ulrike Fischer Oct 24 '23 at 11:47
  • Thanks for the comment. And you're right, this seems like the most reasonable approach. – Artemis Oct 24 '23 at 16:31

0 Answers0