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 (starred)}\quad
}{%
\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…
\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!xparse
neither mentions this problem nor does it suggest a possible fix. I see that reading the docs strictly implies the current behavior, but it doesn't seem desirable.