max-heller / mdbook-pandoc

A mdbook backend powered by Pandoc.
Apache License 2.0
97 stars 7 forks source link

mdbook-pandocLatest Version

A mdbook backend that outsources most of the rendering process to pandoc. By relying on pandoc, many output formats are supported, although this project was mainly developed with LaTeX in mind.

See Rendered Books for samples of rendered books.

Installation

Getting Started

Instruct mdbook to use mdbook-pandoc by updating your book.toml file. The following example configures mdbook-pandoc to generate a PDF version of the book with LaTeX (which must be installed). To generate other output formats, see Configuration.

[book]
title = "My First Book"

+ [output.pandoc.profile.pdf]
+ output-file = "output.pdf"
+ to = "latex"

Running mdbook build will write the rendered book to pdf/output.pdf in mdbook-pandoc's build directory (book/pandoc if multiple renderers are configured; book otherwise).

Configuration

Since mdbook-pandoc supports many different output formats through pandoc, it must be configured to render to one or more formats through the [output.pandoc] table in a book's book.toml file.

Configuration is centered around output profiles, named packages of options that mdbook-pandoc passes to pandoc as a defaults file to render a book in a particular format. The output for each profile is written to a subdirectory with the same name as the profile under mdbook-pandoc's top-level build directory (book/pandoc if multiple renderers are configured; book otherwise).

A subset of the available options are described below:

Note: Pandoc is run from the book's root directory (the directory containing book.toml). Therefore, relative paths in the configuration (e.g. values for include-in-header, reference-doc) should be written relative to the book's root directory.

[output.pandoc]
hosted-html = "https://doc.rust-lang.org/book" # URL of a HTML version of the book

[output.pandoc.code]
# Display hidden lines in code blocks (e.g., lines in Rust blocks prefixed by '#').
# See https://rust-lang.github.io/mdBook/format/mdbook.html?highlight=hidden#hiding-code-lines
show-hidden-lines = false

[output.pandoc.profile.<name>] # options to pass to Pandoc (see https://pandoc.org/MANUAL.html#defaults-files)
output-file = "output.pdf" # output file (within the profile's build directory)
to = "latex" # output format

# PDF-specific settings
pdf-engine = "pdflatex" # engine to use to produce PDF output

# `mdbook-pandoc` overrides Pandoc's defaults for the following options to better support mdBooks
from = "commonmark" # source format; extensions enabled/disabled through this option are preserved
file-scope = true # parse each file individually before combining
number-sections = true # number sections headings
standalone = true # produce output with an appropriate header and footer
table-of-contents = true # include an automatically generated table of contents

# Arbitrary other Pandoc options can be specified as they would be in a Pandoc defaults file
# (see https://pandoc.org/MANUAL.html#defaults-files) but written in TOML instead of YAML...

# For example, to pass variables (https://pandoc.org/MANUAL.html#variables):
[output.pandoc.profile.<name>.variables]
# Set the pandoc variable named 'variable-name' to 'value'
variable-name = "value"

Features

Preprocessing

mdbook-pandoc performs a brief preprocessing pass before handing off a book to pandoc:

Known Issues

Comparison to alternatives

Rendered books

The following table links to sample books rendered with mdbook-pandoc. PDFs are rendered with LaTeX (LuaTeX).

Book Rendered
Cargo Book PDF
mdBook Guide PDF
Rustonomicon PDF
Rust Book PDF
Rust by Example PDF
Rust Edition Guide PDF
Embedded Rust Book PDF
Rust Reference PDF
Rust Compiler Development Guide PDF

Rendering to PDF

Rendering to other formats