Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by h1439878.stratoserver.net (8.14.4/8.14.4/Debian-2ubuntu2.1) with ESMTP id u3493fDA026757 for ; Mon, 4 Apr 2016 11:03:42 +0200 Received: from relay2.uni-heidelberg.de ([129.206.119.212]) by mx-ha.gmx.net (mxgmx009) with ESMTPS (Nemesis) id 0McQwS-1b4fnL1fm4-00HgqH for ; Mon, 04 Apr 2016 11:03:35 +0200 Received: from listserv.uni-heidelberg.de (listserv.uni-heidelberg.de [129.206.100.94]) by relay2.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id u3491dZG000985 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 4 Apr 2016 11:01:39 +0200 Received: from listserv.uni-heidelberg.de (listserv.uni-heidelberg.de [127.0.0.1]) by listserv.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id u348lT74010937; Mon, 4 Apr 2016 11:01:39 +0200 Received: by LISTSERV.UNI-HEIDELBERG.DE (LISTSERV-TCP/IP release 16.0) with spool id 13524654 for LATEX-L@LISTSERV.UNI-HEIDELBERG.DE; Mon, 4 Apr 2016 11:01:39 +0200 Received: from relay.uni-heidelberg.de (relay.uni-heidelberg.de [129.206.100.212]) by listserv.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id u3491dKI003301 for ; Mon, 4 Apr 2016 11:01:39 +0200 Received: from nov-007-i616.relay.mailchannels.net (nov-007-i616.relay.mailchannels.net [46.232.183.170]) by relay.uni-heidelberg.de (8.14.1/8.14.1) with ESMTP id u3491PKU030404 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 4 Apr 2016 11:01:31 +0200 X-Sender-Id: netnames|x-authuser|joseph.wright@morningstar2.co.uk Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 69335A0E81 for ; Mon, 4 Apr 2016 09:01:24 +0000 (UTC) Received: from smtp2.easily.co.uk (ip-10-123-105-117.us-west-2.compute.internal [10.123.105.117]) by relay.mailchannels.net (Postfix) with ESMTPA id 30767A0E80 for ; Mon, 4 Apr 2016 09:01:23 +0000 (UTC) X-Sender-Id: netnames|x-authuser|joseph.wright@morningstar2.co.uk Received: from smtp2.easily.co.uk (smtp2.easily.co.uk [10.36.128.18]) (using TLSv1 with cipher DHE-RSA-AES256-SHA) by 0.0.0.0:2500 (trex/5.6.11); Mon, 04 Apr 2016 09:01:24 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: netnames|x-authuser|joseph.wright@morningstar2.co.uk X-MailChannels-Auth-Id: netnames X-MC-Loop-Signature: 1459760483726:2161417267 X-MC-Ingress-Time: 1459760483726 Received: from [139.222.114.108] (port=52554 helo=[139.222.114.108]) by smtp2.easily.co.uk with esmtpa (Exim 4.43) id 1an0Nt-0006BE-6p for LATEX-L@LISTSERV.UNI-HEIDELBERG.DE; Mon, 04 Apr 2016 10:01:21 +0100 References: <5701B0C1.9080407@free.fr> User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-AuthUser: joseph.wright@morningstar2.co.uk Message-ID: <57022D60.6050803@morningstar2.co.uk> Date: Mon, 4 Apr 2016 10:01:20 +0100 Reply-To: Mailing list for the LaTeX3 project Sender: Mailing list for the LaTeX3 project From: Joseph Wright Subject: Re: Bug in xparse r, or R, or d or D argument specifiers To: LATEX-L@LISTSERV.UNI-HEIDELBERG.DE In-Reply-To: <5701B0C1.9080407@free.fr> Precedence: list List-Help: , List-Unsubscribe: List-Subscribe: List-Owner: List-Archive: Envelope-To: X-GMX-Antispam: 0 (Mail was not recognized as spam); Detail=V3; X-GMX-Antivirus: 0 (no virus found) X-UI-Filterresults: notjunk:1;V01:K0:fqzLq/2Cpzc=:MqAcxeAg9FcL3BJw5pF7rrAy7M OWwQ4baZ+TKf1TLAm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Yg6U0SdPD9wcjjwXo9iygr+UvMM6fmNRQ l9HgcnMFh90qlPx3OcOtO/xweAXVVQBZixH+VoDvNle5lGPP/2bec3MnOM+Fb3bIl6wpSTAek 1BaeNg2vwxyxiHUjm31tnAxW9+ahPJAFZIiTZBdW+VYyF8cHgvqZ78TJYCmlaRScedMX7237Q sVKkWRxPDDNbFyeopMIySXzlfS5LwKf1/jv2hSccGgR X-Scanned-By: MIMEDefang 2.71 on 85.214.41.38 Status: R X-Status: X-Keywords: X-UID: 7920 On 04/04/2016 01:09, Julien RIVAUD (_FrnchFrgg_) wrote: > Hello, > > A command created with > > \NewDocumentCommand \foo { r\OPEN\CLOSE } { } > > seems to work fine, and grabs correctly its argument (even when there is > nesting involved), but leaves OPEN at the beginning of the argument. The > problem is in \__xparse_grab_D_aux:NNnN where you do: > > \token_if_eq_catcode:NNTF + #1 > { > > } > { > \exp_after:wN \l__xparse_fn_tl > \token_to_str:N #1 > } > > But of course \token_to_str:N #1 is several characters long. Suppose now > that there was no nesting, i.e. we used \foo\OPEN hello\CLOSE. > > Then \l__xparse_fn_tl goes to > > \tl_if_blank:oTF { \use_none:n ####1 } > { \__xparse_add_arg:o { \use_none:n ####1 } } > { > \str_if_eq_x:nnTF > { \exp_not:o { \use_none:n ####1 } } > { { \exp_not:o { \use_ii:nnn ####1 \q_nil } } } > { \__xparse_add_arg:o { \use_ii:nn ####1 } } > { \__xparse_add_arg:o { \use_none:n ####1 } } > } > #3 \l__xparse_args_tl > > where the blank test cannot succeed (####1 is \OPEN hello where \ is a > letter so \use_none:n will only gobble that), and the \str_if_eq_x is > also false, because > > \use_none:n ####1 gives OPEN hello (all catcode 12) > > and > > \use_ii:nnn ####1 \q_nil gives OEN hello\q_nil (all catcode 12) The intention of d/D/r/R was always as a generalisation of LaTeX2e's optional arg/co-ordinate arg syntax. As such, my idea at least was that the are intended for handling single character tokens (also true for t-type args, etc.). Certainly xparse is meant to provide 'LaTeX2e-like interfaces' not 'a completely general argument parser', so it's not unreasonable to have a restriction here. I'll look to tighten up the docs but will first wait to see if there are strong views that the behaviour should change. > As a side note, I don't understand what this test is about: it can be > true only when ####1 is two tokens, so only one token, and I didn't find > a situation where \use_none:n didn't cut it (I tried loosing braces > prevention, or loosing space prevention, I never made the test return > true *and* the \use_none:n call be wrong). Of course here it doesn't > matter, the many letters of the opening token make these fine mechanics > go awry. This was added by me in r4462 (https://github.com/latex3/latex3/commit/5aa6ab78f1e035abd73daf41a92b30501bcd27a4). As noted there, the case we are worrying about is the behaviour of the two uses \foo[{bar}]{baz} \foo[bar]{baz} The first use is what is currently required with LaTeX2e if the optional argument itself contains something with an optional argument, which xparse handles by looking correctly for nesting. However, xparse needs to work in a 'mixed' environment and it is also not unreasonable that the two are parsed in the same way. That's what the more complicated test is all about. > [1] iirc, it was to make enumitem overlay-aware in beamer while > respecting the already existing syntax. So > \begin{enumerate}[][enumitem options], where of course any of > them can be present (in that order only according to what beamer does > for its enumerate). I had to resort to grabbing the first optional > argument, check if it began with <, and if so remove the trailing > and > grab another optional argument. A bit ugly, whereas > > \NewDocumentEnvironment {enumerate} { d{[<}{>]} o } would have been > beautifully clean. Till's interface choice here is perhaps a bit unusual but that doesn't mean xparse has to handle it directly. (As noted above, that's not really what xparse is about.) > P.S.: I also encountered a "quirk" in \NewDocumentEnvironment, in that > the environment close is not align-safe (probably because of the > retrieving of arguments, but I didn't check; or just because it is > protected?): it starts a new row (and that's the least worry because > then the closing stuff is in a box group and TeX frowns upon the > \endgroup of \end). I didn't need closing args, so I just used > \NewDocumentCommand. This looks like it needs a separate post with an example! Joseph