A template you can use to write a TTRPG book with Typst.
This code has been used to build Bloodstained Fangs, both the digital PDF and the print version. Go download it (it's free!) to see what the result looks like!
The template includes code that can be used to:
- prepare a PDF for digital publishing
- prepare a print ready PDF for self publishing on Amazon KDP (including the cover!) with bleed handling to support full page illustrations
- prepare itch.io banners and covers
Includes Typst functions to automate:
- bleed handling for the print version
- full page illustrations (with bleed)
- chapter headings
- table of contents (with auto hyperlinks)
- automated hyperlinked PDF bookmarks
- centralized settings for:
- color palette and other theming
- paper size
- table of contents etc
- All kinds of Tables!
- D66 matrix tables
- D66 list tables
- D66 list tables (2 columns)
- Custom tables
The table system automatically handles page breaks in a sensible way etc.
It's a book that contains rules and/or a setting for a TableTop Role Playing Game. You might have heard of "Dungeons & Dragons", that's a TTRPG.
It's a fast and nice system to define the layout and content of the book using code. Being code, complex layouting logic like rolling tables can be modularized and encapsulated so you can focus on content. In addition, being code you can leverage generative AI to help you with the book and the layouting.
Not really, but if you don't then you will need to use some AI assistance in order to adjust the template to your needs. You will also need to learn basic Typst markup (it's similar to markdown, so you will figure it out easily if you know markdown)
In general you won't have much trouble if you worked with HTML, XML or Markdown before and are willing to have AI tools edit the more code-y parts for you.
However you will likely need some sort of software development skills such as version control with git, using the CLI to build the PDFs, and using AI tools for software development and/or vibe coding.
Before diving in, read about the project structure, how to build the outputs (PDFs, banners etc) then how to modify it for your book and finally how to add content.
typst-ttrpg-template/
├── src # Where all the Typst source code is
├───── builds # Contains a Typst file for each thing you can build
├───── content # Where you put the content for your book
├───────── content.typ # Main file to control the structure of the book
├───────── eng # Where the english content goes
├───── template.typ # Contains settings such as paper size used
├── fonts/ # Fonts you use in the book, examples are included
├── art/ # Images you use in the book, examples are included
You need to have Typst installed on your system. Choose one of the following methods:
If you have Nix installed, simply run:
nix-shellThis will automatically load the development environment with Typst installed.
Otherwise, visit Typst's releases page and install Typst on your system.
Once Typst is installed you can use the following scripts:
scripts/build.sh: Compiles all the PDFsscripts/watch.sh: Watches for changes and recompiles the PDF automatically. You can specify a parameter for which file to watch. Useful to preview changes as you work.
Try running the build script now to check the sample output.
To change some text you see in the output, just search it in the codebase and edit it.
For changing colors and fonts, see theme.typ. For general layouting, the table of contents, etc see template.typ
The code for how tables are rendered and all other utility methods is in utils.typ
Modify content.typ to add as many files as you want. Each file can contain as much content as you like, even the whole book, and it can include other files.
Read utils.typ. The main functions included are:
keep_together[ ... ]will keep all content on the same page. preventing things like a single line being broken into a separate pagepagebreak()just makes the next content after it begin on a new pagepage_illustration()makes the given image take up a whole pageinfo-box()creates a box with text that you can use for quotes, or examples of play, or whatever you like- a bunch of table functions.
rpg_tableis the base one used for custom tables and to power all other table functions. You can use one of the others likematrix_d6if it does what you want, which will make you write less code to define a table, otherwiserpg_tableshould be able to handle anything. - some others!
Teaching how to publish the book is out of scope for this project, but I can give you some pointers:
To publish the digital book on itch, you will find the banner and itch cover outputs very useful. Use the regular book.pdf output as your digital book.
To publish the print version on Amazon KDP, you have the book_pod_cover.pdf output which will produce a ready to print cover for Amazon KDP. For the book, book_pod.pdf will include standard Amazon KDP bleed to make the final paperback look like the digital PDF and have perfectly trimmed full page illustrations.
Note that for the printed cover, you will need to adjust book_pod_cover.typ with the measurements from the cover template from Amazon, which you can get using the cover calculator tool on Amazon KDP. This is because the cover size and layout will depend on how many pages your book has.
I have included a sample cover template (unfortunately it's in italian) I used for Bloodstained Fangs. This template can be shown by editing the code in book_pod_cover.pdf so you can verify the content of the cover matches the template (more instruction inside that file).
You can also publish on Drivethrurpg and Lulu, but I have no experience with those so I am not sure what you need to do.
CC BY-SA 4.0
See LICENSE.md for details.