# Use the s (star) argument with \NewDocumentEnvironment

Would it be possible to use the s argument specifier of xparse in \NewDocumentEnvironment so that we get an environment an a starred version of it?

Actually it works, but the star goes to the wrong place:

\documentclass{article}

\usepackage{xparse}

\NewDocumentEnvironment{baz}{s O{Foobar}}{%
\begin{quote}
\IfBooleanTF{#1}{%
}{%
\textbf{#2 (non-starred)}
}%
}{%
\end{quote}
}

\usepackage{lipsum}

\begin{document}
\lipsum[1]
\begin{baz}
\lipsum[2]
\end{baz}
\lipsum[3]
% Star at the wrong place in a LaTeX2e sense
\begin{baz}*[Name]
\lipsum[2]
\end{baz}
\lipsum[3]
\end{document}


It would be great if \NewDocumentEnvironment{baz}{s ... defines {baz} and {baz*}, otherwise one have to define them separately as in 2e syntax…

-
I have some thoughts on how to tackle this, but they are really 'for discussion' (i.e. they don't make a good Q&A answer). For example, you could imagine definition \begin to check for an optional star (there is a bit of complexity to it). However, with LaTeX2e that means messing with some internals: not sure if it's a great idea. One for LaTeX-L! –  Joseph Wright Feb 22 '12 at 14:21

Just say

\NewDocumentEnvironment{baz}{s O{Foobar}}{%
\begin{quote}
\IfBooleanTF{#1}{%
}{%
\textbf{#2 (non-starred)}
}%
}{%
\end{quote}
}
\ExplSyntaxOn
\cs_new:cpn {baz*} {\baz*}
\cs_new_eq:cN {endbaz*} \endbaz
\ExplSyntaxOff


and now \begin{baz*}...\end{baz*} will do as expected.

I'm not certain that an extension of the syntax in this sense is good: the environment's name is the argument to \begin.

-
Ok, I see … thank you! –  Tobi Feb 22 '12 at 14:13