outline
Install Typst and confirm availability on CLI
generate a PDF using default setup (
lapreprint-typst)set up and use
plain_typst_bookset up GHA
play with configuration of website to use PDF
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¶
To produce a PDF output locally, you need to have Typst installed on your system.
If you are not working locally, you will need to use GHA to generate your PDF. You can proceed through this lesson sequentially, however, skip the steps that ask you to build the PDF using your CLI. Once you have updated your myst.yml file to use the plain_typst_book you can set up GHA to build and view the PDF.
WIP: these instructions need improvement.
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: 2PDF 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 --typstMore 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.