#rustdoc #katex #katexit

macro katexit

Insert KaTeX autorender script into rustdoc

6 releases

new 0.1.5 May 10, 2025
0.1.4 Oct 29, 2022
0.1.2 Apr 6, 2022
0.1.1 Aug 30, 2021

#540 in Procedural macros

Download history 3543/week @ 2025-01-22 6758/week @ 2025-01-29 5817/week @ 2025-02-05 6059/week @ 2025-02-12 6321/week @ 2025-02-19 5725/week @ 2025-02-26 7980/week @ 2025-03-05 7456/week @ 2025-03-12 5071/week @ 2025-03-19 4747/week @ 2025-03-26 5674/week @ 2025-04-02 6854/week @ 2025-04-09 10271/week @ 2025-04-16 10320/week @ 2025-04-23 14087/week @ 2025-04-30 18191/week @ 2025-05-07

53,783 downloads per month
Used in 120 crates (16 directly)

MIT/Apache

7KB
60 lines

Crate docs.rs

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.

On nightly rustc, you can use #![katexit::katexit] for module level document:

#![cfg_attr(doc, feature(prelude_import, custom_inner_attributes))]
#![cfg_attr(doc, katexit::katexit)]
//! Module level document example with $\KaTeX$!

Be sure that cargo test will runs rustdoc for executing doc-test, and thus requires nightly compiler. See katexit-example-nightly for detail.

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.

Dependencies

~195–620KB
~15K SLoC