# Quotes in PDF bookmarks when using polyglossia

I am creating a multilingual document, using polyglossia. I would like to include quoted text in a section title, using csquotes, and I would also like to have a PDF bookmark tree in the final file, one bookmark per section, using bookmark. Finally, I am also using polyglossia's babel-style shorthands (babelshorthands=true).

The following MWE fails:

\documentclass{article}
\usepackage{polyglossia}
\setmainlanguage[babelshorthands=true]{german}
\usepackage{csquotes}
\usepackage{bookmark}
\begin{document}
\section{This works}
\section{\enquote{This breaks}}
\end{document}


The error message is as follows:

! Argument of \language@active@arg" has an extra }.
<inserted text>
\par
l.10 \section{\enquote{This breaks}}
[...]


Googling has led me to conclude that the babel shorthands are at issue here (indeed, not enabling them gets rid of the error), and that I should disable the " shorthand before the section title, then re-enable it, using \shorthandoff and \shorthandon respectively (these are babel commands also supplied by polyglossia; in fact, babel's own documentation specifically recommends these for the above error):

\documentclass{article}
\usepackage{polyglossia}
\setmainlanguage[babelshorthands=true]{german}
\usepackage{csquotes}
\usepackage{bookmark}
\begin{document}
\section{This works}
\shorthandoff{"}%
\section{\enquote{This breaks}}
\shorthandon{"}%
\end{document}


However, this still results in the same error message as above.

Using babel itself instead of polyglossia works; the following:

\documentclass{article}
\usepackage[german]{babel}
\usepackage{csquotes}
\usepackage{bookmark}
\begin{document}
\section{This works}
\shorthandoff{"}%
\section{\enquote{This breaks}}
\shorthandon{"}%
\end{document}


produces the desired output without any errors. Alternatively, using polyglossia also works (even without disabling the " shorthand) so long as the bookmark package isn't loaded.

My questions are, thus:

1. is this a bug in polyglossia that I should report (\shorthandoff and \shorthandon not working as desired), and/or in bookmark?, and
2. since I would prefer to keep using both polyglossia and babel shorthands while also retaining the quote in the section title and the PDF bookmarks, is there another work-around for the original error that would allow this, or is this a case of "given X, pick any (X-1)"?

• (1) welcome, (2) the issue here is the bookmarks, it generally does not like handling latex macros, the normal \texorpdfstring{for PDF}{for bookmark} works with your example. Generally bookmarks want unicode only and thus attempts to filter away left behind macros. And it probably does not like active chars one bit. – daleif Sep 14 '18 at 14:59
• With babel in place of polyglossia you don't need \shorthandoff. But the bookmarks quotes are not the German ones (whether or not using \shorthandoff). – user4686 Sep 14 '18 at 15:18

Load the language later. The option babelshorthands=true makes the shorthand directly active and so disturbs packages loaded later:

\documentclass{article}
\usepackage{polyglossia}
\usepackage{csquotes}
\usepackage{bookmark}

\setmainlanguage[babelshorthands=true]{german}
\begin{document}
\section{This works}
\section{\enquote{This breaks}}
\end{document}

• There should be a tag for load-order or package-loading or package-order or something like that. It's pretty prominently important in some cases. – thymaro Sep 19 '18 at 22:19