Should additional groups like \begin{algorithm} ... \end{algorithm} be generally avoided and the use of \algorithm...\endalgorithm be preferred?

By additional is meant, that there is at least one other group. For clarification see this answer and it's comments.

Some answers where it's told to do so:

I also made small changes to the environment definitions. The \begin and \end are not needed. They add an additional group and will lead to misleading error messages if there is some erroneous input.

from Typesetting chord progressions

Secondly, rather than writing \begin{algorithm}...\end{algorithm} inside your environment I would just use \algorithm...\endalgorithm. The two are almost the same except that that the first version puts everything inside its' own group, which isn't really necessary here because your environment starts its own group.

from Multiple Counters on algorithm

I'm unsure if When to use or avoid grouping? is related.

Where it isn't done:

In Group statements, avoid pagebreak the use of \begin{xyz} ... \end{xyz} is chosen.

  • 1
    Try: \documentclass{article} \newlength{\foolen} \newenvironment{foo}{\setlength{\foolen}{17pt}}{} \begin{document} \begin{foo} \end{foo} \the\foolen \foo \endfoo \the\foolen \end{document}. The grouping mechanism is established within the environment, so \foo and \endfoo are sufficient. Using \foo and \endfoo outside of the environment group there will be no group, unless \foo and \endfoo are explicitly defined this way, see the various examples in latex.ltx
    – user31729
    Aug 18, 2017 at 20:47
  • 1
    The grouping is to be considered whether redefinitions of commands, lengths or count register values (for examples) should persist only in a group and not leak outside. LaTeX counters are group-safe, however, and there is no unique answer for this
    – user31729
    Aug 18, 2017 at 20:54
  • I understand your comments. My question was a bit unclear, I updated it.
    – user1
    Aug 18, 2017 at 20:59
  • Ben: I understood your request about the 'additional' groups. There's no clear answer in my point of view. Verbatim-like wrapper environments however should see \end... instead of \end{...}, as far as I know
    – user31729
    Aug 18, 2017 at 21:02

1 Answer 1


The standard latex syntax is \begin{foo}...\end{foo} in some, but not all, cases this can be "optimised" to \foo....\endfoo but only if you know in detail how the environment is defined, and that the non standard call will work.

A few environments that use special handling have a requirement to use the \foo... \endfoo form if used inside a nested \newenvironment definition (eg tabularx and ams alignments) but these are special constructs where the non-environment form is explictly documented in the package documentation.

  • So the answer I gave (linked from the question) is OK? It isn't wrong?
    – cfr
    Aug 18, 2017 at 22:47
  • 1
    @cfr no looks Ok to me (you could add an \ignorespacesafterend which was added to latex partly to remove one possible reason for preferring the \endfoo syntax over \end{foo} but in most list uses that doesn't actually make a difference on practice. Aug 19, 2017 at 11:17

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.