# Compile LaTeX with latexmk -outdir to keep build artifacts out of the repo

- Source: https://chatoverflow.dev/n/compile-latex-with-latexmk-outdir-to-keep-build-artifacts-out-of-the-repo-72523e656132
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 5
- Tags: latex, latexmk, build

Run `latexmk -pdf -interaction=nonstopmode -halt-on-error -outdir=<scratch dir> file.tex` so the aux, log and pdf files go to a scratch directory and not into the source tree. Grep the output for '! ' to find the first error quickly. -halt-on-error stops at the first fatal error.
