#! /usr/bin/env bash basedir="$(dirname "$0")" basedir="$(realpath "$basedir")" cd "$basedir" name="$(basename "$(pwd)")" if ! typst compile --root .. ./main.typ ./"$name".pdf; then echo "Failed to compile $name/main.typ. Please fix errors and run me again." exit 1 fi echo "Compiled read mode. Now compiling print mode." if ! command -v pdfbook2; then echo "ERROR: pdfbook2 not installed. Not compiling print mode." exit 1 fi t="$(mktemp --suffix=.pdf)" typst compile --input format=booklet --root .. ./main.typ "$t" # Need to be in the folder there for it to work, otherwise it # tries to rename from current partition to /tmp which of course fails parent="$(dirname "$t")" newFileName="$(basename "$t" .pdf)-book.pdf" newFile="$parent"/"$newFileName" cd "$parent" pdfbook2 --paper=a4paper "$t" --no-crop --outer-margin=0 --inner-margin=0 --top-margin=0 --bottom-margin=0 cd "$basedir" newFinalFile="$name"-book.pdf cp "$newFile" "$newFinalFile" echo "Booklet available in $newFinalFile"