Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

If I create a custom environment based on the equation environment, I get a spacing issue: the next line of text after my environment closes doesn't start on the left margin.

Example code:

\documentclass{article}
\begin{document}
\newenvironment{myenv}{\begin{equation}}{\end{equation}}
\noindent $| \leftarrow$ this is the left margin.
\begin{myenv}
e ^{i \pi} + 1 = 0
\end{myenv}
$| \leftarrow$ this isn't the left margin.
\end{document}

Output:

enter image description here

Removing the newline after \end{myenv} solves the spacing problem, but the resulting code is not readable.

Of course, in this example I could just use the equation environment itself. My real issue involves a more complex custom environment that suffers from the same problem, and which also includes an equation environment within it.

share|improve this question

1 Answer 1

up vote 10 down vote accepted

The \end{equation} command terminates display math mode, so TeX resumes horizontal mode and only after this action it sees the end-of-line which follows \end{myenv}, processing it as part of the paragraph.

The solution is to append \ignorespacesafterend to the "end" part of the environment definition:

\newenvironment{myenv}
  {\begin{equation}}
  {\end{equation}\ignorespacesafterend}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.