Skip to article frontmatterSkip to article content

outline

With a general understanding of document creation using MyST and our choice to use Typst for PDF generation, you are ready to create a PDF from your book repository using Jupyter Book.

Install Typst¶

Locally
GitHub Actions

To produce a PDF output locally, you need to have Typst installed on your system.

Generate a PDF¶

Change the PDF template¶

As seen in the previous exercise, the PDF generated by the lapreprint-typst template is not ideal for rendering content designed as a website made with the book-theme. Luckily, another Typst template is available: the Plain Typst Book plain_typst_book (not yet listed on the MyST Templates GH Organization). An example YAML snippet that implements this in the myst.yml file is illustrated here:

  exports:
    - format: typst
      template: https://github.com/myst-templates/plain_typst_book.git
      output: exports/book.pdf
      id: output-pdf
      cover: content/figures/logo.svg
      logo: content/figures/logo.svg
      logo_width: 5
      ToC_depth: 2

PDF output with GH Actions¶

Building and including your PDF is possible through a GitHub action that automatically builds the PDF when you push changes to GitHub. This has both is pros and cons. For instance, the build of your PDF is done prior to the build of your book, and if there is an error in the workflow your website may not be updated, or the PDF may not be included as a download. On the other hand, you do not need to install anything locally and the PDF is always up to date when you push changes. The workflow steps are:

    # Install Typst for PDF generation
    - name: Install Typst
      run: |
        typst --version

    # Build the PDF using Typst
    - name: Build PDF
      run: |
        myst build --typst

More fun with PDF’s¶

add MyST action button, add download on page.

Upload as artifact (GHA only). This can be done even if the website build fails.