0

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?

3
  • 1
    Don't do this, just don't. Learn to use your editor properly instead. The full environments makes the code much more readable.
    – daleif
    Aug 7, 2020 at 11:50
  • 1
    environments that grab their body as argument need to find the end by looking for the exact string marker. You can't hide them. And like daleif I think that you shouldn't use such shortcuts. E.g. your editor can do better highlighting if you use the normal syntax. Aug 7, 2020 at 11:52
  • Understood regarding using normal comments for better readability. I should've provided more context on the specific use case: I would like to redefine \( and \) to temporarily hide equations for a word count. texcount doesn't quite do the job because references need to be included in the word count. Aug 7, 2020 at 12:02

1 Answer 1

1

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

\long\def\be#1\ee{someenv: #1}

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

You must log in to answer this question.

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