2

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
|- headerFolder
   |- header.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}

\input{../headerFolder/header.tex} % for standalone compilation

\begin{document}

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

\end{document}

header.tex

\usepackage{tikz}

I was thinking abdout adding something like

if mainFileCompilation
    \input{headerFolder/header.tex}
else
    \input{../headerFolder/header.tex}

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

  • 1
    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
1

I found a simple solution by adding

\IfStandalone{%
    \input{../headerFolder/header.tex}}{%  % for standalone compilation
        \input{headerFolder/header.tex}}

to the preamble of figure.tex.

| improve this answer | |

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.