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


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
| improve this answer | |
  • Should "transferred into" be "expanded into"? – Faheem Mitha Aug 11 '19 at 15:20

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.