Introduction o A simple introductory hands-on course. I assume that you know: - an editor - basic Unix commands o Latex: a text formatter: not a WP o Freely distributable o written by Leslie Lamport, built upon Knuth's tex o A division of labour - composition: author and editor - formatting & style: pre-defined by the program o latex borrows heavily from Scribe - declarative not procedural - descriptive commands 1 Document Parts o "documentstyle - [options]: if multiple, separate options with commas - {style}: one of article, report, book, uwoletter or letter o Title information - Title: multiple lines separated by \\ - Author: multiple lines separated by \\ - Date: optional _ today's used if not included o "begin-document": mark the start of text o "maketitle: place the title information o Text body o "end-document": Always the last line. 2 Article Template "documentstyle [11pt] -article" "title-"bf Your Title here"" " "author-Your Name, DEPT""your@email.address" % "date-1996-03-18" % remove comment to produce the given date. "begin-document" "maketitle % Produces the title. % ... Document Body ... "end-document" % Always the last command 3 Compiling 4 Exercise #1 1. Copy exercise files: tar -xf /usr/doc/courses/latex/ex.tar 2. Convert sample.tex to a .dvi file: latex sample.tex 3. Observe the files produced: ls sample.* 4. Convert the sample.dvi file into PostScript: dvitps -O sample.ps sample.dvi 5 Files Produced by latex and dvitps (results from exercise) 6 Previewing: Saving time and paper. dvi2tty a very rough screen approximation from the .dvi file: o shows page and line breaks o can be hard to read o doesn't display included PostScript fig- ures o can be used to produce readable tty output with modifications to the input file. o Try it: dvi2tty sample.dvi xdvi A fairly accurate rendition of the .dvi file for X-windows based screens. o Doesn't capture included PostScript fig- ures ghostview A rough to very good rendition (screen resolution dependent) of the .ps file. Use- ful if you have included PostScript figures. 7 dvi2tty Example Replace with a printed copy of sample.text 8 xdvi Example Replace with a printed copy of an xdvi screen or two. 9 ghostview Example Replace with a printed copy of a ghostview screen or two. 10 300 dpi Laser Printer Example Replace with a printed copy of sample.ps 11 Compiling & Previewing Summary o Convert a latex file into D__ev_ice I_ndependent (.dvi) format: latex filename.tex o Convert a .dvi file into PostScript dvitps -O filename.ps filename.dvi o Convert a .dvi file into PostScript and send it to the printer: dvitps filename.dvi _ lpr -Pps o Preview a .dvi file on the screen dvi2tty filename.dvi o Preview a .dvi or .ps file on an X-windows screen: xdvi filename.dvi & ghostview filename.ps & 12 Basic Formatting The bulk of most texts is words which are formed into paragraphs and in latex these are, for the most part, typed without change. There are a few things that you have to keep in mind though: o Extra intra-word spaces are generally ig- nored o Paragraphs are delimited by a blank line. o Some characters with special meaning to latex: # $ % & ` - " " ^ " The first seven of these can be included in your text by quoting with a backslash: ". The others require more sophisticated mechanisms. Characters like +=_<> are used primarily in mathematical formulas. 13 o Dashes: - Produces a short dash for hyphens as in part-time. -- Produces a longer dash used in number ranges: 45-54 --- Produces a dash used as punctuation_ like that o latex commands start with a backslash fol- lowed by a number of characters_case is significant: "section is different from "Section. o Manditory arguments to commands are enclosed in braces: "section-Preface" Optional arguments are enclosed in square brackets: "item [Characteristic] o Double quotes are made using `` and ''. Note that the editor emacs will generate this correctly when you type " when edit- ing a file with the .tex extension. 14 Environments o Environments are ways of limiting the scope of a latex command to a certain range. o Environments can be delimited with curly braces: -"env-name ...text..." or as "begin-env-name" ... "end-env-name" pairs. Font changing environments o -"em...text..." to delimit emphasised text. (Italicized, unless the surrounding text is already italicized.) o Other common font changes are made in a similar way: {\bf Bold face} produces Bold face {\tt Typewriter} produces Typewriter * {\sc Small Caps} produces Small Caps * font not available in Slide mode 15 Sectioning Commands \section{Section Name} Start a new numbered section. eg. 3. Section Name \subsection{Sub-Section Name} Start a new num- bered sub-section. eg. 3.2. Sub-Section Name \paragraph{Paragraph Name} Start a new num- bered sub-sub-section. eg. 3.4.2. Paragraph Name o Each of the sectioning commands can be followed by a star "*" to suppress the numbering. o If a table of contents is produced section names are included in it. 16 Input Character Summary The input file can contain o Upper- and lowercase letters o the ten digits o the 16 punctuation characters: . : ; , ? ! ` ' ( ) [ ] / * @ o the characters "_ < >" are only available in mathematics mode. (Bracket them with $ characters.) 17 Input Characters, continued o The following seven characters are special and should be quoted with a backslash to use them in running text: # Is used in defining new commands and environments $ Is used to bracket mathematics mode % Introduces a comment: latex ignores the reset of the line __Is the subscript command {} Delimit manditory arguments and scope o The following characters can usually only be used in a "verb command or a verbatim environment. " Marks a space that can't be split over a line break ^ Is the superscript command \ Introduces a latex command 18 Exercise #2: Making your own Text There are a number of latex "template" files on /usr/doc to help you get started: article-template.tex The most useful and com- monly used for creating short articles. slide-root-template.tex Base file for creat- ing a slide show. slides-template.tex A template for the slides in the show. figure-template.tex Gives the commands needed to include a PostScript figure or diagram into a latex document using the psfig.tex macros. letter-template.tex Latex commands to help you get started on a letter to be printed on UWO letterhead. It uses the University date style: 1996 10 19. 19 Exercise #2, continued 1. Copy the article-template.tex file into your disk area and customize it for yourself. Add in your name, department and e-mail address. 2. Copy your customized article-template.tex into a file named exercise2.tex 3. Edit the file exercise2.tex and insert the file raw.txt into the buffer just before the "end-document" line. 4. Edit the file by adding latex commands to make the output look like the following pages. You will have to add title, name, sectioning and emphasis commands to the text. 5. Send the resulting file to the laser printer for marking! 20 ex-prelim.ps goes here 21 Errors o T ex and latex error messages are notori- ously hard to read. o Latex isn't too bright about files. If it can't find a file it will doggedly keep asking for it. The quick way out is to type null which is a file that always exists. Then type an "x" to get out of the program completely. o Many messages are warnings: Overfull "hbox (2.62048pt too wide) in paragraph at lines 278--282 This one means that latex couldn't find a good spot to break a line: - Bracket the offending paragraph with "sloppy and "fussy declarations, - rewrite the paragraph a bit or - if the amount is small, don't worry that 1 your margins aren't perfect (2pt = ____th 36 of an inch). 22 Errors, continued o Fatal errors stop the processing: LaTeX error. See LaTeX manual for explanation. Type H for immediate help. ! Environment verbatum undefined. "@latexerr ...for immediate help.""errmessage -#1" l.120 "begin-verbatum" ? The message gives you input line number and tries to give you the context. You can try to continue by typing a Return or exit immediately to fix the problem by typing an x. o The most common errors are: - A mis-spelt command or environment name - Improperly matched `{' and `}' or miss- ing "end command. - Trying to use one of the ten special characters # $ % & ` - " " ^ " as an or- dinary printing character. - A missing command argument. 23 Lists o There are 3 standard list making environ- ments: itemize bulleted points enumerate numbered items description user defined item marker o Each is used in the same way as the ex- ample below: "begin-itemize" "item This is the first point "item And this is the second "end-itemize" o For a description, each "item command is followed by a piece of text in square brackets: "item [Habitat] A shoal of bass. o List environments can be nested. 24 Display Environments o The quote environment is used for a series of short (one line) quotations. Each quote is separated from the next by a blank line. o The quotation environment is used to quote a paragraph or paragraphs of text. Para- graphs are separated by blank lines. o The verse environment is for poetry. You mark the end of line with the "" command. o The verbatim environment is used to dis- play text exactly as it appears in the input file. A typewriter font is used. No latex comands operate (except "end-verbatim"). o The verb command is used to include short sequences exactly as typed into the run- ning text. It uses the first character after the command as a delimiter. The text between delimiters must be kept on the same line: "verb+"any old thing"$% is ok+ 25 Footnotes The "footnote command generates a footnote at the bottom of the page where it is encoun- tered. Its argument is the text of the foot- note. Remember to put the "footnote com- mand immediately after the place that you want the footnote marker to occur. Don't add an intervening space. When life"footnote-In its most literal sense" deals you... * When life deals you... The document style determines what symbols are used to mark a footnote. Most styles use a small superscripted number. * In its most literal sense 26 Exercise #3: More Fixes 1. Copy exercise2.tex to exercise3.tex. 2. Add latex commands to exercise3.tex to make it look like the following pages. You will have to use o itemize, o description, o verbatim, o quotation and o footnote to complete this edit. 3. Send the result to the laser printer for marking. 27 ex-final.ps goes here 28 Cross References In larger documents like manuals, cross refer- ences can be an important part of the work. Latex provides some commands to make this task easier: o The "label-tag" command is used to give a name to a certain location in the docu- ment. o The "ref-tag" command inserts the sec- tion number of the tag into the text. o The "pageref-tag" command is used to in- sert the page number of the tag into the text. To handle forward references you may have to run latex twice to get all the "ref and "pageref commands right. 29 Making Tables: The tabular environment "begin-center" "begin-tabular"-l_r_r_r" "hline Item &CCS price &PST & Total "$"" "hline "hline "multicolumn-4"-c"-Medium Cost Option" "" "hline SUN IPX 19'' colour, 16MB &11,312 &904.96 &12,216.96"" "hline "hline Sun 1.3GB disk &4,310 &344.80 &4,654.80"" "hline CD-ROM player &729 &58.32 &787.32 "" "hline "hline Total & & &-"bf 17,659.08" "" "hline "hline "end-tabular" "end-center" ________________________________________________________________________________ __Item______________________________||_CCS_price__||____PST__||______Total_$____ ________________________________________________________________________________ ___________________________Medium_Cost_Option___________________________________ __SUN_IPX_19"_colour,_16MB__||____________11,312__||__904.96__||__12,216.96_____ ________________________________________________________________________________ __Sun_1.3GB_disk_________________||_________4,310__||_344.80__||____4,654.80____ __CD-ROM_player________________||_____________729__||__58.32__||______787.32____ ________________________________________________________________________________ __Total_____________________________||______________||_________||17,659.08______ ________________________________________________________________________________ 30 Simple Indexes o Useful in longer documents like book and report. o In the preamble/headers section include the command "makeindex. o Just before the "end-document" line add the command "include-index". o Mark words in the body of your text with the "index-word" command. o When compiling, use the following sequence latex document.tex makeindex -o index.tex document.idx latex document.tex o Note that latex is run twice to get the latest entries incorporated. 31 Including PostScript files The following code (from /usr/doc/figure-template.tex can be used to include a (well behaved) PostScript file into a latex document: "begin-figure" "centerline- "psfig-figure=.ps,width=4.1in"" % ^name of the PostScript figure % (Should be created without showpage) "vspace-.25in" "caption-" "label-" % ^title ^name ("ref-" &/or "pageref-"to refer) "end-figure" Here's a little PostScript: 32 Headers, another look o Useful options - 12pt - fullpage - screen & dvi2tty o style settings o Exercise: redo exercise3.tex with fullpage and 12pt type. 33 Slides Slitex is a version of latex that provides some special features to make the production of overhead slides easier. The slides for this course were produced using slitex. Here is a simple procedure for getting started into slide production: 1. Copy the template file slide-root-template.tex into your disk area, giving it the name of your slide show. This file is where the global declarations about your slides are stored. If you are making b&w slides, you probably don't need to edit this file. 2. Also copy in the file slides-template.tex from the /usr/doc area as slides.tex. This is where the actual contents of the slides is entered. It is like the body part of an ordinary latex document. 3. Each slide begins with a "begin-slide"-" command and ends with a "end-slide" com- mand. Most latex commands can be put in between. 4. Don't forget to use the command slitex when compiling the slides. 34 Documentation This course has just scratched the surface of latex. You should now be able do a few things, but for any serious work you should explore the documentation available. o Cheap (on-line, on julian.uwo.ca) man latexintro This command will dis- play lots of practical notes about using latex at UWO. /usr/doc/latex-local.ps This manual con- tains things that are not explained in the Users Guide since they are likely to be site dependent. /usr/doc/essential-latex.ps Send this to a PostScript printer for a good basic in- troduction too latex. It hasn't been customized for UWO yet. o A few 10s of $ Latex Users Guide and Reference Manual by Leslie Lamport. This book costs a bit at the campus bookstore, but is essential for doing serious work with latex. 35