# TeX Tips

Clone this Git repository to get started.

## Multiple documents

To prepare a large mathematical document in TeX, one typically works on each section or chapter separately and combine them using TeX mechanism of \input. Unfortunately, one problem with LaTeX document is that they need a preamble in order to be compiled and a document cannot contain two preambles. Consider the following situation: You have the main file

% Main.tex
\documentclass[12pt]{amsart}
\begin{document}
\section{Introduction}
\input{intro.tex}
\end{document}
% intro.tex
\documentclass[12pt]{amsart}
\begin{document}
Content of the introduction.
\end{document}
for the introduction section. In this example above, you also added the preamble in the second file so that you can compile it while writing its content without having to compile the whole thing over and over again; which is inefficient and might be too distracting. But this set-up won't work because when you compile the main file, you get the double preamble (two declarations of the \documentclass).

To fix this problem, the idea is to use conditional compilation; a method of enable/disable a region of code that C/C++ programmer should be familiar of (the #if ... #endif). In your main file, define a dummy command, say

\let\IsMainDocument\relax
% The rest of Main.tex
right at the beginning of the file and then in your section files, wrap the code that should be disabled when included in the main file, in
\unless\ifdefined\IsMainDocument

% Content that should be disabled if this file is \input-ed to the Main.tex;
% and enabled if this file is compiled as a stand-alone document. For example,
% put the preamble as well as the \end{document} of intro.tex.

\documentclass[12pt]{amsart}
\begin{document}

\fi

\unless\ifdefined\IsMainDocument

\bibliography{references}{}
\bibliographystyle{plain}
\end{document}

\fi

This way, you can compile both the intro.tex file by itself and when you are done with all the sections, compile the Main.tex file without any modification.

Remark: Since the preamble and postamble are to be shared between sections, it is best to extract common file for them. You should also add all math commands (notations) there to avoid clashing.

When writing a paper, one usually wants to add personal notes to include some additional information such as complete proofs, TODO notes, etc. which are to be turned off when publishing. An easy way to accomplish that is to make the command

\newcommand{\PERSONALNOTE}[1]{{\color{blue}{#1}}}
and wrap your note in \PERSONALNOTE, for example
It is easy to see that ...
\PERSONALNOTE{Here is the full proof of the easy claim. Blah blah blah.}
When the paper is ready, comment out the definition and replace it as an empty command
%\newcommand{\PERSONALNOTE}[1]{{\color{blue}{#1}}}
\newcommand{\PERSONALNOTE}[1]{}
Although this works, it leaves much to be desired.
• One usually wants some numbering of notes, like theorems, in order to easily refer to them when discussing with colleagues.
• For a long note, it is hard to locate the open/closing braces of the \PERSONALNOTE command.

A better solution is the following: When writing, use

\newtheorem{personalnotes}{Personal Notes}
and put your note similar to theorems or proofs, for example,
\begin{personalnotes}
Here is the full proof of the easy claim. Blah blah blah.
\end{personalnotes}
And finallym, to get the clean version for publishing, comment out the \newtheorem and replace it with comment environment
%\newtheorem{personalnotes}{Personal Notes}
\usepackage{verbatim}
\let\personalnotes\comment
\let\endpersonalnotes\endcomment

Now it is much better since your notes are structured and numbered. See here if you want to style notes, for example, make it in red.