|
|
|||
![]() |
Department of Engineering |
| University of Cambridge > Engineering Department > computing help > LaTeX |
This document doesn't attempt to teach you LaTeX but it does pick out some issues that arise when people start producing long documents. LaTeX was designed with technical reports very much in mind, so before you consider using any other method, look at the list of LaTeX's strengths first.
pdflatex will produce PDF files directly, and accepts JPG, PNG and PDF graphics files (but not encapsulated postscript files). latex will produce DVI files and only copes with encapsulated postscript files. A few facilities (ever fewer) are only available with latex
Another more committal choice is whether to use a front-end like Lyx.
The help system's LaTeX page is quite extensive. It includes information on
and there's also a keyword search of the LaTeX documents on this server.
The document class specified in the "\documentclass" line determines the basic appearance of the document (rather in the way that templates or Master Pages do in other programs). Packages (loaded in using the "\usepackage" command) are add-ons that augment or change the standard LaTeX features. Both classes and packages can be given options by using square brackets (see the use of the graphicx package below as an example).
Journals sometimes have class files for you to use. Use them whenever you can. We have a few of these installed (e.g. the Royal Society's rs class, Elsevier's elsart class and some IEEE material), but many others exist (see, for example, CUP's LaTeX support, and Kluwer Academic's author instructions and style files).
There are several thesis-related classes around. Most are university-specific. Some have been designed for easy customisation. One that's often mentioned is ucthesis from the University of California.
It's possible to write one's own class files. 2 local options are available
\documentclass{IIBproject}
\usepackage[dvips]{graphicx}
\usepackage{fancyhdr}
\usepackage{setspace}
\bibliographystyle{plain}
% The next line sets 1.5 spacing
\onehalfspacing
\begin{document}
% Title Page
\author{A Student (college code)}
\title{Just a Test}
\projectgroup{A}
\pagestyle{empty}
\maketitle
\thispagestyle{empty}
% Summary
\pagestyle{fancy}
\begin{abstract}
...
\end{abstract}
\tableofcontents
\listoffigures
\newpage
%Introduction - load in the intro.tex file
\input{intro}
%Theory and Design of Experiment - load in the theory.tex file
\input{theory}
% ....
%Conclusions
\input{conclusions}
\bibliography{test} % load in the info produced from test.bib
\appendix
\input{appendix}
\end{document}
If you're writing a book you may wish to add \frontmatter,
\mainmatter and \backmatter too, so that arabic
page numbering begins after the contents, etc.
\usepackage{chngcntr}
\counterwithin{figure}{section}
\counterwithin{equation}{section}
\begin{document}
...
The listings
package typesets program listings putting keywords, comments etc into
different font styles. The example below shows how to format inline fragments
and import (part of) external files for C++ code.
...
\usepackage{listings}
\begin{document}
\lstset{language=C++}
...
\begin{lstlisting}{}
for(int i=0; i<n; i++)
cout << "loop";
\end{lstlisting}
\lstinputlisting{test.cc}
\lstinputlisting[first=10,last=50]{test.cc}
Line numbers and other languages are supported too.
@BOOK
{KandR,
AUTHOR = "Kernighan, Brian W. and Ritchie, Dennis M.",
TITLE = "{The C Programming Language Second Edition}",
PUBLISHER = "Prentice-Hall, Inc.",
YEAR = 1988
}
The fields are described in the
bibtex handout.
The first field is the tag used when you \cite the item.
How this appears in the text depends on the packages used and the
bibliography style. If you call the bibtex file test.bib
then the styles in the framework suggested above should work ok.
In your main latex document you need \bibliographystyle{plain}
at the top to set the style and \bibliography{test} where you
want the bibliography to appear.
Note that you'll initially have to run latex, bibtex,
latex and latex
again on your document before everything appears. After that, you only
have to run latex unless you change the bibliography file.
If you want multiple citations sorted, use the citesort package.
If you want citations superscripted, use the overcite package. To have superscripts in the References section, add the following to your LaTeX document
\makeatletter \renewcommand\@biblabel[1]{$^{#1}$} \makeatother
If the journal you're writing for doesn't provide a bibliography style file, we have a number of alternatives online. The natbib package is well documented (see the natbib reference sheet for the essentials).
An alternative to the plain style used in the above example is unsrt which lists references in citation order rather than author order. To have references at the end of each chapter, use chapterbib or bibunits.
If none of the supplied styles are adequate, then the custom-bib can be used by typing latex makebst.tex from the command line to customise your own style - it's self-documenting; just accept the offered defaults if you have doubts.
See the bibliographies page for more information.
\usepackage{appendix}
\renewcommand{\appendixtocname}{TOC appendix title}
\renewcommand{\appendixpagename}{Inline appendix title}
...
\appendix
\appendixpage
\addappheadtotoc
\section{1st appendix section}
\includeonly{chapter1,chapter3}
\include{chapter1}
\include{chapter2}
\include{chapter3}
will process only chapters 1 and 3 and will assume that chapter 2 hasn't
changed since it was last processed. Note however that \include
(unlike \input) will force a page break.| | computing help | LaTeX | |