MathML: spacing after \mathrm containing single letter
See original GitHub issueDescribe the bug:
Extra spacing appears after \mathrm{...} containing a single letter [a-zA-Z], for MathML output.
(La)TeX code:
\mathrm{d}x
See JSFiddle.
Expected behavior:
No spacing between \mathrm{d} and x.
Screenshot:

Environment (please complete the following information):
- KaTeX Version: 0.11.1
- Device: Desktop
- OS: Debian GNU/Linux 9.12 (stretch)
- Browser: Firefox
- Version: 71.0
Additional context:
- Weirdly, if one wraps either a digit (
\mathrm{1}) or more than one character (\mathrm{dd}), the after-spacing does not appear. - Usually I define a total differential macro like this:
\mathop{}\!\mathrm{d}.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
3 Presentation Markup
Also, when style sheet mechanisms are extended to MathML, even one version of a renderer may use different spacing rules for users with...
Read more >Rules for space when using \mathrm{} - LaTeX Stack Exchange
Between two atoms of type Ord, TeX inserts no space. To the contrary, 3\ln\left(x\right). contains again three atoms ...
Read more >Notes on MathML
When the first example is rendered, there is nothing before “Theorem”, one Unicode space character between “Theorem” and “1:”, and nothing after ......
Read more >LaTeX Error: \mathrm allowed only in math mode - Overleaf
LaTeX Error: \mathrm allowed only in math mode ; \mathit{...} This will give text italic letters. These can be different to math italic...
Read more >Help:Displaying a formula - Wikipedia
There are three methods for displaying formulas in Wikipedia: raw HTML, HTML with math templates (abbreviated here as {{math}}), and a subset of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’m not one of the original KaTeX developers and cannot speak to the thinking behind those decisions. I believe that early KaTeX wrote each character in its own MathML element. More recent versions have done some consolidation for better semantics. For instance, numbers,
\text{…}, and\operatorname{…}each consolidate their contents into a single MathML element. Perhaps other consolidations would be beneficial.Adding a
<mi></mi>to work around what appears to be a browser bug isn’t ideal. A Firefox-only CSS tweak to change the spacing might be better.Using
<mo> ⅆ </mo>for differentials would be awesome. The tricky thing is that the LaTeX for thedxis like any other identifiers. In order to recognize it as a differential operator we’d need to introduce a bunch of additional logic.