Skip to content

Building the PDF

Golam Kuadir Khan Prince edited this page Oct 22, 2026 · 2 revisions

Building the PDF

A prebuilt copy is in the repo at pdf/Advanced-Chemistry.pdf. It is A4, about 920 pages (core, specializations and appendices), with clickable contents and PDF bookmarks.

Requirements

  • Node.js 18 or newer.
  • A Chromium-based browser: Chrome, Edge or Chromium. It is found automatically on Windows, macOS and Linux. If yours is elsewhere, set CHROME_PATH.

No LaTeX installation is needed.

Commands

npm install
npm run pdf                                            # whole book -> dist/Advanced-Chemistry.pdf
node scripts/build-pdf.mjs --parts 5,6,A               # selected chapters/appendices
node scripts/build-pdf.mjs --parts 13 --out ch13.pdf   # custom output path
node scripts/build-pdf.mjs --html                      # also keep the intermediate HTML

Parts are chapter numbers (1–23), specializations (S1–S14) or appendix letters (A–E). The full book takes a few minutes to print.

How it works

  1. Collect the parts. lib/book.mjs lists the chapters and appendices in reading order.
  2. Render to HTML. markdown-it renders each file. markdown-it-texmath passes every $…$ and $$…$$ to KaTeX, which typesets it on the server.
  3. Fix image paths. Relative image links are resolved to absolute file URLs, so figures embed correctly.
  4. Assemble one document. A cover page, a linked contents page and one section per part are combined. KaTeX's CSS and fonts are inlined.
  5. Print. puppeteer-core drives your local Chrome to print the PDF, with page numbers and a running header.

Error reporting

The builder reports two kinds of problem:

  • Math that KaTeX could not render, with the file and expression.
  • Image links whose file does not exist.

A clean build prints neither.

Writing math that builds

Follow these rules (see Contributing and House Style):

  • Use $…$ and $$…$$, never \(…\) or \[…\].
  • Use \begin{aligned} inside $$, not align.
  • Inside tables, write \lvert x\rvert instead of |x|.

Clone this wiki locally