# Command for paragraph indentation after equations

I want to write two new commands \eqend and \eqcntd so that when I put the command at the end of an equations,

1. The \eqend command puts a "." after the equation and forces the next paragraph to indent, regardless of the number of blank lines after the equation.
2. The \eqcntd command puts a "," after the equation and forces the next paragraph not to indent, regardless of the number of blank lines after the equation.

This is a sample usage,

$$f(x) = x^2 + 1 \eqend$$
Some text here, but it's gonna get indented.


and another one,

$$f(x) = x^2 + 1 \eqcntd$$

Some text here, but it's not gonna get indented.


Here is my NOT-WORKING solution,

\newcommand{\eqend}{\,. \mbox{\par}}
\newcommand{\eqcntd}{, \mbox{\noindent}}

• You should be controlling this with the blank lines; a blank line means a new paragraph. – You Jul 21 '11 at 8:25
• Thanks "You". I know the meaning of a blank line but I want to overwrite the default meaning in this case. – Helium Jul 21 '11 at 8:35
• whatever goes in a \mbox never gets out of the box, so \par certainly won't indent the next text line. perhaps something with \aftergroup would have a better chance, but i'm not in a position to experiment now. – barbara beeton Jul 21 '11 at 12:44

## 2 Answers

This is not an answer to your question, but perhaps it might help.

I would redefine the equation environment itself. For example, with plain TeX you could define something like (didn't test though)

\def\eqindent#1{$$#1\,.$$\indent\ignorespaces}


and use it like this:

\eqindent{f(x) = x^2 + 1}
Some text here, but it's gonna get indented.


And similarly for the \noindent case. And there ought to be a similar way to do that with LaTeX.

• If you indent lines by 4 spaces, then they are marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). – Caramdir Jul 21 '11 at 15:38

As Barbara Beeton has commented, forcing the first paragraph after an equation environment to indent can be achieved with \aftergroup -- use this command to add a \par after the group established by the environment.

Forcing the first paragraph after an environment not to indent isn't that straightforward. I came up with the following:

• I defined a new macro \@doendeq that will redefine \everypar so that it a) removes the indentation from the first paragraph following it b) reverts to its original (empty) definition. (\@doendeq is an abridged version of LaTeX's \@doendpe which is used after paragraph-making environments.)

• To change every instance of the equation environment to remove indents after it, one could simply add \aftergroup\@doendeq to the definition of \endequation. As you are looking for a command to modify only some instances of equation, I used \csappto from the etoolbox package to locally add\aftergroup\@doendeq to \end<\@currenvir> (\@currenvir being the name of the current environment).

I suspect that there are more elegant ways to do this.

\documentclass{article}

\usepackage{etoolbox}

\makeatletter
\newcommand*{\@doendeq}{%
\everypar{{\setbox\z@\lastbox}\everypar{}}%
}
\newcommand*{\eqend}{\,.\aftergroup\par}
\newcommand*{\eqcntd}{%
\,,%
\csappto{end\@currenvir}{%
\aftergroup\@doendeq
}%
}
\makeatother

\begin{document}

$$f(x) = x^2 + 1 \eqend$$
Some text here, but it's gonna get indented.

$$f(x) = x^2 + 1 \eqcntd$$

Some text here, but it's not gonna get indented.

\end{document}

• Thanks lockstep. It's great. The only problem with it is that I can't get it working in environments like eqnarray! – Helium Jul 23 '11 at 4:42