# Using headers in external TikZ figures with \includestandalone

I am facing an issue using figures in standalone files. My problem is related to the one described here. As I use many similar styled figures I want to put the header into a separate file so I can reuse it. I would like to have a solution for which I either build the figure separately (in a standalone file) or compile it while compiling the main document. I am using the following file structure and files for my MWE:

|- main.tex
|- figureFolder
|- figure.tex


main.tex

\documentclass{article}
\usepackage[%
subpreambles=true,
sort=true,
print=true,
mode=buildnew]{standalone}

\begin{document}
Some text
\begin{figure}
\includestandalone{figureFolder/figure}
\end{figure}
\end{document}


figure.tex

\documentclass{standalone}

\begin{document}

\begin{tikzpicture}
\draw [blue] (0,0)--(1,1);
\end{tikzpicture}

\end{document}


\usepackage{tikz}


I was thinking abdout adding something like

if mainFileCompilation
else


to the preamble of the standalone file but I could not figure out how.

• A symbolic link named header.tex next to figure.tex could do the trick. Otherwise, you could pass a command line argument to the compilation command, or discriminate based on \jobname. – frougon Mar 5 at 12:29

\IfStandalone{%