Fast math typesetting for the web.
JavaScript CSS HTML Other
Clone or download
ylemkimon Add credits to the KaTeX team and contributors (#1601)
* Add credits to the KaTeX team and contributors

* Remove Team

* Update link to contributors in main page, add license information

* Add license information to footer
Latest commit e8f2ecd Aug 15, 2018
Permalink
Failed to load latest commit information.
.circleci Enable environment variable USE_TTF to disable bundling TTF fonts (#1600 Aug 13, 2018
contrib Remove Object.assign() in auto-render which requires expensive polyfi… Aug 12, 2018
dockers Rename Screenshotter -> screenshotter (#1573) Aug 10, 2018
docs Build ECMAScript modules (#1479) Aug 13, 2018
src Add min-height CSS to print (#1594) Aug 14, 2018
static Build ECMAScript modules (#1479) Aug 13, 2018
submodules Update fonts to remove \neq and \notin glyphs (#1499) Jul 22, 2018
test Rename .value to .body in "ordgroup". (#1609) Aug 13, 2018
website Add credits to the KaTeX team and contributors (#1601) Aug 15, 2018
.arcconfig Fix `arc lint` Jun 26, 2015
.arclint Replace `yarn run` and `yarn install` with `yarn`, remove building wi… Jul 30, 2018
.babelrc Build ECMAScript modules (#1479) Aug 13, 2018
.codecov.yml add .codecov.yml and disable patch coverage (#1164) Feb 17, 2018
.eslintignore Lint website (#1519) Jul 28, 2018
.eslintrc Build ECMAScript modules (#1479) Aug 13, 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 changelog for KaTeX - complete w/ links (#1322) May 18, 2018
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md (#553) Nov 3, 2016
CONTRIBUTING.md Rename Screenshotter -> screenshotter (#1573) Aug 10, 2018
LICENSE Remove Object.assign() in auto-render which requires expensive polyfi… Aug 12, 2018
README.md Add jsDelivr badge (#1614) Aug 14, 2018
bower.json Change build directory to `dist` and cleanup NPM scripts (#1500) Jul 23, 2018
check-node-version.js Update css-loader to the latest version 🚀 and use `postcss-loader` an… Jul 22, 2018
cli.js Use local built CSS and fonts for master documentation (#1584) Aug 10, 2018
greenkeeper.json Update dependencies to enable Greenkeeper 🌴 (#1368) May 28, 2018
katex.js Convert ParseNode to struct (#1534) Aug 1, 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 eslint-plugin-transform-runtime-aliasing to the latest version 🚀 Aug 13, 2018
release.sh Use local built CSS and fonts for master documentation (#1584) Aug 10, 2018
rollup.config.js Build ECMAScript modules (#1479) Aug 13, 2018
update-sri.js Add missing `v` prefix to the size badge URL (#1342) May 23, 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 eslint-plugin-transform-runtime-aliasing to the latest version 🚀 Aug 13, 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-beta/dist/katex.min.css" integrity="sha384-9tPv11A+glH/on/wEu99NVwDPwkMQESOocs/ZGXPoIiLE8MU/qkqUcZ3zzL+6DuH" 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-beta/dist/katex.min.js" integrity="sha384-U8Vrjwb8fuHMt6ewaCy8uqeUXv4oitYACKdB0VziCerzt011iQ/0TqlSlv8MReCm" 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-beta/dist/contrib/auto-render.min.js" integrity="sha384-aGfk5kvhIq5x1x5YdvCp4upKZYnA8ckafviDpmWEKp4afOZEqOli7gqSnh8I6enH" 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.