[Tex/LaTex] Command line pdflatex vs TeXShop

compilingmacpdftextexshop

In short my document is compiling without a problem with TeXShop and not at all with command line pdflatex. What is strange is that pdflatex does not recognize some basic packages, that are installed, for sure (ex: url.sty).

I need to use the command line option because I am calling it from another script.

What do I need to update? Is it a question of setting paths?

I am on a OSX 10.6.8, running MacTeX2013. The same set up runs without a problem with command line pdflatex on Ubuntu 12.04 LTS.

Best Answer

By inspecting the output of which pdflatex, it seems you are using a TeX distribution provided by MacPorts. Personally, I think the use of a TeX distro via MacPorts should be discouraged; MacTeX is IMHO the best way of getting an updated and stable TeX distro on a Mac, and not to mention the handy TeX manager in the System Settings.

If you remove the TeX distro from MacPorts, the path inspection will return only one ocurrence of the TeX tools you need, i.e, the one living inside /usr/texbin, which is the one TeXShop is using. In any case, if you want to stick with those two distros, let's see how to handle them.

Setting MacPorts TeX distro in TeXShop

TeX tools from MacPorts live inside /opt/local/bin. If we want to use them in TeXShop, we need to add the full path. In TeXShop, from the menu, go to TeXShop, and Preferences. Select the Engine tab. The following screen will pop up:

Quack

Setting the TeX tools via command line

If you want to set up your terminal to use a certain TeX distro, we need to inspect the path first. Issue

echo $PATH

and see the output. If, say, /usr/texbin comes first than /opt/local/bin, because of path search priority, the TeX tools will be from MacTeX instead of MacPorts. If by any chance you want to reverse the order, we need to edit the path. I'd recommend setting either .bashrc or .bash_profile. I usually prefer the latter.

Go to the terminal and type:

touch ~/.bash_profile
open ~/.bash_profile

The first command will create the .bash_profile if it doesn't exist, while the second will open it in your default editor. Now, add the following line to your file

export PATH=/opt/local/bin:${PATH}

if you want the TeX distro from MacPorts to appear first, or

export PATH=/usr/texbin:${PATH}

to have MacTeX inspected first. Then save the file. You can apply modifications to your current session by issuing

source ~/.bash_profile

Additional info

As egreg and Alan mentioned in the commands, it's way better to rely on the official MacTeX distribution instead of relying on the MacPorts one. Besides, relying on /opt/local/bin as the first search path might interfere with other system tools because of path priority. MacTeX is always the best solution.

Hope it helps. :)