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

Fix handling of _ and ^ followed by command that doesn't push content (mathjax/MathJax#3184) #1060

Merged
merged 1 commit into from Mar 16, 2024

Conversation

dpvc
Copy link
Member

@dpvc dpvc commented Feb 18, 2024

This PR fixes an issue with how _ and ^ interact with macros that don't push any content (like \rm). In the past, something like a_\rm{b}c would not produce an error (as it should), but instead ended up with an a having an upright b subscript, followed by an upright c. This is because \rm doesn't push any nodes onto the parser stack, and so the checking for the _ is not performed until the next token, {, is pushed, and the b becomes the subscript. Because \rm set the normal variant, that affects both the b and the c (and any following characters). What should happen is an error message from the _ concerning missing braces.

In addition, a_\rm{b}c would thrown a math input error in the updateResult() function, since it was being called before the subscript was actually processed, but updateResult() tried to use the subscript, even though it is null.

We fix the latter issue by checking for null children before using them.

We fix the former problem by introducing a new NullItem stack item that is pushed by macros that would not otherwise push any content. That triggers the checkItem() calls for the current stack items (like the one for _) so that they will produce the proper error messages. I looked through all the TeX package methods and added pushing the null item for those that didn't have any other pushes (at least the ones I could see on a quick pass through) and that didn't check foreign inside a specific stack item type. That should introduce error messages if any of them are used with _, for example a_\tag{b}{c}, and so on.

View this without whitespace differences for an easier-to-read difference listing.

Resolves issue mathjax/MathJax#3184.

@dpvc dpvc requested a review from zorkow February 18, 2024 16:32
@dpvc dpvc added this to the v4.0 milestone Feb 18, 2024
Copy link
Member

@zorkow zorkow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. The only thing I am a bit concerned about is whether these are all the cases of "empty" commands.

@dpvc
Copy link
Member Author

dpvc commented Mar 16, 2024

Yes, I'm not positive I found them all, but any that I missed will just work as they always did, so no harm there, and we can fix them in the future if we find any.

@dpvc dpvc merged commit 119fb6b into develop Mar 16, 2024
@dpvc dpvc deleted the issue3184 branch March 16, 2024 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants