added katex documentation

This commit is contained in:
Anurag Dhadse 2023-04-29 19:24:30 +05:30
parent b9db2f734c
commit 3bd214fce6
2 changed files with 71 additions and 0 deletions

70
docs/reference/katex.md Normal file
View File

@ -0,0 +1,70 @@
---
icon: material/alphabet-greek
---
# MathJax
[KaTeX] is a Lightning-fast library to display mathematical expressions
in the browser.
[KaTeX]: https://katex.org/
KaTeX isn't supported by default, but can be easily integrated with Material for MkDocs.
## Configuration
This configuration enables support for rendering block and inline block
equations through [KaTex]. Create a configuration file and add the following
lines to `mkdocs.yml`:
=== ":octicons-file-code-16: `docs/javascripts/katex.js`"
``` js
document$.subscribe(() => { // (1)!
renderMathInElement(document.body, {
delimiters: [
{left: '$$', right: '$$', display: true},
{left: '$', right: '$', display: false},
{left: '\\(', right: '\\)', display: false},
{left: '\\[', right: '\\]', display: true},
],
});
})
```
1. This integrates MathJax with [instant loading].
=== ":octicons-file-code-16: `overrides/main.html`"
```html
{% extends "base.html" %}
{% block libs %}
<!--katex scripts-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.7/katex.min.css" integrity="sha512-t2ALGTyUR6g1HJiHCmSTge2yGseGofdO88Q+zOWQx/N0ikecVw0YuyOet9xZDV8+Vx0Y0n1a3f3Qx3V9CcnsKA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.7/katex.min.js" integrity="sha512-EKW5YvKU3hpyyOcN6jQnAxO/L8gts+YdYV6Yymtl8pk9YlYFtqJgihORuRoBXK8/cOIlappdU6Ms8KdK6yBCgA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.7/contrib/auto-render.min.js" integrity="sha512-iWiuBS5nt6r60fCz26Nd0Zqe0nbk1ZTIQbl3Kv7kYsX+yKMUFHzjaH2+AnM6vp2Xs+gNmaBAVWJjSmuPw76Efg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
{{ super() }}
{% endblock %}
```
=== ":octicons-file-code-16: `mkdocs.yml`"
``` yaml
extra_javascript:
- javascripts/katex.js
```
[instant loading]: ../setup/setting-up-navigation.md#instant-loading
## Usage
### Using block syntax
Blocks must be enclosed in `#!latex $$...$$` or `#!latex \[...\]` on separate
lines.
### Using inline block syntax
Inline blocks must be enclosed in `#!latex $...$` or `#!latex \(...\)`.

View File

@ -220,6 +220,7 @@ nav:
- Images: reference/images.md - Images: reference/images.md
- Lists: reference/lists.md - Lists: reference/lists.md
- MathJax: reference/mathjax.md - MathJax: reference/mathjax.md
- KaTeX: reference/katex.md
- Tooltips: reference/tooltips.md - Tooltips: reference/tooltips.md
- Insiders: - Insiders:
- insiders/index.md - insiders/index.md