# Bookmarks with Unprocessed Commands from chemnum and chemmacros

In my document, I have sections that contain chemmacros \iupac{} command with shorthands provided by chemmacros | as well as my own shorthand =. For some reason, these shorthands are printed in the bookmarks.
I also use chemnums \cmpd{} command, but instead of the number, the compounds label is printed in the bookmarks.

MWE:

\documentclass{scrbook}
\usepackage{chemmacros,chemnum}
\newcommand{\nbh}{\mbox{-}\nobreak\hspace{0pt}} % da \mbox in \iupac problematisch ist, neuer Befehl für non-breaking hyphens
\NewChemIUPACShorthand{=}{\nbh}
\begin{document}
\tableofcontents
\section{\iupac{2=(Phenyl|thio)oxazole}~(\cmpd{Ox-SPh})}
\end{document}


As you can see, the content is printed correctly in the table of contents. I would like to have the same processed output for my bookmarks, though. How can I achieve this?

I think you need to use \texorpdfstring{❬TEXstring❭}{❬PDFstring❭} macros from hyperref. In PDFstring you need to do two things:

• replace \cmpd{...} with \cmpdplain{...};
• don't use \iupac{...}, plain text only (who needs hyphenation in PDF bookmarks, anyways:) ).

\cmpdplain{❬id❭}

Reads a label and writes it expandably without formatting. It is not able to parse a list. Its sole purpose is usage in pdf strings (cf. \texorpdfstring{❬TEX❭}{❬pdf string❭})

\documentclass{scrbook}
\usepackage{chemmacros,chemnum}
\newcommand{\nbh}{\mbox{-}\nobreak\hspace{0pt}} % da \mbox in \iupac problematisch ist, neuer Befehl für non-breaking hyphens
\NewChemIUPACShorthand{=}{\nbh}
\begin{document}
\tableofcontents
\section{
\texorpdfstring{
\iupac{2=(Phenyl|thio)oxazole}~(\cmpd{Ox-SPh})
}{
2-(Phenylthio)oxazole~(\cmpdplain{Ox-SPh})
}
}
\end{document}


• That's brilliant! I tried to use the square brackets of \subsection[]{}, but I lost the bold numbers in the ToC if I only used \cmpdplain. \texorpdfstring avoids this problem. Nice! Btw: The \iupac command was used to prevent longer compound names (which I didn't consider in the question) from being split in the wrong places (e.g. after a number). This function is of course not needed in the bookmarks but might be needed in the ToC or section headings. – basseur Dec 20 '18 at 21:51
• I'd like to add: If there is a compound with sub-labels, you can use \submaincmpdplain{<main id>}{<sub id>}, as \cmpdplain will not work with sub-labels. To just print the sub-label only use \subcmpdplain{<main id>}{<sub id>}. – basseur Mar 27 '19 at 22:18