MacOS – How to access the LaTeX commands from the terminal

macosterminal

I just installed MacTeX onto Yosemite and it installed everything in usr/local/texlive

However if I am in Terminal and try to compile a LaTeX file with pdflatex foo.tex, it cannot find the LaTeX tools. Further whereis pdflatex returns no results.

If I specify the entire path of pdflatex (e.g., /usr/local/texlive/2014/.../bin/pdflatex) it all works well.

How can I get the LaTeX tools to work from the terminal without specifying the entire path?

Best Answer

For binaries to be accessible from the command line, their locations must be part of the PATH environment variable. If you do the following

PATH=$PATH:/usr/local/texlive/2014/.../bin

(filling in the correct path), you will be able to call pdflatex directly (as well as every other program in the same directory. To make the change permanent, export the command in a file sourced by the shell, such as .bash_login or .profile (assuming you use bash). Either use an editor or run

echo "export PATH=$PATH:/usr/local/texlive/2014/.../bin" >> ~/.bash_login

Which will append the output of the echo command to the file and create it if it does not exist.

The shell searches the directories in the PATH in the order they are listed, so usually it is a good idea to always append to the PATH unless you know exactly what is in the added directory. It might contain other executables with the same name as other programs which are already in the PATH. Having these shadowed can sometimes lead to surprises.