# Externalising TikZ pictures using PdfLaTeX

Here there is my problem with the externalising for tiki package with PdfLaTeX. I am not so new to LaTex, nevertheless I have never used the externalisation for the figures. I use texstudio on a mac (OS X El Capitan). I am writing a very long document and I am trying to plot some experimental data using the tikz package. The data is contained into external sources because of the large amount of numbers. I try to plot more than one curve (scatter data) within the same graph because I want to compare all the curves (10 curves). If I plot at maximum 3 curves I have no problem, but when I compile with more than 3 curves I get errors because of the maximum capacity exceeded. Therefore I use the externalisation by means of the strings in the preamble:

\usepgfplotslibrary[external]

\tikzexternalize[prefix=TikzPictures/]


Nevertheless, compiling with this strings I get this error:

  !Package tikz Error: Sorry, the system call 'pdflatex -shell-escape -halt-on-error -interaction=batchmode -jobname "TikzPictures/filename-figure4""\def\tikzexternalrealjob{filename}\input{filename}"' did NOT result in a usable output file 'TikzPictures/filename-figure4' (expected one of .pdf:.jpg:.jpeg:.png:). Please verify that you have enabled system calls. For pdflatex, this is 'pdflatex-shell-escape'


I did add the "-shell-escape" string into the command line of PdfLaTeX, here the string: /Library/TeX/texbin/pdflatex -synctex=1 -interaction=nonstopmode -shell-escape %.tex

In the following there is part of my code:

\documentclass[11pt,twoside,greek]{report}
...
\usepackage{pgfplots}
...
\usepgfplotslibrary[external]
\tikzexternalize[prefix=TikzPictures/]
...
\begin{document}
...
\begin{tikzpicture}
\footnotesize
\centering
\begin{axis}[
xlabel = {$x$},
ylabel = {$y$},
grid = major,
legend entries={a,b,c,d,e,f,g,h,i},
]
\end{axis}
\end{tikzpicture}
...
\end{document}


I compile using PdfLaTeX. This is the log outcome:

! Package tikz Error: Sorry, the system call 'pdflatex -shell-escape -halt-on-e rror -interaction=batchmode -jobname "TikzPictures/filename-figure4" "\def\tikz externalrealjob{filename}\input{filename}"' did NOT result in a usable output f ile 'TikzPictures/filename-figure4' (expected one of .pdf:.jpg:.jpeg:.png:). Pl ease verify that you have enabled system calls. For pdflatex, this is 'pdflatex -shell-escape'. Sometimes it is also named 'write 18' or something like that. Or maybe the command simply failed? Error messages can be found in 'TikzPicture s/filename-figure4.log'. If you continue now, I'll try to typeset the picture.

UPDATE: it seems to be a problem with some specific 'txt' files. In my case I get the error when I use

\addplot[red] table{data_set/N12-C05-1.txt}


In the other cases, for example

\addplot[red] table{data_set/N12-C02-1.txt}


I have no error!!! Hence I tried to change the filename but the error persists. I tried to change the data within the file N12-C05-1.txt and N12-C05-2.txt but the error still persists. It sounds really weird!

• I no longer recall my exact problem but I spent a day trying to get externalize to work (in WinEdT). I spent a lot of that day here at tex.stackexchange. I finally gave up. I hope this question gets a clear answer. – Colin McLarty Oct 20 '16 at 18:15
• Welcome to TeX.SE! Please consider posting with a minimal working example (meta.tex.stackexchange.com/questions/3300/…); it will make it much easier for the community to assist you. – dgoodmaniii Oct 20 '16 at 18:15
• Have you tried starting with the prefix not being a subfolder, but just a name, say, prefix=test- to see if that works, it should then make the files in the same folder as the .tex (untested) – daleif Oct 21 '16 at 8:54
• I haven't try it but I don't think it is the problem because some previous images (not reported in the posted code) come up correctly (in fact the figure is the 4th: TikzPicture s/filename-figure4 ). The previous pictures can be seen in the specified folder (TikzPictures/). – Ceres Oct 21 '16 at 9:11
• "Error messages can be found in 'TikzPicture s/filename-figure4.log' " > Have you checked? – T. Verron Oct 21 '16 at 14:00

I write the solution that works in my case. I strongly recommend the use of .csv files rather than .txt file. Furthermore I recommend the use of the string that indicates the separator used in the cvs file. I post my solution that works:

\usepackage{pgfplots}
\usepgfplotslibrary[external]
\usetikzlibrary{external}
\tikzexternalize[prefix=foldername/]
...
\begin{tikzpicture}
\pgfplotsset{compat=1.14}
\centering
\begin{axis}[...]