2

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}%
5
  • 1
  • Thank you, I am not completely sure if the MWE I have included is sufficient. Please let me know!
    – J Daamen
    Oct 30, 2017 at 12:26
  • What should \tikzset{external/force remake} do? Do you only want to save your tikz image in the folder figures/? Is pdflatex okay?
    – Bobyandbob
    Oct 30, 2017 at 14:07
  • \tikzset{external/force remake} should force pgf to re-externalize all figures. With or without this option, pdflatex gives the memory issue. Without any externalization is does not. Luatex works for all three. Though, it screws up many other functionalities in my file. Yes I want to save the images in <dir>/figures/.... How can I check if pdflatex is ok?
    – J Daamen
    Oct 30, 2017 at 14:13
  • Your MWE does not compile(please check). Nevertheless a add an answer, i hope it works for you. If not please let me know.
    – Bobyandbob
    Oct 30, 2017 at 14:26

1 Answer 1

1

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}%
5
  • Ok this helped clear up a few things. The main problem is that I had a file which was apperently just a bit to large for pdflatex (few kbs). Though, it only gave errors when externalizing. Not when compiling in the normal slow mode. I wanted to fix this by externalizing with luatex. And afterwards run pdflatex so that it would not have to generate that file. Though, after looking at the logs this does not work. So I guess I will either have to make a switch to lualatex. Use the pdf for the spcific file instead. Or downsample further. Thanks for the help.
    – J Daamen
    Oct 30, 2017 at 14:37
  • @JDaamen Okay sorry. So only the size is the problem? You could generate the tikz images with one main file (first) and then load the pdf images of them in the other main file.... Is this an option? Or could you specify your problem with an MWE?
    – Bobyandbob
    Oct 30, 2017 at 14:43
  • 1
    Yes I think this is the most pragmatic solution at this moment. Sorry for the vague questioning. I am not so fluent with latex yet. But you helped me a lot in understanding and solved my problem. Thank you!
    – J Daamen
    Oct 30, 2017 at 14:49
  • @JDaamen. I updated my answer. If you add \usepackage{shellesc}. You could compile with lualatex -shell-escape % instead of pdflatex -shell-escape %. Maybe it is helpful for you ...
    – Bobyandbob
    Oct 30, 2017 at 15:55
  • @JDaamen does the solution with lualatex (see update) works for you? or do you have still trouble with lua?
    – Bobyandbob
    Nov 20, 2017 at 22:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .