MathJax icon indicating copy to clipboard operation
MathJax copied to clipboard

[TeX] e.g. 4.4.4 parsed as 4.4 and .4

Open pkra opened this issue 5 months ago • 4 comments

This is a weird edge case but I thought I'd share it in case it's of interest.

The TeX parser turns e.g. $4.4.4$ into the number 4.4 followed by the number .4. SRE then (naturally) interprets this as an implicit multiplication which is a bit odd.

pkra avatar Jul 23 '25 10:07 pkra

Yes, this does seem to be an unusual situation. What does the 4.4.4 represent, in this case? Is this a section number or something like that? If so, should it really be in text mode rather than math mode?

I'm not sure what would be a better way to handle numbers that would deal with this. I'm not sure I'd want this to be marked as <mn>4.4.4</mn> since it is not really a number. I'm kind of at a loss as to how to address this. Do you have any suggestions?

dpvc avatar Aug 01 '25 17:08 dpvc

Sorry for the slow response.

What does the 4.4.4 represent, in this case?

I think it was a section or figure number.

I'm not sure I'd want this to be marked as <mn>4.4.4</mn> since it is not really a number. I'm kind of at a loss as to how to address this. Do you have any suggestions?

I'd go with whatever makes most sense to SRE.

FWIW mn seems fine to me. a) as I just did, people tend call this a number; b) mn is very permissive (the spec specifically gives "MCMLXIX" and "twenty one" as example content) c) numeral systems are wild https://en.wikipedia.org/wiki/List_of_numeral_systems#By_culture_/_time_period d) decimal markers are wild https://en.wikipedia.org/wiki/Decimal_separator#Examples_of_use.

pkra avatar Aug 18 '25 07:08 pkra

OK, one possible solution would be to use the configuration

MathJax = {
  tex: {
    numberPattern: /^(?:[0-9]+(?:\{,\}[0-9]{3})*(?:\.[0-9]*)*|(?:\.[0-9])+)/
  },
};

to extend the number pattern to allow multiple decimals. The changes here are to change the ? to a * before the | and to add (?: ... )+ around the pattern after the |. The latter might not be needed, but would allow .4.4 as a number.

Does that do what you need?

dpvc avatar Aug 18 '25 17:08 dpvc

Thanks. If you say it works, I'm sure it does.

pkra avatar Aug 18 '25 19:08 pkra