“minted” is good choice for code highlighting in LaTeX.
If you write your LaTeX in Overleaf, just refer to Overleaf: Code Highlighting with minted
If you want to use minted locally, you can continue reading.
Use TeX Live package manager to install minted, then use pip to install pygments that minted requires.
sudo tlmgr install minted
pip install pygments
Package minted: You must invoke LaTeX with the -shell-escape flag.
minted needs -shell-escape
flag to be enabled, add “-shell-escape” in args of the tool you use in the “latex-workshop.latex.tools” in “settings.json”
or simply add that flag in terminal if you directly use command line to build LaTeX project
brew upgrade mactex
to upgrade it. Or you can refer to the official instruction (https://tug.org/texlive/upgrade.html).sudo tlmgr update --self