2

I have multiple equation inserted within equation environment:

\begin{equation}
\label{Eq:SomeEquation}
P = \theta_{C} - \theta_{Y}
\end{equation}

As mentioned in Comma after equation it is good practice to add comma after each equation.

Am I able to do it by means of one LaTeX command or do I need to add comma in each equation manually?

CampanIgnis
  • 4,624
matandked
  • 619
  • 5
    A comma is needed if it goes with the flow: pretend that the formula is a phrase, if a comma is needed after the phrase, it goes after the formula. There could be a period (full stop) or nothing at all. – egreg Mar 28 '17 at 14:34

2 Answers2

4

One may wish to consider separate equation environments that add a comma equationc or a period equationp. In this way, the reading of the source code is straightforward.

\documentclass{article}
\newenvironment{equationc}{\begin{equation}}{,\end{equation}\ignorespacesafterend}
\newenvironment{equationp}{\begin{equation}}{.\end{equation}\ignorespacesafterend}
\begin{document}
One has
\begin{equation}
y = mx + B
\end{equation}
and
\begin{equationc}
y = mx + C
\end{equationc}
lest one ends up with
\begin{equationp}
y = mx + D
\end{equationp}

\end{document}

enter image description here

One can also customize the environment definitions. For example, if one did not wish the comma or period to affect the centering of the equation content, they could be done with lapping:

\newenvironment{equationc}{\begin{equation}}{\rlap,\end{equation}\ignorespacesafterend}
\newenvironment{equationp}{\begin{equation}}{\rlap.\end{equation}\ignorespacesafterend}
3

As @egreg says, it is not a very good idea to do this automatically: sometimes you need a period rather than comma or nothing at all.

Nevertheless as a TeX exercise, here is a solution. LaTeX has the definition

\def\endequation{\eqno \hbox{\@eqnnum}$$\@ignoretrue}

Thus let us redefine it:

\documentclass{article}
\makeatletter
\def\endequation{\unskip,\eqno \hbox{\@eqnnum}$$\@ignoretrue}
\makeatother
\begin{document}
\thispagestyle{empty}
\begin{equation}
\label{Eq:SomeEquation}
P = \theta_{C} - \theta_{Y}
\end{equation}
\end{document}

enter image description here

A better solution is to make the sign at the end of equation a variable:

\documentclass{article}
\makeatletter
\def\endequation{\eqend\eqno \hbox{\@eqnnum}$$\@ignoretrue}
\makeatother
\newcommand{\eqend}{\unskip,}
\begin{document}
\thispagestyle{empty}
We can make equation  end in comma
\begin{equation}
\label{Eq:SomeEquation}
P = \theta_{C} - \theta_{Y}
\end{equation}
or in dot \renewcommand{\eqend}{\unskip.}
\begin{equation}
\theta_{C} =P - \theta_{Y}
\end{equation}

We can omit the sign at all
\renewcommand{\eqend}{}
\begin{equation}
\theta_{Y} =P - \theta_{C}
\end{equation}
if we wish.
\end{document}

enter image description here

Boris
  • 38,129