You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
7.0 KiB

  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. [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
  4. [![CI](https://github.com/KaTeX/KaTeX/workflows/CI/badge.svg?branch=main&event=push)](https://github.com/KaTeX/KaTeX/actions?query=workflow%3ACI)
  5. [![codecov](https://codecov.io/gh/KaTeX/KaTeX/branch/main/graph/badge.svg)](https://codecov.io/gh/KaTeX/KaTeX)
  6. [![Discussions](https://img.shields.io/badge/Discussions-join-brightgreen)](https://github.com/KaTeX/KaTeX/discussions)
  7. [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/katex/badge?style=rounded)](https://www.jsdelivr.com/package/npm/katex)
  8. ![katex.min.js size](https://img.badgesize.io/https://unpkg.com/katex/dist/katex.min.js?compression=gzip)
  9. [![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/KaTeX/KaTeX)
  10. [![Financial Contributors on Open Collective](https://opencollective.com/katex/all/badge.svg?label=financial+contributors)](https://opencollective.com/katex)
  11. KaTeX is a fast, easy-to-use JavaScript library for TeX math rendering on the web.
  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. KaTeX is compatible with all major browsers, including Chrome, Safari, Firefox, Opera, Edge, and IE 11.
  17. KaTeX supports much (but not all) of LaTeX and many LaTeX packages. See the [list of supported functions](https://katex.org/docs/supported.html).
  18. Try out KaTeX [on the demo page](https://katex.org/#demo)!
  19. ## Getting started
  20. ### Starter template
  21. ```html
  22. <!DOCTYPE html>
  23. <!-- KaTeX requires the use of the HTML5 doctype. Without it, KaTeX may not render properly -->
  24. <html>
  25. <head>
  26. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.15.3/dist/katex.min.css" integrity="sha384-KiWOvVjnN8qwAZbuQyWDIbfCLFhLXNETzBQjA/92pIowpC0d2O3nppDGQVgwd2nB" crossorigin="anonymous">
  27. <!-- The loading of KaTeX is deferred to speed up page rendering -->
  28. <script defer src="https://cdn.jsdelivr.net/npm/katex@0.15.3/dist/katex.min.js" integrity="sha384-0fdwu/T/EQMsQlrHCCHoH10pkPLlKA1jL5dFyUOvB3lfeT2540/2g6YgSi2BL14p" crossorigin="anonymous"></script>
  29. <!-- To automatically render math in text elements, include the auto-render extension: -->
  30. <script defer src="https://cdn.jsdelivr.net/npm/katex@0.15.3/dist/contrib/auto-render.min.js" integrity="sha384-+XBljXPPiv+OzfbB3cVmLHf4hdUFHlWNZN5spNQ7rmHTXpd7WvJum6fIACpNNfIR" crossorigin="anonymous"
  31. onload="renderMathInElement(document.body);"></script>
  32. </head>
  33. ...
  34. </html>
  35. ```
  36. You can also [download KaTeX](https://github.com/KaTeX/KaTeX/releases) and host it yourself.
  37. For details on how to configure auto-render extension, refer to [the documentation](https://katex.org/docs/autorender.html).
  38. ### API
  39. Call `katex.render` to render a TeX expression directly into a DOM element.
  40. For example:
  41. ```js
  42. katex.render("c = \\pm\\sqrt{a^2 + b^2}", element, {
  43. throwOnError: false
  44. });
  45. ```
  46. Call `katex.renderToString` to generate an HTML string of the rendered math,
  47. e.g., for server-side rendering. For example:
  48. ```js
  49. var html = katex.renderToString("c = \\pm\\sqrt{a^2 + b^2}", {
  50. throwOnError: false
  51. });
  52. // '<span class="katex">...</span>'
  53. ```
  54. Make sure to include the CSS and font files in both cases.
  55. If you are doing all rendering on the server, there is no need to include the
  56. JavaScript on the client.
  57. The examples above use the `throwOnError: false` option, which renders invalid
  58. inputs as the TeX source code in red (by default), with the error message as
  59. hover text. For other available options, see the
  60. [API documentation](https://katex.org/docs/api.html),
  61. [options documentation](https://katex.org/docs/options.html), and
  62. [handling errors documentation](https://katex.org/docs/error.html).
  63. ## Demo and Documentation
  64. Learn more about using KaTeX [on the website](https://katex.org)!
  65. ## Contributors
  66. ### Code Contributors
  67. This project exists thanks to all the people who contribute code. If you'd like to help, see [our guide to contributing code](CONTRIBUTING.md).
  68. <a href="https://github.com/KaTeX/KaTeX/graphs/contributors"><img src="https://contributors-svg.opencollective.com/katex/contributors.svg?width=890&button=false" alt="Code contributors" /></a>
  69. ### Financial Contributors
  70. Become a financial contributor and help us sustain our community.
  71. #### Individuals
  72. <a href="https://opencollective.com/katex"><img src="https://opencollective.com/katex/individuals.svg?width=890" alt="Contribute on Open Collective"></a>
  73. #### Organizations
  74. Support this project with your organization. Your logo will show up here with a link to your website.
  75. <a href="https://opencollective.com/katex/organization/0/website"><img src="https://opencollective.com/katex/organization/0/avatar.svg" alt="Organization 1"></a>
  76. <a href="https://opencollective.com/katex/organization/1/website"><img src="https://opencollective.com/katex/organization/1/avatar.svg" alt="Organization 2"></a>
  77. <a href="https://opencollective.com/katex/organization/2/website"><img src="https://opencollective.com/katex/organization/2/avatar.svg" alt="Organization 3"></a>
  78. <a href="https://opencollective.com/katex/organization/3/website"><img src="https://opencollective.com/katex/organization/3/avatar.svg" alt="Organization 4"></a>
  79. <a href="https://opencollective.com/katex/organization/4/website"><img src="https://opencollective.com/katex/organization/4/avatar.svg" alt="Organization 5"></a>
  80. <a href="https://opencollective.com/katex/organization/5/website"><img src="https://opencollective.com/katex/organization/5/avatar.svg" alt="Organization 6"></a>
  81. <a href="https://opencollective.com/katex/organization/6/website"><img src="https://opencollective.com/katex/organization/6/avatar.svg" alt="Organization 7"></a>
  82. <a href="https://opencollective.com/katex/organization/7/website"><img src="https://opencollective.com/katex/organization/7/avatar.svg" alt="Organization 8"></a>
  83. <a href="https://opencollective.com/katex/organization/8/website"><img src="https://opencollective.com/katex/organization/8/avatar.svg" alt="Organization 9"></a>
  84. <a href="https://opencollective.com/katex/organization/9/website"><img src="https://opencollective.com/katex/organization/9/avatar.svg" alt="Organization 10"></a>
  85. ## License
  86. KaTeX is licensed under the [MIT License](http://opensource.org/licenses/MIT).