Skip to content

Commit c4ef128

Browse files
committed
Update KaTeX
1 parent 6f611bf commit c4ef128

File tree

86 files changed

+39556
-28786
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+39556
-28786
lines changed

_includes/head/links.html

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919
{% comment %}<!--
2020
This is to avoid hard-coding URLs in JS (where they can't be discovered by automated tools).
2121
-->{% endcomment %}
22-
<link rel="dns-prefetch" href="{{ '/' | relative_url }}" id="_baseURL">
23-
<link rel="dns-prefetch" href="{{ '/assets/js/hydejack-8.2.0.js' | relative_url }}" id="_hrefJS">
24-
<link rel="dns-prefetch" href="{{ '/sw.js' | relative_url }}" id="_hrefSW">
25-
<link rel="dns-prefetch" href="{{ '/assets/bower_components/fontfaceobserver/fontfaceobserver.standalone.js'| relative_url }}" id="_hrefFFO">
26-
<link rel="dns-prefetch" href="{{ '/assets/bower_components/katex/dist/katex.min.js' | relative_url }}" id="_hrefKatexJS">
27-
<link rel="dns-prefetch" href="{{ '/assets/bower_components/katex/dist/katex.min.css' | relative_url }}" id="_hrefKatexCSS">
28-
<link rel="dns-prefetch" href="{{ '/assets/img/swipe.svg' | relative_url }}" id="_hrefSwipeSVG">
22+
<link rel="dns-prefetch" href="{{ '/' | relative_url }}" id="_baseURL">
23+
<link rel="dns-prefetch" href="{{ '/assets/js/hydejack-8.2.0.js' | relative_url }}" id="_hrefJS">
24+
<link rel="dns-prefetch" href="{{ '/sw.js' | relative_url }}" id="_hrefSW">
25+
<link rel="dns-prefetch" href="{{ '/assets/bower_components/fontfaceobserver/fontfaceobserver.standalone.js' | relative_url }}" id="_hrefFFO">
26+
<link rel="dns-prefetch" href="{{ '/assets/bower_components/katex/dist/katex.min.js' | relative_url }}" id="_hrefKatexJS">
27+
<link rel="dns-prefetch" href="{{ '/assets/bower_components/katex/dist/katex.min.css' | relative_url }}" id="_hrefKatexCSS">
28+
<link rel="dns-prefetch" href="{{ '/assets/bower_components/katex/dist/contrib/copy-tex.min.js' | relative_url }}" id="_hrefKatexCopyJS">
29+
<link rel="dns-prefetch" href="{{ '/assets/bower_components/katex/dist/contrib/copy-tex.min.css' | relative_url }}" id="_hrefKatexCopyCSS">
30+
<link rel="dns-prefetch" href="{{ '/assets/img/swipe.svg' | relative_url }}" id="_hrefSwipeSVG">
2931

3032
{% assign disqus = site.disqus | default:site.disqus_shortname %}
3133
{% if disqus %}

_js/src/katex.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ import { hasFeatures, hide } from "./common";
2121
const REQUIREMENTS = ["classlist", "eventlistener", "queryselector"];
2222

2323
const featuresOk = hasFeatures(REQUIREMENTS);
24-
let katexJSLoaded = false;
25-
let katexCSSLoaded = false;
24+
let loaded;
2625

2726
function renderKatex(el) {
2827
try {
@@ -35,29 +34,30 @@ function renderKatex(el) {
3534
displayMode: el.type === "math/tex; mode=display",
3635
});
3736

38-
if (prev) hide.call(prev);
37+
if (prev) prev.parentNode.removeChild(prev);
3938
} catch (e) {
4039
if (process.env.DEBUG) console.error(e);
4140
}
4241
}
4342

