5

I am using TexStudio on Mac with texlive 2016. For my tikz figures I use ktikz and matlab2tikz. Some matlab plots have quite a few data points, therefore I decided to use standalones for all my tikz figures and wanted to use externalize (which is not working).

To keep my main folder clean I use a build folder and set the following pdflatex command (Preferences -> Commands):

/Library/TeX/texbin/pdflatex -shell-escape -synctex=1 -interaction=nonstopmode -output-directory=./build %.tex

Also the BibTex command had to be adjusted:

/Library/TeX/texbin/bibtex build/%.aux

Then I had to use additional search paths (Preferences -> Build -> Show Advances Options -> Log File and Pdf File):

Log File: ./build
Pdf File: ./build
Commands ($PATH): /usr/local/texlive/2016/bin/x86_64-darwin

Every time I use \usetikzlibrary{external} and \tikzexternalize I get the following error although I have -shell-escape option added to the pdflatex command.

Package tikz Error: Sorry, the system call 'pdflatex -shell-escape -halt-on-e
rror -interaction=batchmode -jobname "./tikz_figures/main-figure0" "\def\tikzex
ternalrealjob{main}\input{main}"' did NOT result in a usable output file './tik
z_figures/main-figure0' (expected one of .pdf:.jpg:.jpeg:.png:). Please verify 
that you have enabled system calls. For pdflatex, this is 'pdflatex -shell-esca
pe'. Sometimes it is also named 'write 18' or something like that. Or maybe the
 command simply failed? Error messages can be found in './tikz_figures/main-fig
ure0.log'. If you continue now, I'll try to typeset the picture.

Is there something worng with my path setup or the prefix option to \tikzexternalize?

Commenting the two lines \usetikzlibrary{external} and \tikzexternalize it works.



Edit

MWE

main.tex (folder: ./)

\documentclass{report}

% graphics
\usepackage{graphicx, color}
\graphicspath{
    {./figures/tikz/}{./figures/non_tikz/}
}
\usepackage{tikz}
\usetikzlibrary{external}
%\tikzexternalize[shell escape=-enable-write1 -shell-escape, prefix=./build/]
\tikzexternalize[prefix=./build/tikz_figures/]
%\tikzexternalize
\usepackage{standalone}
%\input{./figures/tikz/tikz_definitions}


\begin{document}

\begin{figure}
\centering
\includestandalone[width=\textwidth]{example}
\caption{example caption.}
\label{fig:example}
\end{figure}

\end{document}

example.tikz (folder: ./figures/tikz/)

\begin{tikzpicture}

% draw help lines
\draw[help lines] (0,0) grid (1\textwidth,5);

\end{tikzpicture}

example.tex (folder: ./figures/tikz/)

\documentclass{standalone}

\input{tikz_definitions}

\begin{document}
\input{example.tikz}
\end{document}

No matter which prefix or options I use for \tikzexternalize I get the same error message.


Additional information:

Here is the folder structuer that I use:

