You are on page 1of 12

A L TEX Tutorial Charles Taragin September 25, 2005

A Introduction to LTEX

A What is L TEX?
A L TEX is a computer program for typesetting documents. It takes a computer le, A prepared according to the rules of LTEX and converts it to a form that may be printed on a high-quality printer, such as a laser writer, to produce a printed document of a quality comparable with good quality books and journals. Simple documents, which do not contain mathematical formula or tables may be produced very easily: eectively all one has to do is to type the text straight in (though observing certain rules relating to quotation marks and punctuation dashes). Typesetting mathematics A is somewhat more complicated, but even here LTEX is comparatively straightforward to use when one considers the complexity of some of the formulas that it has to format and the large number of mathematical symbols which it has to produce.

A How Does L TEX dier from Microsoft Word?

Microsoft Word is an example of what is known as a What You See Is What You Get (WYSIWYG) text editor. The spacing, typeset, and font that appear in Word are exactly what appears when you print your document. A L TEX, to the contrary, is a markup language similar to HTML. Raw text is modied using functions called control sequences and saved in a le with a .tex sux. A The L TEX compiler takes this .tex le and transforms it into a nicely formatted .dvi 1 le that can easily be printed or transformed into a pdf le. A L TEX has two distinct advantages over Word. First, while Word has diculty A handling large documents (like dissertations), LTEX can easily handle documents of
Special thanks to Samara Potter for editing this document. Much of this document was borrowed A from David R. Wilkins Getting Started with L TEX. See References for further details. 1 .dvi stands for device independent a format that may be easily printed by most printers.

2 GETTING STARTED

arbitrary length. Second, Words Equation Editor is extremely cumbersome when A compared to LTEXs ability to construct sophisticated equations.
A How Does L TEX dier from TEX?
A L TEX is one of a number of dialects of TEX, all based on the version of TEX created A by D. E. Knuth which is known as Plain TEX. L TEX (created by L. B. Lamport) is one of these dialects. It is particularly suited to the production of long articles and books, since it has facilities for the automatic numbering of chapters, sections, A theorems, equations etc., and also has facilities for cross-referencing. While L TEX and A X contains many commands that arent available in TEX share many commands LTE A TEX. As such, L TEX is probably one of the most suitable versions of TEX for beginners to use.

Getting Started

A This section covers how to install the LTEX compiler and front-end on your personal 2 computer .

A Installing the L TEX Compiler


A The L TEX compiler may be installed on virtually any operating system you can A name. Excellent installation instructions for the Windows L TEX compiler MiKTeX, are available from http://www.ctan.org/tex-archive/systems/win32/miktex/setup/install.html

Choosing a Text Editor


A While a L TEX document can be composed in any text editor (e.g. Word, WordA pad, Notepad), some editors have been customized for use with L TEX. Two of the more popular editors are WinEdt (Windows only, $40 registration fee) and Emacs (most operating systems, free). While both editors oer similar features, WinEdt is generally considered easier to use3 . Excellent instructions for installing Emacs on a

Note that this isnt strictly necessary; many of the departments computers and servers have all A the requisite software installed. If you want to use L TEX without installing it on your computer, simply open up any text editor (including Word), type in your document with the appropriate control sequences, and save it as a text le with a .tex sux. This le can be then transferred to A a computer with the L TEX compiler, and compiled using the command latex <file.tex>, where A <file.tex> is the upload .tex le. However, if possible, I would recommend installing L TEX on your home computer. It will likely prevent many headaches. 3 Emacs documentation may be found at http://www.lib.uchicago.edu/keith/tcl-course/emacs-tutorial.html.

2 GETTING STARTED

Windows machine are available at http://www.math.auc.dk/~dethlef/Tips/preparation.html , and trial copies of WinEdt may be downloaded from http://www.winedt.com. Important: I recomA mend installing LTEX before installing any text editor. Both editors should automatA ically detect LTEX if it is installed rst. WinEdt and Emacs, when used correctly, can greatly reduce your typing mistakes A (a valuable asset when coding in LTEX). Here are some useful things that you can do with either editor:
A Compile L TEX documents from within your editor4

Place the cursor one space to the right of any right bracket (or on a left bracket) to check for a matching left bracket (right bracket).
A Use the pull down menus (or corresponding key-bindings) to insert various LTEX control sequences (e.g. Greek letters, typefaces, equations, lists, section headings).

Use the version control systems (sometimes referred to as revision control system) to track changes you have made to your program over time. See the WinEdt or Emacs documentation for more about these systems. Use the rectangle commands to cut and paste rectangular areas of text5 . This is something that you just cant do in Word, and is extremely useful for A manipulating individual columns of information (like LTEX tables). See the WinEdt or Emacs documentation for more about these commands.
A A Your editor is only acting as a front-end for L TEX L TEX must still be installed on your computer. 5 All the characters between a certain pair of columns, in a certain range of lines. 4

A 3 A TYPICAL L TEX INPUT FILE

A A Typical LTEX Input File

A In order to produce a document using LTEX, we must rst create a suitable input A le on the computer. We apply the LTEX program to the input le and then use A the printer to print out the so-called DVI le produced by the L TEX program (after rst using another program to translate the DVI le into a form that the printer A can understand). Here is an example of a typical LTEX input le6 :

1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28.

\documentclass[12pt]{article} \begin{document} The foundations of the rigorous study of \textit{analysis} were laid in the nineteenth century, notably by the mathematicians Cauchy and Weierstrass. Central to the study of this subject are the formal definitions of \textit{limits} and \textit{continuity}. Let $D$ be a subset of $\bf R$ and let $f \colon D \to \textbf{R}$ be a real-valued function on $D$. The function $f$ is said to be \textit{continuous} on $D$ if, for all $\epsilon > 0$ and for all $x \in D$, there exists some $\delta > 0$ (which may depend on $x$) such that if $y \in D$ satisfies \begin{eqnarray*} |y - x| < \delta \end{eqnarray*} then \begin{eqnarray} |f(y) - f(x)| < \epsilon. \end{eqnarray} One may readily verify that if $f$ and $g$ are continuous functions on $D$ then the functions $f+g$, $f-g$ and $f.g$ are continuous. If in addition $g$ is everywhere non-zero then $f/g$ is continuous. \end{document}

A As you can see, aside from the odd bracket or dollar sign, LTEX code is fairly readable. Although most characters occurring in this le have their usual meaning, there are
6

Note: Numbers in left column are for reference only and should not be included in your .tex

les

A 3 A TYPICAL L TEX INPUT FILE

A special characters such as \, $, { and } which have special meanings within LTEX. In particular, there are sequences of characters which begin with a backslash \ which are used to produce mathematical symbols and Greek letters and to accomplish tasks such as changing fonts. These sequences of characters are known as control sequences. A When we apply L TEX to these paragraphs we produce the text

The foundations of the rigorous study of analysis were laid in the nineteenth century, notably by the mathematicians Cauchy and Weierstrass. Central to the study of this subject are the formal denitions of limits and continuity. Let D be a subset of R and let f : D R be a real-valued function on D. The function f is said to be continuous on D if, for all > 0 and for all x D, there exists some > 0 (which may depend on x) such that if y D satises |y x| < then |f (y) f (x)| < . (1) One may readily verify that if f and g are continuous functions on D then the functions f + g, f g and f.g are continuous. If in addition g is everywhere non-zero then f /g is continuous.
A Lines 1, 2, and 25 illustrate some important properties of LTEX control sequences A All L TEX control sequences begin with a \ . A L TEX control sequences enclose required parameters with curly brackets. A The L TEX control sequence \begin{} is always matched with an \end{} control sequence later in the document.

Optional parameters are usually included in square brackets prior to required parameters.
A Every L TEX document must begin with a

\documentclass{} statement and contain a \begin{document} and

A 4 COMPILING A L TEX DOCUMENT

\end{document} statement.
A The \documentclass{} statement allows you to specify the type of LTEX document you wish to create. Parameters for this control sequence include

