Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: KaTeX/KaTeX
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.16.15
Choose a base ref
...
head repository: KaTeX/KaTeX
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.16.16
Choose a head ref
  • 4 commits
  • 14 files changed
  • 5 contributors

Commits on Dec 11, 2024

  1. chore(deps): update dependency browserstack-local to v1.5.5 [skip net…

    …lify] (#4004)
    
    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Dec 11, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    7d920a7 View commit details

Commits on Dec 17, 2024

  1. docs/supported.md: typo fix (#4006)

    fonsp authored Dec 17, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    356b6d5 View commit details
  2. feat: ESM exports, TypeScript types (#3992)

    * feat: add typescript definition files
    
    * update typed errorCode
    
    Co-authored-by: Erik Demaine <[email protected]>
    
    * specific string type on strict option
    
    Co-authored-by: Erik Demaine <[email protected]>
    
    * types: macros type allow for macro expansion
    
    Co-authored-by: Erik Demaine <[email protected]>
    
    * types: added TrustContext
    
    * types: removed redundant @types, fixed @default syntax error and moved to bottom of comments, changed any token type to object
    
    * types: import types in mts from cjs definitions
    
    * Non-default ESM exports
    
    * Merge katex.d.{ts,mts} to better reflect exports
    
    * Add tsconfig.json to specify necessary libs
    
    ---------
    
    Co-authored-by: Erik Demaine <[email protected]>
    kelvinsjk and edemaine authored Dec 17, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    ea9c173 View commit details
  3. chore(release): 0.16.16 [ci skip]

    ## [0.16.16](v0.16.15...v0.16.16) (2024-12-17)
    
    ### Features
    
    * ESM exports, TypeScript types ([#3992](#3992)) ([ea9c173](ea9c173))
    KaTeX-bot committed Dec 17, 2024
    Copy the full SHA
    6e3fb74 View commit details
Showing with 326 additions and 62 deletions.
  1. +7 −0 CHANGELOG.md
  2. +3 −3 README.md
  3. +2 −2 contrib/copy-tex/README.md
  4. +5 −5 contrib/mathtex-script-type/README.md
  5. +1 −1 contrib/mhchem/README.md
  6. +8 −8 docs/autorender.md
  7. +12 −12 docs/browser.md
  8. +1 −1 docs/support_table.md
  9. +13 −13 docs/supported.md
  10. +33 −11 katex.js
  11. +9 −3 package.json
  12. +8 −0 tsconfig.json
  13. +221 −0 types/katex.d.ts
  14. +3 −3 yarn.lock
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog
All notable changes to this project will be documented in this file. This CHANGELOG roughly follows the guidelines from [www.keepachangelog.com](https://keepachangelog.com/en/1.0.0/).

## [0.16.16](https://github.com/KaTeX/KaTeX/compare/v0.16.15...v0.16.16) (2024-12-17)


### Features

* ESM exports, TypeScript types ([#3992](https://github.com/KaTeX/KaTeX/issues/3992)) ([ea9c173](https://github.com/KaTeX/KaTeX/commit/ea9c173a0de953b49b2ce5d131e88b785f5dffa1))

## [0.16.15](https://github.com/KaTeX/KaTeX/compare/v0.16.14...v0.16.15) (2024-12-09)


6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -37,13 +37,13 @@ Try out KaTeX [on the demo page](https://katex.org/#demo)!
<!-- 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.16.15/dist/katex.min.css" integrity="sha384-Htz9HMhiwV8GuQ28Xr9pEs1B4qJiYu/nYLLwlDklR53QibDfmQzi7rYxXhMH/5/u" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/katex.min.css" integrity="sha384-hVhzUD6f4fv5e8/SUC8GHMqjmXi+LvI2+QzUZlruhYvV3fub1civI86H6p0cbWFK" crossorigin="anonymous">

<!-- The loading of KaTeX is deferred to speed up page rendering -->
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/katex.min.js" integrity="sha384-bxmi2jLGCvnsEqMuYLKE/KsVCxV3PqmKeK6Y6+lmNXBry6+luFkEOsmp5vD9I/7+" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/katex.min.js" integrity="sha384-Jk0pwVVAMt1QyyB45O8KoWsQT9nXyKcE1h8tXpm0Zw4BwHrsFU6pcDtpFg1far1H" 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.16.15/dist/contrib/auto-render.min.js" integrity="sha384-hCXGrW6PitJEwbkoStFjeJxv+fSOOQKOPbJxSfM6G5sWZjAyWhXiTIIAmQqnlLlh" crossorigin="anonymous"
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/contrib/auto-render.min.js" integrity="sha384-hCXGrW6PitJEwbkoStFjeJxv+fSOOQKOPbJxSfM6G5sWZjAyWhXiTIIAmQqnlLlh" crossorigin="anonymous"
onload="renderMathInElement(document.body);"></script>
</head>
...
4 changes: 2 additions & 2 deletions contrib/copy-tex/README.md
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ This extension isn't part of KaTeX proper, so the script should be separately
included in the page.

```html
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/contrib/copy-tex.min.js" integrity="sha384-HORx6nWi8j5/mYA+y57/9/CZc5z8HnEw4WUZWy5yOn9ToKBv1l58vJaufFAn9Zzi" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/contrib/copy-tex.min.js" integrity="sha384-HORx6nWi8j5/mYA+y57/9/CZc5z8HnEw4WUZWy5yOn9ToKBv1l58vJaufFAn9Zzi" crossorigin="anonymous"></script>
```

(Note that, as of KaTeX 0.16.0, there is no longer a corresponding CSS file.)
@@ -35,5 +35,5 @@ statement with `require('katex/contrib/copy-tex/katex2tex.js')`.

ECMAScript module is also available:
```html
<script type="module" src="https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/contrib/copy-tex.mjs" integrity="sha384-bVEnwt0PtX+1EuJoOEcm4rgTUWvb2ILTdjHfI1gUe/r5fdqrTcQaUuRdHG2DciuQ" crossorigin="anonymous"></script>
<script type="module" src="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/contrib/copy-tex.mjs" integrity="sha384-bVEnwt0PtX+1EuJoOEcm4rgTUWvb2ILTdjHfI1gUe/r5fdqrTcQaUuRdHG2DciuQ" crossorigin="anonymous"></script>
```
10 changes: 5 additions & 5 deletions contrib/mathtex-script-type/README.md
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ included in the page, in addition to KaTeX.
Load the extension by adding the following line to your HTML file.

```html
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/contrib/mathtex-script-type.min.js" integrity="sha384-sg4gBRJTqTCyzYbB7e72xGs3dA2LK994XRZS6urZW6Uh6Mu3j2JJ3YG2s9HALO8U" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/contrib/mathtex-script-type.min.js" integrity="sha384-sg4gBRJTqTCyzYbB7e72xGs3dA2LK994XRZS6urZW6Uh6Mu3j2JJ3YG2s9HALO8U" crossorigin="anonymous"></script>
```
You can download the script and use it locally, or from a local KaTeX installation instead.

@@ -23,9 +23,9 @@ Then, in the body, we use a `math/tex` script to typeset the equation `x+\sqrt{1
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/katex.min.css" integrity="sha384-Htz9HMhiwV8GuQ28Xr9pEs1B4qJiYu/nYLLwlDklR53QibDfmQzi7rYxXhMH/5/u" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/katex.min.js" integrity="sha384-bxmi2jLGCvnsEqMuYLKE/KsVCxV3PqmKeK6Y6+lmNXBry6+luFkEOsmp5vD9I/7+" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/contrib/mathtex-script-type.min.js" integrity="sha384-sg4gBRJTqTCyzYbB7e72xGs3dA2LK994XRZS6urZW6Uh6Mu3j2JJ3YG2s9HALO8U" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/katex.min.css" integrity="sha384-hVhzUD6f4fv5e8/SUC8GHMqjmXi+LvI2+QzUZlruhYvV3fub1civI86H6p0cbWFK" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/katex.min.js" integrity="sha384-Jk0pwVVAMt1QyyB45O8KoWsQT9nXyKcE1h8tXpm0Zw4BwHrsFU6pcDtpFg1far1H" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/contrib/mathtex-script-type.min.js" integrity="sha384-sg4gBRJTqTCyzYbB7e72xGs3dA2LK994XRZS6urZW6Uh6Mu3j2JJ3YG2s9HALO8U" crossorigin="anonymous"></script>
</head>
<body>
<script type="math/tex">x+\sqrt{1-x^2}</script>
@@ -35,4 +35,4 @@ Then, in the body, we use a `math/tex` script to typeset the equation `x+\sqrt{1

ECMAScript module is also available:
```html
<script type="module" src="https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/contrib/mathtex-script-type.mjs" integrity="sha384-4EJvC5tvqq9XJxXvdD4JutBokuFw/dCe2AB4gZ9sRpwFFXECpL3qT43tmE0PkpVg" crossorigin="anonymous"></script>
<script type="module" src="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/contrib/mathtex-script-type.mjs" integrity="sha384-4EJvC5tvqq9XJxXvdD4JutBokuFw/dCe2AB4gZ9sRpwFFXECpL3qT43tmE0PkpVg" crossorigin="anonymous"></script>
2 changes: 1 addition & 1 deletion contrib/mhchem/README.md
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ This extension adds to KaTeX the `\ce` and `\pu` functions from the [mhchem](htt
This extension isn't part of core KaTeX, so the script should be separately included. Write the following line into the HTML page's `<head>`. Place it *after* the line that calls `katex.js`, and if you make use of the [auto-render](https://katex.org/docs/autorender.html) extension, place it *before* the line that calls `auto-render.js`.

```html
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/contrib/mhchem.min.js" integrity="sha384-F2ptQFZqNJuqfGGl28mIXyQ5kXH48spn7rcoS0Y9psqIKAcZPLd1NzwFlm/bl1mH" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/contrib/mhchem.min.js" integrity="sha384-F2ptQFZqNJuqfGGl28mIXyQ5kXH48spn7rcoS0Y9psqIKAcZPLd1NzwFlm/bl1mH" crossorigin="anonymous"></script>
```

If you remove the `defer` attribute from this tag, then you must also remove the `defer` attribute from the `<script src="https://../katex.min.js">` tag.
16 changes: 8 additions & 8 deletions docs/autorender.md
Original file line number Diff line number Diff line change
@@ -12,9 +12,9 @@ This extension isn't part of KaTeX proper, so the script needs to be included
using a CDN:

```html
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/katex.min.css" integrity="sha384-Htz9HMhiwV8GuQ28Xr9pEs1B4qJiYu/nYLLwlDklR53QibDfmQzi7rYxXhMH/5/u" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/katex.min.js" integrity="sha384-bxmi2jLGCvnsEqMuYLKE/KsVCxV3PqmKeK6Y6+lmNXBry6+luFkEOsmp5vD9I/7+" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/contrib/auto-render.min.js" integrity="sha384-hCXGrW6PitJEwbkoStFjeJxv+fSOOQKOPbJxSfM6G5sWZjAyWhXiTIIAmQqnlLlh" crossorigin="anonymous"
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/katex.min.css" integrity="sha384-hVhzUD6f4fv5e8/SUC8GHMqjmXi+LvI2+QzUZlruhYvV3fub1civI86H6p0cbWFK" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/katex.min.js" integrity="sha384-Jk0pwVVAMt1QyyB45O8KoWsQT9nXyKcE1h8tXpm0Zw4BwHrsFU6pcDtpFg1far1H" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/contrib/auto-render.min.js" integrity="sha384-hCXGrW6PitJEwbkoStFjeJxv+fSOOQKOPbJxSfM6G5sWZjAyWhXiTIIAmQqnlLlh" crossorigin="anonymous"
onload="renderMathInElement(document.body);"></script>
```

@@ -31,9 +31,9 @@ want to use a `defer` or `onload` attribute.
For example:

```html
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/katex.min.css" integrity="sha384-Htz9HMhiwV8GuQ28Xr9pEs1B4qJiYu/nYLLwlDklR53QibDfmQzi7rYxXhMH/5/u" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/katex.min.js" integrity="sha384-bxmi2jLGCvnsEqMuYLKE/KsVCxV3PqmKeK6Y6+lmNXBry6+luFkEOsmp5vD9I/7+" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/contrib/auto-render.min.js" integrity="sha384-hCXGrW6PitJEwbkoStFjeJxv+fSOOQKOPbJxSfM6G5sWZjAyWhXiTIIAmQqnlLlh" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/katex.min.css" integrity="sha384-hVhzUD6f4fv5e8/SUC8GHMqjmXi+LvI2+QzUZlruhYvV3fub1civI86H6p0cbWFK" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/katex.min.js" integrity="sha384-Jk0pwVVAMt1QyyB45O8KoWsQT9nXyKcE1h8tXpm0Zw4BwHrsFU6pcDtpFg1far1H" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/contrib/auto-render.min.js" integrity="sha384-hCXGrW6PitJEwbkoStFjeJxv+fSOOQKOPbJxSfM6G5sWZjAyWhXiTIIAmQqnlLlh" crossorigin="anonymous"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
renderMathInElement(document.body, {
@@ -54,9 +54,9 @@ For example:

ECMAScript module is also available:
```html
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/katex.min.css" integrity="sha384-Htz9HMhiwV8GuQ28Xr9pEs1B4qJiYu/nYLLwlDklR53QibDfmQzi7rYxXhMH/5/u" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/katex.min.css" integrity="sha384-hVhzUD6f4fv5e8/SUC8GHMqjmXi+LvI2+QzUZlruhYvV3fub1civI86H6p0cbWFK" crossorigin="anonymous">
<script type="module">
import renderMathInElement from "https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/contrib/auto-render.mjs";
import renderMathInElement from "https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/contrib/auto-render.mjs";
renderMathInElement(document.body);
</script>
```
24 changes: 12 additions & 12 deletions docs/browser.md
Original file line number Diff line number Diff line change
@@ -11,13 +11,13 @@ title: Browser
<!-- 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.16.15/dist/katex.min.css" integrity="sha384-Htz9HMhiwV8GuQ28Xr9pEs1B4qJiYu/nYLLwlDklR53QibDfmQzi7rYxXhMH/5/u" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/katex.min.css" integrity="sha384-hVhzUD6f4fv5e8/SUC8GHMqjmXi+LvI2+QzUZlruhYvV3fub1civI86H6p0cbWFK" crossorigin="anonymous">

<!-- The loading of KaTeX is deferred to speed up page rendering -->
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/katex.min.js" integrity="sha384-bxmi2jLGCvnsEqMuYLKE/KsVCxV3PqmKeK6Y6+lmNXBry6+luFkEOsmp5vD9I/7+" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/katex.min.js" integrity="sha384-Jk0pwVVAMt1QyyB45O8KoWsQT9nXyKcE1h8tXpm0Zw4BwHrsFU6pcDtpFg1far1H" 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.16.15/dist/contrib/auto-render.min.js" integrity="sha384-hCXGrW6PitJEwbkoStFjeJxv+fSOOQKOPbJxSfM6G5sWZjAyWhXiTIIAmQqnlLlh" crossorigin="anonymous"
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/contrib/auto-render.min.js" integrity="sha384-hCXGrW6PitJEwbkoStFjeJxv+fSOOQKOPbJxSfM6G5sWZjAyWhXiTIIAmQqnlLlh" crossorigin="anonymous"
onload="renderMathInElement(document.body);"></script>
</head>
...
@@ -29,15 +29,15 @@ If you include the `katex.js` directly, the `katex` object will be available as
a global variable.

```html
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/katex.css" integrity="sha384-zLeDfjAc8DwENEGNNTkTTnfsm/SivaEXAA2fE7fRzBTXD0tVOIzGYvE5XYRds2T3" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/katex.js" integrity="sha384-FqGJ8MgMYoNdTzskCP+Ug2swwqMiP6ExJPS++zP+EfvbHYHjymfSvGfNrnypPrrj" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/katex.css" integrity="sha384-IAWSeBSZxaXQMfLQ0hzbPevR3LH3eu1iQaKPpoE6DsGuj6WlGp26PPGU7s6/nPd8" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/katex.js" integrity="sha384-FFYxVyBxfjap5mq811c+YckZStxGPUdCYMrrgN/4a4hnL9nUE0MXKnJ8IWPwnNnU" crossorigin="anonymous"></script>
```

KaTeX also provides minified versions:

```html
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/katex.min.css" integrity="sha384-Htz9HMhiwV8GuQ28Xr9pEs1B4qJiYu/nYLLwlDklR53QibDfmQzi7rYxXhMH/5/u" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/katex.min.js" integrity="sha384-bxmi2jLGCvnsEqMuYLKE/KsVCxV3PqmKeK6Y6+lmNXBry6+luFkEOsmp5vD9I/7+" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/katex.min.css" integrity="sha384-hVhzUD6f4fv5e8/SUC8GHMqjmXi+LvI2+QzUZlruhYvV3fub1civI86H6p0cbWFK" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/katex.min.js" integrity="sha384-Jk0pwVVAMt1QyyB45O8KoWsQT9nXyKcE1h8tXpm0Zw4BwHrsFU6pcDtpFg1far1H" crossorigin="anonymous"></script>
```

The examples above load the script [deferred using the `defer` attribute](https://developer.mozilla.org/en/HTML/Element/script#Attributes)
@@ -81,22 +81,22 @@ for more detail.
```html
<script type="text/javascript">
require([
"https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/katex.js",
"https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/katex.js",
], katex => {
...
});
</script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/katex.css" integrity="sha384-zLeDfjAc8DwENEGNNTkTTnfsm/SivaEXAA2fE7fRzBTXD0tVOIzGYvE5XYRds2T3" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/katex.css" integrity="sha384-IAWSeBSZxaXQMfLQ0hzbPevR3LH3eu1iQaKPpoE6DsGuj6WlGp26PPGU7s6/nPd8" crossorigin="anonymous">
```

### ECMAScript module
```html
<script type="module" type="text/javascript">
import katex from 'https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/katex.mjs';
import katex from 'https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/katex.mjs';
...
</script>
<script nomodule defer src="https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/katex.js" integrity="sha384-FqGJ8MgMYoNdTzskCP+Ug2swwqMiP6ExJPS++zP+EfvbHYHjymfSvGfNrnypPrrj" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/katex.css" integrity="sha384-zLeDfjAc8DwENEGNNTkTTnfsm/SivaEXAA2fE7fRzBTXD0tVOIzGYvE5XYRds2T3" crossorigin="anonymous">
<script nomodule defer src="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/katex.js" integrity="sha384-FFYxVyBxfjap5mq811c+YckZStxGPUdCYMrrgN/4a4hnL9nUE0MXKnJ8IWPwnNnU" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/katex.css" integrity="sha384-IAWSeBSZxaXQMfLQ0hzbPevR3LH3eu1iQaKPpoE6DsGuj6WlGp26PPGU7s6/nPd8" crossorigin="anonymous">
```

> Use [`nomodule` attribute](https://developer.mozilla.org/en/HTML/Element/script#Attributes)
2 changes: 1 addition & 1 deletion docs/support_table.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ This is a list of TeX functions, sorted alphabetically. This list includes funct

If you know the shape of a character, but not its name, [Detexify](https://detexify.kirelabs.org/classify.html) can help.

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/katex.min.css" integrity="sha384-Htz9HMhiwV8GuQ28Xr9pEs1B4qJiYu/nYLLwlDklR53QibDfmQzi7rYxXhMH/5/u" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/katex.min.css" integrity="sha384-hVhzUD6f4fv5e8/SUC8GHMqjmXi+LvI2+QzUZlruhYvV3fub1civI86H6p0cbWFK" crossorigin="anonymous">
<style>
table tr,
table td {
26 changes: 13 additions & 13 deletions docs/supported.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ This is a list of TeX functions supported by KaTeX. It is sorted into logical gr

There is a similar [Support Table](support_table.md), sorted alphabetically, that lists both supported and un-supported functions.

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.15/dist/katex.min.css" integrity="sha384-Htz9HMhiwV8GuQ28Xr9pEs1B4qJiYu/nYLLwlDklR53QibDfmQzi7rYxXhMH/5/u" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.16/dist/katex.min.css" integrity="sha384-hVhzUD6f4fv5e8/SUC8GHMqjmXi+LvI2+QzUZlruhYvV3fub1civI86H6p0cbWFK" crossorigin="anonymous">
<style>
p {overflow-wrap: break-word;}
table tr,
@@ -595,18 +595,18 @@ For color definition, KaTeX color functions will accept the standard HTML [pred
**Font**

||||
|:------------------------------------|:-----------------------------------|:--------------------------------|
|$\mathrm{Ab0}$ `\mathrm{Ab0}` |$\mathbf{Ab0}$ `\mathbf{Ab0}` |$\mathsf{Ab0}$ `\mathsf{Ab0}` |
|$\mathnormal{Ab0}$ `\mathnormal{Ab0}`|$\textbf{Ab0}$ `\textbf{Ab0}` |$\textsf{Ab0}$ `\textsf{Ab0}` |
|$\textrm{Ab0}$ `\textrm{Ab0}` |$\bf Ab0$ `\bf Ab0` |$\sf Ab0$ `\sf Ab0` |
|$\rm Ab0$ `\rm Ab0` |$\bold{Ab0}$ `\bold{Ab0}` |$\mathsfit{Ab0}$ `\mathsfit{Ab0}`|
|$\textnormal{Ab0}$ `\textnormal{Ab0}`|$\boldsymbol{Ab0}$ `\boldsymbol{Ab}`|$\Bbb{AB}$ `\Bbb{AB}` |
|$\text{Ab0}$ `\text{Ab0}` |$\bm{Ab0}$ `\bm{Ab0}` |$\mathbb{AB}$ `\mathbb{AB}` |
|$\textup{Ab0}$ `\textup{Ab0}` |$\textmd{Ab0}$ `\textmd{Ab0}` |$\frak{Ab0}$ `\frak{Ab0}` |
|$\mathit{Ab0}$ `\mathit{Ab0}` |$\mathtt{Ab0}$ `\mathtt{Ab0}` |$\mathfrak{Ab0}$ `\mathfrak{Ab0}`|
|$\textit{Ab0}$ `\textit{Ab0}` |$\texttt{Ab0}$ `\texttt{Ab0}` |$\mathcal{AB0}$ `\mathcal{AB0}` |
|$\it Ab0$ `\it Ab0` |$\tt Ab0$ `\tt Ab0` |$\cal AB0$ `\cal AB0` |
|$\emph{Ab0}$ `\emph{Ab0}` | |$\mathscr{AB}$ `\mathscr{AB}` |
|:------------------------------------|:------------------------------------|:--------------------------------|
|$\mathrm{Ab0}$ `\mathrm{Ab0}` |$\mathbf{Ab0}$ `\mathbf{Ab0}` |$\mathsf{Ab0}$ `\mathsf{Ab0}` |
|$\mathnormal{Ab0}$ `\mathnormal{Ab0}`|$\textbf{Ab0}$ `\textbf{Ab0}` |$\textsf{Ab0}$ `\textsf{Ab0}` |
|$\textrm{Ab0}$ `\textrm{Ab0}` |$\bf Ab0$ `\bf Ab0` |$\sf Ab0$ `\sf Ab0` |
|$\rm Ab0$ `\rm Ab0` |$\bold{Ab0}$ `\bold{Ab0}` |$\mathsfit{Ab0}$ `\mathsfit{Ab0}`|
|$\textnormal{Ab0}$ `\textnormal{Ab0}`|$\boldsymbol{Ab0}$ `\boldsymbol{Ab0}`|$\Bbb{AB}$ `\Bbb{AB}` |
|$\text{Ab0}$ `\text{Ab0}` |$\bm{Ab0}$ `\bm{Ab0}` |$\mathbb{AB}$ `\mathbb{AB}` |
|$\textup{Ab0}$ `\textup{Ab0}` |$\textmd{Ab0}$ `\textmd{Ab0}` |$\frak{Ab0}$ `\frak{Ab0}` |
|$\mathit{Ab0}$ `\mathit{Ab0}` |$\mathtt{Ab0}$ `\mathtt{Ab0}` |$\mathfrak{Ab0}$ `\mathfrak{Ab0}`|
|$\textit{Ab0}$ `\textit{Ab0}` |$\texttt{Ab0}$ `\texttt{Ab0}` |$\mathcal{AB0}$ `\mathcal{AB0}` |
|$\it Ab0$ `\it Ab0` |$\tt Ab0$ `\tt Ab0` |$\cal AB0$ `\cal AB0` |
|$\emph{Ab0}$ `\emph{Ab0}` | |$\mathscr{AB}$ `\mathscr{AB}` |

One can stack font family, font weight, and font shape by using the `\textXX` versions of the font functions. So `\textsf{\textbf{H}}` will produce $\textsf{\textbf{H}}$. The other versions do not stack, e.g., `\mathsf{\mathbf{H}}` will produce $\mathsf{\mathbf{H}}$.

44 changes: 33 additions & 11 deletions katex.js
Original file line number Diff line number Diff line change
@@ -138,11 +138,40 @@ const renderToHTMLTree = function(
}
};

const version = __VERSION__;

const __domTree = {
Span,
Anchor,
SymbolNode,
SvgNode,
PathNode,
LineNode,
};

// ESM exports
export {
version,
render,
renderToString,
ParseError,
SETTINGS_SCHEMA,
generateParseTree as __parse,
renderToDomTree as __renderToDomTree,
renderToHTMLTree as __renderToHTMLTree,
setFontMetrics as __setFontMetrics,
defineSymbol as __defineSymbol,
defineFunction as __defineFunction,
defineMacro as __defineMacro,
__domTree,
};

// CJS exports and ESM default export
export default {
/**
* Current KaTeX version
*/
version: __VERSION__,
version,
/**
* Renders the given LaTeX into an HTML+MathML combination, and adds
* it as a child to the specified DOM node.
@@ -158,7 +187,7 @@ export default {
*/
ParseError,
/**
* The shema of Settings
* The schema of Settings
*/
SETTINGS_SCHEMA,
/**
@@ -210,16 +239,9 @@ export default {
/**
* Expose the dom tree node types, which can be useful for type checking nodes.
*
* NOTE: This method is not currently recommended for public use.
* NOTE: These methods are not currently recommended for public use.
* The internal tree representation is unstable and is very likely
* to change. Use at your own risk.
*/
__domTree: {
Span,
Anchor,
SymbolNode,
SvgNode,
PathNode,
LineNode,
},
__domTree,
};
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
{
"name": "katex",
"version": "0.16.15",
"version": "0.16.16",
"description": "Fast math typesetting for the web.",
"main": "dist/katex.js",
"exports": {
".": {
"require": "./dist/katex.js",
"import": "./dist/katex.mjs"
"require": {
"types": "./types/katex.d.ts",
"default": "./dist/katex.js"
},
"import": {
"types": "./types/katex.d.ts",
"default": "./dist/katex.mjs"
}
},
"./contrib/auto-render": {
"require": "./dist/contrib/auto-render.js",
8 changes: 8 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"strict": true,
"lib": ["es2021", "dom"],
"moduleResolution": "bundler",
"forceConsistentCasingInFileNames": true
}
}
221 changes: 221 additions & 0 deletions types/katex.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
// Adapted from
// - https://katex.org/docs/options
// - https://katex.org/docs/api
// - https://katex.org/docs/error
// for v0.16.11 on 2024/12/01
// with some references from https://www.npmjs.com/package/@types/katex

/**
* For the `trust` option in `KatexOptions`, a custom function
* `handler(context)` can be provided to customize behavior depending on the
* context (command, arguments e.g. a URL, etc.)
* @see https://katex.org/docs/options
*/
export type TrustContext =
| { command: "\\url", url: string, protocol?: string }
| { command: "\\href", url: string, protocol?: string }
| { command: "\\includegraphics", url: string, protocol?: string }
| { command: "\\htmlClass", class: string }
| { command: "\\htmlId", id: string }
| { command: "\\htmlStyle", style: string }
| { command: "\\htmlData", attributes: Record<string, string> }

/**
* Options for `katex.render` and `katex.renderToString`.
* @see https://katex.org/docs/options
*/
export interface KatexOptions {
/**
* If `true` the math will be rendered in display mode.
* If `false` the math will be rendered in inline mode.
* @see https://katex.org/docs/options
*
* @default false
*/
displayMode?: boolean;
/**
* Determines the markup language of the output. The valid choices are:
* - `html`: Outputs KaTeX in HTML only.
* - `mathml`: Outputs KaTeX in MathML only.
* - `htmlAndMathml`: Outputs HTML for visual rendering and includes MathML
* for accessibility.
*
* @default "htmlAndMathml"
*/
output?: "html" | "mathml" | "htmlAndMathml";
/**
* If `true`, display math has `\tag`s rendered on the left instead of the
* right, like `\usepackage[leqno]{amsmath}` in LaTeX.
*
* @default false
*/
leqno?: boolean;
/**
* If `true`, display math renders flush left with a `2em` left margin,
* like `\documentclass[fleqn]` in LaTeX with the `amsmath` package.
*
* @default false
*/
fleqn?: boolean;
/**
* If `true`, KaTeX will throw a `ParseError` when it encounters an
* unsupported command or invalid LaTeX.
* If `false`, KaTeX will render unsupported commands as text, and render
* invalid LaTeX as its source code with hover text giving the error, in
* the color given by `errorColor`.
*
* @default true
*/
throwOnError?: boolean;
/**
* A color string given in the format `"#XXX"` or `"#XXXXXX"`. This option
* determines the color that unsupported commands and invalid LaTeX are
* rendered in when `throwOnError` is set to `false`.
*
* @default "#cc0000"
*/
errorColor?: string;
/**
* A collection of custom macros.
* @see https://katex.org/docs/options
*/
macros?: Record<string, string | object | ((macroExpander:object) => string | object)>;
/**
* Specifies a minimum thickness, in ems, for fraction lines, `\sqrt` top
* lines, `{array}` vertical lines, `\hline`, `\hdashline`, `\underline`,
* `\overline`, and the borders of `\fbox`, `\boxed`, and `\fcolorbox`.
* The usual value for these items is `0.04`, so for `minRuleThickness`
* to be effective it should probably take a value slightly above `0.04`,
* say `0.05` or `0.06`. Negative values will be ignored.
*/
minRuleThickness?: number;
/**
* In early versions of both KaTeX (<0.8.0) and MathJax, the `\color`
* function expected the content to be a function argument, as in
* `\color{blue}{hello}`. In current KaTeX, `\color` is a switch, as in
* `\color{blue}` hello. This matches LaTeX behavior. If you want the old
* `\color` behavior, set option colorIsTextColor to true.
*/
colorIsTextColor?: boolean;
/**
* All user-specified sizes, e.g. in `\rule{500em}{500em}`, will be capped
* to `maxSize` ems. If set to `Infinity` (the default), users can make
* elements and spaces arbitrarily large.
*
* @default Infinity
*/
maxSize?: number;
/**
* Limit the number of macro expansions to the specified number, to prevent
* e.g. infinite macro loops. `\edef` expansion counts all expanded tokens.
* If set to `Infinity`, the macro expander will try to fully expand as in
* LaTeX.
*
* @default 1000
*/
maxExpand?: number;
/**
* If `false` or `"ignore"`, allow features that make writing LaTeX
* convenient but are not actually supported by (Xe)LaTeX
* (similar to MathJax).
* If `true` or `"error"` (LaTeX faithfulness mode), throw an error for any
* such transgressions.
* If `"warn"` (the default), warn about such behavior via `console.warn`.
* Provide a custom function `handler(errorCode, errorMsg, token)` to
* customize behavior depending on the type of transgression (summarized by
* the string code `errorCode` and detailed in `errorMsg`); this function
* can also return `"ignore"`, `"error"`, or `"warn"` to use a built-in
* behavior.
* @see https://katex.org/docs/options
*
* @default "warn"
*/
strict?:
| boolean
| "ignore" | "warn" | "error"
| ((errorCode: string, errorMsg: string, token: object) => boolean | "ignore" | "warn" | "error" | undefined | null);
/**
* If `false` (do not trust input), prevent any commands like
* `\includegraphics` that could enable adverse behavior, rendering them
* instead in `errorColor`.
* If `true` (trust input), allow all such commands.
* Provide a custom function `handler(context)` to customize behavior
* depending on the context (command, arguments e.g. a URL, etc.).
* @see https://katex.org/docs/options
*
* @default false
*/
trust?: boolean | ((context: TrustContext) => boolean);
/**
* Run KaTeX code in the global group. As a consequence, macros defined at
* the top level by `\def` and `\newcommand` are added to the macros
* argument and can be used in subsequent render calls. In LaTeX,
* constructs such as `\begin{equation}` and `$$` create a local group and
* prevent definitions other than `\gdef` from becoming visible outside of
* those blocks, so this is KaTeX's default behavior.
*
* @default false
*/
globalGroup?: boolean;
}

/**
* In-browser rendering
*
* Call the `render` function with a TeX expression and a DOM element to
* render into.
*
* @param {string} tex A TeX expression.
* @param {HTMLElement} element A HTML DOM element.
* @param {KatexOptions} options An options object.
* @returns {void}
* @see https://katex.org/docs/api
*/
export function render(
tex: string,
element: HTMLElement,
options?: KatexOptions,
): void;

/**
* Server-side rendering or rendering to a string
*
* Use the `renderToString` function to generate HTML on the server or to
* generate an HTML string of the rendered math.
*
* @param {string} tex A TeX expression.
* @param {KatexOptions} options An options object.
* @returns {string} The HTML string of the rendered math.
* @see https://katex.org/docs/api
*/
export function renderToString(tex: string, options?: KatexOptions): string;

/**
* If KaTeX encounters an error (invalid or unsupported LaTeX) and
* `throwOnError` hasn't been set to `false`, then `katex.render` and
* `katex.renderToString` will throw an exception of type
* `ParseError`. The message in this error includes some of the LaTeX source
* code, so needs to be escaped if you want to render it to HTML.
* @see https://katex.org/docs/error
*/
export class ParseError implements Error {
constructor(message: string, token?: object);
name: "ParseError";
position: number;
length: number;
rawMessage: string;
message: string;
}

export const version: string;

export as namespace katex;

declare const katex: {
version: string;
render: typeof render;
renderToString: typeof renderToString;
ParseError: typeof ParseError;
};

export default katex;
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -4027,15 +4027,15 @@ __metadata:
linkType: hard

"browserstack-local@npm:^1.5.1":
version: 1.5.1
resolution: "browserstack-local@npm:1.5.1"
version: 1.5.5
resolution: "browserstack-local@npm:1.5.5"
dependencies:
agent-base: "npm:^6.0.2"
https-proxy-agent: "npm:^5.0.1"
is-running: "npm:^2.1.0"
ps-tree: "npm:=1.2.0"
temp-fs: "npm:^0.9.9"
checksum: 10/45dc70c0515e26365ceafd30b5474d5baec0f96582d8aa3e7b5f1f77b1c218f037a195c684eff7efbb7be5fb9f898cd71865791f3e571e11f81c35ff66b1ffcc
checksum: 10/e484a29162afd4f522f3bc6a83557fef9e75a1e85eb6830697d1318f51c04f3d6211bde16bbe3a6dfc1b2b18f877ea71a78ee37ba75ad3b1ccb6c0e310e77e76
languageName: node
linkType: hard