I was reading the pgfplots
manual today, and I came across the external
pgfplots library. It should help decrease the compilation time and avoid regenerating every pgfplots
graphics.
We (me and two other colleagues) are currently writing an article, in the Overleaf online editor, with a plot consisting of about 3000 data entries read from an external .csv
file. So the compilation time makes the workflow slow.
I would like to adopt this technique of "convert[ing] every tikzpicture
environment automatically to an external graphics."
How can I tell Overleaf's servers to compile the tex
file in the above described way?
I tried the following:
The main text is written in main.tex
:
% file main.tex
\documentclass{article}
%% Font encoding and input encoding %%
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{multicol} % To write in 2 columns
%% To include figures %%
\usepackage{standalone,import,pgfplots,pdfpages,graphicx,float}
\pgfplotsset{compat=1.7}
%% And here is the call to the external method
%% to reduce compilation time
\usepgfplotslibrary{external}
\tikzexternalize % Activated!
\begin{document}
Article text....
\begin{figure*}
\includestandalone[width=\textwidth]{./figures/plot1}
\caption{Caption for the figure.}
\label{fig:tikz:figure1}
\end{figure*}
Text text text.
\end{document}
The file plot1.tex
compiles with no error, and therefore I am not listing its contents. I did add the two commands (\usepgfplotslibrary{external}
and \tikzexternalize
) to its preamble. It is a standalone
document class.
Lastly, I created a latexmkrc
file that has the following instruction:
$latex = 'pdftex -shell-escape main.tex %O %S';
(I learned about it from here). It lines up (I think) with what is written in the pgfplots manual, subsection 3.2.6 (page 23), to provide a command line switch to pdflatex
.
And, the hierarchical file structure is the following:
root folder
├main.tex
└───figures
| │ plot1.tex
│ │ plot2.tex
│ │ plot3.tex
├latexmkrc
In case you don't know, Overleaf lets the user to select a compiler in the project's settings. I tried both its pdfLatex
and LaTeX
compilers to do this task, and both failed.
The error I get is
Package tikz Error: Sorry, the system call 'pdflatex -shell-escape -halt-on-error -interaction=batchmode -jobname "output-figure0" "\def\tikzexternalrealjob{output}\input{output}"' did NOT result in a usable output file 'output-figure0' (expected one of .pdf:.jpg:.jpeg:.png:). Please 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 'output-figure0.log'. If you continue now, I'll try to typeset the picture.
output-figure0.log
to determine what the error is.main-figure0.log
andmain.log
files.) The solution is to invoke the standalone package with the mode=buildnew option, i.e.,\usepackage[mode=buildnew]{standalone}
. This should accomplish what you want, by requiring standalone to do the compilation ofplot1.tex
, but only if the file has changed.