A Rust version of Katex using wasm. wasm-pack.
katex-wasm
wasm-pack build
Use the custom Cargo profile defined in Cargo.toml ([profile.profiling]):
wasm-pack build --profile profilingNote: wasm-pack build --profiling is wasm-pack's built-in profiling mode and does not select your custom [profile.profiling].
wasm-pack test --headless --firefox
wasm-pack build
cd demo
npm install
npm start
katex-rs-cli now uses clap for argument parsing, so it has standard --help and --version output.
# Show help
cargo run --bin katex-rs-cli -- --help
# Render every formula in a file
cargo run --bin katex-rs-cli -- tests/fixtures/formulas.txt
# Render a specific inclusive line range
cargo run --bin katex-rs-cli -- tests/fixtures/formulas.txt 1 5
# Only print the final summary
cargo run --bin katex-rs-cli -- tests/fixtures/formulas.txt 1 5 --summary-only
# Disable multi-threaded rendering
cargo run --bin katex-rs-cli -- tests/fixtures/formulas.txt 1 5 --multi-threaded falseArguments:
formulas.txt: input file containing one LaTeX formula per linestart_line: optional 1-based inclusive start line, defaults to1end_line: optional 1-based inclusive end line, defaults to the last line in the file--summary-only: optional flag that suppresses per-formula output and only prints the final summary--multi-threaded <BOOL>: optional boolean switch for parallel rendering, defaults totrue
Coverage testing for the CLI is documented in docs/katex-rs-cli-coverage.md.
Quick coverage run with a .txt formula file:
scripts/katex-rs-cli-coverage.sh tests/fixtures/formulas.txtThe coverage script uses katex-rs-cli --summary-only to print only the final summary.
Merge coverage from two formula files:
scripts/katex-rs-cli-coverage.sh tests/fixtures/formulas_part1.txt --profraw-dir coverage/profraw/part1
scripts/katex-rs-cli-coverage.sh tests/fixtures/formulas_part2.txt --profraw-dir coverage/profraw/part2 --merge-profraw coverage/profraw/part1Use tests/diff_harness.mjs to compare JS KaTeX and Rust WASM output on the same formulas.
wasm-pack build
node --experimental-wasm-modules tests/diff_harness.mjs tests/fixtures/formulas.txt 1 5 --log-level errorThe harness now accepts either:
- text input with one formula per line
- YAML input such as
KaTeX/test/screenshotter/ss_data.yaml; it extracts formulas from string values or objecttexfields
For YAML input, start_line and end_line apply to the extracted formula order, not physical file lines.
wasm-pack build
node --experimental-wasm-modules tests/diff_harness.mjs KaTeX/test/screenshotter/ss_data.yaml 1 20 --log-level summaryLog levels:
summary: only the final summaryerror: only render errors or mismatchesnormal: per-formula render results and match statusdebug:normalplus processed JS/Rust settings
YAML parsing in the harness uses demo's js-yaml dependency, so make sure cd demo && npm install has been run at least once before using YAML input.
已经提供自动化工作流:.github/workflows/deploy-demo.yml。
- 推送到
main分支自动部署 - 或在 GitHub Actions 页面手动触发
workflow_dispatch
wasm-pack build在仓库根目录构建 wasm,产物默认输出到pkg/demo/package.json使用"katex-wasm": "file:../pkg",直接消费该产物- 构建 demo 时通过
PUBLIC_PATH=/${{ github.event.repository.name }}/注入 webpackoutput.publicPath - 将
demo/dist上传到 GitHub Pages 并发布
注意:GitHub Pages 项目页不是根路径(
/),如果不设置publicPath,index.js和 wasm 文件会按根路径请求,导致 404。