An mdbook backend for generating LaTeX and PDF documents.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Liam Beckman e8a31573a4
Merge pull request #10 from enaut/fix-images-2
6 months ago
ci Merge branch 'dev' 7 months ago
docs Document date and other config options 7 months ago
examples Add sample-book book. 10 months ago
src Merge branch 'master' into fix-images-2 7 months ago
.gitignore Add template.tex file for all LaTeX data. 1 year ago
.travis.yml Update travis. 7 months ago
Cargo.lock Merge branch 'dev' 7 months ago
Cargo.toml Merge branch 'master' into fix-images-2 7 months ago
Cross.toml Update dockerfile for x86_64-unknown-linux-gnu. 11 months ago
Jenkinsfile Update Jenkinsfile. 7 months ago
LICENSE Add license and gitignore. 1 year ago Update 7 months ago
appveyor.yml Debug CI/CD. 1 year ago
mdbook-latex.kra Add krita file. 8 months ago
mdbook-latex.png Fix image. 8 months ago


mdbook-latex logo

crates badge docs badge ci badge source badge

An mdbook backend for generating LaTeX and PDF documents. Utilizes md2tex for the markdown to LaTeX transformation, but with the goal of allowing alternative markdown to LaTeX converters. If you have developed your own markdown to LaTeX converter, I’d love to talk with you or share ideas! I’m at

Warning: Not yet stable — may eat, shred, and atomize your laundry! See the Are We Stable Yet? section for a roadmap to the production release.

Failure: For what to do if and when mdbook-latex fails, see mdbook-latex failed to build my book! Now what? >:(. I’m also available via e-mail if you have any questions or suggestions!

Status of Rust Bookshelf

  • ✅ compiles successfully
  • 🍊 compiles but with warnings/errors
  • ❌ compilation fails/not yet attempted
Compiles? Generated PDF Generated LaTeX Source Online Version
Cargo Book LaTeX Source HTML
Edition Guide LaTeX Source HTML
Embedded Rust Book LaTeX Source HTML
🍊 Mdbook User Guide LaTeX Source HTML
Rust Reference LaTeX Source HTML
Rust By Example LaTeX Source HTML
🍊 Rust Programming Language LaTeX Source HTML
Rustc Book LaTeX Source HTML
Rustdoc Book LaTeX Source HTML
Rustonomicon LaTeX Source HTML
Unstable Book LaTeX Source HTML



Cargo install + Configuration

cargo install mdbook-latex

Add the following toml configuration to book.toml.

latex    = true  # default = true
pdf      = true  # default = false
markdown = true  # default = false

The next mdbook build command will produce LaTeX and PDF files (and the markdown file of your mdbook) in the book/latex/ directory.


To uninstall mdbook-latex, enter the following in a shell:

cargo uninstall mdbook-latex

Then delete the [output.latex] configuration in book.toml:

- [output.latex]
- latex    = true
- pdf      = true
- markdown = true

Primary Dependencies

mdbook-latex is built upon some really wonderful projects, including:

  • pulldown-cmark: Parses the markdown source AST.
  • Tectonic: Creates the final PDF file from the transformed LaTeX code.
  • md2tex: Transforms the markdown source to LaTeX. This is a fork of md2pdf, a great utility for converting markdown code to LaTeX and PDF’s. I hope to eventually propose some of the updates back upstream. md2tex and mdbook-latex are developed in tandem, but are meant to be independent programs. Therefore, if one wishes to use an alternative markdown-to-tex conveter, they should be able to plug it in to mdbook-latex with ease.

How’s it Work?

Broadly speaking, there are three steps, or “transformations”, from mdbook source to PDF output:

1) mdbook source to JSON-organized markdown (mdbook-latex): retreives the JSON formatted data from mdbook. Calls md2tex and tectonic for LaTeX and PDF generation, respectively. 2) markdown to LaTeX (md2tex): converts markdown input to LaTeX output. 3) LaTeX to PDF (tectonic): creates PDF document from LaTeX input.


Pull requests, forks, and plain old copy-pasting are actively encouraged! Also, I am relatively new to Rust (and programming in general) so recommendations or advice in general is always appreciated.

I found a problem. Should I create an issue with mdbook-latex or md2tex?

