# How to make the (COMPLETE) preamble of a Standalone document available to a Main Document?

I am in the process of generating a lot of content for presentations and scripts. The standalone package and documentclass seems to be a very helpful, but I am running into an issue mentioned by Diac Busquets here

Is it possible to somehow tell standalone to copy the preamble of the files being included? It is sometimes a hassle to keep copying all the \usetikzlibrary commands.

I already tried to use the subpreamble=true and the sort=true options for the standalone package in the main file. But somehow when I use the sort=true option, the presentation compiles fine, but my "standalone tables" do not show up (The "standalone tikz" do though). And when I use subpreamble=true, the package options clash (no matter how much I rearrange the packages)

QUESTION 1: Why does \includestandalone{my tables} produce no result?

How come, I cannot use the \IfStandalone{⟨code for standalone mode⟩}{⟨code for main document⟩}command and place my \usetikzlibrary statement in each of the two curly brackets (pair). The "double code" seems unnecessary, but it should work! Right? ... I tired that, but without any luck.

The main document seems to ignore the {⟨code for main document⟩} statement. Even if I use the sort option.

QUESTION 2: Why is the{⟨code for main document⟩} statement ignored in the main document? Specifically, how can I prevent the "reuse" of the usetikzlibrary{mylibraries} in my main document?

Question 3: How do I fix it?

Here is the StandalonePicture.tex

\documentclass[convert]{standalone}
\usepackage{tikz}

\IfStandalone{
\usetikzlibrary{arrows,decorations.pathmorphing,decorations.markings,decorations.text,}
\tikzset{>=latex}
}
{
% This command does not seem to have an effect in the main document
\usetikzlibrary{arrows,decorations.pathmorphing,decorations.markings,decorations.text,}
\tikzset{>=latex}
}

\begin{document}
\begin{tikzpicture}[node distance=3cm,]

%Define main nodes
\tikzstyle{main node}=[black,draw,circle,minimum size=2.cm,align=center]

% Draw actual nodes
\node [main node] (1) {Text 1};
\node [main node] (2) [ left of=1, ] {Text 2};

% Connecting Arrows
\draw [<-,postaction={decorate,decoration={text along path,raise=-2.5mm,text align=center,text={|\tiny| Bending}}}] (2) to [bend right=-45]  (1);

\end{tikzpicture}
\end{document}


And here is the actual presentation (Presentation.tex) that calls the tikzpicture (or table)

\documentclass[]{beamer}

% It does NOT work with the following line (but it should)
% I don't understand, because the \IfStandalone{}{} command should take care of that.
\usepackage{standalone}

% It does work if the sort option is enabled
% (Of course, since the 'sort' option ensures that the 'subpreamble' is reprinted)
%\usepackage[sort=true]{standalone}

\begin{document}

%%%%%%%%%%%%%%%%%%%
% Begin Unit %%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Frame 1}
\framesubtitle{This one works flawlessly}
\begin{itemize}
\item First slide with no picture
\end{itemize}
\end{frame}
% ---------------------
% Notes ------------
% ---------------------
\note{
\begin{itemize}
\item This works
\end{itemize}
}
% ---------------------
% Skript ------------
% -------------------------------
\mode<article>{

}
%%%%%%%%%%%%%%%%%%%
% End Unit %%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%
% Begin Unit %%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Frame 1}
\framesubtitle{This one won't work because of missing tikzlibrary}

\includestandalone{StandalonePicture}

\end{frame}
% ---------------------
% Notes ------------
% ---------------------
\note{
\begin{itemize}
\item This works
\end{itemize}
}
% ---------------------
% Skript ------------
% -------------------------------
\mode<article>{

}
%%%%%%%%%%%%%%%%%%%
% End Unit %%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%

\end{document}

• Please provide an MWE rather than expecting other people to create one for you. If you don't provide one, others have to create one to try to reproduce the problem you are seeing. The fact that the problem is general, if it is, is irrelevant. Why would that mean you didn't need to provide an MWE? The fact that all of your documents are large is also irrelevant. Why would that affect the need to provide an MWE? An MWE is something you create to demonstrate the issue - not a copy of an existing document where you see the problem. All questions should include an MWE. – cfr Aug 20 '14 at 21:36
• @cfr You are right! I should have provide the MWE earlier. I guess, I was to fed up with my presentation and did not wanna spend more time "in LaTeX". Not that this is an excuse, it is rather an apology and explanation. So sorry for the confusion. – Raphael Aug 21 '14 at 20:05
• As I understand it, when you just use \usepackage{standalone}, basically everything between \documentclass and \begin{document} in the standalone file is ignored. So \IfStandalone... will not be read at all in this case and so will naturally have no effect when the document is included in the main file. Do you see something in the documentation suggesting otherwise? – cfr Aug 21 '14 at 22:41
• @cfr That makes perfect sense, and I did not find anything in the documentation that would suggest otherwise. In that case, I just wonder what the purpose of the \IfStandalone{⟨code for standalone mode⟩}{⟨code for main document⟩} command is. Or rather; why is there a ⟨code for main document⟩ ? Since we have the \ifstandalone{⟨code for standalone mode⟩} command, we would not need the \IfStandalone{}{}. But maybe I am overlooking something. – Raphael Aug 22 '14 at 6:17
• I'm not sure. Is it possible that you might use this in the main body of the standalone document? – cfr Aug 22 '14 at 14:16