# Is it possible to use \acrfull \acrshort in the \subsection etc commands [duplicate]

I use the \acrfull \acrshort commands. Sometimes I also used them in the \section, \subsection etc. commands. Now I get the warning:

Token not allowed in a PDF string (Unicode):(hyperref) removing '\acrfull'

Is it possible to get rid of this message and that the correct string is shown in the pdf?

## marked as duplicate by Bobyandbob, Mensch, TeXnician, Andrew Swann, SchweinebackeNov 2 '17 at 16:36

The glossaries manual warns against using commands like \acrfull in section and caption commands.

I strongly recommend that you don’t use the commands defined in this chapter in the arguments of sectioning or caption commands or any other command that has a moving argument.

Aside from problems with expansion issues, PDF bookmarks and possible nested hyperlinks in the table of contents (or list of whatever) any use of the commands described in §6.1 The \gls-Like Commands (First Use Flag Queried) will have their first use flag unset when they appear in the table of contents (or list of whatever).

The above warning is particularly important if you are using the glossaries package in conjunction with the hyperref package. Instead, use one of the expandable commands listed in §9 Using Glossary Terms Without Links (such as \glsentrytext but not the non-expandable case changing versions like \Glsentrytext). Alternatively, provide an alternative via the optional argument to the sectioning/caption command or use hyperref’s \texorpdfstring. Examples:

\chapter{An overview of \glsentrytext{perl}}
\chapter[An overview of Perl]{An overview of \gls{perl}}
\chapter{An overview of \texorpdfstring{\gls{perl}}{Perl}}


If you want to retain the formatting that’s available through commands like \acrshort (for example, if you are using one of the small caps styles), then you might want to consider the glossaries-extra package which provides commands for this purpose.

So with just the base glossaries package, you need something like:

\documentclass{article}

\usepackage{glossaries}
\makeglossaries

\newacronym{html}{HTML}{hypertext markup language}

\begin{document}
\tableofcontents

\section[\glsentrylong{html} (\glsentryshort{html})]{\acrfull{html}}

\acrshort{html}.

\printglossaries
\end{document}


With the glossaries-extra extension package, you can use one of the commands listed in 4. Entries in Sectioning Titles, Headers, Captions and Contents. For example:

\documentclass{article}

\usepackage{glossaries-extra}
\makeglossaries

\setabbreviationstyle[acronym]{long-short}
\newacronym{html}{HTML}{hypertext markup language}

\begin{document}
\tableofcontents

\section{\glsfmtfull{html}}

\glsxtrshort{html}.

\printglossaries
\end{document}


Note that commands like \glsfmtfull don't index or form a hyperlink but they do honour the abbreviation style and they use \texorpdfstring to provide a version for the PDF bookmarks. Compare this with \acrfull which indexes and creates a hyperlink, which means with \section{\acrfull{html}} the entry in the table of contents ends up indexed, as well as every page with the section title in the header.

Note that with glossaries-extra, you can use the short abbreviation style if you don't want the full form on first use, which means you can use the shorter \gls rather than the longer \glsxtrshort:

\documentclass{article}

\usepackage{glossaries-extra}
\makeglossaries

\setabbreviationstyle[acronym]{short}
\newacronym{html}{HTML}{hypertext markup language}

\begin{document}
\tableofcontents

\section{\glsfmtfull{html}}

\gls{html}.

\printglossaries
\end{document}


The full form can be obtained with \glsxtrfull in normal text and \glsfmtfull in section and caption commands.