7

The LaTeX file

\documentclass[12pt]{article}
\begin{document}
$$ a \eqno 1 $$
N\\N

$$ a \eqno 1 $$% N\N \end{document}

produces an unwanted space after the first displayed equation under "LaTeX2e <2022-11-01> patch level 1":

Under previous versions of LaTeX such as "LaTeX2e <2021-11-15> patch level 1", the file produced

I tried to obtain the previous behavior by inserting

\setcounter{localmathalphabets}{0}

before the \begin{document} command, following the suggestion in this related question, but that did not change the output. I also tried to obtain the previous behavior by inserting

\RequirePackage[2021/11/15]{latexrelease}

before the \begin{document} command, but that did not change the output either. What can I do so that old documents produce the same output as they did before?

(If one removes \eqno then the unwanted space disappears.)

  • 3
    Welcome to tex.sx. It's recommended that $$ not be used with LaTeX; \begin{equation} ... \end{equation} is recommended instead, and equation numbers are provided automatically. (There's also the problem with $$ that, if the equation is very long, an equation number is overprinted. I don't know any automatic fix for that; it isn't a problem with equation.) – barbara beeton Apr 28 '23 at 19:47
  • 1
    \RequirePackage[2021-06-01]{latexrelease} before \documentclass as a provisory measure. – user691586 Apr 28 '23 at 20:09
  • I can confirm that the suggestion by @user691586 works. – Gabriel A. Lozada Apr 28 '23 at 20:56
  • It turns out that \RequirePackage[2021-11-14]{latexrelease} also works. – Gabriel A. Lozada Apr 29 '23 at 23:11
  • 2
    This is so screwed up. Easily a third or more of LaTeX documents use $$, if not more. Many of them, such as arXiv papers, simply cannot be changed. Are they all going to have wrong formatting from now on? arXiv is known to periodically upgrade and recompile LaTeX documents, which means this regression will now propagate into older papers that used to have correct formatting. – Dmitri Pavlov Apr 30 '23 at 04:41
  • @DmitriPavlov a third of latex documents use \eqno , really?? in any case https://github.com/latex3/latex2e/issues/1059 – David Carlisle Apr 30 '23 at 12:11
  • 1
    @DavidCarlisle: Probably less than a third of LaTeX documents use \eqno, but a lot of them do use \eqno, including many papers on arXiv that cannot be fixed. Thank you for filing the bug report, I hope this regression gets fixed. – Dmitri Pavlov Apr 30 '23 at 16:39
  • i'll have a search I don't think I have ever seen \eqno in a latex document in over 30 years supporting latex, but as I say we'll probably fix it – David Carlisle Apr 30 '23 at 16:41
  • @DavidCarlisle: A fix would help with documents written by authors using robust workarounds forged in the difficult "before 1992" era described by egreg: "For mathematical writing, AMS-TeX... was essentially the only choice. LaTeX provided for automatic numbering and cross-references, but only offered... eqnarray (the latter producing plainly wrong output). People using LaTeX for mathematics often resorted to plain TeX constructs... AMS-TeX provided no automatic numbering nor cross-references." – Gabriel A. Lozada Apr 30 '23 at 18:11
  • @GabrielA.Lozada sure but that is rather less than a third of the entire latex corpus-) – David Carlisle Apr 30 '23 at 18:19
  • @DavidCarlisle: I'll defer to you on that! – Gabriel A. Lozada May 01 '23 at 15:07
  • This small formatting problem with old documents is probably a (very) small price to pay, and it may finally make people to change to proper latex syntax. – Máté Wierdl May 02 '23 at 19:31
  • 1
    @MátéWierdl: Price to pay for what, exactly? There is no benefit compared to the situation when this bug is fixed. – Dmitri Pavlov May 02 '23 at 21:21
  • @DmitriPavolv People finally writing proper latex documents instead of passing down incorrect syntax for generations. Because of this practice, I still see graduate students who do not know that latex can automatically number equations which then can be referenced via labels. These students never ever open a latex reference since "all compiles fine". Only later they may see that when they send their files to collaborators, the collaborators may have a hard time with corrections and additions. – Máté Wierdl May 02 '23 at 22:57
  • 1
    @MátéWierdl: But it's not incorrect syntax; “incorrect syntax” has a precise meaning: the compiler must give an error or a diagnostic message, and LaTeX processes $$...$$ and \eqno just fine without any warnings whatsoever. By the way, it is trivial to automatically number equations using $$...$$ and \eqno, and in fact that's what some of us use (e.g., with a macro). It produces a far more readable source code than the clumsy \begin{equation}...\end{equation}, especially if you use lots of displayed formulas. In addition, $$...$$ does not have the infamous spacing bug present in \[...\]. – Dmitri Pavlov May 03 '23 at 00:58
  • @MátéWierdl: I mentioned in my first comment on David Carlislie's answer that I, just like Dmitri Pavlov, use macros to automatically number equations using $$...$$ and \eqno. Indeed it is because I wanted to automatically number complicated equation numbers that I originally used $$...$$ and \eqno. (Well that and to avoid the awful \eqnarray.) – Gabriel A. Lozada May 03 '23 at 23:57
  • @DmitriPavlov: What is the "infamous spacing bug present in \[...\]"? Is it the displayshortskip problem? I can confirm that, as Barbara Beeton observed, the Plain TeX equation alignment commands (which I've been using) don't have that problem. Until this is fixed in amsmath, Plain's $$...$$ constructs seem superior to LaTeX's (given automatic numbering macros). – Gabriel A. Lozada May 04 '23 at 01:01
  • @GabrielA.Lozada: The spacing bug is described in detail here: https://tex.stackexchange.com/questions/503/why-is-preferable-to/163205#163205 – Dmitri Pavlov May 04 '23 at 16:16
  • @DmitriPavlov: Thanks! That problem is inconsistent spacing between displayed equations denoted by [...] and immediately following each other and beginning a paragraph. It could be fixed by using amsmath's "gather." The displayshortskip problem I referenced above is different and harder to fix, although wea0 proposed a solution there (revised by Bolpat). – Gabriel A. Lozada May 05 '23 at 01:34
  • (To use Plain's $$...$$ multi-equation constructs in LaTeX, one would have to copy Plain's definitions for \eqalign, \eqalignno, \leqalignno, and \displaylines; see for example the cjwplain package.) – Gabriel A. Lozada May 05 '23 at 02:00
  • The bug has been fixed in the git repository of LaTeX: https://github.com/latex3/latex2e/commit/cb79452f43b76a3248a9d4a2128a435f3952fb88 – Dmitri Pavlov May 14 '23 at 22:12
  • The problem has been fixed in the LaTeX release of 2023-06-01, as documented on page 5 of the corresponding issue of LaTeX News. Thanks to @DavidCarlisle for his willingness to fixing the problem. – Gabriel A. Lozada Jun 25 '23 at 04:54

1 Answers1

11

$$ has never been supported latex syntax, so this should never have appeared in a latex document, but you could do:

\documentclass[12pt]{article}
\let\xxeqno\eqno
\def\eqno{\xxeqno\aftergroup\ignorespaces}
\begin{document}
$$ a \eqno 1 $$
N\\N

$$ a \eqno 1 $$% N\N \end{document}

David Carlisle
  • 757,742
  • 1
    I can confirm that this works, so I can process legacy documents without much change, which is great! For equation numbers on the left, one would use, e.g., \let\yyleqno\leqno \def\leqno{\yyleqno\aftergroup\ignorespaces}. As for $$ "should never have appeared in a LaTeX document," my excuse is that in 1989 when I wrote macros to automatically number equations such as (7'), (A1), (A2), (A1'), (A3a), (A3b), I could not figure out how to do it using then-existing LaTeX constructs, so I used Plain TeX constructs. For more than 30 years those macros didn't break so I didn't fix them. – Gabriel A. Lozada Apr 28 '23 at 22:45
  • 1
    There are tons and tons of LaTeX documents out there that use $$. Is it really reasonable to suggest that they all be edited to change $$ to \[ or add percent signs after $$? What about documents that cannot be changed, such as arXiv papers etc.? Are there any plans to fix this regression in a future version of LaTeX? – Dmitri Pavlov Apr 30 '23 at 04:39
  • 1
    @DmitriPavlov oh we will probably fix it but it is important to stress that $$ has never been supported syntax it is not even mentioned in the latex book. also note here $$ is not the problem it is \eqno I have hardly ever seen eqno used in a latex document – David Carlisle Apr 30 '23 at 08:46
  • @DmitriPavlov The problem presents itself only when \eqno is used together with $$. This combination is surely not in "tons and tons" of documents, and those people who are outraged by this tiny formatting change potentially appearing in their old documents will indeed be very small,and they can safely be asked to add those two corrective lines to their outdated and incorrectly written documents. – Máté Wierdl May 02 '23 at 19:47
  • 1
    @MátéWierdl: In many contexts, it is not possible to “add corrective lines”. For example, papers on arXiv cannot be changed, and although new versions can be uploaded, in many cases it is impractical (e.g., if the author died). This is not a “tiny formatting change”: it can change page numbers, potentially rendering existing references to arXiv papers invalid. – Dmitri Pavlov May 02 '23 at 21:20
  • @DmitriPavlov there are some, eg https://arxiv.org/format/1801.08138 but you have to search quite hard, your suggestion that it is a third of all documents is rather unreasonable:-) however it's a pointless discussion since (a) I show the fix here and (b) at no point did I suggest a similar fix wouldn't be added to latex. – David Carlisle May 02 '23 at 21:47
  • Hm, so latex developers are at a crossroads: should they let people continue to write incorrect latex documents or from now on people will start using proper latex facilities instead of mixing in TeX. The change from latex 2.09 to latex 2e was much more dramatic, but people adjusted, because they saw the fantastic benefits. As @GabrielALozada wrote, if things don't work, people will fix incorrect syntax---but only then. – Máté Wierdl May 02 '23 at 22:37
  • 2
    @MátéWierdl if it gave an error, perhaps, but not silently adding bad space. Are you offering to check a couple of million arxiv files and update as needed? The change to 2e was not that dramatic, if you kept \documentstyle the vast majority of documents ran unchanged – David Carlisle May 02 '23 at 22:49
  • @DavidCarlisle It certainly gets hopelessly confusing that one gets an error about bad usage in case \[ a \eqno 1 \] N\\ N but not when $$ a \eqno 1 $$ N\\ N. And the error message disappears when I add \usepackage{amsmath}. – Máté Wierdl May 04 '23 at 03:30
  • David Carlisle discusses in the git repository how the LaTeX project team could address the conflict that this fix can have with amsmath. – Gabriel A. Lozada May 15 '23 at 00:11