Katex: auto-render options not documented

Created on 17 Apr 2019  Â·  8Comments  Â·  Source: KaTeX/KaTeX

I was surprised to not see documentation of the special options supported by renderMathInElement, in particular delimiters which we often get questions about, in the auto-render extension documentation page. Before I forget, we should add that, ideally along with a common alternative for delimiters (and warnings about order).

contrib documentation

Most helpful comment

This issue is resolved by PR #1979. After the next KaTeX update, the documentation at https://katex.org/docs/autorender.html will be complete. Until then, the complete version is visible at https://katex.org/docs/next/autorender.html.

All 8 comments

Huh, that's timely, I just ran into the same issue. Would someone mind posting an example here? Because I want to configure the delimiters and I don't know how.

oh, never mind, UTSL revealed the magic:

https://github.com/KaTeX/KaTeX/blob/master/contrib/auto-render/auto-render.js#L96

 optionsCopy.delimiters = optionsCopy.delimiters || [
        {left: "$$", right: "$$", display: true},
        {left: "\\(", right: "\\)", display: false},
        // LaTeX uses $…$, but it ruins the display of normal `$` in text:
        // {left: "$", right: "$", display: false},

        //  \[…\] must come last in this array. Otherwise, renderMathInElement
        //  will search for \[ before it searches for $$ or  \(
        // That makes it susceptible to finding a \\[0.3em] row delimiter and
        // treating it as if it were the start of a KaTeX math zone.
        {left: "\\[", right: "\\]", display: true},
    ];

...so a complete workable example seems to be:

<script type="text/javascript">
  document.addEventListener("DOMContentLoaded", function() {
    renderMathInElement(document.body, {
      delimiters: [
        {left: "$$", right: "$$", display: true},
        {left: "\\(", right: "\\)", display: false},
      ]
    });
  });
</script>

@jason-s would be interested in updating the example in https://github.com/KaTeX/KaTeX/blob/master/docs/autorender.md?

@edemaine https://github.com/KaTeX/KaTeX/blob/master/docs/autorender.md does mention delimiters but agree that it needs a warning about the order. Are there options that are missing from that page?

@kevinbarabash Ah, indeed it does, but that's not getting output to https://katex.org/docs/autorender.html . Docusaurus bug?

Thanks for pointing that out. Sounds like it could be a Docusaurus bug.

It turns out it's not a Docusaurus bug. There's an unclosed HTML comment in that .md file which is causing the issue.
Screen Shot 2019-05-13 at 9 50 31 AM

This issue is resolved by PR #1979. After the next KaTeX update, the documentation at https://katex.org/docs/autorender.html will be complete. Until then, the complete version is visible at https://katex.org/docs/next/autorender.html.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

janosh picture janosh  Â·  4Comments

hagenw picture hagenw  Â·  3Comments

HughGrovesArup picture HughGrovesArup  Â·  4Comments

OisinMoran picture OisinMoran  Â·  4Comments

fabiospampinato picture fabiospampinato  Â·  4Comments