How can \newrobustcmd and NewDocumentCommand be used in section titles with hyperref enabled? The MWE below shows that, while the rendered PDF looks correct, the bookmarks do not show the macro contents.
\documentclass[11pt]{article}
\usepackage{hyperref}
\usepackage{xparse}
\usepackage{etoolbox}
\newcommand{\testA}[0]{world}
\newrobustcmd{\testB}[0]{world}
\NewDocumentCommand{\testC}{}{world}
\begin{document}
\section{Hello \testA}
\section{Hello \testB}
\section{Hello \testC}
\end{document}
The MWE.out file looks as follows.
\BOOKMARK [1][-]{section.1}{Hello world}{}% 1
\BOOKMARK [1][-]{section.2}{Hello }{}% 2
\BOOKMARK [1][-]{section.3}{Hello }{}% 3

\newrobustcmdis to not expand the macro in\edef, which is whathyperrefdoes for bookmarks;\NewDocumentCommanddoes the same. So what you get is expected. Why should you define those macros as robust? – egreg Apr 12 '17 at 13:20\section{Hello \protect\testa}for the\newcommandversion is a bypass in order to prevent breaking apart during the writing process to the.auxfile concerning the ToC and still having the expanded\testain the bookmarks (assuming that\testaexpands to valid content for the bookmarks, however) – Apr 12 '17 at 13:39