[Tex/LaTex] tikz externalization using lualatex over pdflatex

luatexpdftextikz-externaltikz-pgf

I am trying to externalize tikz plots using lualatex while encapsulating the whole tex file with pdflatex. I still couldn't figure out why this method is not working.
I am using miktex and texstudio. calling pdflatex by:

pdflatex -shell-escape -synctex=1 -interaction=nonstopmode %.tex

where texstudio replaces % with filename to be processed.

I have a matlab plot given below, that is converted to tikz. Let's call it myfile.tikz:

\begin{tikzpicture}
\begin{axis}[%
width=\figurewidth,
height=\figureheight,
scale only axis,
xmin=1,
xmax=3,
ymin=1,
ymax=6,
name=plot
]
\addplot [
color=blue,
solid
]
table[row sep=crcr]{
1 2\\
2 4\\
3 6\\
};

\end{axis}
\end{tikzpicture}%

A minimal example using tikz would be:

\documentclass{article}
\usepackage{pgfplots} % to use tikz graphics as given in http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz
  \pgfplotsset{compat=newest}
  \pgfplotsset{plot coordinates/math parser=false}
  \newlength\figureheight
  \newlength\figurewidth
\usetikzlibrary{external}
\tikzexternalize[prefix=tikz/,shell escape=-enable-write18]
\tikzset{external/system call={lualatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"}}

\begin{document}
\begin{figure}
    \centering
    \setlength\figureheight{4.00cm} 
    \setlength\figurewidth{6.00cm} 
    \input{myfile.tikz}
\end{figure}
\end{document}

I am getting the following error:

! Package tikz Error: Sorry, the system call 'lualatex -enable-write18 -halt-on
-error -interaction=batchmode -jobname "tikz/example-figure0" "\def\tikzexterna
lrealjob{example}\input{example}"' did NOT result in a usable output file 'tikz
/example-figure0' (expected one of .pdf:.jpg:.jpeg:.png:). Please verify that y
ou have enabled system calls. For pdflatex, this is 'pdflatex -shell-escape'. S
ometimes it is also named 'write 18' or something like that. Or maybe the comma
nd simply failed? Error messages can be found in 'tikz/example-figure0.log'. If
 you continue now, I'll try to typeset the picture.

Best Answer

This works for me

\tikzset{external/system call={lualatex
\tikzexternalcheckshellescape -halt-on-error -interaction=batchmode
-jobname "\image" "\texsource"}}

The only other thing I am doing is to have write18 enabled in my pdflatex call so pdflatex can call lualatex. Works fine also with large data, but it is painfully slow.

Also if there is an error in the plot you have to check the individual log file. My editor (TexnicCenter) is not smart enough to jump to that log file so I have to go to the folder where the plot is located, open the log and check what went wrong....