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.

Usage. 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 for MacOS.

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

{
  "cmd": ["/Library/TeX/texbin/xelatex", "$file"],
  "selector": "text.tex.latex"
}

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"
}

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"
}

LaTeX (GitHub Actions): A workflow is a set of instructions to be carried out as actions in a container provided 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

Python (Windows): Python-Win.sublime-build:

{   
  "shell_cmd" : "python \"$file_name\"",
  "selector" : "source.py",
  "path" : "C:\\path_to_python_binary_folder;$path",
  "working_dir" : "$file_path"
}

Typst (Windows Cygwin): Typst-Cyg.sublime-build:

{   
  "shell_cmd" : "typst compile \"$file_name\"",
  "selector" : "source.typ",
  "path" : "C:\\Cygwin\\bin;$path",
  "working_dir" : "$file_path"
}

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>"])

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