KaTeX/contrib/auto-render
Martin von Gagern 53e416e296 Revert "Remove trailing commas for IE 9 compatibility"
This reverts commit 4d2e46e7f6.

Having trailing commans makes diffs easier to read as it avoids modifying a
line just to add a trailing comma if there is another item to add at the end
of a list.  There are plans to switch to ES6 notation and to translate that
to ES5 as part of the build process.  Since that translation would remove
trailing commas, the IE9 problems that originally motivated the commit
should vanish soon.
2017-01-11 13:26:00 +01:00
..
auto-render-spec.js Revert "Remove trailing commas for IE 9 compatibility" 2017-01-11 13:26:00 +01:00
auto-render.js Revert "Remove trailing commas for IE 9 compatibility" 2017-01-11 13:26:00 +01:00
index.html [auto-render] Don't stop parsing when one expression fails 2015-04-26 17:04:11 -07:00
Makefile Add basic auto-render extension 2015-04-01 15:57:10 -07:00
README.md Provide link to auto-render.min.js in usage example (#522) 2016-09-17 15:23:26 -07:00
splitAtDelimiters.js Revert "Remove trailing commas for IE 9 compatibility" 2017-01-11 13:26:00 +01:00

Auto-render extension

This is an extension to automatically render all of the math inside of text. It searches all of the text nodes in a given element for the given delimiters, and renders the math in place.

Usage

This extension isn't part of KaTeX proper, so the script should be separately included in the page:

<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.6.0/contrib/auto-render.min.js"></script>

Then, call the exposed renderMathInElement function in a script tag before the close body tag:

<body>
  ...
  <script>
    renderMathInElement(document.body);
  </script>
</body>

See index.html for an example.

API

This extension exposes a single function, window.renderMathInElement, with the following API:

function renderMathInElement(elem, options)

elem is an HTML DOM element. The function will recursively search for text nodes inside this element and render the math in them.

options is an optional object argument with the following keys:

  • delimiters: This is a list of delimiters to look for math. Each delimiter has three properties:

    • left: A string which starts the math expression (i.e. the left delimiter).
    • right: A string which ends the math expression (i.e. the right delimiter).
    • display: A boolean of whether the math in the expression should be rendered in display mode or not.

    The default value is:

    [
      {left: "$$", right: "$$", display: true},
      {left: "\\[", right: "\\]", display: true},
      {left: "\\(", right: "\\)", display: false}
    ]
    
  • ignoredTags: This is a list of DOM node types to ignore when recursing through. The default value is ["script", "noscript", "style", "textarea", "pre", "code"].