Files
KaTeX/website/versioned_docs/version-0.10.0-rc.1/api.md
ylemkimon 7ca6f51b9a Release v0.10.0-rc.1 (#1654)
Bump master to v0.10.0-pre
2018-08-23 02:42:24 +09:00

1.3 KiB

id, title, original_id
id title original_id
version-0.10.0-rc.1-api API api

In-browser rendering

Call katex.render with a TeX expression and a DOM element to render into:

katex.render("c = \\pm\\sqrt{a^2 + b^2}", element, {
    throwOnError: false
});

To avoid escaping the backslash (double backslash), you can use String.raw (but beware that ${, \u and \x may still need escaping):

katex.render(String.raw`c = \pm\sqrt{a^2 + b^2}`, element, {
    throwOnError: false
});

Server-side rendering or rendering to a string

To generate HTML on the server or to generate an HTML string of the rendered math, you can use katex.renderToString:

var html = katex.renderToString("c = \\pm\\sqrt{a^2 + b^2}", {
    throwOnError: false
});
// '<span class="katex">...</span>'

Handling errors

The examples above use the throwOnError: false option, which renders invalid inputs as the TeX source code in red (by default), with the error message as hover text. Without this option, invalid LaTeX will cause a katex.ParseError exception to be thrown. See handling errors.

Configuring KaTeX

The last argument to katex.render and katex.renderToString can contain a variety of rendering options.