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 o77KYFqs026177 for ; Sat, 7 Aug 2010 22:34:17 +0200 Received: (qmail 31772 invoked by alias); 7 Aug 2010 20:34:10 -0000 Delivered-To: GMX delivery to rainer.schoepf@gmx.net Received: (qmail invoked by alias); 07 Aug 2010 20:34:10 -0000 Received: from relay.uni-heidelberg.de (EHLO relay.uni-heidelberg.de) [129.206.100.212] by mx0.gmx.net (mx074) with SMTP; 07 Aug 2010 22:34:10 +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 o77KWIAw001393 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 7 Aug 2010 22:32:18 +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 o76M14Va015867; Sat, 7 Aug 2010 22:32:12 +0200 Received: by LISTSERV.UNI-HEIDELBERG.DE (LISTSERV-TCP/IP release 16.0) with spool id 452535 for LATEX-L@LISTSERV.UNI-HEIDELBERG.DE; Sat, 7 Aug 2010 22:32:12 +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 o77KWCht007997 for ; Sat, 7 Aug 2010 22:32:12 +0200 Received: from smtp6.freeserve.com (smtp5.freeserve.com [193.252.22.151]) by relay2.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id o77KWTQi001429 for ; Sat, 7 Aug 2010 22:32:33 +0200 Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf3538.me.freeserve.com (SMTP Server) with ESMTP id 6E44C1C00085 for ; Sat, 7 Aug 2010 22:31:59 +0200 (CEST) Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf3538.me.freeserve.com (SMTP Server) with ESMTP id 609371C00088 for ; Sat, 7 Aug 2010 22:31:59 +0200 (CEST) Received: from palladium.local (unknown [109.181.41.32]) by mwinf3538.me.freeserve.com (SMTP Server) with ESMTP id 6D1961C00085 for ; Sat, 7 Aug 2010 22:31:54 +0200 (CEST) X-ME-UUID: 20100807203155447.6D1961C00085@mwinf3538.me.freeserve.com User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-GB; rv:1.9.2.8) Gecko/20100802 Thunderbird/3.1.2 MIME-Version: 1.0 References: <4C5D662F.60101@gmx.de> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Message-ID: <4C5DC2B7.9000004@morningstar2.co.uk> Date: Sat, 7 Aug 2010 21:31:51 +0100 Reply-To: Mailing list for the LaTeX3 project Sender: Mailing list for the LaTeX3 project From: Joseph Wright Subject: Re: optional (#1:#2) with xparse To: LATEX-L@listserv.uni-heidelberg.de In-Reply-To: <4C5D662F.60101@gmx.de> Precedence: list List-Help: , List-Unsubscribe: List-Subscribe: List-Owner: List-Archive: X-GMX-Antispam: 0 (Mail was not recognized as spam); Detail=5D7Q89H36p77e5KAPs1l6v/Sb97LojnDtMgfETrECMLUO9erHzOJe7j3G660N4yBY6XHH YPYtmQj6mbYUTZ3LnaFANLWrKE7/wIDhnv+VrW0hxOapLRUwuY9oBqo5h+Dh9B42XlFTMTKlXDju GaV8Q==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: 6353 On 07/08/2010 14:57, Arno Trautmann wrote: > Hi all, > > I am looking for a way to define an environment that takes a range as an > optional argument. This should be given in the following way: > > \begin{environment}(15:5.23) > > with a default value, say (1:3). The two limits should then be parsed as > single arguments which are separated by the colon. > I am trying to do this with xparse and got some possible solutions with > the u and d argument type, but I didn’t manage to get the parentheses > optional. I guess what I need is some kind of an optional u argument … > > Does anyone have a suggestion how to easily implement these requests? > > cheers > Arno > Hello Arno, Parse the argument first as a 'd', then use \SplitArgument to do the subsequent work: \documentclass{article} \usepackage{xparse} \NewDocumentEnvironment{example}{>{\SplitArgument{1}{:}}d()} {} { \IfNoValueTF{#1} {#1} {\showargs#1}% } \NewDocumentCommand\showargs{mm}{Arg 1: #1, Arg 2: #2} \begin{document} \begin{example} First \end{example} \begin{example}(1:2) Second \end{example} \end{document} Here, \SplitArgument will return the result as two groups, unless there was \NoValue in which case nothing happens. -- Joseph Wright