I am trying to define an Environment myEnv s.t.

\end{myEnv} text2}

expands to

} { 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:





\end{myEnv} text2}

testing \myCommand testing


which gives the error

! Too many }'s.
l.13 \end{myEnv} text2}

The expected document output would be

text2 testing text1 testing
  • It's quite unclear what the role of {text1} and {text2} is, as apparently \myCommand is defined without arguments. Do you need to define a command or to use it? – egreg Jan 4 '12 at 9:52
  • Yes, \myCommand is 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 4 '12 at 14:32
  • So, what \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 4 '12 at 14:37
  • Please observe that there is a whitespace before the { text2}. Thus the resulting code is \renewcommand{\myCommand}{<n>text1<n>} { text2}. This redefines myCommand and then simply emits text2 as normal text. text2 is not in any way part of the command definition! – Daniel Anderson Jan 4 '12 at 14:46

It's however quite difficult to understand what you need to achieve. If you want to write multiple paragraphs, you can simply say

\newcommand{\myCommand}{text of first paragraph\par text of second paragraph\par}

In order to cope with the bizarre syntax you want to use, then


will work. But it's always difficult to understand what you really need.

  • Yup, the code from your last edit works! Thank you very much! – Daniel Anderson Jan 4 '12 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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