Search code examples
mathjaxdigits

mathjax commas in digits


This is a TeX legacy issue---it would have made more sense to require a whitespace when a whitespace is desired: 12,123 is probably a number, while 12, 123 is probably a list. Alas, it is what it is.

Related to MathJax rendering of commas in numbers, where the solution is suppression of spaces via {,}. Works, but inconvenient. Is there a way to make this automatic?

The hack in https://github.com/mathjax/MathJax/issues/169#issuecomment-2040235 is concerned with European vs Anglo. The equivalent hack,

<script type="text/x-mathjax-config">
  MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
    MathJax.InputJax.TeX.Definitions.number =
      /^(?:[0-9]+(?:\,[0-9]{3})*(?:\{\.\}[0-9]*)*|\{\.\}[0-9]+)/
  });
</script>

solves the comma problem in 1,234.56 but now there is a space after the period (i.e., before 5). I am not sure how the regex above works. can someone help?


Solution

  • Change the pattern to

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

    to allow 12,345.6 to be treated as a number, while 12, 345 is a list of two numbers. In the original pattern, the \{\.\} requires a literal {.} (braces included), not just a decimal.