I'm not sure whether the order of \texorpdfstring
inside headings matters or if some part of the newcommand
s/NewDocumentCommand
s are messing with my MWE:
% !TeX program = lualatex
\documentclass{scrreprt}
\usepackage{lipsum}
\usepackage{xparse}
\usepackage[hidelinks,%
colorlinks=false, %
linktoc=all,%
plainpages=false,%
pdfpagelabels=true%
]{hyperref}
\usepackage[acronym]{glossaries-extra}
\setabbreviationstyle[acronym]{long-short} % Stil des Abkürzungen im Text
\newacronym{ac:test}{TEST}{Only an acronym for testing purposes}
\NewDocumentCommand{\GT}{m m}{
\S\,#1~#2%
}
\NewDocumentCommand{\TESTGLS}{s m}{%TEST
\IfBooleanTF{#1}{%
\GT{#2}{%
\texorpdfstring{\glsfmtshort{ac:test}}{TEST}%
}%
}{%
\GT{#2}{%
\glsxtrshort{ac:test}%
}%
}%
}
\newcommand{\TEST}[1]{
\texorpdfstring{\S~#1~\glsfmtshort{ac:test}}{\S~#1~TEST}}
\begin{document}
\chapter{Different Tests}
\gls{ac:test}: \lipsum[1]
\section{\texorpdfstring{\S~1~\glsfmtshort{ac:test}}{\S~1~TEST}}
\gls{ac:test}: \lipsum[2]
\section{\TEST{2}}
\gls{ac:test}: \lipsum[3]
\section{\TESTGLS{3}}
\gls{ac:test}: \lipsum[4]
\section{\TESTGLS*{4}}
\gls{ac:test}: \lipsum[5]
\end{document}
In the first two section headings everything is fine, but in the last two (that contain my own commands) I get a warning Token not allowed in a PDF string (Unicode):(hyperref) removing '\TESTGLS'
in both cases.
Looking at the log-file unfortunately didn't reveal any further information for me.
\texorpdfstring
inside robust commands (defined e.g. with\NewDocumentCommand
) hyperref will never see it and it does nothing. You always need something expandable at the outer level: