[Tex/LaTex] Question regarding pgfplots externalize

luatexpdftexpgfplotstikz-externaltikz-pgf

For the sake of speed and potential file size errors I have been trying to set up the externalization of pgfplots/tikz for my figures including/excluding luatex.

I have the following question which is unclear to me:

  • After externalization, should you call the figure from the pdf, or does tikz/pgf automatically determine if it should run the .tex file or if it should load the pdf?

It is giving me a few issues:

  • When externalizing using pdflatex, I get a memory exceedance error. Which is not produced with externalization switched of.
  • If externalization is performed all the way using lualatex, it still crashes when compiling with pdflatex afterwards.

I am not sure if this is a correct MWE:

Compile with either:

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

lualatex.exe -synctex=1 -shell-escape -interaction=nonstopmode %.tex

In the main document:

\documentclass{book}

\usepackage{pgf}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{external}
\tikzexternalize
\tikzsetexternalprefix{figures/}
\tikzset{external/force remake}

\begin{figure}[h!]
{\input{Figure1.tex}}
\end{figure}

\end{document}

A random tikz figure document (actually contains thousends of datapoints):

Figure1.tex:
\begin{tikzpicture}
\begin{axis}[%
\addplot [color=black, forget plot]
table[row_sep=crcr][%
0 0 \\
0.1 20\\
}
\end{axis}
\end{tikzpicture}%

Best Answer

I'm not sure if it get the problem. But you could try to compile with pdflatex:

pdflatex -shell-escape %


EDIT: Or with lualatex:

lualatex -shell-escape %

NOTE: For lualatex you nedd the package \usepackage{shellesc} (Ref. @UlrikeFischer)


Folder structure and result:

enter image description here

MWE:

main.tex:

\documentclass{book}
\usepackage{shellesc}% to compile with lualatex
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{external}

\tikzexternalize
\tikzsetexternalprefix{figures/}
\tikzset{external/force remake} %up-to-date checks of all following figures (see: 50.4.3 Remaking Figures or Skipping Figures in pgf manual)

%\pgfplotstableread[row sep=crcr]{
%0 0 \\
%5 20\\
%}\mytable

\begin{document}

\tikzsetnextfilename{SaveNameFigureOne}%image name
\input{Figure1.tex}

%\tikzsetnextfilename{TestImageTwo}%image name
%\input{Figure2.tex}

\end{document}

Figure1.tex

\begin{tikzpicture}
\begin{axis}
\addplot [color=black, forget plot]table[row sep=crcr]{0 0 \\
0.1 20\\};
\end{axis}
\end{tikzpicture}%
Related Question