This guide shows how I write LaTeX on macOS: I edit in Zed and view the PDF in Skim. Every save formats and builds the document and jumps to the current line in the PDF.

Install the tools

brew install --cask mactex-no-gui skim zed

In Zed, install the LaTeX extension (zed: extensions). It brings the language server texlab, which builds the document.

Enable forward search in Zed

Forward search jumps from the source to the PDF. Configure it in ~/.config/zed/settings.json:

"lsp": {
  "texlab": {
    "settings": {
      "texlab": {
        "build": {
          "onSave": true,
          "forwardSearchAfter": true
        },
        "forwardSearch": {
          "executable": "/Applications/Skim.app/Contents/SharedSupport/displayline",
          "args": ["-r", "-g", "%l", "%p", "%f"]
        }
      }
    }
  }
}

Enable backward search in Skim

Backward search jumps from the PDF to the source. In Skim, open Settings → Sync and set PDF-TeX Sync support to the preset Custom, with command zed and arguments "%file":%line.

Now ⇧⌘-click in the PDF opens the line in Zed.

Format with latexindent

latexindent comes with MacTeX. Zed runs it through texlab on save. Add this to ~/.config/zed/settings.json:

"languages": {
  "LaTeX": {
    "tab_size": 2,
    "formatter": "language_server"
  }
},
"lsp": {
  "texlab": {
    "settings": {
      "texlab": {
        "latexFormatter": "latexindent",
        "latexindent": {
          "local": "/Users/mf/.config/latexindent/latexindent.yaml"
        }
      }
    }
  }
}

My latexindent.yaml indents with 2 spaces instead of a tab:

defaultIndent: "  "
indentRules:
  item: "  " # continuation lines of \item

Use XeLaTeX with a latexmkrc

The default engine is pdflatex. For XeLaTeX, for example to load system fonts with fontspec, create a latexmkrc next to the main file:

# 1 means pdflatex, 4 lualatex, 5 xelatex
$pdf_mode = 5;

Zed picks this up on the next save. In the terminal, build without -pdf, because it would override the latexmkrc:

latexmk -synctex=1 main.tex

Sources