How to install the minimal basictex LaTeX on macOS and install related dependency packages (macros)

Why Use BasicTeX

On the macOS platform, there are BasicTeX, MacTeX-no-GUI, MacTeX, and LiveTeX.
All of these can be installed via brew install.

From left to right, the size increases.
BasicTeX is about a few hundred MB, MacTeX is 5 GB, and LiveTeX is 10 GB.

I only use LaTeX sporadically to convert markdown to PDF, so there’s no need to install the huge MacTeX package. Therefore, I chose

brew install basictex

How to Install LaTeX Packages After Installing BasicTeX

After installing BasicTeX, you will find that various .sty files are missing when running LaTeX.
For example:

Conversion failed: Pandoc died with exitcode "43" during conversion: Error producing PDF.
! LaTeX Error: File `footnotebackref.sty' not found.

Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: sty)

Enter file name: 
! Emergency stop.
<read *>
         
l.58 \setcounter

Another example:

Conversion failed: Pandoc died with exitcode "43" during conversion: Error producing PDF.
! LaTeX Error: File `xeCJK.sty' not found.

Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: sty)

Enter file name: 
! Emergency stop.
<read *>
         
l.74     \setCJKmainfont

If you don’t want to bother, just honestly install MacTeX. But if you want to face the challenge, keep reading.

Installing Relevant LaTeX Packages via TeX Live’s Package Manager tlmgr

At this point, you need to use TeX Live’s built-in package manager tlmgr (similar to apt, pip, etc.) to install the missing LaTeX packages.
For example:

# This command requires sudo privileges
sudo tlmgr update --self       # update tlmgr itself
sudo tlmgr install footnotebackref # install footnotebackref

What if tlmgr Can’t Find the Relevant Package?

Method 1: Manual Download

For example, if the xeCJK package can’t be found:

tlmgr install: package xeCJK not present in repository.

However, it is available on the official website (for some reason, tlmgr cannot find packages that even exist on the official site). Download it, unzip it, and place it in the relevant local directory:

/usr/local/texlive/basictex-2025/texmf-local/tex/latex/xecjk  # Note to find your own BasicTeX path and place it there; don’t just copy my path

Especially note that you need to create the texmf-local folder yourself.

In the TeX Live installation layout, there are usually several “texmf” trees (directory trees), such as:

After installation, remember to update the TeX filename database so that LaTeX can find the new files:

sudo mktexlsr
# The following might also work
# sudo texhash

Method 2: Download a Larger Package That Contains the Small Package

For example:

tlmgr install: package zref-abspage not present in repository.

Use tlmgr to install the entire zref package:

sudo tlmgr install zref

References