LATEX-L Archives

Mailing list for the LaTeX3 project

LATEX-L@LISTSERV.UNI-HEIDELBERG.DE

Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Joseph Wright <[log in to unmask]>
Reply To:
Mailing list for the LaTeX3 project <[log in to unmask]>
Date:
Sat, 7 Aug 2010 21:31:51 +0100
Content-Type:
text/plain
Parts/Attachments:
text/plain (50 lines)
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

ATOM RSS1 RSS2