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.




% 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):

% Part two:
% Problem: The following command can be robust, but cannot be defined via 
% \NewDocumentCommand.

% All these definitions work:


% This one doesn't:


% Done!

\section{The \TitleLambda{}-calculus}

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:


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.

  • 1
    Motivation: I don't like to use \texorpdfstring directly in the section header, it's distracting for me and coauthors. Commented Nov 7, 2013 at 23:54
  • 1
    It's simple: \NewDocumentCommand creates a robust command similarly to \DeclareRobustCommand, but hyperref doesn't know how to deal with it. You just need \newcommand.
    – egreg
    Commented Nov 7, 2013 at 23:54
  • So hyperref would need to add explicit support for \NewDocumentCommand? How inelegant. Commented Nov 7, 2013 at 23:55
  • @egreg: yours should really be an answer, however short. Commented Nov 7, 2013 at 23:56
  • I think the recommended approach here would be to use \DeclareExpandableDocumentCommand. Commented Nov 8, 2013 at 2:04

1 Answer 1


While hyperref is able to cope with \DeclareRobustCommand, it isn't with \NewDocumentCommand (this might be a feature request).

But \newcommand is all you need.

There is another way, though. It's incompatible with utf8x, but you can judge about its elegance.



\section{The λ-calculus}

enter image description here

  • This should not be a feature request for hyperref, but for the L3 team: Integrate hyperref into L3. Commented Nov 8, 2013 at 22:50
  • @MartinSchröder That's of course in the (long term) plans.
    – egreg
    Commented Nov 8, 2013 at 22:53
  • I agree the second solution is rather elegant for people like me. Commented Nov 22, 2013 at 17:16
  • I also wonder whether that could be integrated in something like unicode-math, but probably people don't want this to interfere with Unicode in normal input (outside of $). Commented Nov 22, 2013 at 17:29
  • @Blaisorblade What makes you think it doesn't work with unicode-math? It does, by the way. ;-) Of course not if the document is in Greek.
    – egreg
    Commented Nov 22, 2013 at 17:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .