Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MJ4.0.0-beta.4: \rm in subscript yields Math input error #3184

Open
AlexEdgcomb opened this issue Feb 16, 2024 · 2 comments
Open

MJ4.0.0-beta.4: \rm in subscript yields Math input error #3184

AlexEdgcomb opened this issue Feb 16, 2024 · 2 comments
Labels
Accepted Issue has been reproduced by MathJax team Merged Merged into develop branch Test Needed v4
Milestone

Comments

@AlexEdgcomb
Copy link

AlexEdgcomb commented Feb 16, 2024

Issue Summary

\rm in the subscript yields Math input error in beta.4, but not beta.3 and earlier

Steps to Reproduce:

  1. Go to https://codepen.io/alexedgcomb/pen/BabMpmG
    Observed: \(a_\rm{b}\) yields `Math input error
image

Expected: No such error, like in 4.0.0-beta.3
https://codepen.io/alexedgcomb/pen/QWoYdOR
image

Technical details:

  • MathJax Version: 4.0.0-beta.4
  • Client OS: MacOS 13.4
  • Browser: Firefox 122 and Chrome 121

I am not using a MathJax configuration and loading MathJax via

<script src="https://cdn.jsdelivr.net/npm/mathjax@4.0.0-beta.4/tex-mml-svg.js"></script>

Supporting information:

Interestingly, the following typeset as expected:

  • \(\rm{b}\): So, not just a bad \rm
  • \(a_\textrm{b}\): So, not just a bad subscript followed by command

Repro steps:

  1. Go to https://codepen.io/alexedgcomb/pen/QWoYdOR
    Observed:
image
@dpvc
Copy link
Member

dpvc commented Feb 17, 2024

Actually, both v3 and v4 are incorrect for this, as a_\rm{b} is not a valid LaTeX expression (actual LaTeX throws an error for this). Note that \rm is not a macro that takes an argument, like \mathrm, but is a switch that makes everything following it be in upright letters. So a_\rm{b} is effectively {a_\rm}{b}, which produces an error in LaTeX (due to how \rm is implemented). Note that if you did \rm{b}x then the x would also be upright since \rm makes everything after it be upright. The macros \bf, \it, etc. also work the same way. So you should do {\rm b} not \rm{b}, and a_{\rm b} would do what you expect.

This is in contrast to commands like \mathrm, \textrm, \symrm, and so on, which take an argument and put that in upright form. Because of that (and how they are implemented), a_\mathrm{b} is effectively the same as a_{\rm b}, which is a valid expression. Similarly, \mathrm{b}x should have the b upright, but the x in italics, where \rm{b}x has both upright.

I was surprised to see that v3 didn't give an error for a_\rm{b} as it should have, but looking into the internals, I have found out why. It is not an easy fix, and I will have to think about how best to handle it.

The error in v4 is due to new code that tries to attach to the internal MathML nodes the LaTeX that produced that node, and it is crashing on this construction. I know where it is happening, but haven't tried to resolve the issue yet.

In any case, you should be using either a_{\rm b} or a_\mathrm{b}, but not a_\rm{b}, which will produce an error in future versions.

@dpvc dpvc added Accepted Issue has been reproduced by MathJax team v4 labels Feb 17, 2024
@AlexEdgcomb
Copy link
Author

Thank you for explaining!

@dpvc dpvc added this to the v4.0 milestone Feb 18, 2024
dpvc added a commit to mathjax/MathJax-src that referenced this issue Mar 16, 2024
Fix handling of _ and ^ followed by command that doesn't push content (mathjax/MathJax#3184)
@dpvc dpvc added Merged Merged into develop branch and removed Ready for Review labels Mar 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Issue has been reproduced by MathJax team Merged Merged into develop branch Test Needed v4
Projects
None yet
Development

No branches or pull requests

2 participants