Sign up ×
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.

Do you know how LaTeX implements environments? To be more precise, what does


in terms of TeX commands (i.e., how is the LaTeX command \newenvironment defined in TeX)?

share|improve this question
Please have a look at Defining environments based on other ones: What's the right way? where I show and discuss the internal definitions of \begin and \end. – Martin Scharrer Jun 2 '12 at 13:49

1 Answer 1

The command \newenvironment{<env-name>}[<n-args>][<default>]{<begin-code>}{<end-code>} is equivalent to:


The reason is that \begin{<env-name>}...\end{<env-name>} is transferred into

<check whether the command \<env-name> exists
\csname <env-name>\endcsname % this is a way to call macro \<env-name> by its name
<check whether the inner-most environment is really <env-name>
\csname end<env-name>\endcsname % calls \end<env-name>

The problem is that you cannot do \newcommand{\#1}... so the command \csname...\endcsname is actually used by \newenvironment to overcome this problem.

The exact definition of \newenvironment is very complicated since the presence of * (that indicate the environment to be defined without \long), presence of [<n-args>] and [<default>] has to be tested, which in the terms of LaTeX means a lot of inner macros. To explore the details, you can run the following short source code that shows the macro definitions:

\meaning\newenvironment   % <-- put any macro name here
\meaning\newcommand   % <-- put any macro name here
share|improve this answer

Your Answer


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.