Last active
April 4, 2024 03:06
-
-
Save ckunte/6c47b20dd2d77364dc652fdf091e9f24 to your computer and use it in GitHub Desktop.
Compile Typst document to PDF using Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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