Fast math typesetting for the web.
Clone or download
ylemkimon and kevinbarabash Include only necessary fonts for target environment specified by Brow…
…serslist (#1674)

* Include only necessary fonts for target environment specified by Browserslist

Allow WOFF and WOFF2 to be controlled using environment variables

* Fix links

* Fix merge error

* Update dependencies

* Replace uglifyjs-webpack-plugin with terser-webpack-plugin

* Do not set `targets` if !isESMBuild
Latest commit ce3840d Dec 2, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci Replace Khan/KaTeX with KaTeX/KaTeX (#1781) Nov 20, 2018
contrib Add mhchem extension (#1436) Nov 24, 2018
dockers Allow screenshotter to be run on IE, Edge, Safari and remote, e.g., B… Oct 28, 2018
docs Include only necessary fonts for target environment specified by Brow… Dec 2, 2018
src Add mhchem extension (#1436) Nov 24, 2018
static Build ECMAScript modules (#1479) Aug 13, 2018
submodules Update fonts to remove \neq and \notin glyphs (#1499) Jul 22, 2018
test Add catcode to Lexer, move comment parsing back to Lexer (#1789) Nov 24, 2018
website Remove Supported Functions onPageNav style (#1767) Nov 21, 2018
.browserslistrc Add browserslist (#1662) Aug 28, 2018
.codecov.yml add .codecov.yml and disable patch coverage (#1164) Feb 17, 2018
.eslintignore Add mhchem extension (#1436) Nov 24, 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 Replace Khan/KaTeX with KaTeX/KaTeX (#1781) Nov 20, 2018
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md (#553) Nov 3, 2016
CONTRIBUTING.md Replace Khan/KaTeX with KaTeX/KaTeX (#1781) Nov 20, 2018
LICENSE Remove Object.assign() in auto-render which requires expensive polyfi… Aug 12, 2018
README.md Replace Khan/KaTeX with KaTeX/KaTeX (#1781) Nov 20, 2018
babel.config.js Include only necessary fonts for target environment specified by Brow… Dec 2, 2018
bower.json Replace Khan/KaTeX with KaTeX/KaTeX (#1781) Nov 20, 2018
cli.js cli's default maxSize should be Infinity, not 0 (#1739) Oct 13, 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 Generate ECMAScript module for contrib (#1624) Oct 31, 2018
package.json Include only necessary fonts for target environment specified by Brow… Dec 2, 2018
release.sh Replace Khan/KaTeX with KaTeX/KaTeX (#1781) Nov 20, 2018
rollup.config.js Generate ECMAScript module for contrib (#1624) Oct 31, 2018
update-sri.js Replace Khan/KaTeX with KaTeX/KaTeX (#1781) Nov 20, 2018
webpack.analyze.js Lint webpack.*.js (#1467) Jul 7, 2018
webpack.common.js Include only necessary fonts for target environment specified by Brow… Dec 2, 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 Include only necessary fonts for target environment specified by Brow… Dec 2, 2018

README.md

KaTeX

npm CircleCI codecov Join the chat at https://gitter.im/KaTeX/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/dist/katex.min.css" integrity="sha384-9eLZqc9ds8eNjO3TmqPeYcDj8n+Qfa4nuSiGYa6DjLNcv9BtN69ZIulL9+8CqC9Y" 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/dist/katex.min.js" integrity="sha384-K3vbOmF2BtaVai+Qk37uypf7VrgBubhQreNQe9aGsz9lB63dIFiQVlJbr92dw2Lx" 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/dist/contrib/auto-render.min.js" integrity="sha384-kmZOZB5ObwgQnS/DuDg6TScgOiWWBiVt0plIRkZCmE6rDZGrEOQeHM5PcHi+nyqe" 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.