2

I am currently writing a larger document containing many Tikz figures, and to speed up compilation I would want to generate them as separate PDFs using the standalone package. Despite running fine with no errors, my code does not seem to output any separate PDF upon compilation. I've skimmed through the documentation of the Standalone package, but without finding anything that would solve my problem. Therefore I've created this minimal document based on how things are done in my project, hoping some of you might know a way to fix this.

FYI, I am running PDFLaTeX with shell ecape enabled like this:

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

Note that you will have to include 3dplot.sty in the same repository as the Main.tex file to run the compilation successfully.

Main document file:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
    \usetikzlibrary{decorations.pathreplacing,decorations.pathmorphing,calc}
\usepackage{amsmath}
\usepackage{3dplot}
\usepackage{standalone}

\newlength\figureheight
\newlength\figurewidth

\title{Test}
\author{Hkonrost}

\begin{document}
    \maketitle

\begin{figure}[ht]
    \centering
    \setlength\figureheight{0.4\textwidth}
    \setlength\figurewidth{0.7\linewidth}
    \input{testStandalone.tex}
    \caption[Excitation vectors]{I wish standalone worked for this document.}
\end{figure}

\end{document}

The input file testStandalone.tex contains the following:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,decorations.pathmorphing,calc}
\usepackage{amsmath}
\usepackage{3dplot}
\begin{document}
%set the plot display orientation
%syntax: \tdplotsetdisplay{\theta_d}{\phi_d}
\tdplotsetmaincoords{70}{110} % 60 110
% Define dimensions of sample box
\newcommand{\Depth}{8}
\newcommand{\Height}{0.5}
\newcommand{\Width}{8}
\begin{tikzpicture}[thick,tdplot_main_coords]

% Setting up coordinates
% -------------------------------
% x = depth, y = width, z = height
% Back face coordinates
\coordinate (O) at (0,0,0);
\coordinate (A) at (0,0,\Height);
\coordinate (B) at (0,\Width,\Height);
\coordinate (C) at (0,\Width,0);
% Front face coordinates
\coordinate (D) at (\Depth,0,0);
\coordinate (E) at (\Depth,0,\Height);
\coordinate (F) at (\Depth,\Width,\Height);
\coordinate (G) at (\Depth,\Width,0);
% Origin coordinate
\coordinate (origin) at (\Depth/6,\Width/6,0);

% Drawn structures
% --------------------------------------

% K-vector
\draw[red,ultra thick,->] (origin) --++ (0.58,0,-0.45) node[right] {$\Vec{k}$}; % K-vector

% Substrate surface planes
\draw[blue,fill=cyan!80,opacity=0.5] (O) -- (A) -- (B) -- (C) -- cycle; % Back Face
\draw[blue,fill=cyan!80,opacity=0.5] (O) -- (D) -- (G) -- (C) -- cycle; % Bottom Face
\draw[blue,fill=cyan!80,opacity=0.5] (O) -- (D) -- (E) -- (A) -- cycle; % Back Left Face
\draw[blue,fill=cyan!80,opacity=0.5] (C) -- (G) -- (F) -- (B) -- cycle; % Front Right Face
\draw[blue,fill=cyan!80,opacity=0.5] (D) -- (E) -- (F) -- (G) -- cycle; % Front Face
\draw[blue,fill=cyan!80,opacity=0.5] (E) -- (A) -- (B) -- (F) -- cycle; % Top Face

% Axes
\draw[very thick,black,->] (origin) --++ (\Depth*0.95,0,0) node [below] {x};
\draw[very thick,black,->] (origin) --++ (0,\Width*0.95,0) node [right] {y};
\draw[very thick,black,->] (origin) --++ (0,0,\Depth*0.5) node [above] {z, $\hat{\Vec{n}}$};

% Negative x-axis extension
\draw[thick,dashed] (origin) --++ (-3.5,0,0);

% Incoming photon;
\draw [violet,ultra thick,decorate,decoration={snake}] ($(origin)+(-3.5,0,2.7)$) -- ($(origin)$); % Photon

% xy projection plane
\draw[black,dashed] ($ (origin) + (4.5,0,0) $) --++ (0,4.5,0) --++ (-4.5,0,0);
\draw[black, dashed] (origin) --++ (4.5,4.5,0);

