I am trying to use the subpreambles option with the standalone package. My main file is:
\documentclass[subpreambles]{standalone}
\usepackage{standalone}
\newtoks{\MyToken}
\MyToken={MainFile}
\begin{document}
Before Input: MyToken = \the\MyToken \par
\input{MySubfile.tex} \par
After Input: MyToken = \the\MyToken
\end{document}
and the MySubfile.tex content is:
\documentclass{standalone}
\usepackage{standalone}
\ifdefined\MyToken% prevent redfintion.
\else%
\newtoks{\MyToken}%
\fi%
\MyToken={Subfile}
\begin{document}
In sub file: MyToken = \the\MyToken
\end{document}
The output from this is:
Before Input: MyToken = Subfile
In sub file: MyToken = Subfile
After Input: MyToken = Subfile
but I what I want is this:
Before Input: MyToken = MainFile
In sub file: MyToken = Subfile
After Input: MyToken = MainFile
I tried using \begingroup \endgroup around the input and that did not work. I don't want to use different tokens in the standalone and main files, as what is currently the main file, will eventually also be a subfile. I am not stuck using \newtoks, any method that I can use to achieve this is fine.
I am also ok with last line printing
Input: MyToken = Subfile
Is this possible?

\ifdefined\MyTokeninstead? The\TokensDeclaredisn't really required. – Martin Scharrer♦ Apr 21 '11 at 8:33