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:
- The used
\capitalisewords
doesn't do anything for me, I have to use the expanding version of the macro. - The option
list-caps
which seems to tellacro
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.