Security News
NVD Backlog Tops 20,000 CVEs Awaiting Analysis as NIST Prepares System Updates
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
KaTeX is a fast, easy-to-use JavaScript library for TeX math rendering on the web. It provides a way to display mathematical notation in web pages, supporting a wide range of TeX functions and symbols.
Render TeX to HTML
This feature allows you to convert TeX expressions into HTML. The `renderToString` method takes a TeX string and returns an HTML string that can be inserted into a web page.
const katex = require('katex');
const html = katex.renderToString('c = \pm\sqrt{a^2 + b^2}');
console.log(html);
Render TeX to DOM
This feature allows you to render TeX expressions directly into a DOM element. The `render` method takes a TeX string and a DOM element, and it updates the element's content with the rendered math.
const katex = require('katex');
const element = document.getElementById('math');
katex.render('E = mc^2', element);
Auto-render TeX in HTML
This feature automatically finds and renders all TeX expressions within a given DOM element. The `renderMathInElement` function scans the element for TeX expressions and replaces them with rendered math.
const katex = require('katex');
const renderMathInElement = require('katex/contrib/auto-render');
renderMathInElement(document.body);
MathJax is another popular JavaScript library for displaying mathematical notation in web pages. It supports a wider range of input formats, including TeX, MathML, and AsciiMath. MathJax is known for its high-quality rendering and extensive configurability, but it is generally slower than KaTeX.
AsciiMath is a simpler alternative to KaTeX and MathJax, designed for ease of use. It uses a more human-readable syntax compared to TeX. While it is easier to write and understand, it does not support as many advanced mathematical features as KaTeX or MathJax.
KaTeX is a fast, easy-to-use JavaScript library for TeX math rendering on the web.
KaTeX is compatible with all major browsers, including Chrome, Safari, Firefox, Opera, Edge, and IE 11.
KaTeX supports much (but not all) of LaTeX and many LaTeX packages. See the list of supported functions.
Try out KaTeX on the demo page!
<!DOCTYPE html>
<!-- KaTeX requires the use of the HTML5 doctype. Without it, KaTeX may not render properly -->
<html>
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/katex.min.css" integrity="sha384-Xi8rHCmBmhbuyyhbI88391ZKP2dmfnOl4rT9ZfRI7mLTdk1wblIUnrIq35nqwEvC" crossorigin="anonymous">
<!-- The loading of KaTeX is deferred to speed up page rendering -->
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/katex.min.js" integrity="sha384-X/XCfMm41VSsqRNQgDerQczD69XqmjOOOwYQvr/uuC+j4OPoNhVgjdGFwhvN02Ja" crossorigin="anonymous"></script>
<!-- To automatically render math in text elements, include the auto-render extension: -->
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/contrib/auto-render.min.js" integrity="sha384-+XBljXPPiv+OzfbB3cVmLHf4hdUFHlWNZN5spNQ7rmHTXpd7WvJum6fIACpNNfIR" crossorigin="anonymous"
onload="renderMathInElement(document.body);"></script>
</head>
...
</html>
You can also download KaTeX and host it yourself.
For details on how to configure auto-render extension, refer to the documentation.
Call katex.render
to render a TeX expression directly into a DOM element.
For example:
katex.render("c = \\pm\\sqrt{a^2 + b^2}", element, {
throwOnError: false
});
Call katex.renderToString
to generate an HTML string of the rendered math,
e.g., for server-side rendering. For example:
var html = katex.renderToString("c = \\pm\\sqrt{a^2 + b^2}", {
throwOnError: false
});
// '<span class="katex">...</span>'
Make sure to include the CSS and font files in both cases. If you are doing all rendering on the server, there is no need to include the JavaScript on the client.
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. For other available options, see the
API documentation,
options documentation, and
handling errors documentation.
Learn more about using KaTeX on the website!
This project exists thanks to all the people who contribute code. If you'd like to help, see our guide to contributing code.
Become a financial contributor and help us sustain our community.
Support this project with your organization. Your logo will show up here with a link to your website.
KaTeX is licensed under the MIT License.
FAQs
Fast math typesetting for the web.
The npm package katex receives a total of 0 weekly downloads. As such, katex popularity was classified as not popular.
We found that katex demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.