Skip to content

Instantly share code, notes, and snippets.

@ckunte
Last active April 4, 2024 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ckunte/6c47b20dd2d77364dc652fdf091e9f24 to your computer and use it in GitHub Desktop.
Save ckunte/6c47b20dd2d77364dc652fdf091e9f24 to your computer and use it in GitHub Desktop.
Compile Typst document to PDF using Python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Compile Typst document
ctd.py 2024 ckunte
Usage: ctd.py (-f <file>)
ctd.py --help
ctd.py --version
Options:
-h, --help Show this help
-f, --file Specify Typst input file to compile (required)
"""
import typst
from docopt import docopt
def main(typstfile):
pdffile = f"{typstfile.rsplit('.', 1)[0]}.pdf"
print(f"Compiling {typstfile} to {pdffile}...", end="")
typst.compile(typstfile, output=pdffile)
print("done.")
if __name__ == '__main__':
args = docopt(__doc__, version="Compile Typst document, 0.1")
main(args["<file>"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment