5

For my thesis I have a lot of TikZ plots exported from Matlab using the matlab2tikz library.

I want to use the tikzscale package together with externalization of the plots to save compiling time. Using externalization is recommended in the tikzscale documentation but does not work as expected.

Plots included via \includegraphics to make use of the tikzscale are recompiled with every pdflatex run, even if the figure is not changed, this is not the expected behaviour and causes the compiling time to become even longer.

Plots included via \input, so not making use of the tikzscale, features are not recompiled, this is what I expect.

Am I doing something wrong during the export with matlab2tikz or with including the .tikz files with \includegraphics or is this a bug of the tikzscale package?

I need the additional scaling features of tikzscale, so I cannot simply avoid the tikzscale package.

Setup: WIN7+TexLive2014 / Ubuntu 14.04+TexLive2013, behaviour is the same on both systems

MWE:

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\usepackage{pgfplots}
\usepackage{tikzscale} 
\usepgfplotslibrary{external} 
\tikzexternalize[prefix=tikzTest/] 
\newlength\figureheight 
\newlength\figurewidth

\begin{document}
\begin{figure}
\tikzsetnextfilename{test}
\includegraphics[width=0.75\textwidth]{tikzTest/test.tikz}
\end{figure}

\begin{figure}
\setlength\figureheight{0.75\textwidth} 
\setlength\figurewidth{0.75\textwidth}
\tikzsetnextfilename{test2}
\input{tikzTest/test2.tikz}
\end{figure}
\end{document}

Matlab export

x = linspace(0,10,11);
y = x.^2;
figure(1);
plot(x,y);
cleanfigure;
%prepare figure to be included with tikzscale and \includegraphics
matlab2tikz('<pathToTexFolder>\tikzTest\Test.tikz','noSize',true,'extraTikzpictureOptions','trim axis left, trim axis right');
%prepare figure to be included with \input
matlab2tikz('<pathToTexFolder>\tikzTest\Test2.tikz','height','\figureheight','width','\figurewidth');

test.tikz

% This file was created by matlab2tikz.
% Minimal pgfplots version: 1.3
%
%The latest updates can be retrieved from
%  http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz
%where you can also make suggestions and rate matlab2tikz.
%
\begin{tikzpicture}[%
trim axis left, trim axis right
]

\begin{axis}[%
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
xmin=0,
xmax=10,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
ymin=0,
ymax=100
]
\addplot [color=black,solid,forget plot]
  table[row sep=crcr]{%
0   0\\
1   1\\
2   4\\
3   9\\
4   16\\
5   25\\
6   36\\
7   49\\
8   64\\
9   81\\
10  100\\
};
\end{axis}
\end{tikzpicture}%

test2.tikz

% This file was created by matlab2tikz.
% Minimal pgfplots version: 1.3
%
%The latest updates can be retrieved from
%  http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz
%where you can also make suggestions and rate matlab2tikz.
%
\begin{tikzpicture}

\begin{axis}[%
width=0.95092\figurewidth,
height=\figureheight,
at={(0\figurewidth,0\figureheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
xmin=0,
xmax=10,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
ymin=0,
ymax=100
]
\addplot [color=black,solid,forget plot]
table[row sep=crcr]{%
0   0\\
1   1\\
2   4\\
3   9\\
4   16\\
5   25\\
6   36\\
7   49\\
8   64\\
9   81\\
10  100\\
};
\end{axis}
\end{tikzpicture}%
| improve this question | | | | |
  • Plan B: external/export next=false – Symbol 1 Mar 4 '15 at 15:03
  • when using external/export next =false, will this only omit creating external pdfs while already exported pdfs (from a previous run) will still be included in the document or will the pdf not be used at all? – roteiro Mar 5 '15 at 9:06
  • Experiments shows that TikZ love compiling pictures... you can only turn it on but cannot stop it. In case export next=false, TikZ will leave the external PDFs there and recompile pictures again per compilation. Probability you need a complex macro to include those pictures and comment out the tikzpicture yourself. (Will this is plan B--) – Symbol 1 Mar 5 '15 at 15:38
  • @Symbol Thanks for your comment, this was what I was afraid of. Still I can't really believe that \tikzcale documentation encourages the user to use externalization because of faster compiling times but does not avoid recompiling tikz-pictures. Either I implemented it wrong or there is a bug in the \tikzscale package – roteiro Mar 5 '15 at 15:57
  • Problem still persists, opened a bug report at tikzscale github – roteiro Feb 9 '16 at 8:55
1

Edit: I just realized this question was asked 2 years ago...

Have you tried using LuaLaTeX with tikzexternalcheckshellescape? It worked for me before.

Try with the above preamble:

\documentclass[11pt]{article}
\usepackage{pgfplots}
\usepgfplotslibrary{external}
\tikzsetexternalprefix{figurescache/} %folder for temp figures
\tikzset{external/system call={lualatex \tikzexternalcheckshellescape -shell-escape -synctex=1 -halt-on-error -jobname "\image" "\texsource"}}
\begin{document}
[Tikz stuff in here]
\end{document}

And then to compile your document, type:

lualatex filename.tex

After this, a filename filename.makefile will be created and type

make -f filename.makefile

then another

lualatex filename.tex
| improve this answer | | | | |
  • This is rather a comment because you ask OP to do something or you can also do this and show the results to make a self contained answer. – percusse Apr 30 '17 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.