main folder
    main.tex (main tex file)
    references.bib
    build (folder)
        epstopdf (folder)
        tikz_figures (folder
        *.aux, *.log, *.pdf, *.toc, (output files)
    chapters (folder)
        *.tex (tex files)
    figures (folder)
        non_tikz (folder)
            *.png, *.jpg, (all non tikz figures)
        tikz (folder)
            blocks (folder containing figures for tikz figures)
            *.tex (multiple standalone tex files)
            *.tikz (multiple tikz files editable with ktiz)
            tikz_definitions.tex (one tikz definition file)

----------

even more information

non MWE

The preamble of my main.tex file looks like this:

\documentclass[a4paper,twoside, openright,12pt]{report}

\graphicspath{
    {./figures/tikz/}{./figures/non_tikz/}
}
\usepackage{graphicx, color}
\usepackage{tikz}
\usetikzlibrary{external}
%\tikzexternalize[shell escape=-enable-write1 -shell-escape, prefix=./build/]
\tikzexternalize[prefix=./tikz_figures/]
%\tikzexternalize
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
%% the following commands are needed for some matlab2tikz features
\usetikzlibrary{plotmarks}
\usetikzlibrary{arrows.meta}
\usepgfplotslibrary{patchplots}
\usepackage{grffile}
\usepackage{amsmath}

\usetikzlibrary{arrows.meta}
\usepackage{standalone}
\input{./figures/tikz/tikz_definitions}


\begin{document}

\begin{figure}[H]
\centering
\includestandalone[width=\textwidth]{example}
\caption{example caption.}
\label{fig:example}
\end{figure}


\addcontentsline{toc}{chapter}{Bibliography}
\bibliography{references}
\bibliographystyle{alphaurl}

\end{document}

Because ktikz cannot handle standard latex packages, I use a template for all the tikz figures. This results in one tikz_definitions.tex (template) and a *.tikz and a *.tex (standalone) for every drawn ktikz figure.

tikz_definitions.tex

\usepackage{tikz}

\usetikzlibrary{arrows}

\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

\definecolor{oneColor}{RGB}{47,128,0}
\definecolor{secondColor}{RGB}{242,30,0}
\definecolor{thirdColor}{RGB}{106,178,248}

\tikzstyle{line} = [dash pattern=on 15pt off 25pt]

%% define reusable figure 
\newcommand{\reusablefigure}[4]{
    % a figure
    \begin{pgfonlayer}{foreground}
    \node[anchor=center, rotate=#4, opacity=0.6, inner sep=0] 
        (#1) at (#2,#3) {\includegraphics[scale=0.8]{blocks/a_figure.pdf}};
    \end{pgfonlayer}

    % white background rectangle
    \begin{pgfonlayer}{main}
    \begin{scope}[shift=(#1.center), rotate=#4]
        \fill [white, rounded corners=10pt] (-1.35,-0.53) rectangle (1.35,0.53);
    \end{scope}
    \end{pgfonlayer}

    % coordinate frame
    \begin{pgfonlayer}{foreground}
    \begin{scope}[shift=(#1.center), rotate=#4]
        \draw [<->, thick, color=#1Color] 
            (-0.8,1.1) node [left] (y) {$y_{#1}$} -- 
            (-0.8,0) -- 
            (2,0) node [below right] (x) {$x_{#1}$};
    \end{scope}
    \end{pgfonlayer}
}

%% define another reusable figure
\newcommand{\anotherfigure}[2]{
    \begin{pgfonlayer}{foreground}
        \draw [fill=red] (#1,#2) circle (0.07cm);
    \end{pgfonlayer}
}

Here is an example of a figure (consisting of *.tikz and *.tex file)

*example.tikz

\begin{tikzpicture}[
    scale=0.8, 
    axis/.style={very thick, ->, >=stealth'},
]

    % draw lines
    \draw[line, ultra thick] (0.2\textwidth, 4) -- (0.95\textwidth, 4);
    \draw[line, ultra thick] (0.2\textwidth, 2) -- (0.95\textwidth, 2);

    % a figure
    \reusablefigure{name1}{0}{0}{45}

    % the same figure
    \reusablefigure{name2}{10}{3}{0}


    % measurements
    \anotherfigure{1}{1}
    \anotherfigure{2}{2}
    \anotherfigure{4}{3}

\end{tikzpicture}

*example.tex

\documentclass{standalone}

\input{tikz_definitions}

\begin{document}
\input{overview.tikz}
\end{document}
3
  • 1
    Hi, have you tried starting from a small, minimal example (MWE)? For example, your overview.tikz need not be so complicated. Just draw a line. You can do away with all your \newcommands as well, they (probably) don't contribute to the externalization process. Once you're done setting up a minimal example which still gives the same error, post it here as an edit.
    – Troy
    Mar 28, 2017 at 12:28
  • Thanks for the hint. I've added a minimal example resulting in the same error.
    – evolving
    Mar 28, 2017 at 13:11
  • If you still have this problem, check out ebosi's answer to a similar question. It solved a very similar issue for me. Oct 31, 2018 at 16:24

1 Answer 1

1

Updated: Here is a minimal working example for a simple folder structure like this below. You have to compile the main.tex with pdflatex -shell-escape -output-directory=build %.tex. With \tikzsetnextfilename{<...>} you can set the output name. You have to create the folder build(first) manually before compiling.

main.tex

InputTikz (folder)

---exampletikz.tex (tikz)

build (folder)

The MWE produces a new folder (OutputTikz) with pdf files(standalone figures) and main.aux,main.auxlock,main.txt,main.pdf are saved in the build directory.

main.tex

InputTikz (folder)

---exampletikz.tex(tikz)

OutputTikz(folder)

---testname.pdf(standalone pdf)

---B_name.pdf(standalone pdf)

build (folder)

---main.aux

---main.auxlock

---main.txt

---main.pdf

compilation:

  1. Create the folder build first!
  2. Please compile with: pdflatex -shell-escape -output-directory=build %.tex

main.tex

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize[prefix=./OutputTikz/]    
\begin{document}
\tikzsetnextfilename{testname}
\input{InputTikz/exampleTikz}

\tikzsetnextfilename{B_name}
\input{InputTikz/exampleTikz}
\end{document}

exampletikz.tex

\begin{tikzpicture}
\draw (0,0) -- (0,1) -- (1,1) -- (2,1) -- (2,0);
\end{tikzpicture}
16
  • 1
    Sorry, I meant the additional output-directory option for pdflatex. Though, I think this option should still work. However, adding \tikzsetnextfilename{figurename} changed the error message. When I try using \input or \includestandalone, I get: I can't write on file ./build/tikz_figures/figurename.md5'.
    – evolving
    Mar 28, 2017 at 18:06
  • 2
    One folder for all tikz figures is great but I would like to have another folder for intermediate latex files (build folder). The command I wrote in my question: /Library/TeX/texbin/pdflatex -shell-escape -synctex=1 -interaction=nonstopmode -output-directory=./build %.tex uses an output-directory option for all intermediate latex generated files (aux, log, pdf, ...). Using this option there seems to be some path problems.
    – evolving
    Mar 28, 2017 at 19:38
  • 1
    I noticed that the *.md5 files are created inside the build folder.
    – evolving
    Apr 14, 2017 at 16:46
  • 1
    I believe the problem is that for some reason, TikZ tries to combine the output-directory and prefix paths when creating the .md5 files - see ebosi's answer to a similar question for details. As for why it apparently worked for you - perhaps differences between TeX distributions? I've noticed before that output-dir doesn't quite work the same between my installations of TeXLive on Linux and MikTeX on Windows (this specific issue was on Linux, haven't tested Windows yet). Oct 31, 2018 at 15:16
  • 1
    Update to my previous comment: I've tested it on Windows and it still puts the .md5 files in the wrong location, but the target directory is created automatically, so there's no error. On Linux I had to create the extra .\build\build folder myself. The OP's Mac is probably the same. Oct 31, 2018 at 16:20

You must log in to answer this question.

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