Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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…

share|improve this question
2  
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

1 Answer 1

up vote 7 down vote accepted

Just say

\NewDocumentEnvironment{baz}{s O{Foobar}}{%
   \begin{quote}
   \IfBooleanTF{#1}{%
      \textbf{#2 (starred)}\quad
   }{%
      \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.

share|improve this answer
    
Ok, I see … thank you! –  Tobi Feb 22 '12 at 14:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.