43+
const promisify = (f, href) => new Promise(resolve => f(href).addEventListener("load", resolve));
44+
4445
export const upgradeMathBlocks = !featuresOk
4546
? () => {}
4647
: () => {
4748
const mathBlocks = document.querySelectorAll('script[type^="math/tex"]');
4849
if (mathBlocks.length) {
49-
if (katexJSLoaded && katexCSSLoaded) {
50-
Array.from(mathBlocks).forEach(renderKatex);
51-
} else {
52-
loadJS(document.getElementById("_hrefKatexJS").href).addEventListener("load", () => {
53-
katexJSLoaded = true;
54-
if (katexJSLoaded && katexCSSLoaded) upgradeMathBlocks();
55-
});
56-
loadCSS(document.getElementById("_hrefKatexCSS").href).addEventListener("load", () => {
57-
katexCSSLoaded = true;
58-
if (katexJSLoaded && katexCSSLoaded) upgradeMathBlocks();
59-
});
50+
if (!loaded) {
51+
loaded = Promise.all([
52+
promisify(loadJS, document.getElementById("_hrefKatexJS").href),
53+
promisify(loadCSS, document.getElementById("_hrefKatexCSS").href),
54+
promisify(loadJS, document.getElementById("_hrefKatexCopyJS").href),
55+
promisify(loadCSS, document.getElementById("_hrefKatexCopyCSS").href),
56+
]);
6057
}
58+
loaded.then(() => {
59+
Array.from(mathBlocks).forEach(renderKatex);
60+
});
6161
}
6262
};
6363

_sass/hydejack/__link__/_katex.scss

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,23 @@ article {
2727
.katex-display, div.MathJax_Preview {
2828
@extend .pre-base;
2929
padding: 2rem;
30-
text-align: left;
30+
& > .katex {
31+
text-align: left;
32+
}
3133
}
3234

33-
div.MathJax_Preview {
35+
.MathJax_Preview {
3436
font-family: var(--code-font-family);
37+
}
38+
39+
div.MathJax_Preview {
3540
font-size: .75em;
3641
line-height: 1.45;
3742
white-space: pre;
3843
margin-bottom: 2rem;
3944
}
4045

4146
span.MathJax_Preview {
42-
font-family: var(--code-font-family);
4347
padding: .25em .5em;
4448
font-size: .85em;
4549
background-color: var(--code-bg);

_sass/hydejack/_katex.pre.scss

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,23 @@ article {
1818
.katex-display, div.MathJax_Preview {
1919
@extend .pre-base;
2020
padding: 2rem;
21-
text-align: left;
21+
& > .katex {
22+
text-align: left;
23+
}
2224
}
2325

24-
div.MathJax_Preview {
26+
.MathJax_Preview {
2527
font-family: var(--code-font-family);
28+
}
29+
30+
div.MathJax_Preview {
2631
font-size: .75em;
2732
line-height: 1.45;
2833
white-space: pre;
2934
margin-bottom: 2rem;
3035
}
3136

3237
span.MathJax_Preview {
33-
font-family: var(--code-font-family);
3438
padding: .25em .5em;
3539
font-size: .85em;
3640
background-color: var(--code-bg);

assets/bower_components/katex/.bower.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"dist/katex.js",
55
"dist/katex.css"
66
],
7-
"homepage": "http://khan.github.io/KaTeX/",
7+
"homepage": "https://katex.org/",
88
"description": "Fast math typesetting for the web.",
99
"moduleType": [
1010
"amd",
@@ -18,29 +18,30 @@
1818
},
1919
"ignore": [
2020
"**/.*",
21-
"/*.txt",
2221
"/*.js",
22+
"/*.json",
2323
"/*.md",
24+
"!/README.md",
2425
"/*.sh",
2526
"/package.json",
2627
"/Makefile",
27-
"/build",
2828
"/test",
2929
"/src",
3030
"/contrib",
3131
"/dockers",
32-
"/metrics",
33-
"/static"
32+
"/submodules",
33+
"/static",
34+
"/website"
3435
],
35-
"version": "0.9.0",
36-
"_release": "0.9.0",
36+
"version": "0.10.0",
37+
"_release": "0.10.0",
3738
"_resolution": {
3839
"type": "version",
39-
"tag": "v0.9.0",
40-
"commit": "a4fad9138210d5a4dfe0a786cc116422409d216f"
40+
"tag": "v0.10.0",
41+
"commit": "e1361b5ea5e750aa09833eed7f0a92f042387675"
4142
},
4243
"_source": "https://github.com/Khan/KaTeX.git",
43-
"_target": "^0.9.0",
44+
"_target": "0.10.0",
4445
"_originalSource": "katex",
4546
"_direct": true
4647
}

assets/bower_components/katex/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2013-2018 Khan Academy
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

assets/bower_components/katex/bower.json

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

0 commit comments

Comments
 (0)