TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can I safely do this:


where foo is a standard LaTeX environment? Probably the verbatim environment breaks, but others as well? That way one could write

inside the foo environment

instead of the longer

inside the foo environment

I'd appreciate a technical statement, not a "I wouldn't do this, because it is unreadable". For a fact, I just want to know its implications and I wouldn't do this, because I think it is not very readable.

share|improve this question
i don't know whether you consider the multi-line display environments of amsmath to be "standard", but those, like verbatim, require an exact match for the \end{...} component. this is at least partly because of the multi-pass mechanism used for measuring the contents, required for proper placement; the details are complicated, but i think they are explained sufficiently (if not with total clarity) in the file amsmath.dtx (texdoc -l amsmath and choose amsmath.pdf). however, equation, being a "basic" environment, can be abbreviated as you describe. – barbara beeton Aug 2 '12 at 12:23
up vote 9 down vote accepted

As you say, anything based on finding the \end{foo} construct will fail. That includes any verbatim-like, which includes for example beamer's frame environment, but also some of the AMS math environments such as align.

A second issue is space skipping, as

inside the foo environment

has a space before inside which the \bfoo version does not include. You might feel that is no bad thing, but it is changing how the interface works. (Note: some environments deliberately \ignorespaces at the start, and this won't apply, for example lrbox.)

share|improve this answer

There are many cases, where this shortcuts can be used, but in general it is not safe.

Body collectors

Prominent example is package amsmath. It has the feature that in its displayed equation environments (gather, align, ...) the handling of the equation number is improved. The number moves down instead of clashing with the equation. But for this purpose amsmath needs to know the width of the equation. Therefore it defines macro \collect@body that looks for \end in the parameter text to dig through the inner nested environments to find the right \end that closes the environment.

\def\collect@@body#1\end#2{...}% the relevant internal

Therefore \end must be visible at the same level and not hidden inside macros, aliases or groups. However the \begin part is not affected, thus it can be used for a definition:


Now, \end{foo} is visible for the code in \begin{foo}. Disadvantage of this method that proper nesting is problematic:

\bfoo ... \bfoo ... \efoo ... \efoo

The first \bfoo would find the first \efoo, not the correct last \efoo. Workaround:

\bfoo ... {\bfoo ... \efoo} ... \efoo

Package environ makes the method of amsmath available as standalone package.


Environments that process their body with changed catcodes, mostly because they do not want that the macros and commands in the body gets executed. In case of verbatim they should print unchanged. But this also affects the end macro, that is read as seqence of characters and it is not build and called as macro token. This includes \end{...}. The verbatim environment solves this by looking for the sequence of characters \, e, n, d, {, v, … as end marker. Therefore something like \efoo is not detected.

Package verbatim uses a slightly different method, it scans line by line and collects token until it finds the string \end with the matching environment name in it.

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.