Function tectonic::latex_to_pdf

source ·
pub fn latex_to_pdf<T: AsRef<str>>(latex: T) -> Result<Vec<u8>>
Expand description

Compile LaTeX text to a PDF.

This function is an all-in-one interface to the main Tectonic workflow. Given a string representing a LaTeX input file, it will compile it to a PDF and return a byte vector corresponding to the resulting file:

let latex = r#"
\documentclass{article}
\begin{document}
Hello, world!
\end{document}
"#;

let pdf_data: Vec<u8> = tectonic::latex_to_pdf(latex).expect("processing failed");
println!("Output PDF size is {} bytes", pdf_data.len());

The compilation uses the default bundle, the location of which is embedded in the crate or potentially specified in the user’s configuration file. The current working directory will be searched for any \\input files. Messages aimed at the user are suppressed, but (in the default configuration) network I/O may occur to pull down needed resource files. No outputs are written to disk; all supporting files besides the PDF document are discarded. The XeTeX engine is run multiple times if needed to get the output file to converge.

For more sophisticated uses, use the driver module, which provides a high-level interface for driving the typesetting engines with much more control over their behavior.

Note that the current engine implementations use lots of global state, so they are not thread-safe. This crate uses a global mutex to serialize invocations of the engines. This means that if you call this function from multiple threads simultaneously, the bulk of the work will be done in serial. The aim is to lift this limitation one day, but it will require extensive work on the underlying C/C++ code.