# How to use different preamble in subfiles root file and child file

I have both \maketitle \tableofcontents in the root file and child file when using subfiles package. When I compiling the child file, it works OK. But when I compiling the root file, the title and author information and an extra 'Content' are also appeared. I do not know how to erase these informations.

I tried to use macros to control the actions. But it does not work very well.

I have several puzzles.

1.Does the new definition of the variable in child file erased its value transfered from root file?

2.Is there a command to test if a variable here like multiple has already been difnied?

3.When debugging latex, how to output the value you definied in latex?

4.Are there any other graceful ways to achieve my aim?

Thank you!

Here is the root file named root.tex

\documentclass[a4paper, 12pt]{article}
\usepackage{subfiles}

\newif\ifmultiple  %\multipletrue means called by main file
\multipletrue

\author{Ct586}
\title{How to use subfiles}
\date{\today}

\begin{document}

\maketitle

\tableofcontents

\subfile{child}

\end{document}


Here is the child file named child.tex:

\documentclass[Dynamic.Network.Embryonic.Development.tex]{subfiles}

\newif\ifmultiple  %\multipletrue means called by main file
%\multipletrue
\ifmultiple
\begin{document}
\else
\author{Ct586}
\title{How to use subfiles}
\date{\today}
\begin{document}
\maketitle
\tableofcontents
\fi

\section{child}
child

\end{document}

-
You may find Martin Scharrer's standalone package useful. The package is more recent and actively maintained. – Brent.Longborough Mar 31 '12 at 15:25
standalone looks very powerful. Thank you. I will try to use it. And also I wonder how to make my way, setting a variable, work? – ct586 Apr 1 '12 at 1:07
verbatim package has a comment environment which will allow you to configure your document according to whether it is called from the master or not. I'm sorry I can't give you a proper answer, but I'm completely overwhelmed by stuff at the moment. – Brent.Longborough Apr 1 '12 at 11:07
Thank you very much. I will try them as soon as possible. When I get the right way, I will post here. Do not be sorry, your information is truely the great help. – ct586 Apr 4 '12 at 0:54

set \let\tableofcontents\relax after the main one:

\RequirePackage{filecontents}
\begin{filecontents*}{child.tex}
\documentclass[main.tex]{subfiles}
\author{Ct586}
\title{How to use subfiles}
\date{\today}
\begin{document}
\maketitle
\tableofcontents

\section{child}
child

\end{document}
\end{filecontents*}
\documentclass[a4paper, 12pt]{article}
\usepackage{subfiles}
\author{Ct586}
\title{How to use subfiles}
\date{\today}
\begin{document}
\maketitle
\def\author#1{} \def\title#1{}
\tableofcontents
\let\tableofcontents\relax

\subfile{child}
\end{document}

-
Thanks for your answer. \let\tableofcontents\relax worked well. The word 'Content' disappeared. I save two files named 'main.tex' and 'child.tex'. When I am compiling 'child.tex', get LaTeX Warning: Overwriting file ./child.tex'.. When I am compiling 'main.tex', the author and title information of child.tex still exist. So what is the question? Thank you! – ct586 Apr 1 '12 at 0:58
Insert \def\author#1{} \def\title#1{} just rightafter the \maketitle in main.tex`. See my edited answer – Herbert Apr 1 '12 at 6:03
This works really well. Thank you very much! – ct586 Apr 4 '12 at 0:58