2

To avoid unnecessary effort, please note that I'm asking specifically about the error's cause, as opposed to how to avoid it. Furthermore, I'm aware that \NewDocumentEnvironment now offers the b option.

Consider the following MNWE,

\documentclass[]{article}
\usepackage{newenviron}
\begin{document}
hylo
\end{document}

This fails to compile, claiming there's an extra \endgroup, so that \document ends with \endgroup.

This is pdfTeX, Version 3.141592653-2.6-1.40.25 (TeX Live 2023) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./prawf.tex
LaTeX2e <2023-06-01> patch level 1
L3 programming layer <2023-10-10>
(/usr/local/texlive/2023/texmf-dist/tex/latex/base/article.cls
Document Class: article 2023/05/17 v1.4n Standard LaTeX document class
(/usr/local/texlive/2023/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2023/texmf-dist/tex/latex/newenviron/newenviron.sty
(/usr/local/texlive/2023/texmf-dist/tex/latex/catoptions/catoptions.sty))
! Extra \endgroup.
\document ->\endgroup 
                      \let \BeforeStartOfDocument \@firstofone \cpt@beforest...
l.199 \begin{document}
                      
? 

What causes this error exactly?

5
  • 2
    newenviron (opposing to the environ package) loads catoptions. catoptions in turn redefines many of LaTeX's internals. Some few years ago changes in the LaTeX kernel finally lead to catoptions being incompatible with it in such a way that it actually breaks with an error. Previously catoptions did break LaTeX, but silently... Search this site, there are a few questions regarding catoptions.
    – Skillmon
    Commented Oct 28, 2023 at 19:59
  • Another example of catoptions breaking stuff (before it became incompatible): tex.stackexchange.com/questions/461783/…
    – Skillmon
    Commented Oct 28, 2023 at 20:07
  • The aim of newenviron was to allow nested calls of environments defined with \newenviron, in order to avoid some shortcomings of environ which only used \BODY. The idea was nice, but Bruno's implementation of the b argument type for \NewDocumentEnvironment is much better (and doesn't break LaTeX).
    – egreg
    Commented Oct 28, 2023 at 21:54
  • @egreg Thanks. This wasn't actually the right question, but David had answered before I realised that.
    – cfr
    Commented Oct 28, 2023 at 23:04
  • @Skillmon Thanks. Hopefully this will be of use to somebody as a pointer. (It's not actually the right question because I screwed up.)
    – cfr
    Commented Oct 28, 2023 at 23:05

1 Answer 1

3

While adding the hook code a couple of years back, some details of the \document command changed, in order to add the hooks, which means that packages that patched \document may have made assumptions that are no longer valid. catoptions as used here was always intentionally changing latex internals in unsupported ways, and finally it broke and has not so far been updated.

In practice most uses of newenviron (and environ) packages are better done these days with the \NewDocumentEnvironment b argument type which does not require any package to be loaded.

2
  • Thanks. Actually, it was trying to use b which got me into trouble in the first place, but I think that's actually due to some other change. If environments of these kinds are nested, is it better for the outer one to use environ if the inner one does? Or is it OK for the outer one to use b, even if the inner uses environ?
    – cfr
    Commented Oct 28, 2023 at 20:16
  • 1
    @cfr it should be ok to nest environ with b or the other way round. Commented Oct 28, 2023 at 20:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .