# Error with TextMate 2, PATH, --shell-escape and gnuplot in 10.8.2

I reopen this post, which was started some time ago but didn't came with a solution. I don't really remember what was the exact problem with this (well, of course, gnuplot didn't work correctly). So I write here my actual problem, which is the same as before.

## Problem

I reinstalled the operating system (Mac OS X 10.8.2), installed MacTeX (the last one), installed MacPorts and gnuplot through it (in an administrator account). In this account, the command port works correctly from terminal (which let mi install gnuplot), and also does gnuplot app (from terminal). Then created a new (non-admin) account, and then neither port nor gnuplot worked. After little hacking (here it is more info), I solved it. Now port and gnuplot work both from terminal in both accounts.

But here is the problem. I use TextMate to compile my documents, which compiles everything perfectly. But if I use some code which needs of gnuplot it isn't able to call it. See at the bottom for some examples.

On the contrary, if I call the file from the terminal with pdflatex --shell-escape file.tex then it compiles perfect.

## Question

What happens? Is it a PATH problem? How can I solve it? (I don't really understand what is a PATH, therefore I can't try/imagine by myself)

## Code and Logs

### Example 1:

\documentclass{scrartcl}
\usepackage{gnuplottex}
\begin{document}
\begin{gnuplot}
plot sin(x)
\end{gnuplot}
\end{document}


Part of the .log file

\openout3 = Ejercicio1-gnuplottex-fig1.gnuplot'.

Opening gnuplot stream Ejercicio1-gnuplottex-fig1.gnuplot
runsystem(gnuplot Ejercicio1-gnuplottex-fig1.gnuplot)...executed.

Package gnuplottex Warning: Conversion of Ejercicio1-gnuplottex-fig1.gnuplot fa
iled.

Package gnuplottex Warning: Please convert Ejercicio1-gnuplottex-fig1.gnuplot m
anually.


And from the terminal no error at all.

### Example 2:

\documentclass{scrartcl}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\end{axis}
\end{tikzpicture}
\end{document}


The .log problems from TextMate:

Latex Error: ./Ejercicio1.tex:6 Package pgfplots Error: Sorry, the gnuplot-result file 'Ejercicio1.pgf-plot.table' could not be found. Maybe you need to enable the shell-escape feature? For pdflatex, this is '>> pdflatex -shell-escape'. You can also invoke '>> gnuplot .gnuplot' manually on the respective gnuplot file..

! Package pgfplots Warning: You have an axis with empty range. Replacing it with a default range and clearing all plots.

And no errors from terminal with pdflatex --shell-escape file.tex.

-

## migrated from superuser.comDec 29 '12 at 3:16

This question came from our site for computer enthusiasts and power users.

It may be that an upgraded installation of TextMate caused the -shell-escape option to be turned off. Recheck this option under Preferences in your LaTeX bundle. See How and Why to use TextMate for LaTeX (starting from Setup). Since I don't have TextMate nor a Mac, I'm unable to test this myself. –  Werner Dec 28 '12 at 17:48
@Werner Well, thanks for the answer. That manual is for TM 1.5 (which I used before), but I don't know how to make it work in TM 2.0. And, of course, I'm not sure the problem is TextMate or gnuplot or whatever! Anyway, thank you for the answer. –  Manuel Dec 28 '12 at 22:57
So there's nothing in TM 2.0 under Preferences that you can change to include an option that is passed to pdflatex? –  Werner Dec 28 '12 at 23:05
@Werner Yes, in TM 1.5 and TM 2.0 is the same: Bundles › LaTeX › Preferences…. But it seems that it's unresponsive in TM 2.0 with Mac OS X 10.8.2 (I'm asking because I updated so many things and I don't know which is the reason). –  Manuel Dec 28 '12 at 23:07
Can you successfully execute pdflatex --shell-escape on the command line? –  Percival Ulysses Dec 29 '12 at 0:42

This might be an issue with TextMate's PATH, which is not (necessarily) the same as the PATH when you work from Terminal. You can check that TextMate is able to find gnuplot by opening a new file in TextMate, typing the line which gnuplot, and running that line with Ctrl-R. If TextMate gives you an error message, then it can't find gnuplot; if it prints a directory name then it can.

So assuming that TextMate can't find gnuplot, the easiest way to fix this is to go to TextMate's Preferences > Variables and edit the entry for PATH. You should change this so that the directory containing gnuplot is in the list, for example

/usr/texbin:$PATH:/opt/local/bin:/opt/local/sbin:/opt/bin  might work for you. (It's important that you keep $PATH in this list too, otherwise TextMate won't be able to use many important commands.) Make sure the check box next to PATH is checked. Now if you open a new file and type which gnuplot, Ctrl-R, it should give you something, and if you type which pdflatex, Ctrl-R, it should say /usr/texbin.

Finally, you need to make sure that TextMate runs pdflatex with the shell-escape option. TextMate allows you to pass options to the TeX compiler using comments at the beginning of your document. Try adding this

%!TEX TS-options = --shell-escape


as the first line of your file. Both of the examples you provided compile without any problems on my machine if I include this as the first line. (TextMate 2.0-alpha.9387)

-
This is crazy. Now it works pgfplots's commands which include calling gnuplot, but now gnuplottex's commands doesn't work at all (neither from terminal nor TextMate). By the way, could you explain me what do you mean by typing the line which gnuplot and running that line? If I write a document with only that line, TextMate tells me Latex Error: ./file.tex:1 LaTeX Error: Missing \begin{document}. ! Emergency stop. ! ==> Fatal error occurred, no output PDF file produced!. I will try again all possible cases and then comment. –  Manuel Mar 3 '13 at 18:51
@Manuel you want to use the "Execute Line" action in the Shell Script bundle, not the "Typeset & View" command from the LaTeX bundle. Ctrl-R, not Cmd-R. This is like telling TextMate to run a line in a terminal that TextMate launches for itself. –  DGrady Mar 3 '13 at 18:59
Done, of course it recognizes gnuplot: /opt/local/bin/gnuplot. And that folder is in my TextMate PATH. I have edited my question to explain what happens now. Read there. By the way, what does checking the PATH's checkbox do? –  Manuel Mar 3 '13 at 19:12
@Manuel, PATH is an environment variable that lists locations to look for programs. When you check the checkbox in TM, it tells TM to use a different setting for this variable than the default. gnuplot is installed in a directory that is not in the default list of directories, so TM (and any program that TM runs) can't find gnuplot unless you change the value of PATH yourself. The PATH that TM sees is not the same PATH` that you see when you run commands in Terminal. –  DGrady Mar 3 '13 at 19:28
I don't know, closed all, reopened all, and now it just works. The only thing I had to do was checking the PATH's checkbox. Thank you. –  Manuel Mar 3 '13 at 19:28