Skip to content

Commit 23d3ed2

Browse files
committed
v1.4.0: updated and simplified KaTeX config
1 parent 4e6a859 commit 23d3ed2

File tree

3 files changed

+68
-41
lines changed

3 files changed

+68
-41
lines changed

_config.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,15 @@ collections:
2626
markdown: kramdown
2727

2828
kramdown:
29+
# we use KaTeX
30+
math_engine: null
31+
# ↩ followed by a symbol to prevent emoji conversion
2932
footnote_backlink: "↩︎"
30-
enable_coderay: false
31-
# math_engine: null # pending https://github.com/github/pages-gem/pull/545
33+
# don't make typographical conversions like >> to »
34+
gfm_quirks: [no_auto_typographic]
35+
# disables syntax highlighter
36+
#syntax_highlighter_opts:
37+
# disable: true
3238

3339
# Exclusions from the final site
3440
exclude:

_includes/head.html

+18-29
Original file line numberDiff line numberDiff line change
@@ -30,42 +30,31 @@
3030
<meta property="og:image:height" content="200" />
3131

3232
<!-- KaTeX -->
33-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.10.2/dist/katex.min.css"
34-
integrity="sha384-yFRtMMDnQtDRO8rLpMIKrtPCD5jdktao2TV19YiZYWMDkUR5GQZR/NOVTdquEx1j" crossorigin="anonymous" />
35-
<script src="https://cdn.jsdelivr.net/npm/katex@0.10.2/dist/katex.min.js"
36-
integrity="sha384-9Nhn55MVVN0/4OFx7EE5kpFBPsEMZxKTCnA+4fqDmg12eCTqGi6+BB2LjY8brQxJ" crossorigin="anonymous"></script>
33+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.21/dist/katex.min.css"
34+
integrity="sha384-zh0CIslj+VczCZtlzBcjt5ppRcsAmDnRem7ESsYwWwg3m/OaJ2l4x7YBZl9Kxxib" crossorigin="anonymous"/>
35+
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.21/dist/katex.min.js"
36+
integrity="sha384-Rma6DA2IPUwhNxmrB/7S3Tno0YY7sFu9WSYMCuulLhIqYSGZ2gKCJWIqhBWqMQfh" crossorigin="anonymous"></script>
3737
<!-- KaTeX auto-render extention: https://katex.org/docs/autorender.html -->
38-
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js"
39-
integrity="sha384-kWPLUVMOks5AQFrykwIup5lo0m3iMkkHrD0uJ4H5cjeGihAutqP0yW0J6dpFiVkI" crossorigin="anonymous"></script>
38+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js"
39+
integrity="sha384-hCXGrW6PitJEwbkoStFjeJxv+fSOOQKOPbJxSfM6G5sWZjAyWhXiTIIAmQqnlLlh" crossorigin="anonymous"></script>
40+
<!-- KaTeX copy-tex extention: https://github.com/KaTeX/KaTeX/tree/main/contrib/copy-tex -->
41+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/copy-tex.min.js"
42+
integrity="sha384-HORx6nWi8j5/mYA+y57/9/CZc5z8HnEw4WUZWy5yOn9ToKBv1l58vJaufFAn9Zzi" crossorigin="anonymous"></script>
4043
<script>
4144
var macros = {
42-
"\\P": "\\mathbb{P}"
43-
}, delimiters = [
44-
{ left: "$$", right: "$$", display: true}, // Technically, this does not work. See below.
45-
{ left: "\\[", right: "\\]", display: true},
46-
{ left: "$", right: "$", display: false},
47-
{ left: "\\(", right: "\\)", display: false}
48-
];
45+
"\\PP": "\\mathbb{P}", "\\AA": "\\mathbb{A}", "\\NN": "\\mathbb{N}", "\\ZZ": "\\mathbb{Z}",
46+
"\\kk": "\\mathbb{k}", "\\QQ": "\\mathbb{Q}", "\\RR": "\\mathbb{R}", "\\CC": "\\mathbb{C}",
47+
};
4948

50-
document.addEventListener("DOMContentLoaded", function() {
51-
renderMathInElement(document.body, { delimiters: delimiters, macros: macros });
49+
function renderKaTeX() {
50+
renderMathInElement(document.body, { macros: macros });
51+
// KaTeX auto-renders $$..$$, \\(..\\), \\[..\\], and equation, align, gather, and CD envs, but not $..$!
52+
renderMathInElement(document.body, { macros: macros, delimiters: [{ left: "$", right: "$", display: false }] });
53+
}
5254

53-
// Currently GitHub pages overrides math-engine: mathjax in _config, hence $$..$$ are converted to to scripts tags.
54-
// See: https://github.com/github/pages-gem/pull/545
55-
document.querySelectorAll("script[type='math/tex']").forEach(function(el) {
56-
el.outerHTML = katex.renderToString(el.textContent, { displayMode: false, macros: macros });
57-
});
58-
59-
document.querySelectorAll("script[type='math/tex; mode=display']").forEach(function(el) {
60-
el.outerHTML = katex.renderToString(el.textContent.replace(/%.*/g, ''), { displayMode: true, macros: macros });
61-
});
62-
});
55+
document.addEventListener("DOMContentLoaded", renderKaTeX);
6356
</script>
6457
<style>.katex { font-size: 1.15em; }</style>
65-
<!-- KaTeX copy-tex extention: https://github.com/KaTeX/KaTeX/tree/master/contrib/copy-tex -->
66-
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/copy-tex.css" rel="stylesheet" type="text/css" />
67-
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/copy-tex.min.js"
68-
integrity="sha384-XhWAe6BtVcvEdS3FFKT7Mcft4HJjPqMQvi5V4YhzH9Qxw497jC13TupOEvjoIPy7" crossorigin="anonymous"></script>
6958

