Skip to content

Commit 16d7b3f

Browse files
authored
Merge pull request #202 from rust-ndarray/katex-doc
Display math formulas in document by KaTeX
2 parents 40273f8 + 6c2bad3 commit 16d7b3f

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,5 @@ harness = false
6161
name = "eigh"
6262
harness = false
6363

64+
[package.metadata.docs.rs]
65+
rustdoc-args = ["--html-in-header", "katex-header.html"]

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,22 @@ extern crate ndarray;
7777
extern crate ndarray_linalg;
7878
extern crate openblas_src; // or another backend of your choice
7979
```
80+
81+
Generate document with KaTeX
82+
------------------------------
83+
84+
You need to set `RUSTDOCFLAGS` explicitly:
85+
86+
```shell
87+
RUSTDOCFLAGS="--html-in-header katex-header.html" cargo doc --no-deps
88+
```
89+
90+
This **only** works for `--no-deps` build because `katex-header.html` does not exists for dependent crates.
91+
If you wish to set `RUSTDOCFLAGS` automatically in this crate, you can put [.cargo/config](https://doc.rust-lang.org/cargo/reference/config.html):
92+
93+
```toml
94+
[build]
95+
rustdocflags = ["--html-in-header", "katex-header.html"]
96+
```
97+
98+
But, be sure that this works only for `--no-deps`. `cargo doc` will fail with this `.cargo/config`.

katex-header.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!-- This file includes the work that is distributed in MIT or Apache-2.0 license at https://github.com/paulkernfeld/rustdoc-katex-demo -->
2+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-9eLZqc9ds8eNjO3TmqPeYcDj8n+Qfa4nuSiGYa6DjLNcv9BtN69ZIulL9+8CqC9Y" crossorigin="anonymous">
3+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-K3vbOmF2BtaVai+Qk37uypf7VrgBubhQreNQe9aGsz9lB63dIFiQVlJbr92dw2Lx" crossorigin="anonymous"></script>
4+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" integrity="sha384-kmZOZB5ObwgQnS/DuDg6TScgOiWWBiVt0plIRkZCmE6rDZGrEOQeHM5PcHi+nyqe" crossorigin="anonymous"></script>
5+
<script>
6+
document.addEventListener("DOMContentLoaded", function() {
7+
renderMathInElement(document.body, {
8+
delimiters: [
9+
{left: "$$", right: "$$", display: true},
10+
{left: "\\(", right: "\\)", display: false},
11+
{left: "$", right: "$", display: false},
12+
{left: "\\[", right: "\\]", display: true}
13+
]
14+
});
15+
});
16+
</script>

0 commit comments

Comments
 (0)