# Using “latex” to externalize tikz graphics wont work

I am lost in tex! I try to run a tay example, which you can find here: EXAMPLE If I run it, using

pdflatex -src -interaction=nonstopmode -shell-escape faster-latex-part2.tex


everything works fine, but if I use

latex -src -interaction=nonstopmode -shell-escape faster-latex-part2.tex


the following error occures:

===== 'mode=convert with system call': Invoking 'pdflatex -shell-escape -halt-o
n-error -interaction=batchmode -jobname "tikz/mysphere" "\def\tikzexternalrealj
ob{faster-latex-part2}\input{faster-latex-part2}"' ========
This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012/Debian)
\write18 enabled.
entering extended mode

! Package tikz Error: Sorry, the system call 'pdflatex -shell-escape -halt-on-e
rror -interaction=batchmode -jobname "tikz/mysphere" "\def\tikzexternalrealjob{
faster-latex-part2}\input{faster-latex-part2}" ................etc pp


Do you have any idea what my fault is? I need to run it with "latex", because my original problem is a huge matlab2tikz-graphic in my thesis.

PS.: My system is a stock Kubuntu 12.11.

-
Welcome to TeX.SX! Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. –  Henri Menke Jun 16 '13 at 10:52
As you can read in, there is a given example (you can follow the link behind link). There you can find a whole project, where I applied the commands written in my post. –  Tik0 Jun 17 '13 at 9:06
Sounds like a XY problem to me. Maybe you would be better off explaining what your problem with the “matlab2tikz-graphic” in your thesis is. –  mSSM Jun 18 '13 at 7:37

# Remarks

You weren't able to compile the version downloaded from the website using latex, because you can't embed pdf figures in a document compiled with pure latex. Here you need to fall back to pdflatex.

If you look it up in the pgfplots manual, there is a way to compile your externalized figures using latex and create a ps or eps file, which can then be embedded. Section 7.1.1 covers your problem.

# Implementation

I don't want to paste mysphere.tikz here, because it is a very longish file, only containing coordinates. Here is the original link, which is also given in the question: http://www.howtotex.com/tips-tricks/faster-latex-part-ii-external-tikz-library/

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{external}
\tikzexternalize[prefix=tikz/]
%%%% From section 7.1.1 of the pgfplots manual
\tikzset{external/system call={latex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource" && dvips -o "\image".ps "\image".dvi && ps2eps "\image".ps}}
%%%%
\begin{document}
\begin{figure}
\centering
\newlength\figureheight         % define length \figureheight
\newlength\figurewidth          % define length \figurewidth
\setlength\figureheight{6cm}    % set \figureheight
\setlength\figurewidth{6cm}     % set \figurewidth
\tikzsetnextfilename{mysphere}  % name next TikZ figure
\input{mysphere.tikz}           % input TiKZ figure code
\caption{A plot of a sphere}    % caption
\label{fig:sphere}              % label
\end{figure}
\end{document}


To compile everything, including building ps and pdf output, run latexmk with the following command line

latexmk -pdfps -e '\$latex=q/latex --shell-escape %O %S/' faster-latex-part2


# Output

-
That solved my problem! Big Thanks! –  Tik0 Jun 22 '13 at 19:15