# Type-setting from within ST

For all the years I’ve been using Sublime Text to write my reports in LaTeX, creating a build system had escaped my list of to-dos. Build systems are handy: they enable building (compiling, type-setting) from within Sublime Text. Here are a couple of steps for MacOS:

1. Select Tools > Build System > New Build System… and replace the entire pre-populated JSON instruction with the following:

{
"cmd": ["/Library/TeX/texbin/xelatex", "$file"], "selector": "text.tex.latex" }  To explain the above, I use xelatex as my type-setting system. Finding the path of xelatex is as easy as running a query at command line like so: $ which xelatex

2. Save it as LaTeX.sublime-build. (It will be saved under the folder ~/Library/Application Support/Sublime Text 3/Packages/User/.)

3. This above allows one to type-set (or build) by pressing + B.

A minor wrinkle with the build system is that unlike running xelatex from Terminal, building from within Sublime Text does not recognise artefacts (like class and style files) placed within ~/texmf folder, and so common resources require a full path. Following is an example. Note, e.g., ckunte.sty (style) file has been given a full path like so:

\usepackage{/Users/ckunte/texmf/ckunte}


Same goes for any resource within ~/texmf/ckunte.sty. For instance, I use a custom pythonhighlight.sty within ~/texmf/ckunte.sty. That needs to have a full path as well:

\usepackage{/Users/ckunte/texmf/pythonhighlight}


I am still figuring out how to replicate this on a hybrid system on my work machine with Sublime Text as native app in Windows 10, while xelatex is only accessible via Cygwin. Worst case scenario, I will have to stick to my old ways, which is to write in Sublime Text, and type-set via command line.

## Via WSL

As shared elsewhere, building using Ctrl+B is possible via Windows Subsystem for Linux (WSL) v2. My LaTeX.sublime-build looks like so in Windows 10:

{
"cmd" : ["bash", "-c", "/usr/local/texlive/2022/bin/x86_64-linux/xelatex ${file_name}"], "shell" : true, "working_dir" : "${file_path}",
"selector" : "text.tex.latex"
}


For a successful compilation, any user style called must have the full path to custom styles, e.g. \usepackage{/home/ckunte/texmf/ckunte}.