# Sample LaTeX Root File

What we have here is a root LaTeX file that references a number of other files and gives the document a basic structure. The fun stuff has been placed in include files to make writing the document manageable. If you have used FrameMaker, you will see a pattern: the FrameMaker Book file works basically the same way as this LaTeX root file.

\documentclass[a4paper,12pt,draft,twoside]{book}
\usepackage{styles/mystyles}

\begin{document}

\frontmatter

\include{tex/title}

\tableofcontents

\mainmatter

\include{tex/preface}
\include{tex/intro}
\include{tex/chap01}
\include{tex/chap02}
\include{tex/summary}

\backmatter

\end{document}


So, let's go through this file section by section.

#### Defining the Document Class

The first line tells the LaTeX generator the type of document it is about to generate (or typeset) and what styles are to be used.

\documentclass[a4paper,12pt,draft,twoside]{book}


All these elements are defined in separate class files. More about these classes later.

The \documentclass line defines the type of document you intend to create. This document will be printed (or output to pdf) in A4 format. The base font will be 12 points, although this can be modified in the document. It is marked as draft initially. And it will be printed on both sides.

The word book within the curly braces tells the typesetter to use the Book class. This is a set of predefined outputting instructions, which in this case has functionality that can handle large multi-chapter documents, which manuals tend to be.

Note: Another option is using the memoir class, which offers a useful alternative.

#### Externally Referencing the Stylesheet

Following the document class definition, you tell the typesetting engine to use the styles defined in an external document called mystyles located in a directory below the root called styles.

\usepackage{styles/mystyles}


mystyles is a stylesheet in which I have defined all the styles that will be used in this document. This allows me to update the stylesheet without having to worry about finding the styles within the root file (the alternate location for styles).

#### Beginning the Document

Like the body tag in HTML, the actual content follows this tag:

\begin{document}


It tells the typesetter that what follows is the document. The document section is divided into three subsections: frontmatter, mainmatter and backmatter.

#### Defining a Title Page

In the frontmatter section, I included a title page, although the book class has a default title page which can be referred to simply as titlepage. In this section I want my table of contents as well, which is automatically generated during output.

\frontmatter

\include{tex/title}

\tableofcontents


#### Indicating the Document Body

The document itself, namely, the contents, is contained within the mainmatter section.

\mainmatter


To keep this simple and to allow chapters to be toggled off or on, all content is placed in external files in a subdirectory called tex. The \include command is used to tell the typesetter to go locate the file within the curly braces and generate the output and include it at the location in the list of includes.

\include{tex/preface}
\include{tex/intro}
\include{tex/chap01}
\include{tex/chap02}
\include{tex/summary}


Note: You would also define your headers and footers here, but I excluded them in this example to keep it simple. I will get to them in due time. I also included an appendix, but is not shown in my example.

A backmatter section is also included, which typically includes the Index.

\backmatter


#### Closing the Document

You need to tell the typesetter when the document is complete, that is, there is no more files to generate. In other words, you need to close your document, as in all tagged files.

\end{document}


This simple command indicates the end of the document and go ahead and generate the output.

We will get into more detail in an upcoming post.

Categories:

Updated: