Katex: \bmod in inline math mode adds extra following space

Created on 23 Nov 2017  路  6Comments  路  Source: KaTeX/KaTeX

Test file: https://cdn.rawgit.com/akalin/98bc47f5e54f7529462f12a1d7336858/raw/28a50452296c9d7bd4dc9e5023056cf64412a913/test-0.8.3.html

Using \bmod in inline math mode seems to add some extra following space, which seems like a bug. Not sure if it's a problem with other binary operators.

bug

All 6 comments

This is a consequence of #836, I'm afraid. (Not quite sure why \bmod is implemented with negative space, but it is.) We still don't know how to fix it (or the exact cause).

Hmm...but does it need negative space? If I use \mathbin{\mathrm{mod}} that works perfectly fine: see
https://cdn.rawgit.com/akalin/98bc47f5e54f7529462f12a1d7336858/raw/b71b173e7fdc3459938d7f362574da51eacdad6a/test-0.8.3.html

So I guess that's a workaround for now.

For some reason, LaTeX (latex.ltx) defines \bmod as follows:

\def\bmod{%
  \nonscript\mskip-\medmuskip\mkern5mu%
  \mathbin{\operator@font mod}\penalty900\mkern5mu%
  \nonscript\mskip-\medmuskip}

So KaTeX is mimicking that. Basically, in display/textstyle, we want 5mu minus \medmuskip (which is 4mu plus 2mu minus 1mu skip), while in script/scriptscriptstyle, we want 5mu skip. Given the #836 bug, I think it'd be nice to remove the negative space in \bmod. I've created PR #984 to this effect.

Meanwhile, you can define a macro of "\\bmod": "\\kern1mu\\mathbin{\\mathrm{mod}}}\\kern1mu", assuming you're not using \bmod in subscripts.

Hmm, that \bmod macro seems to have too little space after mod. With

\begin{aligned}
& (a \cdot b) \bmod 257 \\
& (a \cdot b) \mathbin{\mathrm{mod}} 257 \\
& (a \cdot b) \kern1mu\mathbin{\mathrm{mod}}\kern1mu 257
\end{aligned}

I get

screen shot 2017-11-23 at 2 04 04 pm

\mathbin{\mathrm{mod}} seems closer to \bmod.

Although the 2nd \kern1mu should _add_ space, right? It's weird that putting it in _removes_ space...

I saw that too. Must be a bug of some sort... Should track it down.

The PR has the right space though.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pyramation picture pyramation  路  4Comments

trollanfer picture trollanfer  路  5Comments

hagenw picture hagenw  路  3Comments

mpolyak picture mpolyak  路  3Comments

q2apro picture q2apro  路  3Comments