Skip to content

build and publish a pdf of the book with pandoc - #88

Open
bc1cindy wants to merge 2 commits into
mainfrom
pdf
Open

bc1cindy wants to merge 2 commits into
mainfrom
pdf

Conversation

@bc1cindy

@bc1cindy bc1cindy commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

closes #87. nix build .#pdf renders the book through mdbook-pandoc and pdflatex instead of headless chrome; the second commit publishes it next to the site.

Captura de Tela 2026-11-14 às 21 38 09

mdbook-pandoc hands the book to pandoc, which converts it to LaTeX and
runs pdflatex on it, instead of printing the HTML with headless Chrome
as mdbook-pdf does.

The mermaid preprocessor gives the pandoc renderer each diagram as an
image, because pandoc drops the inline svg that the HTML renderer gets.

Fixes #87
Comment thread contrib/book.py Resolved
@github-actions

Copy link
Copy Markdown
range-diff for force push 38a32a2cf0 → 1103c59283 November 15, 2026 02:27 UTC: 1 unchanged, 1 dropped, 1 added

reproduce: git range-diff cbb5404..38a32a2 cbb5404..1103c59

1:  fd71da6d88 = 1:  fd71da6d88 Build a PDF of the book with pandoc
2:  38a32a2cf0 < -:  ---------- Publish the PDF next to the site
-:  ---------- > 2:  1103c59283 Publish the PDF next to the site

Comment thread contrib/book.py Resolved
The site build hands the PDF to book.py, which reads it before writing
anything to src/, so the contents page links the PDF only when the copy
can be made. The preview and the PDF itself are built without it, so
they have no dead link. The links check runs on the published site, so
it covers the new link.
@github-actions

Copy link
Copy Markdown
range-diff for force push 1103c59283 → f95e9a88a2 November 15, 2026 03:42 UTC: 1 modified, 1 unchanged

reproduce: git range-diff cbb5404..1103c59 cbb5404..f95e9a8

1:  fd71da6d88 = 1:  fd71da6d88 Build a PDF of the book with pandoc
2:  1103c59283 ! 2:  f95e9a88a2 Publish the PDF next to the site
2: 1103c59283 ! 2: f95e9a88a2 Publish the PDF next to the site
@@ Metadata
  ## Commit message ##
     Publish the PDF next to the site
 
-    The site build hands the PDF to book.py, which copies it into the book
-    and only then links it from the contents page. The preview and the PDF
-    itself are built without it, so they have no dead link. The links check
-    runs on the published site, so it covers the new link.
+    The site build hands the PDF to book.py, which reads it before writing
+    anything to src/, so the contents page links the PDF only when the copy
+    can be made. The preview and the PDF itself are built without it, so
+    they have no dead link. The links check runs on the published site, so
+    it covers the new link.
 
  ## contrib/book.py ##
 @@ contrib/book.py: without their descriptions, so an entry must name a chapter, by a path
@@ contrib/book.py: def assemble(root):
 -        CONTENTS: contents(index),
 +        CONTENTS: contents(index, pdf is not None),
      }
++    pdf_bytes = pdf.read_bytes() if pdf is not None else None
      # mdbook serve watches src/ itself and skips what the root .gitignore
      # matches, so src/ is emptied rather than replaced, and ignores itself
+     # before anything else is written to it.
 @@ contrib/book.py: def assemble(root):
      for name, text in pages.items():
          (out / name).parent.mkdir(parents=True, exist_ok=True)
          (out / name).write_text(strip_frontmatter(text))
-+    if pdf is not None:
-+        shutil.copyfile(pdf, out / PDF)
++    if pdf_bytes is not None:
++        (out / PDF).write_bytes(pdf_bytes)
  
  
  def main(argv=None):
@@ contrib/test_book.py: def test_contents_keep_descriptions_under_one_title():
 +    assert "[PDF](fungi-docs.pdf)" in (out / "contents.md").read_text()
 +    assert (out / "fungi-docs.pdf").read_bytes() == b"%PDF"
 +
++
++def test_a_missing_pdf_leaves_src_as_it_was(tmp_path):
++    root, out = tmp_path / "root", tmp_path / "root" / "src"
++    (root / "docs").mkdir(parents=True)
++    (root / "README.md").write_text("# Intro\n")
++    (root / "docs" / "index.md").write_text("# Part\n")
++    book.assemble(root)
++    before = (out / "contents.md").read_text()
++    with pytest.raises(FileNotFoundError):
++        book.assemble(root, tmp_path / "missing.pdf")
++    assert (out / "contents.md").read_text() == before
++
 +
  @pytest.mark.parametrize(
      "line, error",

@oakagent

Copy link
Copy Markdown

ACK f95e9a8

oakagent · automated · fd71da6..f95e9a8 · 2 commits · 0 findings

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mdbook -> pdf

2 participants