#document #latex #escaping #tex #generate #render #wrapper

texrender

Thin wrapper around running latexmk to render LaTeX documents. Also supports generating Tex documents.

9 releases

0.3.3 Nov 18, 2020
0.3.2 Oct 26, 2020
0.2.1 Oct 26, 2020
0.1.2 Oct 22, 2020

#1726 in Text processing

MIT/Apache

32KB
666 lines

texrender

A small crate to run latexmk from Rust, similar to latex, escape LaTeX code and generate LaTeX documents programmatically.

Example: Rendering latex

let doc = r"
      \documentclass{article}
      \begin{document}
      hello, world.
      \end{document}
      ";

let tex = TexRender::from_bytes(doc.into());
let _pdf = tex.render().expect("latex rendering failed");

Example: Generating latex code

use texrender::elems;
use texrender::tpl::TexElement;
use texrender::tpl::elements::{N, doc, document, documentclass, section, t};

let tex = doc(elems!(
    documentclass(N, "article"),
    document(elems!(
        section("Hello, world"),
        t("This is fun & easy.")
    ))
));

let output = tex.render().expect("rendering failed");

assert_eq!(output,
           "\\documentclass{article}\n\
            \\begin{document}\n\
            \\section{Hello, world}\n\
            This is fun \\& easy.\n\
            \\end{document}\n");

Dependencies

~0.7–1.3MB
~25K SLoC