Hans Aberg wrote --

>   The apparent reason this gives "improved syntax checking" is due to a bug
> in LaTeX!:
>   When nesting environments, there are more than environment to keep track
> of for the error checking, which LaTeX does not do.

This is an area where we have some ideas but it is necessary to think
clearly about what is needed.

Here are some desirable features of such a specification:

-- provide a straightforward means of extending the available
document-level environments (and commands), with clearly
defined rules for what is allowed;

-- distinguish (to both humans and software) clearly between such
extensions (where the detailed syntax is very flexible) and an
inner-level which has a rigorously defined syntax that is extensible
only in more complex ways within (something like) package files;

-- hence fix such "bugs".

If anyone is intersted in putting substantial work into implementing
such ideas, please contact Them.

This would involve some major programming using the LaTeX3 PL (and of
course developing it) and implementing in it any low-level structures