Build

These are instructions for setting Sublime Text up to build (i.e., compile, run, or type-set) a source to produce some output. Owing to different file paths, these would be different obviously for different systems. In all of these, be sure to adjust paths as necessary.

Select Tools > Build System > New Build System…, and replace the entire pre-populated instructions with the following respectively. With a source file open in Sublime Text, Build is invoked with either Ctrl b (Windows) or Cmd b (MacOS).

  1. LaTeX (MacOS) LaTeX-Mac.sublime-build:

     {
       "cmd": ["/Library/TeX/texbin/xelatex", "$file"],
       "selector": "text.tex.latex"
     }
    
  2. LaTeX (Windows WSL) LaTeX-WSL.sublime-build:

     {
       "cmd" : ["bash", "-c", "/usr/local/texlive/2022/bin/x86_64-linux/xelatex ${file_name}"],
       "shell" : true,
       "working_dir" : "${file_path}",
       "selector" : "text.tex.latex"
     }
    
  3. LaTeX (Windows Cygwin) LaTeX-Cyg.sublime-build:

     {   
       "shell_cmd" : "xelatex \"$file_name\"",
       "selector" : "source.tex",
       "path" : "C:\\Cygwin\\<path-to-xelatex>;$path",
       "working_dir" : "$file_path"
     }
    
  4. LaTeX (GitHub Actions) rel.yml:

    A workflow is a set of instructions to be run as actions in a container by GitHub. Save it under the repository like so .github/workflows/rel.yml. The build is triggered when a commit has a tag number (e.g. v1.0.3) with tag pushed to GitHub.

     name: Build LaTeX document
     on: 
     push:
         tags:
         - "v*.*.*"
    
     permissions:
     contents: write
     
     jobs:
     build_latex:
         runs-on: ubuntu-latest
         steps:
         - name: Set up Git repository
             uses: actions/checkout@v4
         - name: Compile LaTeX document
             uses: xu-cheng/latex-action@v3
             with:
             root_file: test.tex
             latexmk_use_xelatex: true
         - name: release
             uses: softprops/action-gh-release@v2
             if: startsWith(github.ref, 'refs/tags/')
             with:
             files: |
                 test.pdf
    
  5. Python (Windows) Python-Win.sublime-build:

     {   
       "shell_cmd" : "python \"$file_name\"",
       "selector" : "source.py",
       "interactive": true,
       "path" : "C:\\path_to_python_binary_folder;$path",
       "working_dir" : "$file_path"
     }
    
  6. Typst (Windows) Typst-Win.sublime-build:

     {   
       "shell_cmd" : "typst compile \"$file_name\"",
       "selector" : "source.typ",
       "path" : "C:\\path_to_typst_binary_folder;$path",
       "working_dir" : "$file_path"
     }
    
  7. Typst-py Typst-py.sublime-build:

     {   
       "shell_cmd" : "python3 \\${HOME}/ctd.py -f \"$file_name\"",
       "selector" : "source.typ",
       "working_dir" : "$file_path"
     }
    

    This is if for reasons Typst cannot be installed on your system, but Python can be, then Typst can be used via the typst-py package. The above needs this script ctd.py to work:

     #!/usr/bin/env python3
     # -*- coding: utf-8 -*-
    
     """Compile Typst document
     ctd.py 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>"])
    
  8. Typst (GitHub Actions) .github/workflows/rel.yml:

     name: Build Typst document
     on: 
       push:
         tags:
           - "v*.*.*"
    
     permissions:
       contents: write
    
     jobs:
       build:
         runs-on: ubuntu-latest
         steps:
           - name: checkout
             uses: actions/checkout@v4
    
           - name: prep typst
             uses: typst-community/setup-typst@v3
           - run: typst compile m1.typ
    
           - name: release
             uses: softprops/action-gh-release@v2
             if: startsWith(github.ref, 'refs/tags/')
             with:
               files: |
                 m1.pdf
    
  9. Compile documents en-masse (2026):

    Taking a leaf from my work some years ago, and knowing Typst supports multi-core processing, I was able to write a simple fish script to take advantage of this and compile documents in a flash:

     #!/usr/bin/env fish
     for FILE in *-FABM-076.typ *-STRU-{154,158,199,214,217,581,597}.typ
         typst c $FILE &
     end
    

    The ampersand in line 3 does the heavy-lifting as it relegates each job to a background task, and is ready for the next file, enabling parallel execution. It’s likely that if thousands of documents are compiled like this, then it may crash, esp. if you’re on a humble set of computing resources, but if in tens, then it’s no sweat.