7059
{%- if site.gtag %}
7160
<!-- Global site tag (gtag.js) - Google Analytics -->

_posts/2019-05-27-katex.md

+42-10
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,24 @@ date: 2019-05-27
88
Proof supports the typesetting mathematics using [$\KaTeX$](https://katex.org).
99
You can use `$ .. $` to write formulas following the $\LaTeX$ math syntax:
1010

11-
~~~ markdown
11+
```tex
1212
The function $\nu$ is written inline, but can also be in a block:
1313
\\[ \nu: \mathbb{P}^{1} \to \mathbb{P}^{3} \\]
14-
~~~
14+
```
1515

1616
The function $\nu$ is written inline, but can also be in a block:
17-
\\[ \nu: \R\P^{1} \to \P^{3}. \\]
17+
\\[ \nu: \R\PP^{1} \to \PP^{3}. \\]
1818

1919
Multiple math formats work:
20-
- `$5\times 5$` gives $5\times 5.$
20+
2121
- `\\(5\times 5\\)` gives \\(5\times 5.\\)
22+
- `$5\times 5$` gives $5\times 5.$
2223
- `\\[5\times 5.\\]` gives: \\[5\times 5.\\]
24+
- `$$5\times 5$$` (on a separate line) gives
2325

24-
**Note:** while `$$ 5\times 5 $$` also works, it will enclose the math in a
25-
script tag, which is undesirable[^katex].
26+
$$5\times 5.$$
27+
28+
**Note:** while `$$ 5\times 5 $$` works, it will enclose the math in a separate block, which is undesirable.
2629

2730
$\KaTeX$ supports a [long list] of fonts and functions, but you can also add
2831
$\LaTeX$ macros in `<script>` tags. For instance:
@@ -37,17 +40,46 @@ macros["\\f"] = "\\mathscr{F}"
3740
macros["\\f"] = "\\mathscr{F}"
3841
</script>
3942

40-
\\[ 0\to\Gamma_Y(X,\f')\to\Gamma_Y(X,\f)\to\Gamma_Y(X,\f'')\to 0. \\]
43+
$$ 0\to\Gamma_Y(X,\f')\to\Gamma_Y(X,\f)\to\Gamma_Y(X,\f'')\to 0. $$
44+
45+
$\KaTeX$ even has support for commutative diagrams, though for now only using
46+
the [amscd](https://tug.ctan.org/macros/latex/required/amsmath/amscd.pdf)
47+
syntax, which does not allow diagonal arrows for instance.
48+
49+
<div markdown=0>
50+
\begin{CD}
51+
A @>{a}>> B \\
52+
@V{b}VV @VV{c}V \\
53+
C @>{d}>> D
54+
\end{CD}
55+
</div>
56+
57+
So do numbered equations, in `equation`, `align`, and `gather`.
58+
59+
<div markdown=0>
60+
\begin{equation}
61+
\begin{split} a &=b+c\\
62+
&=e+f
63+
\end{split}
64+
\end{equation}
65+
</div>
66+
67+
To use either of these, your input needs to be excluded from Markdown processing like this:
68+
69+
~~~ html
70+
<div markdown=0>
71+
\begin{CD}
72+
...
73+
\end{CD}
74+
</div>
75+
~~~
4176

4277
If you are not familiar with writing mathematics in $\LaTeX$, I highly
4378
recommend reading and bookmarking this [Wikibooks reference] and using
4479
it to typeset problem sets or exercises to practice. Another great reference
4580
is [this "short" guide] by the AMS. To learn more about $\LaTeX$ itself,
4681
[D.R.Wilkins' Primer] is a decent place to start.
4782

48-
[^katex]:
49-
This will change once this [issue](https://github.com/github/pages-gem/pull/545) is fixed.
50-
5183
[long list]: https://katex.org/docs/supported.html
5284
[Wikibooks reference]: https://en.wikibooks.org/wiki/LaTeX/Mathematics
5385
[this "short" guide]: https://mirrors.ibiblio.org/CTAN/info/short-math-guide/short-math-guide.pdf

0 commit comments

Comments
 (0)