TransWikia.com

Unable to use macro for end{} for environment defined using NewEnviron

TeX - LaTeX Asked by Till Hoffmann on May 22, 2021

I would like to use a shorthand to begin and end an environment, such as be and ee. This works as expected for standard environments, such as equation as illustrated below.

% this compiles fine
documentclass{article}
usepackage{environ}

newcommand{be}{begin{equation}}
newcommand{ee}{end{equation}}

begin{document}
be y = ax + c ee
end{document}

However, using an environment defined using NewEnviron as shown below does not compile.

% this does not compile: ! LaTeX Error: begin{someenv} on input line 10 ended by end{document}.
documentclass{article}
usepackage{environ}

NewEnviron{someenv}{someenv: BODY}
newcommand{be}{begin{someenv}}
newcommand{ee}{end{someenv}}

begin{document}
be y = ax + c ee
end{document}

Using end{someenv} explicitly compiles fine again.

% this compiles fine
documentclass{article}
usepackage{environ}

NewEnviron{someenv}{someenv: BODY}
newcommand{be}{begin{someenv}}
% newcommand{ee}{end{someenv}}

begin{document}
be y = ax + c end{someenv}
end{document}

Do you know why using ee does not compile and how I might be able to fix this issue?

One Answer

TL;DR You can’t.

The contents of someenv has to be grabbed by looking for explicit end{someenv}.

If you want to obfuscate your code, do

longdefbe#1ee{someenv: #1}

but then don’t ask how to use something else instead of ee, because the problem is the same.

Answered by egreg on May 22, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP