mathlive icon indicating copy to clipboard operation
mathlive copied to clipboard

Whitespace after \neq command

Open benjaminwols opened this issue 2 months ago • 1 comments

Using the \neq command always adds whitespace after the symbol, which leads to awkward typesetting.

(\neg (a \Rightarrow \neg b) \lor {(c \land \neg a)}) \Leftrightarrow (a \Leftrightarrow d)

is rendered as Image

When comparing to KaTeX it gets rendered correctly: Image

We can advise users to workaround this by using mathord, but it is not very user friendly

(\mathord{\neg} (a \mathbin{\Rightarrow} \mathord{\neg} b) \mathbin{\lor} {(c \mathbin{\land} \mathord{\neg} a)}) \mathbin{\Leftrightarrow} (a \mathbin{\Leftrightarrow} d)
Image

Is this intentional?

benjaminwols avatar Sep 07 '26 13:09 benjaminwols

Nice report — the \mathord comparison makes the cause pretty clear.

I think this isn't whitespace being added, it's \neg being classified as a relation (mrel)​ instead of ordinary (mord)​.

MathLive 0.111.1 renders \neg b as:

<span class="ML__ams">¬</span>
<span style="display:inline-block;width:0.28em"></span>
<span class="ML__mathit">b</span>

That 0.28em is the same gap MathLive puts on both sides of \Rightarrow. \lor gets 0.23em. The ratio 0.28 / 0.23 ≈ 1.22 lines up with TeX's thick space vs medium space (5mu : 4mu), so it's the atom class driving the width, not the spacing logic.

Two more data points that support this:

  • \forall x and \exists y produce no gap. (The 0.04em on y is italic correction, unrelated.) So this isn't "all prefix logic operators are treated as relations" — it's specific to \neg / \lnot.
  • \neg(a) also gets the gap before the (, which fits relation-class spacing rather than something applied only between an operator and its operand.

So my guess is it's unintentional — TeX defines \neg as class 0 (Ord), and \lnot is the same glyph mapped to the same character.

Suggested fix:​ change the atom class of \neg (and \lnot) from mrel to mord in the definitions.

On catching the rest:​ rendering the full symbol set and looking for a zero-content display:inline-block span with a fixed width inserted between two atoms is a cheap way to find this whole class of bug at once, instead of reporting them one at a time. I haven't run it across the whole set, but among the logic operators I tested, \neg / \lnot were the only ones affected.

Image

liliyang857 avatar Oct 23 '26 09:10 liliyang857