Fast math typesetting for the web.
Clone or download
greenkeeper[bot] and ylemkimon Update rollup to the latest version πŸš€ (#1716)
* chore(package): update rollup to version 0.66.0

* chore(package): update lockfile yarn.lock
Latest commit c52d3be Sep 16, 2018
Permalink
Failed to load latest commit information.
.circleci Remove greenkeeper-lockfile (#1710) Sep 12, 2018
contrib Move to katex.org (#1680) Aug 31, 2018
dockers Fix screenshotter race conditions (#1643) Aug 21, 2018
docs Added correct hash for katex.min.css (#1692) Sep 2, 2018
src Remove duplicate defineFunction invocation for \mathop. (#1701) Sep 6, 2018
static Build ECMAScript modules (#1479) Aug 13, 2018
submodules Update fonts to remove \neq and \notin glyphs (#1499) Jul 22, 2018
test Upgrade to Babel 7 (#1595) Sep 3, 2018
website Use local built KaTeX on the main page for local and Netlify deploy p… Sep 3, 2018
.arcconfig Fix `arc lint` Jun 26, 2015
.arclint Replace `yarn run` and `yarn install` with `yarn`, remove building wi… Jul 30, 2018
.browserslistrc Add browserslist (#1662) Aug 28, 2018
.codecov.yml add .codecov.yml and disable patch coverage (#1164) Feb 17, 2018
.eslintignore Use local built KaTeX on the main page for local and Netlify deploy p… Sep 3, 2018
.eslintrc Upgrade to Babel 7 (#1595) Sep 3, 2018
.flowconfig Change build directory to `dist` and cleanup NPM scripts (#1500) Jul 23, 2018
.gitattributes Set up a diff attribute and textconv instructions for font files Jan 19, 2017
.gitignore Use local built CSS and fonts for master documentation (#1584) Aug 10, 2018
.gitmodules Add unicode-fonts as submodule (#1182) Mar 6, 2018
.stylelintrc Use local built CSS and fonts for master documentation (#1584) Aug 10, 2018
CHANGELOG.md Release v0.10.0-rc (#1634) Aug 19, 2018
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md (#553) Nov 3, 2016
CONTRIBUTING.md Move to katex.org (#1680) Aug 31, 2018
LICENSE Remove Object.assign() in auto-render which requires expensive polyfi… Aug 12, 2018
README.md Move to katex.org (#1680) Aug 31, 2018
babel.config.js Upgrade to Babel 7 (#1595) Sep 3, 2018
bower.json Update bower.json (#1694) Sep 2, 2018
check-node-version.js Improve prestart and tests (#1610) Aug 17, 2018
cli.js Use local built CSS and fonts for master documentation (#1584) Aug 10, 2018
greenkeeper.json Enable Greenkeeper on website/package.json (#1687) Sep 1, 2018
katex.js Remove indexOf & textContent polyfill for IE 8 (#1645) Aug 20, 2018
katex.webpack.js move katex.less into src (#1120) Jan 31, 2018
lint_blacklist.txt Change build directory to `dist` and cleanup NPM scripts (#1500) Jul 23, 2018
package.json Update rollup to the latest version πŸš€ (#1716) Sep 16, 2018
release.sh Move to Netlify (#1683) Sep 2, 2018
rollup.config.js Upgrade to Babel 7 (#1595) Sep 3, 2018
update-sri.js Update release script to use pull request (#1603) Aug 17, 2018
webpack.analyze.js Lint webpack.*.js (#1467) Jul 7, 2018
webpack.common.js Enable environment variable USE_TTF to disable bundling TTF fonts (#1600 Aug 13, 2018
webpack.config.js enforce consistent object brace spacing (#1376) May 28, 2018
webpack.dev.js enforce consistent object brace spacing (#1376) May 28, 2018
yarn.lock Update rollup to the latest version πŸš€ (#1716) Sep 16, 2018

README.md

KaTeX

npm CircleCI codecov Join the chat at https://gitter.im/Khan/KaTeX Greenkeeper badge jsDelivr

KaTeX is a fast, easy-to-use JavaScript library for TeX math rendering on the web.

  • Fast: KaTeX renders its math synchronously and doesn't need to reflow the page. See how it compares to a competitor in this speed test.
  • Print quality: KaTeX’s layout is based on Donald Knuth’s TeX, the gold standard for math typesetting.
  • Self contained: KaTeX has no dependencies and can easily be bundled with your website resources.
  • Server side rendering: KaTeX produces the same output regardless of browser or environment, so you can pre-render expressions using Node.js and send them as plain HTML.

KaTeX is compatible with all major browsers, including Chrome, Safari, Firefox, Opera, Edge, and IE 9–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!

Getting started

Starter template

<!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.10.0-rc.1/dist/katex.min.css" integrity="sha384-D+9gmBxUQogRLqvARvNLmA9hS2x//eK1FhVb9PiU86gmcrBrJAQT8okdJ4LMp2uv" crossorigin="anonymous">

    <!-- The loading of KaTeX is deferred to speed up page rendering -->
    <script defer src="https://cdn.jsdelivr.net/npm/katex@0.10.0-rc.1/dist/katex.min.js" integrity="sha384-483A6DwYfKeDa0Q52fJmxFXkcPCFfnXMoXblOkJ4JcA8zATN6Tm78UNL72AKk+0O" 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.10.0-rc.1/dist/contrib/auto-render.min.js" integrity="sha384-yACMu8JWxKzSp/C1YV86pzGiQ/l1YUfE8oPuahJQxzehAjEt2GiQuy/BIvl9KyeF" 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.

API

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.

Demo and Documentation

Learn more about using KaTeX on the website!

Contributing

See CONTRIBUTING.md

License

KaTeX is licensed under the MIT License.