Thursday, January 6, 2011

Combining Several Latex Files to Produce a Complete Report

Latex is a very popular type setting system for technical and scientific writing. Here I will show, how you can combine several latex files produce one complete document

Latex code for Combining Several Files
First you need a main file for combining everything. This file will not contain actual content of the report. This is just a latex file just for to be used as an interface to each chapterfile.

Magic is in the \include{} command

Here is the main.tex file

\documentclass[10pt,a4paper,final]{report}
% parameters with in square brackets are optional
% document class should be larger one like book, report, or memoir
% because they allow using chapters
\begin{document}
\include{./titlepage} % including the cover page

\pagenumbering{roman}
\tableofcontents
\listoffigures
\listoftables
\chapter*{Acknowledgements}
\begin{abstract}
\end{abstract}

\pagenumbering{arabic}
% including separate chapter files. use relative path for portability
\include{./chapter1} % including chapter1.tex file
\include{./chapter2}

\bibliographystyle{IEEEtran} % I described on installing IEEEtran bibliography format in my previous article
\bibliography{./relative/path/to/bibtexfiles}
\end{document}

As you can see I am adding some other files using include command. File that contain the first chapter is named chapter1.tex.

Note : We do not write file extension when including the file.

Writing Chapter Files

If you have noted, We have defined the document class as 'report'. We have also declared the start of the file and end of the file in the main.tex file. So chapterfiles must not have any of these commands. Simply start the chapter file with \chapter{} command. Since we do not write document start at the top we don't write the document end command at the end either.

Here is sample chapter1.tex file

\chapter{The Chapter Heading} 
\section{Section heading} 
This is the section content 
\subsection{sub section heading} 
This is the subsection content  
% end of file

The Titlepage

This is the coverpage that I am using. You can change the formatting for your liking.

\begin{titlepage}
\begin{center}
% Upper part of the page 
\textsc{\LARGE University of Colombo \\[0.1cm] School of Computing}\\[1.5cm]
\textsc{\Large final year research project}\\[2.5cm]

% Title
\huge \bfseries Feel3D\\[0.5cm]
\Large free-viewpoint 3D video recording mechanism\\[1.0cm]
\large Introduction Chapter \& Literature Review\\[4.0cm]

% Author and supervisor
\begin{minipage}{0.4\textwidth}
\begin{flushleft} \large
\emph{Author:}\\
B.N. \textsc{Wickramsinghe}
end{flushleft}
\end{minipage} 

\begin{minipage}{0.4\textwidth}
\begin{flushright} \large
\emph{Supervisor:} \\
Prof. N.D. \textsc{Kodikara}
\end{flushright}
\end{minipage}
\vfill 

% Bottom of the page 
{\large \today} 
\end{center}
\end{titlepage}
Now we are ready to finalize our document. First compile the main.tex file uisng
pdflatex command, then with bibtex and twice more with pdflatex. Now we are done
pdflatex main
bibtex main
pdflatex main
pdflatex main

This will produce a pdf document which will have a cover page, two chapters and at the end of the document the complete bibliography.

When specifying file paths, using relative path is a good practice because it will increase the portability of your documents.
If you want to references at the end of each chapter try 'chapterbib' package and if you want to categorise your references use 'multiib' package.
(some of the info on this page were studied from here)

No comments:

Post a Comment