Copyright © 2005 The University Of Birmingham
| Revision History | ||
|---|---|---|
| Revision 0.1 | 20 November 2005 | AJS |
| This tutorial was written in 2001, at that time I had little LaTeX experience. Please bear this in mind, and please do not consider this revision as an indicator of the quality of the entire tutorial set. Since 2001 I have written many documents in LaTeX and so if time permits I will update this tutorial. | ||
Table of Contents
LaTeX (pronounced Lay-Tex) is a macro package originally created by Leslie Lamport for the document generation language TeX (pronounced like the tech in technology). TeX was created by Donald E. Knuth around 1970 in order to provide him with the necessary tools to produce his legendary The Art Of Computer Programming series of books (which are still being written) and various other books. A more comprehensive description of TeX can be found at http://www.tug.org/whatis.html and the TeX FAQ can be found at http://www.tex.ac.uk/cgi-bin/texfaq2html?introduction=yes. TeX is famous for it's excellent mathematical and scientific typesetting capabilities. TeX is also Turing complete.
TeX is a program which manipulates the TeX language used to describe the structure of a document. A TeX document be processed in order to generate printable output, this is achieved using TeX the program. Other tools such as dvips are then used to convert the DVI(Device Independent) output produced by the TeX tools to a device dependent Postscript format.
LaTeX is a layer on top of TeX t abstract functionality and more. Author-friendly development is coupled with an emphasis in generating high quality output. LaTeX2e (pronounced Lay-Tech-Two-E), is the latest development of LaTeX available at the time of writing. You can find a lot more about LaTeX and LaTeX2e at http://www.latex-project.org/. This tutorial will focus on LaTeX2e, the reason for the weird capitalization in TeX, LaTeX and LaTeX2e is because the ASCII characters are representing Greek letters. Images of how these words should actually look are shown below:
Leslie Lamports Book LaTeX: A Document Preparation System, Second Edition is still regarded as a very worthwhile reference, any serious LaTeX user should consider obtaining it.
It is assumed that you know how to setup environment variables and install software on your operating system, for a comprehensive guide to doing so for Windows see Configuring A Windows Working Environment, for Unix see Configuring A Unix Working Environment Follow these instructions to install JDOM:
Installing a TeX distribution should suffice here as it is more likely than not that any TeX distribution you care to install will install the LaTeX2e macro extensions by default.
If you need extra packages for your TeX distribution, it is extremely likely that these can be obtained from CTAN (Comprehensive TeX Archive Network). The UK mirror of this file tree is hosted by Cambridge University and can be found here http://www.tex.ac.uk/.
A basic knowledge of operating system concepts, such as changing environment variables, is assumed. Detail pertaining to this topic can be found in the documents: Configuring A Windows Working Environment and Configuring A Unix Working Environment.
For the Windows user, TeXLive (ftp://ftp.dante.de/pub/fptex/current/TeXSetup.exe) is an excellent all-in-one TeX package that this tutorial will be using. Download it and follow the installation instructions, change the installation directory to something suitable; C:\tools\TeXLive\. Install the Generic recommend TeXLive scheme but check the box that says “I want to customize the selected scheme”. The next screen presents the user with a list of all possible packages on offer. Make sure you select the LaTeX package if it is not already selected.
![]() | Note |
|---|---|
During the TeXLive setup, when on the Root of installation page I advise you only to change the “Root directory” field (the others will update automatically, leave the Extra TeXMF tree and Home TeXMF Tree fields alone. In other words, do not check the box that says “You can change the default configuration for the main directories.”. | |
If you are using Unix there are a number of schools of thought on which is the best TeX distribution to install on your system, a good one is TeXLive. The Unix distribution of TeXLive is available to download off ftp at http://www.tex.ac.uk/ or is available on CDROM. The CDROM is available free and can be downloaded as an ISO-Image to be burned or you can order it from a UK based supplier. If you don't want to install TeXLive you may want to consider teTeX which is available from ftp. Your Unix distribution may have came pre-installed with TeX/LaTeX, perform this test to check. This test can also be used to check if you have installed a distribution correctly. Create the document test.tex:
\documentclass[a4paper,12pt]{article}
\begin{document}
blah blah blah
\end{document}
|
Process this with the command:
latex test.tex |
If all goes well, the following will be output:
This is TeX, Version 3.14159 (Web2c 7.3.7x)
(./test.tex
LaTeX2e <2001/06/01>
--SNIP--
(c:/Program Files/TeXLive/texmf/tex/latex/base/article.cls
Document Class: article 2001/04/21 v1.4e Standard LaTeX document class
(c:/Program Files/TeXLive/texmf/tex/latex/base/size12.clo)) (./test.aux)
[1] (./test.aux) )
Output written on test.dvi (1 page, 232 bytes).
Transcript written on test.log.
|
In order to view and print PostScript files it is necessary to install GhostScript and GhostView.
If you are using Windows, download GhostScript from http://www.cs.wisc.edu/~ghost/doc/AFPL/get704.htm and GhostView from ftp://mirror.cs.wisc.edu/pub/mirrors/ghost/ghostgum/gsv43w32.exe. Run the executables to install the software.
GhostScript doesn't add the lib or bin directories to your path when you install it on Windows (because it expects you to be using the GUI). Which means that you cannot access the 31 auxiliary tools from the command line. To be able to use them, add the lib and bin directories to your PATH environment variable (prefix lib and bin with the base directory where GhostScript was installed).
If you are using Unix, Download GhostScript from: http://sourceforge.net/projects/ghostscript/ and GhostView from: http://www.cs.wisc.edu/~ghost/doc/AFPL/get704.htm you may also find this resource page useful: http://www.cs.wisc.edu/~ghost/
Notice that you can download either the sources or the rpms, choose whichever method you feel most comfortable with. Install the software.
To convert a tex file to DVI:
latex blah.tex |
Which outputs:
blah blah blah...
Output written on blah.dvi (1 page, 676 bytes).
Transcript written on template.log.
|
You may have to execute the command several times to ensure that yourfile.aux is correctly updated with page numbers and file references etc, the recommendation is "at least twice". This will generate blah.dvi, which as explained, is a device independent format, you will need to convert it to something else in order to print it (well actually, you can print it from DVI if your tools/printer support it). If errors are encountered, you will be presented with a prompt in the form of a question mark, type another question mark and hit enter and the following options will be displayed:
Type <return> to proceed, S to scroll future error messages,
R to run without stopping, Q to run quietly,
I to insert something, E to edit your file,
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
H for help, X to quit.
|
Generally you should try S or R to suppress errors and let TeX handle them as it sees best, or you could learn TeX inside out and deal with the errors yourself, you will probably have to deal with errors some day. Thankfully the error-output specifies the line the error occurred on and you have the option to edit the file there or insert something. For more information about dealing with errors see the section entitled The joy of TeX errors in the TeX FAQ: http://www.tex.ac.uk/cgi-bin/texfaq2html.
You can view the DVI file with WinDVI in Windows, assuming a TeXLive installation, this can be done by double clicking on the file or typing:
windvi in.dvi |
If you do not have WinDVI, obtain it. If you are using Unix then you can use XDVI:
xdvi in.dvi |
If you do not have XDVI, obtain it from http://math.berkeley.edu/~vojta/xdvi.html.
To convert DVI output into PostScript:
dvips blah.dvi -o |
Which will produce blah.ps. You can now use ps2pdf to convert the ps file to PDF or one of the other tools that came with GhostScript to get some other output format. Alternatively you can open the ps file in GhostView and use the File...Convert menu item to export the file to various formats.
Here is an extremely simple LaTeX2e article template to get you started:
When the above document is processed with LaTeX, the resulting DVI file looks like this:
It is recommended that you read A not very short introduction to LaTeX2e, available from http://people.ee.ethz.ch/~oetiker/lshort/, you will probably want the PDF file at the bottom. This provides many examples of how to get things done with LaTeX2e, it is an excellent document written by Tobi Oetiker, Hubert Partl, Irene Hyna and Elisabeth Schlegl. I am not going to replicate that document here. It covers almost everything you could possibly want to do with LaTeX. You can even download the source code to see how the document was produced.
LaTeX2e uses what are known as environments to markup content in a document. An environment is opened with:
\begin{environmentName} |
And is closed with:
\end{environmentName} |
The text between the opening and closing of the environment will be subject to the constraints of this particular environment. Some environments may be nested. There are many environments available in LaTeX2e, with special applications such as creating tables, inserting images, displaying literal text and creating bibliographies.
One of the most common ways to use images within LaTeX is to use eps(encapsulated PostScript) images. In order to convert your files to this format you will have to install some kind of image manipulation program, The GIMP(GNU Image Manipulation Program) is a free image manipulation program with the capability to do this conversion (it would probably be overkill to install this program just to do this but the program is very good so you should install it anyway). It is available for both Unix and Windows, the Unix version can be obtained from the GIMP homepage: http://www.gimp.org/. The windows version can be obtained from here: http://www2.arnes.si/~sopjsimo/gimp/.
The basic template for inserting an image is shown below:
\documentclass[a4paper,12pt]{article}
\usepackage{fullpage, graphicx}
\begin{document}
\begin{center}
\includegraphics{yourimage.eps}
\end{center}
\end{document}
|
There are many other options that can go with this, but the key points are the epsfig package import and the \epsfbox directive, which is centered.
A better way to include images within LaTeX is to use the eepic package. epic is an extension to LaTeX's own picture format pic (extended pic) and provides a simpler and more powerful interface, it inherits many of the limitations of LaTeX, to overcome these limitations one generally uses eepic (extended epic). The extensions provide the ability to draw lines in any slopes, draw discs and circles with any diameter that TeX supports and various other enhancements. The main bonus of using eepic is it's ability to include LaTeX mathematical symbols and special commands so that figures may contain mathematical formula which are consistent with the rest of the document.
The eepic image not a bitmapped image but a LaTeX document containing the relevant markup required to produce the desired effect, for example:
\setlength{\unitlength}{0.00083333in}
%
\begingroup\makeatletter\ifx\SetFigFont\undefined%
\gdef\SetFigFont#1#2#3#4#5{%
\reset@font\fontsize{#1}{#2pt}%
\fontfamily{#3}\fontseries{#4}\fontshape{#5}%
\selectfont}%
\fi\endgroup%
{\renewcommand{\dashlinestretch}{30}
\begin{picture}(4137,2325)(0,-10)
.
.
.
|
It is not necessary for one to understand this kind of markup in order to use eepic. Instead, one uses a program such as xfig to create the image, xfig is loaded up like this:
xfig -specialtext |
The -specialtext option is required so that inserted text is treated as special and the LaTeX escaped commands can be used. A screenshot of xfig showing a created image can be seen below:

The image is exported, using xfig, as LaTeX picture + eepic macros:

The LaTeX picture + eepic macros file generated is included in the LaTeX document like this:
\documentclass[a4paper,12pt]{article}
\usepackage{fullpage, epic, eepic}
\begin{document}
\begin{center}
\input{cool.eepic}
\end{center}
\end{document}
|
Notice the inclusion of the packages epic and eepic. The eepic file generated is imported into the document verbatim by using the \input command. When output as PDF the LaTeX generated from the xfig screenshot shown above looks like this:

Xfig is only available for Unix or unix emulators such as Cygwin for Windows. Instructions on obtaining and installing xfig can be found at http://www-epb.lbl.gov/xfig/installation.html. Information about using fig with Microsoft windows can be found at http://duke.usask.ca/~macphed/soft/fig/winfig.html.
Windows users will probably have to install jfig, available for download at http://tech-www.informatik.uni-hamburg.de/applets/javafig/download.html, fig2dev must also be available so that jfig can export as eepic, this can be obtained from the same place as jfig, mentioned above. A screenshot of jfig showing an eepic export in progress is shown below:

If one wants to include LaTeX escaped commands within jfig text insert, for instance to include a mathematical formula one should set the text type to special via the drop-down menu box at the bottom of the jfig screen:

Tables are a common document inclusion, here is a simple example:
\documentclass[12pt]{article}
\usepackage{a4}
\begin{document}
\begin{center}
\begin{tabular}{|l|l|c|c|c|}
\hline
NAME & MAKE & HP & YEAR & PRICE \\
\hline \hline
GSX250 & Honda & 26 & 1981 & œ300 \\
\hline
GS250T & Honda & 26 & 1982 & œ250 \\
\hline
NSR250R & Honda & 60 & 1993 & œ1340 \\
\hline
NSR250R-SP & Honda & 65 & 1994 & œ2000 \\
\hline
KR1S & Kawasaki & 60 & 1989 & œ1250 \\
\hline
RGV250 & Suzuki & 60 & 1993 & œ1400 \\
\hline
RGV250-SP & Suzuki & 65 & 1994 & œ2400 \\
\hline
\end{tabular}
\end{center}
\end{document}
|
The table is opened with \begin{tabular} after that the parameters are specified, the parameters indicate how each column should be displayed. A pipe symbol ('|') is used to designate a vertical line so one is placed at the start so that the table will have a left edge, the next character is an 'l', this specifies that we would like this column to be left justified, the choices are (l - left, r - right, c - centre). So you can see how the column justification has been specified for each column and the columns have been separated by vertical lines and the there is a vertical line after the last column to close off the right edge of the table. Each line is terminated with a double backslash.
Next comes the table data itself, well actually, first we draw a horizontal line with the \hline directive to indicate that the table should have a top to it. Then comes the table headings, the '&' character is used as a column separator and each row is terminated with a double backslash (\\). Finally, we end the table with a horizontal line so it has a bottom to it and then close of the tabular directive and our center directive. The finished table will look like this when output:
A more advanced template created by Alan P Sexton is shown below:
\documentclass{article}
% for information about the packages, look in Lamport's book and in "The
% Latex Companion" by Goosens et al. For definitive info, the package
% files themselves are self documenting so you can download and read
% them from http://www.tex.ac.uk/ (here at Bham CS, we mostly only have
% the style files installed that have had the documention stripped from them
\usepackage{calc}
\usepackage{theorem}
\input{prooftree} % Paul Taylor's natural deduction
% prooftree package
\usepackage{amsmath} % These three lines are only for heavy maths
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{stmaryrd} % extra symbols
\usepackage{verbatim}
% \usepackage{longtable} % for tables that go over multiple pages
% Use xfig for figures and export them as eepic macros
\usepackage{epic}
\usepackage{eepic}
%\usepackage[ps,all]{xy}
% The following is to set up margins and paper size
\usepackage{vmargin}
\setpapersize{A4}
%% the args to setmarginsrb are as follows (note that the distance from
%% the top of the page to the first line of (non-header) text is
%% topmargin+headheight+headsep:
%% \setmarginsrb{leftmargin}{topmargin}{rightmargin}{bottommargin}%
%% {headheight}{headsep}{footheight}{footskip}
\setmarginsrb{35mm}{10mm}{25mm}{25mm}%
{12pt}{11mm}{0pt}{11mm}
% The following is to set up headers and footers conveniently
\usepackage{fancyheadings}
\pagestyle{fancy}
%\setlength{\headrulewidth}{0.4pt}
%\setlength{\footrulewidth}{0.4pt}
\chead{}
\lhead{}
\rhead{}
\lfoot{}
\rfoot{\tiny\thepage}
\cfoot{}
% The following allows putting comments in the margin: "\marginpar{comment}"
%\reversemarginpar
%\setlength{\marginparwidth}{24mm}
%\input{abbr} %This should be a list of user specific abbreviations and macros
\begin{document}
\title{XXXXX}
\author{XXXXX\\[.5ex]
School of Computer Science\\
University of Birmingham\\[.5ex]
XXXXX@cs.bham.ac.uk}
\date{}
\maketitle
\input{XXXXX} % use a separate file for each section of your document
\input{XXXXX}
\bibliographystyle{plain}
\bibliography{bib}
\end{document}
|
Well, that concludes the brief introduction to LaTeX. By searching the references and links in this page you should be able to find anything you need to know about LaTeX.
The Book LaTeX: A Document Preparation System, Second Edition by Leslie Lamport.
http://www-h.eng.cam.ac.uk/help/tpl/textprocessing/LaTeX_intro.html
Text Processing using LaTeX
http://www.sci.usq.edu.au/staff/robertsa/LaTeX/
LaTeX: from quick and dirty to style and finesse
by Prof Tony Roberts
Dept of Mathematics and Computing
University of Southern Queensland
3 August, 1998
http://www.maths.tcd.ie/~dwilkins/LaTeXPrimer/
Getting Started with LaTeX
By David R. Wilkins
2nd Edition
Copyright David R. Wilkins 1995
http://www.cs.cornell.edu/Info/Misc/LaTeX-Tutorial/LaTeX-Home.html
Beginning LaTeX tutorial
LaTeX on Athena
http://www.colorado.edu/ITS/docs/latex/FAQ/
Frequently Asked Questions
about using LaTeX at C.U.
These are just a few of the tutorials available on the Internet, there are a lot more, just try your favourite search engine.