Received: from mx0.gmx.net (mx0.gmx.net [213.165.64.100]) by h1439878.stratoserver.net (8.14.2/8.14.2/Debian-2build1) with SMTP id p5EMBdGN013329 for ; Wed, 15 Jun 2011 00:11:40 +0200 Received: (qmail 5512 invoked by alias); 14 Jun 2011 22:11:34 -0000 Delivered-To: GMX delivery to rainer.schoepf@gmx.net Received: (qmail invoked by alias); 14 Jun 2011 22:11:34 -0000 Received: from relay.uni-heidelberg.de (EHLO relay.uni-heidelberg.de) [129.206.100.212] by mx0.gmx.net (mx013) with SMTP; 15 Jun 2011 00:11:34 +0200 Received: from listserv.uni-heidelberg.de (listserv.uni-heidelberg.de [129.206.100.94]) by relay.uni-heidelberg.de (8.14.1/8.14.1) with ESMTP id p5EM96aw016412 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 15 Jun 2011 00:09:06 +0200 Received: from listserv.uni-heidelberg.de (localhost.localdomain [127.0.0.1]) by listserv.uni-heidelberg.de (8.13.1/8.13.1) with ESMTP id p5EM19hU013891; Wed, 15 Jun 2011 00:09:06 +0200 Received: by LISTSERV.UNI-HEIDELBERG.DE (LISTSERV-TCP/IP release 16.0) with spool id 1231008 for LATEX-L@LISTSERV.UNI-HEIDELBERG.DE; Wed, 15 Jun 2011 00:09:06 +0200 Received: from relay2.uni-heidelberg.de (relay2.uni-heidelberg.de [129.206.210.211]) by listserv.uni-heidelberg.de (8.13.1/8.13.1) with ESMTP id p5EM95A8015256 for ; Wed, 15 Jun 2011 00:09:06 +0200 Received: from mail-bw0-f49.google.com (mail-bw0-f49.google.com [209.85.214.49]) by relay2.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id p5EM8jmN009122 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=FAIL) for ; Wed, 15 Jun 2011 00:08:48 +0200 Received: by bwz1 with SMTP id 1so13134bwz.22 for ; Tue, 14 Jun 2011 15:08:45 -0700 (PDT) Received: by 10.204.82.143 with SMTP id b15mr5628390bkl.118.1308089324936; Tue, 14 Jun 2011 15:08:44 -0700 (PDT) Received: from irwin.vpn.uni-freiburg.de ([93.216.225.148]) by mx.google.com with ESMTPS id q20sm6016077bka.5.2011.06.14.15.08.44 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 14 Jun 2011 15:08:44 -0700 (PDT) Received: by irwin.vpn.uni-freiburg.de (Postfix, from userid 500) id 38C795379; Wed, 15 Jun 2011 00:12:43 +0200 (CEST) Mail-Followup-To: LATEX-L@LISTSERV.UNI-HEIDELBERG.DE References: <4DF7CBEF.6080402@arcor.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Message-ID: <20110614221243.GA9520@oberdiek.my-fqdn.de> Date: Wed, 15 Jun 2011 00:12:43 +0200 Reply-To: Mailing list for the LaTeX3 project Sender: Mailing list for the LaTeX3 project From: Heiko Oberdiek Subject: Re: xparse and hyperref: Token not allowed in a PDF string (PDFDocEncoding) To: LATEX-L@listserv.uni-heidelberg.de In-Reply-To: <4DF7CBEF.6080402@arcor.de> Precedence: list List-Help: , List-Unsubscribe: List-Subscribe: List-Owner: List-Archive: X-GMX-Antispam: 0 (eXpurgate); Detail=5D7Q89H36p4Soy7Wh8yBhg9+MekPOwJN5z31XeDq0rZSalEFPxfUmGB6+/VZeCvlI/nDf Auj2rO4UGjdwTy5Sk6rZTpSa0w1Pdkr69NOqSukyM0/BkBkqnipay1p2m73ibTlAwRkyyhGbgein 2+XAGW1mlHhCzauUcTpbEu2dEShlWZCuLM7hEXYdxJmoc2UWSOnouqEc3hY3TSjK9gc0unC9jdlA qJgAI3/Cd+NEYE=V1; X-Resent-By: Forwarder X-Resent-For: rainer.schoepf@gmx.net X-Resent-To: rainer@rainer-schoepf.de Status: R X-Status: X-Keywords: X-UID: 6783 On Tue, Jun 14, 2011 at 11:00:31PM +0200, Stephan Hennig wrote: > xparse's \NewDocumentCommand doesn't seem to play well with hyperref > bookmarks. In this code > > \listfiles > \documentclass{article} > \usepackage{xparse} > \usepackage{hyperref} > \begin{document} > \NewDocumentCommand{\fooa}{}{FooA} > \DeclareExpandableDocumentCommand{\foob}{m}{FooB} > \section{aaa \fooa\ bbb \foob{} ccc} > \end{document} > > text from macro \fooa doesn't show up in the bookmark. Fortunately, it > works at least for macro \foob. > > Is that expected behaviour? Yes. \NewDocumentCommand defines the macro using e-TeX's \protected. The result of \show\fooa: | \fooa=\protected macro: | ->FooA. \pdfstringdef uses \edef to expand the string, \protected prevents this and the unexpandable macro is then filtered out: | Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding): | (hyperref) removing `\fooa' on input line 9. > Would it be possible to make > \NewDocumentCommand macros work with hyperref bookmarks? No, even worse, you cannot provide a bookmark string (\texorpdfstring) inside the definition, because it will not be expanded and \texorpdfstring is not seen. > I'd prefer > using \NewDocumentCommand macros because of the mandatory argument of > \DeclareExpandableDocumentCommand macros which I don't need in my context. I don't see that mandatory arguments matter here. But probably you are refering to "1.7 Fully-expandable document commands": | * The function must have at least one mandatory argument, and in | particular the last argument must be one of the mandatory types | (l, m or u). The section 1.7 contains advice against \DeclareExpandableDocumentCommand: | do not use these functions! One translation is: Good bye bookmarks. Of course there are macros, whose definition text makes it difficult for bookmarks anyway (assignments, ...). But the expandable macros are excluded using \DeclareDocumentCommand. Workarounds: * \pdfstringdefDisableCommands can be used, but an expandable macro needs to be added for each \protected macro that might appear in bookmarks. Then the redefinition takes place for each bookmark string conversion, not very efficient. * Expandable wrapper command that expands to the bookmark string if inside bookmarks and calls the unexpandable macro otherwise. * LuaTeX would add access to node lists, thus the bookmark string could be set in a \hbox and the node list examined and converted to a text string. Some cases are probably quite easy, other cases are very difficult and would cry for OCR methods. * ...? Yours sincerely Heiko