Getting started with LaTeX

Objective

Install LaTex with minimal fuss.

What not to do

Like many others, your first instinct when installing LaTeX may be to

brew search tex

…and you may see the following:

If you meant "tex" specifically:
Installing TeX from source is weird and gross, requires a lot of patches,
and only builds 32-bit (and thus can't use Homebrew dependencies)

We recommend using a MacTeX distribution: https://www.tug.org/mactex/

You can install it with Homebrew-Cask:
  brew cask install mactex

If you are okay with downloading approximately 3.0G (as of 24 May 2017), go ahead and follow homebrew’s instructions:

brew cask install mactex

Please be aware this will install a lot of cruft on your system…

MacTeX consists of two pieces: MacTeX-2017 and MacTeXtras. MacTeX-2017 is
an install package which installs everything needed to run TeX on Mac OS X.
The package uses Apple's standard installer; installation takes four to
eight minutes and is automatic. MacTeXtras is a collection of optional
extras: Additional Front Ends, Spell Checkers, Documentation, and Showcase
items.

What you should do

Instead of downloading mactex, which is approximately 3.0G, you can download basictex instead: at a reasonable 72M (as of 07 June 2017):

brew cask install basictex

You won’t be able compile your .tex files into .pdf until you are able to reach your binaries. Unfortunately, homebrew does not install tex binaries in /usr/local/bin. Instead, on macOS, you will need to update your path:

export PATH="/Library/TeX/texbin:$PATH"

Awesome! Now you call tex, latex, pdftex, pdflatex, etc.

latexindent

I like tools that help you maintain a consistent coding style. Unfortunately, basictex does not come with latexindent installed (the full mactex does include this). Here’s my solution.

Use the standard perl package manager to install a more streamlined perl package manager (yes, you read that right…):

sudo cpan App::cpanminus

You might need to add cpanm to the $PATH:

export PATH="${HOME}/perl5/bin:$PATH"

Install missing perl packages necessary for latexindent to work:

sudo cpanm YAML::Tiny
sudo cpanm Unicode::GCString
sudo perl -MCPAN -e 'install "File::HomeDir"'

Update tlmgr, the native TeX Live Manager:

tlmgr update --self

Finally, install latexindent:

sudo tlmgr install latexindent

Normally, I avoid using sudo when installing software because it’s easy to end up overwriting shipped installations or adding noise to system dirs. In this case, we are using homebrew’s perl, and everything will be sudo‘ed in homebrew dirs anyway–no harm, no foul.

Congrats! You can now indent your code using:

latexindent -w FILE

The -w flag will overwrite the file and create a backup.