LaTeX An Introduction
November 2011CS A characterisation of LaTeX ● Very high quality typesetting – For traditional printed output ● Unrivalled mathematical typesetting (ref)ref ● A standard for scientific publications ● Used by publishers ● Based on TeX (faq)faq
November 2011CS The production cycle ● Edit (plain text editor) ● Process (perhaps more than once) ● Preview (pdf, usually) ● Repeat as required
November 2011CS Editing ● plain text – any editor ● gedit, vim, notepad, gwd, whatever ● Like html in that you use markup – editor may “know” about the mark-up and help
November 2011CS Marking it up ● 2 aspects to creating the document – The content ● What you write, diagrams, pictures etc – marking up ● partially structural (headings etc) ● much presentational (bold, italics etc) ● The machine follows the instructions to produce the document
November 2011CS Process ● Processing may reveal typos or logical errors in your document – think of this as checking and quality control ● not a hassle – it's a good thing! ● You may need to process the document 2 or even 3 times – some things can't be known the first time through ● e.g. – table of contents with page numbers – “Page n of m” ● LaTeX squirrels such information away in a series of files with different extensions
November 2011CS Additional processing ● There is additional processing you might do – Make an index – Use a fully cross referenced bibliography – Spell check
November 2011CS Files ● “The” document is in a file with ending.tex ● This is processed to produce a printable file – Traditionally postscript in.ps, via.dvi – Now PDF in a.pdf file ● “By-product” files.log logs the processing.aux auxiliary file – other stuff.toc table of contents is maintained here.lof list of figures (if you asked for one)
November 2011CS File naming ● All files have same name (before the extension) – This is the way LaTeX works ● don’t try to change it ● mydoc.tex mydoc.pdf – leaving mydoc.aux, mydoc.log etc. ● Don’t delete by-products until the end – They’re not a problem and they speed up the processing
November 2011CS Anatomy of LaTeX source ● Conventions – Characters with a special meaning ● $ & % # { } ● Of course, there are ways to get these if you need them – \command – {} and [] ● arguments (parameters) and options – environments ● begin and end
November 2011CS A simple example \documentclass{article} % Specifies the % document class \begin{document} % Start of text. \section{A Section Heading} This is a paragraph. This is a \emph{second} paragraph. \end{document} % End of document.
November 2011CS Simple example output ● The source is available – try itavailable
November 2011CS Big message ● Layout in the source has almost no effect on output – except that blank lines start a new paragraph ● Lay out the source for your convenience – Make it readable – Make it editable – You know about doing this by now for HTML, Java etc…
November 2011CS Commands ● Comes with most Linux/UNIX – Just use a command shell – Not with Ubuntu by default – easy to install (install the package tetex-common – and probably tetex-extra too) ● On Microsoft, use the “DOS” prompt – Utilities Command Prompt – On Aber machines, but you'll have to install it if you want it at home ( ● pdflatex mydoc – Or pdflatex mydoc.tex ● latex mydoc – Produces.dvi – Must be further processed
November 2011CS Document classes ● Several available – article – report – book – letter ● Others can be written – Journals – Conferences ● Determines presentation ● Controls applicability of constructs – chapter? – abstract? ref
November 2011CS Paragraphs and headings ● Blank lines indicate new paragraph – \par command can be useful occasionally ● \section{title} – \subsection{title} ● \subsubsection{title} – \paragraph{title} ● \subparagraph{title} ● \chapter{title} ● \part{title} ● \appendix{title}
November 2011CS Some commands ● \pagestyle{plain} ● \pagestyle{headings} ● \pagestyle{empty} ● \LaTeX \TeX \LaTeXe ● \footnote{An interesting footnote}
November 2011CS Some environments ● itemize – Bulleted list (the UL of html) ● enumerate – Numbered list (the OL of html) ● Environments “nest” – These will cause other style bullets to be printed – according to the document class
November 2011CS A list example \documentclass{article} \begin{document} \begin{enumerate} \item Eins \item Zwei \begin{itemize} \item this \item is \item nested \end{itemize} \item Drei \end{enumerate} \end{document}
November 2011CS Lists example ● The source is availableavailable
November 2011CS Tables ● tabular environment ● Must specify columns and alignment – And vertical lines ● Cells separated by & ● Rows separated by \\ ● A command for horizontal lines – \hline
November 2011CS Table Example \documentclass{article} \begin{document} \begin{tabular}{|r|l|} \hline Header & Row \\ \hline \hline A & Silly \\ \hline tabular & structure \\ \hline with & some lines missing\\ \end{tabular} \end{document}
November 2011CS Table Example Output The source is availableavailable
November 2011CS The table environment ● The tabular environment merely creates an object which will be treated as a character (i.e. not nicely spaced). ● Use the table environment around it to place table neatly ● e.g. \begin{table}[h] ● h means “put table here” – t for top, b for bottom, p for page of floats – Default is tbp
November 2011CS Additional lessons from the examples ● Commands can have more than one argument ● Source code layout does not influence LaTeX – But it can make source hard to read ● Some things happen automatically – Surprising things need commands ● \backslash, \verb+~+ (not \~), same for ^ ● \^ (etc) used for accenting characters
November 2011CS Document titles and TOC ● \maketitle – Takes info from preamble ● \title{} ● \author{} ● \date{} – Or makes it up ● \date{} ● \tableofcontents – Generated – Needs 2 (or more) runs
November 2011CS Title and TOC example \documentclass{article} \title{The House} \author{A.G. Mason} \begin{document} \maketitle \tableofcontents \section{Roof} \subsection{Loft} \section{Upstairs} \section{Downstairs} \end{document}
November 2011CS Title and TOC example output The source is availableavailable
November 2011CS Inserting pictures, images etc ● \includegraphics{myimage.png} – Need to have \usepackage{graphicx} at the top of the file ● Also possible: \pdfimage ● Can do scaling, positioning etc. ● Google it for options
November 2011CS Running LaTeX ● Free ● Originally UNIX based – Now available for PCs and Macs – … ● MiKTeX (the Windows version) claims to be 100Mb (installed) - download is only about 23 Mb
November 2011CS Documentation ● “The Not So Short Introduction to LaTeX2e” – Or LaTeX2e in 90 minutes ● lshort – Comes with distribution ftp://ftp.tex.ac.uk/tex-archive/info/lshort/english/lshort.pdf IS machines have it at: E:\Programs\Tex\texmf\doc\guides\short-english\lshort.pdf (and I’ve linked it from the CS10110 main page anyway)linked ● Other languages available (see here)here ● See also
November 2011CS Recommended steps 1.Process the simple example Perhaps also the others 2.Read and process sample2e.texsample2e.tex A nice quick overview 3.Skim “The Not So Short Introduction to LaTeX2e Don’t try to read/learn it Ignore the maths (if not a maths student) 4.Do the practical!
November 2011CS A useful header section (just copy to the top of your own file) \documentclass[a4paper, 12pt]{article} % ******* Set normal page margins ******** \setlength{\oddsidemargin}{0in} \setlength{\evensidemargin}{0in} \setlength{\textwidth}{6.2in} \setlength{\topmargin}{-0.3in} \setlength{\textheight}{9.8in}
November 2011CS Other recommended reading: Get your own copy for Windows For Ubuntu Install package texlive-latex-base