I am trying to construct a command which would automatically redefine an environment of given in both starred and not starred version. The goal is to have \setenviron{foo}
redefining environments foo
and foo*
. I tried to use code from Use the s (star) argument with \NewDocumentEnvironment to work with star arguments, but I can't use variable name of environment there (replacing foo
with #1
doesn't work, even after my attempt to write \csname #1* \endcsname
instead of \foo*
and expand it with \expandafter
). What can I do?
I have no idea how \cs_new
and \cs_new_eq
work and I couldn't find any guides online (expl3
documentation on CTAN doesn't cover these) so I would be grateful for some little explanation of the solution.
MWE:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xparse}
\newenvironment{foo}{}{}
\ExplSyntaxOn
\NewDocumentCommand{\setenviron}{m}{%
\RenewDocumentEnvironment{#1}{s +b}{%
\IfBooleanTF{##1}{do~~ star~ things\par ##2}{##2}%
}{%
\IfBooleanTF{##1}{\par stop~ doing~ star~ things}{}%
}
\cs_new:cpn {#1*} {\foo*} %I have problem with these two lines
\cs_new_eq:cN { end#1*} \endfoo %
}
\ExplSyntaxOff
\begin{document}
\setenviron{foo}
\begin{foo}
normal foo
\end{foo}
\begin{foo*}
starred foo
\end{foo*}
\end{document}