article for articles in scientic journals, presentations, short reports, program documentation, invitations, ... report for longer reports containing several chapters, small books, PhD theses, ... book for real books slides for slides. The class uses big sans serif letters. You might want to consider using FoilTEX or the excellent Prospect package instead.
A Coding Mathematical Formulae in LTEX
A An important control sequence is the $ , which is used to activate LTEXs math mode. A Math mode is a special environment inside LTEX where whitepaces arent recognized, all numbers and letters are printed in italics, and a whole new set of control sequences are available. For instance, the control sequence

\delta which prints the greek letter , may only be used in math mode. While the $ is useful for embedding equations within text (see line 14), sometimes it useful for equations to stand out. In these instances, you will activate math mode using the control sequence \begin{eqnarray} ... \end{eqnarray}
A where the ellipses signify your equation (see lines 20-22). Notice that LTEX automatically numbers each equation, and that numbering may be suppressed by using * (see lines 16-18).

A Compiling a LTEX Document Open a blank document in your favorite editor and input your text along with A the appropriate LTEX code. Both WinEdt and Emacs require your document to be saved with a .tex sux.

A 4 COMPILING A L TEX DOCUMENT

In WinEdt, select Accessories TeXify . This will open a terminal where your A L TEX code will be compiled. If your code is error-free, the terminal window A should close, and WinEdt will automatically display the .dvi le LTEX generated in the viewer Yap. During the compilation process, WinEdt generates the following les on < f ile >.tex < f ile >.tex.bak : This a backup copy of < f ile >.tex, serves no real purpose, and may deleted with impunity.
A < f ile >.dvi : This le is the output from a successful L TEX compilation. Use this le to make sure the document is correctly formatted and to print drafts. This le may also be deleted with impugnity, unless you want to generate a pdf le. A in Emacs7 , select Command LaTeX. If you havent saved your LTEX le, Emacs will prompt you to save your document. Emacs will then compile your A document using LTEX. If Emacs doesnt report any compilation errors, select Command View to view your < f ile >.dvi le. Like WinEdt, Emacs always generates a backup le (designated < f ile >.tex), as well as a < f ile >.dvi if A the L TEX compilation was successful. Feel free to delete either, although the < f ile >.dvi le should be kept if you intend to generate a pdf document.

