2

MWE:

\documentclass{article}
\begin{document}
  $$x\eqno (1)$$
  N\\N
  $$y\leqno (2)$$
  N\\N
\end{document}

enter image description here

The lines following display equations $$...$$ with \eqno or \leqno are slightly indented. Looks like this is a known bug: https://github.com/latex3/latex2e/issues/1059

Is there any workaround or alternative?

9
  • 2
    Don't use $$...$$ in latex - Why is \[ … \] preferable to $$? Commented May 27 at 13:52
  • 1
    Update your TeX distribution? It is fixed in current LaTeX.
    – cfr
    Commented May 27 at 14:02
  • @cfr, my TeX distribution is installed as a system package.
    – Alexey
    Commented May 27 at 14:03
  • 1
    Well, you have to install upstream or persuade your distro to patch/update or wait. Theoretically, I guess you could try to do something local, but that sounds as if it would be messy (judging from the bug discussion). As @samcarter_is_at_topanswers.xyz says, this isn't LaTeX syntax anyway, so the real solution is not to use $$ in LaTeX.
    – cfr
    Commented May 27 at 14:06
  • 1
    duplicate of tex.stackexchange.com/questions/684207/…
    – user691586
    Commented May 27 at 14:11

2 Answers 2

3

You're asking for an alternative.

First off, equation numbers should be either all on the right or all on the left. In LaTeX you use equation and not $$. This way, the equation number is automatically provided and you don't need to take care of them manually.

In the following examples, I use twocolumn just for making smaller pictures.

No option, numbers on the right

\documentclass[twocolumn]{article}
\begin{document}

\begin{equation}
x
\end{equation}
text that wraps over to the next line,
showing that no indentation appears
\begin{equation}
y
\end{equation}
text that wraps over to the next line,
showing that no indentation appears

\end{document}

enter image description here

With leqno numbers are on the left

\documentclass[leqno,twocolumn]{article}
\begin{document}

\begin{equation}
x
\end{equation}
text that wraps over to the next line,
showing that no indentation appears
\begin{equation}
y
\end{equation}
text that wraps over to the next line,
showing that no indentation appears

\end{document}

enter image description here

With fleqn equations are at a fixed distance from the margin

\documentclass[fleqn,twocolumn]{article}
\begin{document}

\begin{equation}
x
\end{equation}
text that wraps over to the next line,
showing that no indentation appears
\begin{equation}
y
\end{equation}
text that wraps over to the next line,
showing that no indentation appears

\end{document}

enter image description here

You can also get numbers on the left by adding the leqno option.

enter image description here

Comments

You see that the document code doesn't change, only the options.

Workaround

If you insist in using the deprecated $$ and manually providing equation numbers, with all the problems this creates, you can do what the current LaTeX kernel does.

\documentclass[fleqn,leqno,twocolumn]{article}

\makeatletter
\@ifundefined{@kernel@eqno}{%
  \let\@kernel@eqno\eqno
  \let\@kernel@leqno\leqno
  \protected\def\eqno{\@kernel@eqno\aftergroup\ignorespaces}%
  \protected\def\leqno{\@kernel@leqno\aftergroup\ignorespaces}%
}
\makeatother

\begin{document}

$$
x\eqno(1)
$$
text that wraps over to the next line,
showing that no indentation appears
$$
y\leqno(1)
$$
text that wraps over to the next line,
showing that no indentation appears

\end{document}

enter image description here

Tested with TeX Live from 2012 to 2024.

3
  • "First off, equation numbers should be either all on the right or all on the left" -- it depends. I may want to show examples of different styles in the same document, or (as is my case) quote various sources while trying to keep their style and layout.
    – Alexey
    Commented May 27 at 16:33
  • @Alexey Look at nccmath that provides environments for switching the position of equation numbers mid document. If you want manual numbering, there's \tag from amsmath. You have to work harder to find an argument that will convince me that $$ has any place inside a LaTeX document environment (it can be used for defining environments, though).
    – egreg
    Commented May 27 at 16:50
  • Thanks, I'll check out nccmath. I was not saying that $$ "had a place". I was using it as a quick solution. Of course ideally LaTeX should function like a modern programming language, where you can do anything locally without messing up the whole.
    – Alexey
    Commented May 27 at 17:18
2

I think the fix as applied to LaTeX kernel was

\documentclass{article}
\makeatletter
\let\@kernel@eqno\eqno
\let\@kernel@leqno\leqno
\protected\def\eqno{\@kernel@eqno\aftergroup\ignorespaces}
\protected\def\leqno{\@kernel@leqno\aftergroup\ignorespaces}
\makeatother

\begin{document}
  $$x\eqno (1)$$
  N\\N
  $$y\leqno (2)$$
  N\\N
\end{document}

But don't do that with LaTeX 2023-06-01 or later as it creates infinite loop.

You must log in to answer this question.

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