I am trying to define an Environment myEnv s.t.
\begin{myEnv}
text1
\end{myEnv} text2}
expands to
\renewcommand{\myCommand}{
text1
} { text2}
The reason for the obviously unbalanced expression in the first code sample is the limited capability of LyX when it comes to defining macro parameters over multiple paragraphs - I have to cope with it at the moment. I've already tried
\NewEnviron{myEnv}{\expandafter\newcommand\csname myCommand \endcsname{\BODY} \bgroup}
however, this isn't working at all.
Edit: Based on egreg's answer, I give a minimal, non-working example:
\documentclass{scrartcl}
\usepackage{environ}
\newcommand{\myCommand}{}
\NewEnviron{myEnv}{%
\expandafter\gdef\expandafter\myCommand\expandafter{\BODY}}
\begin{document}
\begin{myEnv}
text1
\end{myEnv} text2}
testing \myCommand testing
\end{document}
which gives the error
! Too many }'s.
l.13 \end{myEnv} text2}
The expected document output would be
text2 testing text1 testing
{text1}and{text2}is, as apparently\myCommandis defined without arguments. Do you need to define a command or to use it? – egreg Jan 04 '12 at 09:52\myCommandis defined without arguments - it is just a textual definition. I really need to define a command here; the code given above is really what I want to achieve. Note that this construction is only necessary to circumvent some nasty habits of LyX. – Daniel Anderson Jan 04 '12 at 14:32\renewcommand{\myCommand}{<n>text1<n>}{ text2}(<n>stands for the new line) should mean? However, if you want to say\renewcommand{\myCommand}{<n>text1<n>}, you only need to say\renewcommand{\myCommand}{ text1 }(a new line there is exactly like a space). – egreg Jan 04 '12 at 14:37{ text2}. Thus the resulting code is\renewcommand{\myCommand}{<n>text1<n>} { text2}. This redefinesmyCommandand then simply emitstext2as normal text.text2is not in any way part of the command definition! – Daniel Anderson Jan 04 '12 at 14:46