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)?


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
  • 1
    Should "transferred into" be "expanded into"? Aug 11, 2019 at 15:20
  • Remark: \begin{X} is expanded/executed strictly before \end{X}, and in some special cases (verbatim environment for example) \end{X} is read as-is without any expansion, and the begin command (macro) uses it to delimit the end of the environment.
    – user202729
    Nov 14, 2021 at 6:06

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.