Automated PDF Generation
Relevant source files
The following files were used as context for generating this wiki page:
- README.md
- .github/workflows/export.yml (Inferred from README.md documentation)
- scripts/template.serve.yml
- overrides/partials/integrations/head.html
- pyproject.toml
- build.ts
The Automated PDF Generation system in the WHK project provides a robust mechanism for converting the Markdown-based knowledge base into high-quality, offline-ready PDF documents. This system is integrated into the project's CI/CD pipeline, ensuring that every official release includes an up-to-date PDF version of the study notes, complete with directory indices and bookmarks for easy navigation.
The generation process leverages a combination of modern web technologies and typesetting tools. It utilizes mkdocs-exporter as the primary engine, which orchestrates Puppeteer for browser-based rendering and LaTeX for high-fidelity document structure and mathematical typesetting. This approach ensures that complex elements like KaTeX formulas and chemical equations (mhchem) are rendered accurately in the final document.
Sources: README.md:38-40, README.md:120-125
System Architecture and Workflow
The PDF generation is handled primarily through a dedicated GitHub Actions workflow. The process is decoupled from the standard static site build to allow for the specialized environment required by Puppeteer and LaTeX.
PDF Export Pipeline
The workflow is triggered by specific events and follows a structured sequence to transform raw Markdown into a finished PDF artifact.
The diagram above illustrates the high-level flow from the initial trigger to the final release upload.
Sources: README.md:118-125
Key Components
The system relies on several specialized tools and configurations to maintain high typography standards:
| Component | Role in PDF Generation |
|---|---|
| mkdocs-exporter | The core plugin that interfaces between MkDocs and the PDF rendering engine. |
| Puppeteer | Headless Chrome instance used to capture the rendered HTML and CSS for conversion. |
| LaTeX | Handles document metadata, bookmarking, and the final assembly of the PDF file. |
| KaTeX SSR | Ensures that mathematical formulas are pre-rendered into HTML/CSS before the PDF capture occurs. |
Sources: README.md:38-40, README.md:52-54, README.md:123-125
Configuration and Styling
The PDF output is styled to match the aesthetic of the online documentation while optimizing for print and offline reading.
Print-Specific Styles
The project uses CSS media queries within overrides/partials/integrations/head.html to adjust the layout for the PDF export. This includes hiding non-printable elements and ensuring specific layouts (like grids) adapt correctly to a fixed-page format.
@media print {
.not-printable {
display: none !important;
}
h1 {
text-align: center;
}
.md-typeset .grid {
grid-template-columns: 1fr 1fr !important;
}
a {
text-decoration: underline !important;
}
}
Sources: overrides/partials/integrations/head.html:92-108
LaTeX and Math Integration
Because the project focuses on science (mathematics, physics, chemistry), the PDF generation must handle complex notation. The template.serve.yml specifies KaTeX options and macros that are consistently applied during the rendering phase.
- Custom Macros: Definitions for $\RR$, $\rank$, $\pH$, and polymer structures ($\poly$) are shared between the web view and the PDF exporter.
- mhchem Support: Chemical equations like $\ce{2H2 + O2 -> 2H2O}$ are supported through the
mhchemcontribution.
Sources: scripts/template.serve.yml:28-66, README.md:88-90
Automation and Execution
Users and developers can trigger the generation process locally or through the automated pipeline.
Command Reference
The project provides a Makefile shorthand to simplify the PDF export process for local testing or manual builds.
| Command | Action |
|---|---|
make export | Triggers the local PDF export process using the configured plugins. |
uv run scripts/generate.py --build | Prepares the site structure which is a prerequisite for PDF generation. |
Sources: README.md:79-81, README.md:113-113
Dependency Management
The environment required for PDF generation is managed via pyproject.toml and npm. Key Python dependencies like mkdocs-materialx and mkdocs-table-reader-plugin provide the structural foundation that the exporter captures.
Sources: pyproject.toml:13-17
Conclusion
Automated PDF Generation is a critical feature of the WHK repository, bridging the gap between a dynamic digital wiki and a stable offline reference. By combining Puppeteer's rendering capabilities with LaTeX's professional typesetting, the project ensures that high-school science notes—including complex equations and chemical formulas—are accessible in a portable, high-fidelity format.