% Projection line O vector
\draw[black,dashed] ($ (origin) + (4.5,4.5,0) $) --++ (0,0,3.5);

% O vector
\draw[ultra thick,teal,->] (origin) --++ (4.5,4.5,3.5) node[above right] {$\Vec{O}$}; % E parallel

% xz plane
\draw[black,dashed] ($ (origin) + (4.5,0,0) $) --++ (0,0,3.5) --++ (-4.5,0,0);

% E-field vector components
\draw[ultra thick,red,->] (origin) --++ (4.5,0,3.5) node[above left] {$\Vec{\mathcal{E}}_{\parallel}$}; % E parallel
\draw[ultra thick,red,->] (origin) --++ (0,1,0) node[above right] {$\Vec{\mathcal{E}}_{\perp}$};;
\draw[very thick,red,dashed] ($(origin)+(0,0.45,0)$) --++ (0.58,0,0.45) --++ (0,-0.45,0);

% Drawing the arcs
% ----------------------------------------------------
% For drawing the different arcs, the plane spanned by theta rotation is rotated about the z-axis (azimuthally). Syntax: \tdplotsetthetaplanecoords{\phi}

% Azimuthal angle to vector O projection onto xy plane
\tdplotdrawarc{(origin)}{3}{0}{45}{anchor=north}{$\phi$};

% Angle theta to E parallel vector from z-axis
\tdplotsetthetaplanecoords{0}
\tdplotdrawarc[tdplot_rotated_coords]{(origin)}{1.5}{0}{52.1}{anchor=south east}{$\theta$};

% Angle alpha to O vector from z-axis
\tdplotsetthetaplanecoords{52.1}
\tdplotdrawarc[tdplot_rotated_coords]{(origin)}{1.5}{0}{58.44}{anchor=south west}{$\alpha$};

% Angle theta from x axis to incoming photon
\tdplotsetthetaplanecoords{180}
\tdplotdrawarc[tdplot_rotated_coords]{(origin)}{2.4}{52.1}{90}{anchor=west}{$\theta$};

\end{tikzpicture}
\end{document}

Any help here is kindly appreciated!

  • ... and TikZ provides externalize precisely to speed up the compilation. – marmot Mar 11 '18 at 13:56
  • 1
    @marmot: Yes, you can, this is exactly what the standalone package does in the main file. It strips the \documentclass in subfiles away. It is an alternative to the externalize feature of TikZ, but also works with other code. – Martin Scharrer Mar 21 '18 at 8:33
  • @MartinScharrer Oh, I see. Thanks! I'll delete my comment. – marmot Mar 21 '18 at 14:29
2

The standalone bundle can indeed create a separate PDF for the subfiles. For this please set the mode package option to build, buildmissing or buildnew and use \includestandalone{file} (without the .tex extension!) instead of \input{file.tex}. This requires the -shell-escape compiler switch which you already using.

If you then use build=tex instead for your final compilation the source files will be used. Note that buildnew doesn't work with XeLaTeX as it can not check for file changes.

Full main file is:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
    \usetikzlibrary{decorations.pathreplacing,decorations.pathmorphing,calc}
\usepackage{amsmath}
\usepackage{3dplot}
\usepackage[mode=build]{standalone}

\newlength\figureheight
\newlength\figurewidth

\title{Test}
\author{Hkonrost}

\begin{document}
    \maketitle

\begin{figure}[ht]
    \centering
    \setlength\figureheight{0.4\textwidth}
    \setlength\figurewidth{0.7\linewidth}
    \includestandalone{testStandalone}
    \caption[Excitation vectors]{I wish standalone worked for this document.}
\end{figure}

\end{document}
  • Thanks, @MartinScharrer . I may well have missed this reading the manual or examples online. Anyways, this solved my problem! – Haakon Rost May 28 '18 at 8:10
  • A quick follow-up comment: when including .tikz files found in a different repository than the main file, e.g. \includestandalone{TIKZ/testStandalone} , my compilations fail to produce any PDF, returning with error 256. Do you know any way around this problem? – Haakon Rost May 29 '18 at 20:21

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.