LHTML+ lhtml-site

Your slides as a PDF

For the organizers of a conference, for the students, or to print: the same slides, as a PDF. This recipe starts from a talk, such as the one made by lhtml-site init my-talk --theme slides. For a course of several decks, one per chapter, see A course of several chapters at the end.

Needs: lhtml-site installed; Playwright and its Chromium, about 200 MB, downloaded once (step 1)Time: 10 minYou get: slides.pdf and an image of each slide

1. Install the PDF export, once

The export runs Chromium through Playwright: two Python packages and a browser, no Node.js. After pipx install lhtml-site:

pipx inject lhtml-site pypdf
pipx inject --include-apps lhtml-site playwright
playwright install --only-shell chromium
lhtml-site doctor

The PDF export line of lhtml-site doctor says ready when everything is found; otherwise it gives the command to run.

  • Chromium is downloaded once, about 200 MB.
  • In a virtual environment instead of pipx: pip install "lhtml-site[pdf]", then python -m playwright install --only-shell chromium.
  • On Linux, Playwright may also ask for Chromium's system libraries: playwright install-deps chromium.

2. Change the theme

In configure.yaml, replace the line theme: 'slides' with:

theme: 'slides-pdf'

lhtml-site then writes slides.pdf, and images/ with an image of each slide (slide_000.jpg, ..., 3840 px wide). With this single theme, both land next to configure.yaml, not in .site/: there is no .site/ at all. A few seconds for a few slides. An example: the PDF of the starter talk.

The export waits for each slide to be ready (fonts, formulas, images, a frame of each video) before printing it. With this theme the HTML of the slides is only a step towards the PDF: put theme: 'slides' back to work on the slides in the browser, or build both.

3. Both at each build

To get the slides in the browser and the PDF with one command, remove the theme: line and declare two targets instead (theme: and targets: together are an error):

targets:
  html: {theme: slides}
  pdf: {theme: slides-pdf}

With targets, everything lands in .site/:

.site/html/index.html     the slides, in the browser
.site/slides.pdf          the PDF
.site/images/             an image of each slide

lhtml-site --target html builds only the slides, when you are writing.

A course of several chapters

A course is often several decks, one per chapter, each wanted as slides and as a PDF. With decks: directories, each directory of src/ becomes a deck of its own, built for each target:

decks: directories        # src/01_procedural/, src/02_rigid/, ...
targets:
  html: {theme: slides}
  pdf: {theme: slides-pdf}
.site/01_procedural/html/index.html
.site/01_procedural/01_procedural.pdf
.site/01_procedural/images/

Each chapter directory holds its slides as subdirectories (src/01_procedural/01_intro/, ...). lhtml-site --only 01_procedural rebuilds one chapter. More in Decks and targets.

If it goes wrong

  • The PDF export line of lhtml-site doctor is not ready: run the command it prints.
  • On Linux, Chromium does not start (a missing .so library): playwright install-deps chromium.
  • A slide is cut in the PDF: it overflows in the browser too; lhtml-site --layout lists the blocks that go past the slide, in .layout/ (Check your slides automatically).
  • theme: and targets: together are an error: keep only one of them.

Next: put the slides and the PDF online.

Built with lhtml-site, the docs theme. Part of ScholarTools.