(Recommended) Generate a pdf le8 . In WinEdt, choose Accessories PDF PDF TeXify. A terminal will open where your pdf le will be compiled. If there are no errors, this terminal window should close automatically and < f ile >.pdf le should now exist in the same directory as < f ile >.tex . Note: this command compiles your document using MiKTeX before creating the pdf le, so you dont need to execute TeXify before PDF TeXify9 . In Emacs, choose Command LaTeX PDF. Emacs will attempt to compile your pdf le and report the result. If successful, < f ile >.pdf le should now exist in the same directory as < f ile >.tex .
Assuming the Auctex package is also installed. Why do this? While most computers do not have a program installed able to read .dvi les, virtually all computers have Adobe Acrobat Reader installed. Hence, if you want your work to be accessible to the largest audience possible, you should convert it to Acrobat Readers pdf format. 9 Why bother executing TeXify when you can just execute PDF TeXify? Basically, PDF TeXify takes a long time (roughly 10 seconds to display your document, while TeXify is almost A instantaneous. Since you should be compiling your L TEX document regularly, using PDF TeXify can waste a lot of time.
8 7

A 5 TROUBLESHOOTING YOUR LTEX DOCUMENT

A Compiling L TEX Remotely


A Unfortunately, most computer owners are not enlightened LTEX users. As such, you A might nd yourself sitting in front of a computer without a LTEX compiler. Happily, there is no need to panic; so long as our computer has an Internet connection and A the SSH protocol installed, you have access to a LTEX compiler. Heres what to do:

1. Log onto either your U of M account (login.itd.umich.edu) or your Economics Account (econstat1.econ.lsa.umich.edu) using the SSH protocol. 2. Enter pico <file>.tex to either create a new le called <file>.tex or open <file>.tex (If you already started writing in a text editor on the local machine, simply upload the le to your account). Pico is just one text editor available on most Unix-style machines. Feel free to use the editor of your choice, including Emacs.
A 3. Save your LTEX program and exit your le editor. At the prompt, type latex A <file>.tex to compile your LTEX program. If you receive no errors, this statement should have produced <file>.dvi. Type dvipdf <file>.dvi to generate a pdf le from <file>.dvi .

4. Download the pdf le and check for formatting errors. 5. (Optional) Repeat. Admittedly, the above procedure is not very ecient; uploading and downloading les can grow tedious. Life gets better if the computer your sitting in front of has X Windows (X) installed. With X installed, you can view the pdf le you compiled without having to download it to your computer. For more information regarding X, see Computer Networking for Michigan Economists, available on the Departments website.

A Troubleshooting Your LTEX Document

A From time to time, you will try to compile your LTEX document only to nd that the WinEdt terminal window does not happily disappear, or Emacs returns a compilation A error. DONT PANIC! you have simply made a coding error. Sometimes, the L TEX compiler will oer a useful hint as to the location and type of error that you have made. Often, these messages will be less than clear, and you will spend hair-pulling minutes trying to nd your error. Here are a few troubleshooting tips: A Compile your LTEX documents early and often. Not only will this enable you to spot formatting errors quickly, it will help give a general sense of where the errors actually are.

6 ADDING FUNCTIONALITY Make sure you have employed matching $ signs when invoking math mode.

Make sure all of your control sequences begin with a \ , and that control sequences have matching curly brackets {} . Furthermore, make sure that you have spelled your control sequences correctly. Some control sequences may only be used in specic modes. For instance, control sequences for most greek letters may only be invoked in math mode. Trying to invoke them outside of math mode will result in errors. As such, Make sure all of your control sequences are invoked in the appropriate modes. Use Emacs (or WinEdt) features to minimize typing mistakes.

Adding Functionality

A While most of the control sequences you will need are including in your base LTEX A installation, from time to time you may have to install additional LTEX packages in order to accomplish a particularly esoteric formatting task. The easiest way to discover which packages you need to install is to either do a Google or CTAN search on the type of formatting you want to implement. For example, if you wanted to A add endnotes rather than footnotes to your document, a search on LTEX endnotes would reveal which style les need to be downloaded. A Unfortunately, installing additional LTEX style les an be a frustrating process. Here ae some instructions for installing new packages on dierent platforms:

6.1

MikTeX
StartAll ProgramsMikTeXMikTeX Package Manager

Start the MikTeX package manager by clicking on

It will take a few moments to load all available packages. If you are asked to congure a Package Repository, select Internet and choose a package repository in the US (the last one in the list usually works well). You can enter a package name into the the Name eld of the Package manager and click on Filter. To search for the prosper package, for example, enter prosper and click on Filter: Click on the package you are interested in. If the package is already installed, the minus sign will be active. If the package is not yet installed, the plus sign will be active. Click on the plus sign to install the selected package and follow the instructions.

A 7 LTEX AND STATISTICAL PACKAGES

10

6.2

Tetex on IFS

A Tetex is the version of LTEX installed on many *nix machines, including most of Michigans servers. If you are working on one of these machines, chances are you dont have permission to add new packages to the base Tetex installation. Instead, A you will need to create a local LTEX repository. Here is how you do it:

1. create a directory on your IFS space called texmf. 2. create fonts, tex,docs, and bibtex subdirectories underneath texmf.
A 3. download and unarchive the desired LTEX package(s), and follow the installation instructions. Typically, all you should have to do is save the package in the tex directory.

4. create a backup copy of the .cshrc le (just in case). 5. open .cshrc and add the folowing line after Place local customizations after this line and before end source setenv TEXINPUTS ./:/usr/share/texmf/tex/:~/texmf/tex/<package directory>/: 6. at the command lien, type texhash. for additional information on how to install packages, go to http://www.tex.ac.uk/cgi-bin/texfaq2html?label=instpackages and http://www.tex.ac.uk/cgi-bin/texfaq2html?label=wherefiles for instructions on on how and where to install new packages.

A LTEX and Statistical Packages

A Another great feature of LTEX is that some of the more prominently used statistical packages in Economics will output information that can be easily placed into your A A L TEX documents. The following programs support LTEX formatting10

Stata: Stata contains some excellent commands for formatting output. My personal favorites are sutex, which transforms the output from the summarize A command into a LTEX table, and outtex, which does the same thing as sutex but for regression output. A slightly more supped up version of sutex called est2tex may be used to collect the results from assorted stata regression procedures into a single table. While these commands are not included in the base Stata installation, they are easily installed using findit <command name>, where <command
10 Again, this isnt a complete list. A Google search on a particular package should tell you what is available, though.

A 8 LTEX WYSIWYG FRONTENDS

11

name> is the name of the stata command you want to install. A complete list of A L TEX extensions as well as a plethora of useful Stata material is available from http://www.ats.ucla.edu/stat/stata/ . Matlab: Matlab possesses the excellent LAT EX(S) command which returns A the L TEX representation of the symbolic expression S. Type help latex at the matlab prompt for further information.
A Sas: Sass Output Delivery System (ODS) can create LTEX-readable output from Sas procedures. Excellent instructions for using the ODS system may be found at http://support.sas.com/rnd/base/topics/odsmarkup/markup_stmt.html .

A LTEX WYSIWYG frontends

A Although LTEX is a powerful typsetting tool, many people nd its learning curve a A bit too steep. One solution is to use a LTEX WYSIWYG frontend. The WYSIWYG A frontends have two distinct advantages over compiling your own L TEX documents

they allow you to use easy pull-down menus to insert lists, tables, equations, etc. they allow you to view your documents format without having to compile your .tex le. Perhaps the biggest disadvantage to using these WYSIWYG frontends is that you are gambling on these frontends choose the appropriate control sequences. Normally, choosing the appropriate control sequence wont matter, but if you drastically change the documents format (say when you reformat your article for publication), the wrong choice of control sequence will not only make your paper look pretty funny, but could require you to invest lots of time making painful format corrections that will probably A involve you learning at least some LTEX control sequences. As you might expect, these WYSIWYG frontends come in free and commercial avors. Documentation and installation instructions for the freely available LyX may be found at http://www.lyx.org . The commercially available Scientic Word may be purchased from http://www.mackichan.com .

A Formatting your Thesis Using LTEX

A One benet of using LTEX is the ability to easily format your dissertation according A to the myriad of arcane rules necessary for graduation. LTEX style les that provide these formats may be found at

10 CONCLUSION http://www.math.lsa.umich.edu/graduate/templates/index.shtml, or at http://texcatalogue.sarovar.org/entries/umich-thesis.html.

12

10

Conclusion

This tutorial has only briey touched on the multitude of formatting options available A through LTEX. More thorough tutorials and excellent reference manuals are cited in A the References section. In my experience, however, the only way to really learn LTEX A X whenever is through practice. I urge you to format your documents using LTE possible.

11

References

http://www.ctan.org/ CTAN is a searchable database containing useful A extensions and customizations for LTEX. Moreover, it contains many useful code snippets that can be readily copied and pasted into your documents.
A The (Not So) Short Introduction to LaTeX2e A must have for any LTEX user. This book is lled with clear instructions on how to implement most of A the commonly used LTEX commands. This book is freely downloadable from CTAN (http://www.ctan.org/starter.html).

http://www.maths.tcd.ie/~dwilkins/LaTeXPrimer/ A An excellent L TEX tutorial. While not as comprehensive as either of the above A resources, this primer provides an excellent avenue for mastering LTEX. In fact, much of this tutorial was lifted from this primer. http://www.tex.ac.uk/cgi-bin/texfaq2html?introduction=yes The UK TEXUsers Group Frequently Asked Questions (FAQ) Database. This resource has answers to many commonly asked questions. econ-latex@listserver.itd.umich.edu You can use this email address to contact knowledgeable Economics PhD stuA dents with your LTEX questions. This should only be done after you have exhausted the above resources.
A I recommend that all students intending to use LTEX regularly sign up for this mailing list. As an econ-latex list member, you will have access to all the soluA tions your colleagues have proposed for specic LTEX problems. Furthermore, A you will be able to assist your colleagues in solving dicult L TEX problems. You can become a member of the econ-latex mailing list by lling out the following form http://listserver.itd.umich.edu/cgi-bin/lyris.pl?enter=econ-latex .

You might also like