Search code examples
javascriptlatexmathjax

How to not show parsing error in MathJax?


I am using MathJax for showing equations on my webpage. Using the below config script. But in case of syntax error, I Don't wanna show the exception instead it should show the Jax as it is. Gone through about formatError in here https://docs.mathjax.org/en/latest/options/input/tex.html but How to use it? tried a couple of methods but it does not help.

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    showMathMenu: false,
    extensions: ["tex2jax.js"],
    messageStyle: "none",
    showProcessingMessages : false,
    jax: ["input/TeX", "output/SVG"],
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
      processEscapes: true,
      preview: "none",
      
    },
    processEnvironments: true,
  });
</script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js"></script>

enter image description here


Solution

  • You probably want to use the noUndefined and noErrors extensions. The first will cause undefined macros to show as a red version of the macro name, but will typeset the rest of the expression. For example x + \3 would appear as

    enter image description here

    rather than the undefined control sequence message that you are seeing above.

    The second causes any other type of error to just display the original TeX code rather than the error message. So \frac{a}{b with a missing close brace would just display as \frac{a}{b rather than the error message.

    To do this, you would add

    TeX: {
      extensions: ['noErrors.js', 'noUndefined.js']
    },
    

    to your configuration. See the documentation for noUndefined and noErrors for more details.