LaTeX on Mac OS X

LaTeX is a very powerful language for writing documents. Unfortunately, making sure you can work with LaTeX and exploit its full potential can be quite cumbersome. To my best knowledge, a guide for quickly preparing your system for the use of LaTeX and some of its important extensions is currently not available. This quick guide to LaTeX on a Mac is targeted at first time users and is meant as an aid to minimize the amount of effort it takes to prepare your system, and to maximize the time you can use to (learn to) write beautiful documents and conduct reproducible research.

Update: ShareLaTeX has evolved into a very accessible yet powerful online editor. It’s free (up to a certain extent), and enables you to work from anywhere, explore your document history, collaborate with ease, sync to Dropbox/GitHub, and use tons of templates. It even allows you to knit some R into your documents. Worth a try!

Update 2: Overleaf offers a service similar to that of ShareLaTeX.


1. How to install and use LaTeX

1.1 Set up

Download and install the latest MacTeX distribution. This distribution contains everything you need to start typesetting beautiful documents. To check whether LaTeX was installed correctly, open the Terminal (Applications > Utilities > Terminal) and run:


This should return the message This is pdfTeX.

We might also update the packages used by LaTeX and update the TeX Live package manager itself:

sudo tlmgr update –self
sudo tlmgr update –all

The sudo command is used to run the update as an administrator, which is necessary because MacTeX installs as root, and the tlmgr command calls the package manager. You might be asked to provide the administrator password of your Mac. Notice that nothing is shown while typing it, but it is registered nonetheless.

Now download and install R and RStudio. RStudio is a graphical user interface for R, but also supports LaTeX and Sweave. Although it is not necessary to use RStudio (MacTeX includes its own editor, TeXShop), we will do so as it comes with many great features, such as syntax highlighting (watch the screencast on RStudio’s website). Please note however that TeXShop is more stable and is sometimes preferred to compile a document.

1.2 Learn to use

Read the excellent but not so short introduction to LaTeX, and print the cheat sheet. Open RStudio or TeXShop and start fooling around with everything you’ve just learned. In RStudio choose File > New > TeX Document, and once you have completed a document compile it by hitting the Compile PDF button (Shift-Cmd-I). In TeXShop hit Typeset to compile a document (Cmd-T).

A lot of reference material is available, such as the great Wikibook or a more specialized tutorial on how to construct graphical models in LaTeX.

1.3 Templates and examples

Explore LaTeX’s possibilities by trying some examples. Just open the .tex files with RStudio or TeXShop, edit them if you want, and compile them to watch the result. Remember to compile it a few times if your document is not rendered correctly the first time.

2. How to write an APA style (6) paper in LaTeX

2.1 Set up

To install the apa6 package open the Terminal (Applications > Utilities > Terminal) and run:

sudo tlmgr install apa6

If you run into an error you may need to update the package manager (see 1.1). Make sure the package is successfully installed:

tlmgr show apa6

Installing other packages works the same way, just replace apa6 by the name of the other package.

In order to manage your bibliography and refer to articles properly, you need to prepare your system for biblatex and biber. These are relatively new packages, but are supposed to become the new standard for reference management in LaTeX.

Follow the instructions in the most preferred answer to the question in this link (the one that asks you to make a file called Moving the file to the proposed directory can be done by opening the Terminal (Applications > Utilities > Terminal) and running:

open /usr/texbin

Copy the script to this folder. Go back to the Terminal again and run:

sudo chmod +x /usr/texbin/

Now complete the instructions in the above link.

Download and install JabRef. With JabRef you will be able to manage all your references. To activate BibLaTeX mode go to Options > Preferences > Advanced and tick BibLaTeX mode.

Make sure you can easily import references through Google Scholar. Open Google Scholar, go to Settings in the top right of the website, set the Bibliography Manager to Show links to import citations into BibTeX, and hit Save. Now search for an article, hit Import into BibTeX, save the text, and follow the instructions in this video. Once you have stored some articles in JabRef, save the .bib file in the folder where you keep the .tex file you want to use the references in.

Finally make sure to add the line below in the first twenty lines of your TeX document:

% !BIB TS-program = biber

Do not forget to select BibTeX and hit Typeset (Shift+CMD+B), before selecting LaTeX and hitting Typeset (Shift+CMD+L), to create your APA style 6 document in TeXShop.

You can also use RStudio, but remember to run biber in TeXShop (Shift+CMD+B) every time you add new references to your document. Fix warnings if there are any, before compiling your document in RStudio.

2.2 Learn to use

Read the documentation for JabRef and the apa6 package manual. Keep the BibLaTeX manual for reference.

2.3 Templates and examples

Get instant satisfaction by compiling an excellent short example or long example. Do not forget to download the bibliography and figures to the same folder.

3. How to handle R output in LaTeX

NB: you might want to check out knitr before starting to use Sweave.

3.1 Set up

Download the shell script. Now open the Terminal (Applications > Utilities > Terminal) and run:

open /usr/local/bin

Copy the script to this folder. Go back to the Terminal again and run:

sudo chmod +x /usr/local/bin/

When using TeXShop as your editor, you need to specify the location of the script. Go to TeXShop > Preferences…, click the Misc tab, and type in the Personal Script > LaTeX Program field:

/usr/local/bin/ -ld

3.2 Learn to use

Make sure to read the excellent Learning to Sweave in APA Style. The official manual could come in handy as well, and you might want to read The Joy of Sweave.

3.3 Templates and examples

Open an example in RStudio, edit it if you want, and compile it. Make sure to install the R package xtable, which is required for running the particular R code in this example.

Another example (remove the line library(ctest) before compiling). Yet another example.

4. How to make a presentation in LaTeX

4.1 Set up

Make sure the packages beamer, pgf, and xcolor are installed:

tlmgr show beamer
tlmgr show pgf
tlmgr show xcolor

If not, install them:

sudo tlmgr install beamer
sudo tlmgr install pgf
sudo tlmgr install xcolor

4.2 Learn to use

The beamer user guide is a must read and excellent reference. Soon more.

Scientific posters can be made using the beamerposter package.

4.3 Templates and examples

Examples abound: conference talk, here, here, and here. Soon more.

And templates for your own use: conference talk, short talk, generic talk.

5. How to collaborate on LaTeX documents

Use ShareLaTeX, Overleaf, or Weavr to share your documents, collaborate on them, or just have easy access anywhere. You can even TeXify your email by using GmailTeX.