2

Normally LaTeX puts equation numbers at the righthand margin. I know that this can be changed by using the leqno class option to put them at the lefthand margin. What I would like is to have local control over which margin the numbers are adjacent to. Trying somewhat optimistically

\documentclass{article}
\begin{document}
\begin{equation}
a + b = c          % numbered at right
\end{equation}

\bgroup
\leqno            % ERROR can't use \leqno in vertical mode
\begin{equation}
a + b = c
\end{equation}
\egroup

\begin{equation} \leqno  % ERROR can't use \eqno in math mode
a + b = c
\end{equation}

\end{document}

As you can see my attempts failed. Any suggestions?

EDIT The above MWE didn't tell the whole story. I should have given the initial code more appropriately as:

\documentclass{memoir}
\usepackage{memsty}    % pages of code
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{newpxtext}
\usepackage{newpxmath}
\begin{document}
 ...

Both answers solved my problem, and it was a close-run thing between them, as initially presented but ...

I will look into the problems generated by the various ...math... packages and hope to resolve these. The memsty package I will deal with. You may find, however, another question on the topic at a later date, but I hope not.

Peter Wilson
  • 28,066

2 Answers2

2

\leqno is a primitive and not used in latex. The option in latex redefines \@eqnnum:

\documentclass{article}
\makeatletter
\newcommand\useleqno{\renewcommand\@eqnnum{\hb@xt@.01\p@{}%
                      \rlap{\normalfont\normalcolor
                        \hskip -\displaywidth(\theequation)}}}
\begin{document}
\begin{equation}
a + b = c          % numbered at right
\end{equation}

\bgroup
\useleqno
\begin{equation}
a + b = c
\end{equation}
\egroup

\begin{equation} 
a + b = c
\end{equation}

\end{document}

enter image description here

Ulrike Fischer
  • 327,261
  • Your solution to my original MWE worked but I didn't supply the whole story, which I have edited my original question to include. Applying your solution to the extended case the packages amsmath and newpxmath set the equation numbers all at the right but references to these are all OK. I will try and sort this out. – Peter Wilson Sep 13 '19 at 18:40
2

The commands only work in displaymath mode. Try:

$$ E = m c^2 \eqno (1) $$
$$ E = m c^2 \leqno (2) $$

Your examples cannot work as the definion of \endequation already uses \eqno:

% from latex.ltx
\def\equation{$$\refstepcounter{equation}}
\def\endequation{\eqno \hbox{\@eqnnum}$$\@ignoretrue}

So you can define your own environment (full MWE):

\documentclass{article}
% The definitions:
\makeatletter
\let\endeqno@equation\endequation
\def\endleqno@equation{\leqno \hbox{\@eqnnum}$$\@ignoretrue}
%
\def\lefteqnnum{\let\endequation\endleqno@equation}
\def\righteqnnum{\let\endequation\endeqno@equation}
\makeatother

\begin{document}

\begin{equation} E=mc^2 \end{equation}

\lefteqnnum
\begin{equation} E=mc^2 \end{equation}

\righteqnnum
\begin{equation} E=mc^2 \end{equation}

\end{document}

enter image description here

  • Your solution to my original MWE worked but there was a problem with the extended MWE. With the packages amsmath and newpxmath I couldn't reference a left aligned label but everything else was OK. However, your answer requires less code in the document body than the other one. – Peter Wilson Sep 13 '19 at 18:27