Building a Latex Environment With Basictex on Macos
LaTeX is a popular typesetting system, especially useful in academia. For macOS users, BasicTeX offers a lightweight alternative to the full MacTeX distribution.
What is BasicTeX?
BasicTeX is a minimal version of MacTeX. It’s only 80 MB compared to several GBs of MacTeX, including just the core TeX command-line tools.
Install BasicTeX
Use Homebrew to install BasicTeX:
brew install --cask basictex
Install local::lib
The local::lib
is a Perl module that creates a locally installed perl module library.
cpan install local::lib
Add Perl to PATH
In order to use the local::lib
module, you need to add Perl to your PATH. You can do this by adding the following lines to your shell profile (~/.zshrc
):
echo 'eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)"' >> ~/.zshrc
source ~/.zshrc
After this, you should be able to use your locally installed Perl modules.
Update All Built-In TeX Packages
Keeping your TeX packages up to date is crucial for maintaining compatibility and receiving the latest features and bug fixes. You can update all built-in TeX packages using the TeX Live Manager (tlmgr):
sudo tlmgr update --self --all
Additional Tools for LaTeX
Install Latexpand
Latexpand is a useful tool for LaTeX users. It helps in flattening a LaTeX document by expanding \input
and \include
commands, which is useful for submission to journals that require a single .tex
file.
To install Latexpand via tlmgr:
sudo tlmgr install latexpan
Install Latexdiff
Latexdiff is a program that compares two LaTeX files and marks up significant differences between them (similar to the diff
utility but specialized for LaTeX). It is a useful tool for version control and for reviewing changes in LaTeX documents.
To install Latexdiff using Homebrew:
brew install latexdiff
Example Usage
The following example demonstrates how to use Latexpand and Latexdiff to compare two versions of a LaTeX document:
- First, use Latexpand to flatten each version of the document:
latexpand --expand-bbl draft.bbl draft.tex -o draft-bbl.tex
latexpand --expand-bbl revision.bbl revision.tex -o revision-bbl.tex
- Then, use Latexdiff to generate a diff file highlighting the changes:
latexdiff draft-bbl.tex revision-bbl.tex > diff.tex
This diff.tex
file will visually show the differences between the two versions, which can be compiled to PDF for an easier review process.