Learn from a particle physicist

Sep 23, 2022 learning LaTeX Mac

# most of the time, these are all you need:
brew install basictex
sudo tlmgr install latexmk
tlmgr init-usertree
tlmgr --usermode install collection-fontsrecommended
# now try to compile your project using latexmk:
cd /path/to/your/LaTeX/project
latexmk
# if some.sty is missing,
# use the following command to find out which package includes it
tlmgr search --global --file some.sty
# and then install it
tlmgr --usermode install missingPackage

MacTeX is large (~4 GB). BasicTeX is a much smaller option that provides basic functionality of LaTeX on macOS. A similar package TinyTeX works well for Windows and Linux. However, BasicTeX does not include latexmk and some common fonts. Fortunately, the tlmgr command is provided in BasicTeX. One can use tlmgr to find and install missing packages. Binary folder from BasicTeX is automatically added to $PATH. latexmk will be available in the user’s command line as soon as it is installed.

Except for latexmk, other packages can be installed into the user’s texmf folder, the location of which can be found using command kpsewhich -var-value TEXMFHOME. In a Mac, it defaults to ~/Library/texmf and can be initialized using tlmgr init-usertree. Option --usermode for tlmgr is used to interact with the user’s texmf folder instead of the system one.

Update

BasicTeX updates once per year. It wil be updated in a Mac automatically with brew upgrade. latexmk installed with the previous version will be missing. Run the following command to recover it.

sudo tlmgr install latexmk

One may also want to run the following command to update packages installed in the user’s texmf folder:

tlmgr --usermode update --all

To list all installed packages in one’s own texmf folder, run:

tlmgr --usermode list --only-installed

Useful Packages

tlmgr --usermode install enumitem pgf
  • enumitem: Control layout of itemize, enumerate, description
  • pgf: Create PostScript and PDF graphics in TeX

Packages Needed for Springer Nature Journals

Since December 2024, a new LaTeX package is recommended for Springer Nature Journals. Place sn_jnl.cls and sn_mathphys-num.bst together with your main.tex for European Physics Journal series. Install the following packages to compile.

tlmgr --usermode install algorithms algorithmicx appendix multirow ncctools rsfs sttools threeparttable

Integration with VS Code

brew install tex-fmt

Install LaTeX Workshop extension. Select tex-fmt as the formatter. The extension uses latexmk to automate the compilation.