1

I am trying define a environment that displays a text specified by the parameter of the environment. The following example demonstrates it:

\documentclass{article}
\usepackage{environ}
\usepackage{etoolbox}
\csdef{bla1}{Bla1Text}
\csdef{bla2}{Bla2Text}
\NewEnviron{myenv}[1][]{%
    env: #1 
    \csuse{bla#1} % does not work
    \BODY
}
\begin{document}
    \csuse{bla1}\\ % works as expected
    \begin{myenv}{1} body1 \end{myenv} \\
    \begin{myenv}{2} body2 \end{myenv}
\end{document}

Is \NewEnviron incompatible with the etoolbox package or is there a possibility to fix my code above?

Note: In a regular environment \csuse works without problems but I want to change the behavior of the environment so that it hides the content if the \csuse variable is defined or not and this can AFAIK only be done using \NewEnviron. And changing \csuse is not an option as it is already used widely in my real document.

0

1 Answer 1

3

The syntax you're using specifies that the argument to the myenv environment is optional, with empty default value.

So with your definition,

\begin{myenv}
body
\end{myenv}

will execute \csuse{bla}, while

\begin{myenv}[1]
body
\end{myenv}

will execute \csuse{bla1}. If you want a mandatory argument in braces, which seems the case by looking at your example, the code should be

\NewEnviron{myenv}[1]{%
    env: #1 
    \csuse{bla#1} % does not work
    \BODY
}

and in this case

\begin{myenv}{2}
body
\end{myenv}

will execute \csuse{bla2}.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .