LaTeX syntax highlight with Minted

LaTeX code highlighting is possible using the minted LaTeX package, which uses Pygments as a backend. Minted is available in Overleaf as well.

If needed, install minted via TeX Live Manager (tlmgr)

tlmgr install minted

Install Python Pygments:

python -m pip install pygments
# or
brew install pygments

If using a GUI, the --shell-escape option may need to be added. In TeXmaker / TeXstudio, under “Options → Configure → Commands” add --shell-escape right after the compiler executable like xelatex --shell-escape or pdflatex --shell-escape or latexmk --shell-escape.

If “pygmentize” isn’t found, under TeXstudio Preferences → Build, check Show Advanced Options in the lower left checkbox and set Additional Search Paths → Commmands ($PATH) to the directory containing “pygmentize”, e.g. /opt/homebrew/bin on macOS with Homebrew or whatever directory comes up for which pygmentize in a Terminal.