1# [<img src="https://katex.org/img/katex-logo-black.svg" width="130" alt="KaTeX">](https://katex.org/) 2[![npm](https://img.shields.io/npm/v/katex.svg)](https://www.npmjs.com/package/katex) 3[![CircleCI](https://circleci.com/gh/KaTeX/KaTeX.svg?style=shield)](https://circleci.com/gh/KaTeX/KaTeX) 4[![codecov](https://codecov.io/gh/KaTeX/KaTeX/branch/master/graph/badge.svg)](https://codecov.io/gh/KaTeX/KaTeX) 5[![Join the chat at https://gitter.im/KaTeX/KaTeX](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/KaTeX/KaTeX?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 6[![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=KaTeX/KaTeX)](https://dependabot.com) 7[![jsDelivr](https://data.jsdelivr.com/v1/package/npm/katex/badge?style=rounded)](https://www.jsdelivr.com/package/npm/katex) 8![](https://img.badgesize.io/KaTeX/KaTeX/v0.11.1/dist/katex.min.js?compression=gzip) 9 10KaTeX is a fast, easy-to-use JavaScript library for TeX math rendering on the web. 11 12 * **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](http://www.intmath.com/cg5/katex-mathjax-comparison.php). 13 * **Print quality:** KaTeX's layout is based on Donald Knuth's TeX, the gold standard for math typesetting. 14 * **Self contained:** KaTeX has no dependencies and can easily be bundled with your website resources. 15 * **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. 16 17KaTeX is compatible with all major browsers, including Chrome, Safari, Firefox, Opera, Edge, and IE 9–11. 18 19KaTeX supports much (but not all) of LaTeX and many LaTeX packages. See the [list of supported functions](https://katex.org/docs/supported.html). 20 21Try out KaTeX [on the demo page](https://katex.org/#demo)! 22 23## Getting started 24 25### Starter template 26 27```html 28<!DOCTYPE html> 29<!-- KaTeX requires the use of the HTML5 doctype. Without it, KaTeX may not render properly --> 30<html> 31 <head> 32 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css" integrity="sha384-zB1R0rpPzHqg7Kpt0Aljp8JPLqbXI3bhnPWROx27a9N0Ll6ZP/+DiW/UqRcLbRjq" crossorigin="anonymous"> 33 34 <!-- The loading of KaTeX is deferred to speed up page rendering --> 35 <script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.js" integrity="sha384-y23I5Q6l+B6vatafAwxRu/0oK/79VlbSz7Q9aiSZUvyWYIYsd+qj+o24G5ZU2zJz" crossorigin="anonymous"></script> 36 37 <!-- To automatically render math in text elements, include the auto-render extension: --> 38 <script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/contrib/auto-render.min.js" integrity="sha384-kWPLUVMOks5AQFrykwIup5lo0m3iMkkHrD0uJ4H5cjeGihAutqP0yW0J6dpFiVkI" crossorigin="anonymous" 39 onload="renderMathInElement(document.body);"></script> 40 </head> 41 ... 42</html> 43``` 44 45You can also [download KaTeX](https://github.com/KaTeX/KaTeX/releases) and host it yourself. 46 47For details on how to configure auto-render extension, refer to [the documentation](https://katex.org/docs/autorender.html). 48 49### API 50 51Call `katex.render` to render a TeX expression directly into a DOM element. 52For example: 53 54```js 55katex.render("c = \\pm\\sqrt{a^2 + b^2}", element, { 56 throwOnError: false 57}); 58``` 59 60Call `katex.renderToString` to generate an HTML string of the rendered math, 61e.g., for server-side rendering. For example: 62 63```js 64var html = katex.renderToString("c = \\pm\\sqrt{a^2 + b^2}", { 65 throwOnError: false 66}); 67// '<span class="katex">...</span>' 68``` 69 70Make sure to include the CSS and font files in both cases. 71If you are doing all rendering on the server, there is no need to include the 72JavaScript on the client. 73 74The examples above use the `throwOnError: false` option, which renders invalid 75inputs as the TeX source code in red (by default), with the error message as 76hover text. For other available options, see the 77[API documentation](https://katex.org/docs/api.html), 78[options documentation](https://katex.org/docs/options.html), and 79[handling errors documentation](https://katex.org/docs/error.html). 80 81## Demo and Documentation 82 83Learn more about using KaTeX [on the website](https://katex.org)! 84 85## Contributing 86 87See [CONTRIBUTING.md](CONTRIBUTING.md) 88 89## License 90 91KaTeX is licensed under the [MIT License](http://opensource.org/licenses/MIT). 92