I have a scenario where xparse's \NewDocumentCommand has a regression compared to any alternative I know, including ones defining robust commands. So I'm avoiding \NewDocumentCommand in this case, but I would like to understand where the problem lies.
I am trying to understand the difference between robust commands and commands defined by \NewDocumentCommand, from the point of view of hyperref's processing of bookmarks. Consider the following MWE and the comments inside.
\documentclass{article}
\usepackage{xparse}
\usepackage[T1]{fontenc}
\usepackage[utf8x]{inputenc}
\usepackage[unicode=true]{hyperref}
\usepackage{bookmark}
% The problem appears also without bookmark, but you need to compile twice to
% see the correct result.
% Allow using \lambda in section headers, in two parts.
% Part one (no problem here):
\PrerenderUnicode{λ}
% Part two:
% Problem: The following command can be robust, but cannot be defined via
% \NewDocumentCommand.
% All these definitions work:
%\def\TitleLambda{\texorpdfstring{$\lambda$}{λ}}
%\newcommand{\TitleLambda}{\texorpdfstring{$\lambda$}{λ}}
%\DeclareRobustCommand{\TitleLambda}{\texorpdfstring{$\lambda$}{λ}}
% This one doesn't:
\NewDocumentCommand{\TitleLambda}{}{\texorpdfstring{$\lambda$}{λ}}
% Done!
\begin{document}
\section{The \TitleLambda{}-calculus}
\end{document}
The above MWE gives the warning:
Package hyperref Warning: Token not allowed in a PDF string (Unicode):
(hyperref) removing `\TitleLambda' on input line 34.
As a consequence, the bookmark in the resulting file will contain no lambda character, unlike intended.
Replacing \NewDocumentCommand by any alternative avoids the problem. So the problem does not happen simply because \NewDocumentCommand defines robust commands, though what is happening appears similar.
I've even tested using \def + \MakeRobustCommand from the makerobust package:
\usepackage{makerobust}
\MakeRobustCommand\TitleLambda
and everything still worked.
Who's at fault? I see three possibilities:
- me;
- xparse;
- hyperref.
Edit: I should have phrased my question better. I'm mainly curious about what happens, given that I have a working solution.

\NewDocumentCommandcreates a robust command similarly to\DeclareRobustCommand, buthyperrefdoesn't know how to deal with it. You just need\newcommand. – egreg Nov 07 '13 at 23:54hyperrefwould need to add explicit support for\NewDocumentCommand? How inelegant. – Blaisorblade Nov 07 '13 at 23:55\DeclareExpandableDocumentCommand. – Bruno Le Floch Nov 08 '13 at 02:04xparseis how to handle 'might need to be expandable' in a general manner. At present, we've not got a good plan for that (it's OK in your case but what about commands with optional arguments, etc.). – Joseph Wright Nov 08 '13 at 07:03