Fix handling of _ and ^ followed by command that doesn't push content (mathjax/MathJax#3184) #1060
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes an issue with how
_
and^
interact with macros that don't push any content (like\rm
). In the past, something likea_\rm{b}c
would not produce an error (as it should), but instead ended up with ana
having an uprightb
subscript, followed by an uprightc
. 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 theb
becomes the subscript. Because\rm
set the normal variant, that affects both theb
and thec
(and any following characters). What should happen is an error message from the_
concerning missing braces.In addition,
a_\rm{b}c
would thrown amath input error
in theupdateResult()
function, since it was being called before the subscript was actually processed, butupdateResult()
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 thecheckItem()
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 examplea_\tag{b}{c}
, and so on.View this without whitespace differences for an easier-to-read difference listing.
Resolves issue mathjax/MathJax#3184.