4 releases
0.1.4 | Oct 29, 2022 |
---|---|
0.1.3 | Oct 29, 2022 |
0.1.2 | Apr 6, 2022 |
0.1.0 | Aug 28, 2021 |
#8 in #katex
4KB
Insert KaTeX autorender script into rustdoc
Usage
#[cfg_attr(doc, katexit::katexit)]
/// We can write $\LaTeX$ expressions
///
/// Display style
/// -------------
///
/// $$
/// c = \\pm\\sqrt{a^2 + b^2}
/// $$
pub fn my_func() {}
See rendered result on docs.rs.
How it works
#[katexit]
proc-macro inserts KaTeX autorender script as #[doc = "{script}"]
.
Since the markdown to HTML translator of rustdoc do not touch HTML partitions embedded in markdown,
they will be passed as it is to the browser.
The autorender script starts rendering the math expression enclosed by $
written in the document section
when you open the page generated by rustdoc, i.e. this does not work offline.
Links
- rustdoc-katex-demo and similar demo projects
- They uses
--html-in-header
option in rustdoc to inserts KaTeX auto-render script. But it requires some complicated setting in Cargo.toml.
- They uses
- aquamarine
- The idea using proc-macro for cargo-doc is based on this crate.
- katex-rs
- This is "Rust bindings to KaTeX". This crate aims to run KaTeX using QuickJS without external dependencies.
Dependencies
~1.5MB
~37K SLoC