tex and l tex document preparation toolspjh/modules/current/06991/lectures/latex/latex1_slides.pdfa...
TRANSCRIPT
06-06991 – Research Skills
TEX and LATEX
Document preparation tools
This lecture will introduce software necessary to produce documents using
LATEX in the School of Computer Science. It will also show the basics of producing a
first LATEX document.
06-06991 – Research Skills
1 - TeX and LaTeX - 1 1
What is TEX?
A powerful typesetting system designed for scientific documents.
Created by Donald Knuth in reaction to the poor phototypesetting of the second edition of his The Art of Computer Programming.
Intended to
– allow production of books with reasonable effort
– give same result on all computers now and in the future
06-06991 – Research Skills
1 - TeX and LaTeX - 1 2
What Knuth was setting
But the printing technology of the day relied on casting single letters …
06-06991 – Research Skills
1 - TeX and LaTeX - 1 3
Setting and casting type
Books were printed from many individual letters:
“Ordinary” text could be set by machine but Knuth’s
text was not “ordinary”.
06-06991 – Research Skills
1 - TeX and LaTeX - 1 4
Setting and casting type
Books were set by essentially typing the text on a
Monotype type setter:
This produced instructions on
paper tape to a casting machine:
Monotype caster in action (but
with the volume turned down)
Knuth supplied the commands to
the caster.
06-06991 – Research Skills
1 - TeX and LaTeX - 1 5
What is TEX?
Its particular strengths are in:
– spacing in setting mathematics
– its automatic line breaking/justification algorithm
It consists of about 300 macros:
Example: A trivial TEX document
Hello! \end
06-06991 – Research Skills
1 - TeX and LaTeX - 1 6
Advantages of TEX
Flexibility
Full-power programming language allows:
– automation of typesetting
– addition of macros built from primitive TEX macros
Nicer output -
– especially for maths
– Produces nice paragraphs, formulas, tables, …
Easy global changes
06-06991 – Research Skills
1 - TeX and LaTeX - 1 7
Advantages of TEX
Well-programmed - Knuth’s literate programming
Architecture independent
– works the same on any hardware/OS
Free
Extended to use any PostScript font
Can incorporate PostScript code to add fancy graphics and effects, e.g. rotating and scaling text, including graphic objects
06-06991 – Research Skills
1 - TeX and LaTeX - 1 8
Disadvantages of TEX
TEX is not WYSIWYG
Designed for traditional typesetting
– fancy typesetting might get complicated and cumbersome.
Not easy to learn
– needs to memorize many commands but a lot of good documentation is available.
06-06991 – Research Skills
1 - TeX and LaTeX - 1 9
What is LATEX?
A set of TEX macros to make typesetting easier
TEX has 300 primitive commands
So-called Plain TEX defines 600 basic macros
LATEX is much larger, containing:
– different structuring macros for typesetting different types of documents: letter, article, report, book, ...
– packages – user-defined macros bundles for specific tasks, e.g. creating appendices.
06-06991 – Research Skills
1 - TeX and LaTeX - 1 10
Ubiquity of LATEX
LATEX has been adopted by scientific and technical publishers as the format to receive manuscripts because LATEX:
– is widely available
– because the style of documents can be easily changed by changing parameters
– incorporating multiple documents/chapters is very easy
– indexes, reference lists etc. are easy to create
06-06991 – Research Skills
1 - TeX and LaTeX - 1 11
LATEX2e
Many incompatible versions of LATEX were developed, causing problems for system maintainers (who had to keep several versions running).
It wasn’t always clear what version a package had been written for.
LATEX2e is an attempt at standardisation.
It is easy to spot a LATEX2e document: it starts with \documentclass – not \documentstyle.
06-06991 – Research Skills
1 - TeX and LaTeX - 1 12
What does LATEX do?
LATEX also includes:
– facility to automatically produce a table of contents, list of figures, list of tables, footnotes, header, title page, bibliography
– font management macros, e.g. \textit \large, \textsc
– easy creation of tables
– easy-to-use macros for complex mathematical formulas
– excellent cross-referencing macros
06-06991 – Research Skills
1 - TeX and LaTeX - 1 13
Developing a LATEX document
Step 0: Ensure that your .login file has LATEX enabled.
Step 1: Prepare an input file for LATEX using your favourite editor.
The input file should be plain text, with .tex as its extension, eg: test1.tex
OR: Use Texmaker under linux (see handout)
06-06991 – Research Skills
1 - TeX and LaTeX - 1 14
Developing a LATEX document
Step 2: Run LATEX under Unix with your input file as the argument to the command, eg:
latex test1.tex
If errors are reported, return to Step 1 and correct them; otherwise:
LATEX will have produced an output file with the extension .dvi, eg: test1.dvi
06-06991 – Research Skills
1 - TeX and LaTeX - 1 15
Developing a LATEX document
Step 3: Convert the .dvi output into a form suitable for viewing or driving a PostScript printer, for instance using the translator:
xdvi test1.dvi
dvips will produce an PostScript file with the extension ps, eg: test1.ps
or dvipdf test1.dvi
Step 4: Print the PostScript file on your chosen printer, eg:
lpr –Prothko test1.{ps,pdf}
06-06991 – Research Skills
1 - TeX and LaTeX - 1 16
A simple LATEX document - 1
\documentclass[12pt]{article}
% Use PS palatino fonts \usepackage{palatino}
\begin{document}
Hello!
\end{document}
Compulsory arguments of macros are enclosed in { }
Optional arguments are enclosed in [ ]
06-06991 – Research Skills
1 - TeX and LaTeX - 1 17
A simple LATEX document - 2
Commands can have a number of optional arguments.
At most one compulsory argument is allowed for each command and follows optional arguments.
The macro \documentclass{} is the first thing you have to write. Its only mandatory argument is the type of document. Its optional argument is a list of comma-separated options
e.g. a4paper, 1Opt,11pt,12pt, landscape,...
06-06991 – Research Skills
1 - TeX and LaTeX - 1 18
A simple LATEX document - 3
The macro \usepackage{<package-name>} loads additional macros from the file:
<package-name>.sty
Watch out for reserved characters.
These have to be represented by:
# \# $ \$
% \% & \&
_ \_ \ $\backslash$
06-06991 – Research Skills
1 - TeX and LaTeX - 1 19
A simple LATEX article - 1
\documentclass[12pt]{article}
% The document preamble
\usepackage{times} % Use PS times fonts
% Details of the titlepage
\title{A Very \textsc{Simple} Document Indeed}
\author{\textit{W. Clinton and M. Lewinsky}}
\date{\today} % Use the system date
06-06991 – Research Skills
1 - TeX and LaTeX - 1 20
A simple LATEX article - 2
\begin{document}
\maketitle
\section{Introduction}
This is the first paragraph.
Paragraphs must end with an empty line this like this.
This is another paragraph.
Let's force a line break: \\
Now, we’d like to continue with this paragraph.
06-06991 – Research Skills
1 - TeX and LaTeX - 1 21
A simple LATEX article - 3
\noindent This is a non-indented paragraph.
\subsection{Aim of this lecture}
Blah, \dots %'\dots' makes 3 nice dots
A footnote looks
this \footnote{I'm a footnote.}
\section{Conclusion}
This is it! Easy!!!
\end{document}
06-06991 – Research Skills
1 - TeX and LaTeX - 1 22
LATEX tables - 1
Each table begins with: \begin{tabular}{<table-specification>}
Table specification “lcr” means:
– 3 columns
– 1st column: left justified
– 2nd column: centred
– 3rd column: right justified
Column entries separated by “&” and lines ended by “\\”
06-06991 – Research Skills
1 - TeX and LaTeX - 1 23
LATEX tables - 2
% A Simple Table
\begin{tabular}{lcr}
Date & : & \today \\
Time & : & 3 p.m. \\
Venue & : & Computer Science\\
\end{tabular}
06-06991 – Research Skills
1 - TeX and LaTeX - 1 24
LATEX tables - 3
The table specification in the following example uses “|” to separate each column by a vertical line \begin{tabular}{|c|p{8cm}|}
– the first column is centered.
– the second column is justified and is 8 cm wide.
Horizontal lines in the table are specified by adding \hline after the line ending command “\\”.
06-06991 – Research Skills
1 - TeX and LaTeX - 1 25
LATEX tables - 4
% A table with border and
% fixed column width
\begin{tabular}{|c|p{8cm}|}\hline
\textbf Phrasal Verb & \textbf Meaning \\ \hline
fish for & If you {\textbf fish for}
information or praise, you try
and get it from someone in an
indirect way. \\ \hline
% one entry omitted from slide
\end{tabular}
06-06991 – Research Skills
1 - TeX and LaTeX - 1 26
Including figures - 1
The first thing is, of course, to have a figure to insert.
\begin{figure}[hbpt]
\begin{verbatim}
procedure CreateEntry (NextTerm : Termptr;
CopyEntry : EntryRec);
end; {of CreateEntry}
\end{verbatim}
\caption{Pascal algorithm}
\label{pascal_alg}
\end{figure}
06-06991 – Research Skills
1 - TeX and LaTeX - 1 27
Including figures - 2
What does this mean?
\begin{figure}[hbpt]
The following text is a figure.
h: place here if there is room
b: place at the bottom of a text page
p: place on a “page of floats”
t: place at top of next text page
The figure isn’t
inserted at exactly
the point in the text
where this command
is placed.
06-06991 – Research Skills
1 - TeX and LaTeX - 1 28
Including figures - 3
What do these mean?
\caption{Pascal algorithm}
The text that will appear with the figure. Note, you don’t have to include (e.g.) “Figure 2”
\label{pascal_alg}
A label by which we can refer to this figure within the document.
06-06991 – Research Skills
1 - TeX and LaTeX - 1 29
Including figures - 4
We are certain to want to refer to figures from within our text, but:
– we may add more figures or remove figures
– we may move the order of figures around
To avoid manually renumbering figures, we use in the text:
...given in Figure~\ref{pascal_alg}.
This automatically adds (usually) a number into the text.
06-06991 – Research Skills
1 - TeX and LaTeX - 1 30
Graphics formats - 1
What if your figure is not text – e.g. a photo or line drawing?
Resolution-independent vector graphics, e.g.
– EPS – Encapsulated PostScript
– WMF – Windows Meta File
for (e.g.)
– block diagrams
– flow charts
– diagrams with text labels
06-06991 – Research Skills
1 - TeX and LaTeX - 1 31
Graphics formats - 2
Pixel-based raster-graphic formats, e.g.
– PNG – Portable Network Graphics
– TIFF – Tagged Image File Format
– JPEG – [Joint Photographic Experts Group]
– GIF – Graphics Interchange Format
for (e.g.)
– screen shots
– photos
– scanned images of pages
06-06991 – Research Skills
1 - TeX and LaTeX - 1 32
Graphics formats - 3
Note JPEG and GIF are “lossy” compression formats – continual editing can degrade the images.
Prefer non-lossy formats, e.g. PNG.
Note: stretching JPEGs doesn’t work well!
but stretching vector
graphic images does
06-06991 – Research Skills
1 - TeX and LaTeX - 1 33
Adding a PostScript figure - 1
Adding a PostScript file is only a little more complicated than adding a normal figure.
Step 1: Prepare a graphic using your favourite package
Step 2: Save or convert your graphic in a suitable format, eg:
repr_terms.pdf
06-06991 – Research Skills
1 - TeX and LaTeX - 1 34
Adding a PostScript figure - 2
In the preamble, add the following: \usepackage{graphicx}
Then the illustration can be added to your text by using \begin{figure} as before: \begin{figure}
\includegraphics{repr_terms}
\caption{PDF diagram}
\label{pdf_diagram}
\end{figure}
06-06991 – Research Skills
1 - TeX and LaTeX - 1 35
What to do next
Copies of the two LATEX documents used in the lecture are available from the module web page as: example1.tex
example2.tex
Make copies of these and use your copies to:
– create .dvi files
– create .ps or .pdf files
– print .ps or .pdf files to a printer
– edit the files to add more text and features.
06-06991 – Research Skills
1 - TeX and LaTeX - 1 36
Sources of further information
There are numerous sources of information about LATEX, ranging from the introductory to the obscure.
The best places to start are on the School’s
– local guide to using LATEX
and
– The Not So Short Introduction to LATEX2e
(both linked from the module web page).