T E X and L A T E X Document preparation tools This lecture will introduce software necessary to produce documents using L A T E X in the School of Computer Science. It will also show the basics of producing a first L A T E X document. What is T E X? 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 1 - TeX and LaTeX - 1 1 What Knuth was setting Setting and casting type Books were printed from many individual letters: But the printing technology of the day relied on casting single letters Ordinary text could be set by machine but Knuth s text was not ordinary. 1 - TeX and LaTeX - 1 2 1 - TeX and LaTeX - 1 3 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. 1 - TeX and LaTeX - 1 4 What is T E X? Its particular strengths are in: spacing in setting mathematics its automatic line breaking/justification algorithm It consists of about 300 macros: Example: A trivial T E X document Hello! \end 1 - TeX and LaTeX - 1 5 1
Advantages of T E X Flexibility Full-power programming language allows: automation of typesetting addition of macros built from primitive T E X macros Nicer output - especially for maths Produces nice paragraphs, formulas, tables, Easy global changes 1 - TeX and LaTeX - 1 6 Advantages of T E X 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 1 - TeX and LaTeX - 1 7 T E X is not WYSIWYG Disadvantages of T E X 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. 1 - TeX and LaTeX - 1 8 What is L A T E X? A set of T E X macros to make typesetting easier T E X has 300 primitive commands So-called Plain T E X defines 600 basic macros L A T E X 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. 1 - TeX and LaTeX - 1 9 Ubiquity of L A T E X L A T E X has been adopted by scientific and technical publishers as the format to receive manuscripts because L A T E X: 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 L A T E X2ε Many incompatible versions of L A T E X 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. L A T E X2ε is an attempt at standardisation. It is easy to spot a L A T E X2ε document: it starts with \documentclass not \documentstyle. 1 - TeX and LaTeX - 1 10 1 - TeX and LaTeX - 1 11 2
L A T E X also includes: What does L A T E X do? 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 Developing a L A T E X document Step 0: Ensure that your.login file has L A T E X enabled. Step 1: Prepare an input file for L A T E X 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) 1 - TeX and LaTeX - 1 12 1 - TeX and LaTeX - 1 13 Developing a L A T E X document Step 2: Run L A T E X 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: L A T E X will have produced an output file with the extension.dvi, eg: test1.dvi Developing a L A T E X 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} 1 - TeX and LaTeX - 1 14 1 - TeX and LaTeX - 1 15 A simple L A T E X 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 [ ] A simple L A T E X 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,... 1 - TeX and LaTeX - 1 16 1 - TeX and LaTeX - 1 17 3
A simple L A T E X 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$ A simple L A T E X 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 1 - TeX and LaTeX - 1 18 1 - TeX and LaTeX - 1 19 A simple L A T E X 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. A simple L A T E X 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} 1 - TeX and LaTeX - 1 20 1 - TeX and LaTeX - 1 21 L A T E X 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 L A T E X tables - 2 % A Simple Table \begin{tabular}{lcr} Date & : & \today \\ Time & : & 3 p.m. \\ Venue & : & Computer Science\\ \end{tabular} Column entries separated by & and lines ended by \\ 1 - TeX and LaTeX - 1 22 1 - TeX and LaTeX - 1 23 4
L A T E X 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 \\. L A T E X 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} 1 - TeX and LaTeX - 1 24 1 - TeX and LaTeX - 1 25 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} 1 - TeX and LaTeX - 1 26 What does this mean? \begin{figure}[hbpt] Including figures - 2 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. 1 - TeX and LaTeX - 1 27 What do these mean? Including figures - 3 \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. 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. 1 - TeX and LaTeX - 1 28 1 - TeX and LaTeX - 1 29 5
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 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 1 - TeX and LaTeX - 1 30 1 - TeX and LaTeX - 1 31 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 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 1 - TeX and LaTeX - 1 32 1 - TeX and LaTeX - 1 33 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} What to do next Copies of the two L A T E X 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. 1 - TeX and LaTeX - 1 34 1 - TeX and LaTeX - 1 35 6
Sources of further information There are numerous sources of information about L A T E X, ranging from the introductory to the obscure. The best places to start are on the School s local guide to using L A T E X and The Not So Short Introduction to L A T E X2ε (both linked from the module web page). 1 - TeX and LaTeX - 1 36 7