Either one. mdbook-latex can be thought of as a frontend for the LaTeX generation done by md2tex. So if there is a LaTeX error, you may favor creating an issue with md2tex. Otherwise, creating an issue with mdbook-latex is a good bet. But any issue is a good issue, so don’t worry if it’s in the “right” repository or not, I should be able to see it regardless!

Are We Stable Yet?

Below is a list of features I am currently working on (loosely in a “top-down” direction).

  • Add support for equation delimiters “( x^2 )” “[ x^2 ]”.
  • Allow SVG images (convert to PNG for LaTeX).
    • Configure resvg library to convert SVG’s to PNG.
    • Save SVG’s in book/latex directory to keep src clean.
  • Add CI/CD pipeline (travis)
  • Move all LaTeX data to single template file (src/template.tex).
  • Add support for raw HTML tables.
  • Add syntax highlighting via syntect à la lumpy-leandoc.
  • Add parallel transformations via Rayon à la lumpy-leandoc.
  • Use lumpy-leandoc’s method for handling events (replace current event with fold).
  • Compile The Rust Book and mdbook documentation without any errors or warnings (e.g. missing Unicode characters). See Status of Rust Bookshelf for up to date progress.
  • Put “tectonic” dependency in “pdf” feature configuration.
  • Add “table of contents” mdbook toml option.
  • Add “markdown” mdbook toml option.
  • Add “number of words” mdbook toml option.
  • Add “examples” directory.
  • Create documentation and move relevent docs to md2tex.
  • Add option for custom LaTeX headers.
  • Add option for alternative markdown-to-latex converter plugin.
  • Add test suites.
  • Cross compile binaries (trust)
  • Add option to generate PDF with mdproof to skip LaTeX dependencies.
  • Complete acordance with the CommonMark spec.

See Also

The following projects served as guidance for mdbook-latex (or are simply cool enough that they deserve to be shared!):

  • mdbook-epub: A backend for mdbook that creates EPUB files.
  • mdbook-linkcheck: A backend for mdbook that will verify URL links.
  • LaTeX-rs: A cool library for programmatic LaTeX generation that I hope to eventually incorporate.
  • crowbook: A rich program that can generate HTML, PDF, and EPUB files from markdown code. Has a neat online demo page to try it out interactively. Similar in some respects to mdbook, but with an added focus on “novels and fiction”. Though general enough to handle a lot of different projects.
  • no starch press: The Rust Programming Language made professionally by a proper publishing company. Guranteed to have fewer errors than mdbook-latex!
  • lumpy-leandoc: A more elegant approach to markdown-LaTeX conversion via pulldown_cmark than that currently provided by md2tex. Also includes parallelism via Rayon and syntax highlighting via syntect!

mdbook-latex failed to build my book! Now what? >:(

Automatic Approach

Oops! That means I still have more work to do. If you absolutely need your PDF right now, then the quicket option is to select the print icon in the upper right corner of the online page of your book.

Another method is to run the markdown file through an alternative markdown to LaTeX converter like pandoc:

pandoc --from markdown --to latex book/latex/ -o book/latex/MY_BOOK.pdf

Or run it through a free (as in free parking) online solution:

Manual Approach

If, however, you don’t mind getting your hands dirty with LaTeX, here is my process for when the build step fails:

1) Change the latex configuration in book.toml to only output LaTeX and markdown files:

latex = true
pdf = false
markdown = true

2) First see where tectonic is running into errors by manually running it and looking for ! LaTeX Error:

tectonic book/latex/MY_BOOK.tex

note: this is a BETA release; ask questions and report bugs at
Running TeX ...
error: something bad happened inside TeX; its output follows:

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.

l.260 \clearpage

No pages of output.
Transcript written on MY_BOOK.log.

error: the TeX engine had an unrecoverable error
caused by: halted on potentially-recoverable error as specified

Aha! ! LaTeX Error: Missing \begin{document}.

In this example, mdbook-latex failed to output the very important \begin{document} line.

3) Fix the grievous goof-up in your favorite editor and rerun tectonic (repeat this step until tectonic successfully compiles the PDF):

ed book/latex/MY_BOOK.tex

tectonic book/latex/MY_BOOK.tex

Is it an elegant approach? No. Does it work? Sometimes. Is it a pain? Always.


If you’re feeling especially adventurous, create an issue or get in touch with me ( to help prevent the same errors in the future. I’m more than happy to work with you to get your document compiled!

^ )

Status of Binary Releases

  • ✅ binary available
  • ❌ binary not available
Binary? Target