University of Michigan: LaTex Tutorial
12 pages
English

University of Michigan: LaTex Tutorial

Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres
12 pages
English
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres

Description

ALT X TutorialE
∗Charles Taragin
September 25, 2005
A1 Introduction to LT XE
AWhat is LT X?E
ALT X is a computer program for typesetting documents. It takes a computer file,E
Aprepared according to the rules of LT X and converts it to a form that may beE
printedonahigh-qualityprinter,suchasalaserwriter,toproduceaprinteddocument
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:
effectively all one has to do is to type the text straight in (though observing certain
rules relating toquotation marks and punctuation dashes). Typesetting mathematics
Ais somewhat more complicated, but even here LT X is comparatively straightforwardE
tousewhenoneconsidersthecomplexity ofsomeoftheformulasthatithastoformat
and the large number of mathematical symbols which it has to produce.
AHow Does LT X differ from Microsoft Word?E
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.
ALT X, to the contrary, is a markup language similar to HTML. Raw text is mod-E
ified using functions called control sequences and saved in a file with a “.tex” suffix.
AThe LT X compiler takes this “.tex” file and transforms it into a nicely formattedE
1“.dvi” file that can easily be printed or transformed into a pdf file.
ALT X has two distinct advantages over ...

Sujets

Informations

Publié par
Nombre de lectures 387
Langue English

Extrait

A LT X Tutorial E
Charles Taragin
September 25, 2005
A 1 Introduction to LT X E A What is LT X? E A LT X is a computer program for typesetting documents. It takes a computer file, E A prepared according to the rules of LT X and converts it to a form that may be E 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: effectively 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 LT X is comparatively straightforward E 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 LT X differ from Microsoft Word? E 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 LT X, to the contrary, is a markup language similar to HTML. Raw text is mod E ified using functions called control sequences and saved in a file with a “.tex” suffix. A The LT X compiler takes this “.tex” file and transforms it into a nicely formatted E 1 “.dvi” file that can easily be printed or transformed into a pdf file. A LT X has two distinct advantages over Word. First, while Word has difficulty E A handling large documents (like dissertations), LT X can easily handle documents of E Special thanks to Samara Potter for editing this document. Much of this document was borrowed A from David R. Wilkins’Getting Started with L T X. See References for further details. E 1 “.dvi” stands for device independent – a format that may be easily printed by most printers.
1
2
GETTING STARTED
2
arbitrary length. Second, Word’s Equation Editor is extremely cumbersome when A compared to LT X’s ability to construct sophisticated equations. E
A How Does LT X differ from T X? E E A LT X is one of a number of ‘dialects’ of T X, all based on the version of T X created E E E A by D. E. Knuth which is known as Plain T X. LT X (created by L. B. Lamport) E E 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 LT X and E A T X share many commands LT X contains many commands that aren’t available in E E A T X. As such, LT X is probably one of the most suitable versions of T X for beginners E E E to use.
2
Getting Started
A This section covers how to install the LT X compiler and frontend on your personal E 2 computer .
A Installing the LT X Compiler E A The LT X compiler may be installed on virtually any operating system you can E A name. Excellent installation instructions for the Windows LT X compiler MiKTeX, E are available from http://www.ctan.org/texarchive/systems/win32/miktex/setup/install.html
Choosing a Text Editor A While a LT X document can be composed in any text editor (e.g. Word, Word E A pad, Notepad), some editors have been customized for use with LT X. Two of the E more popular editors are WinEdt (Windows only, $40 registration fee) and Emacs (most operating systems, free). While both editors offer similar features, WinEdt is 3 generally considered easier to use . Excellent instructions for installing Emacs on a
2 Note that this isn’t strictly necessary; many of the department’s computers and servers have all A the requisite software installed. If you want to use L T X without installing it on your computer, E simply open up any text editor (including Word), type in your document with the appropriate control sequences, and save it as a text file with a ‘.tex’ suffix. This file can be then transferred to A a computer with the L T X compiler, and compiled using the commandlatex <file.tex>, where E A <file.tex>is the upload “.tex” file. T X onHowever, if possible, I would recommend installing L E 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
3
Windows machine are available at http://www.math.auc.dk/~dethlef/Tips/preparation.html, and trial copies of WinEdt may be downloaded fromhttp://www.winedt.com.Important:I recom A mend installing LT XbeforeBoth editors should automatinstalling any text editor. E A ically detect LT X if it is installed first. E WinEdt and Emacs, when used correctly, can greatly reduce your typing mistakes A (a valuable asset when coding in LT X). Here are some useful things that you can E do with either editor:
4 A Compile LT X documents from within your editor E 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 LT X E control sequences (e.g. Greek letters, typefaces, equations, lists, section head ings).
Use the version control systems (sometimes referred to as revision control sys tem) to track changes you have made to your program over time. See the WinEdt or Emacs documentation for more about these systems.
5 Use the “rectangle” commands to cut and paste rectangular areas of text . This is something that you just can’t do in Word, and is extremely useful for A manipulating individual columns of information (like LT X tables). See the E WinEdt or Emacs documentation for more about these commands.
4 A A Your editor isonlyacting as a frontend for L X must still be installed on yourL T T X– E E computer. 5 All the characters between a certain pair of columns, in a certain range of lines.
3
A A TYPICAL LT X INPUT FILE E
4
A 3 A Typical LT X Input File E A In order to produce a document using LT X, we must first create a suitableinput E A fileWe apply the LT X program to the input file and then useon the computer. E A the printer to print out the socalled ‘DVI’ file produced by the LT X program (after E first using another program to translate the ‘DVI’ file into a form that the printer 6 A can understand). Here is an example of a typical LT X input file : E
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, LT X code is fairly readable. E Although most characters occurring in this file have their usual meaning, there are 6 Note: Numbers in left column are for reference only and should not be included in your .tex files
3
A A TYPICAL LT X INPUT FILE E
5
A special characters such as\,$,{and}X. Inwhich have special meanings within LT E 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 ascontrol sequences. A When we apply LT X to these paragraphs we produce the text E
The foundations of the rigorous study ofanalysiswere laid in the nine teenth century, notably by the mathematicians Cauchy and Weierstrass. Central to the study of this subject are the formal definitions oflimits andcontinuity. LetDbe a subset ofRand letf:DRbe a realvalued function on Dfunction. The fis said to becontinuousonDif, for all >0 and for allxD, there exists someδ >0 (which may depend onx) such that if yDsatisfies
|yx|< δ
then |f(y)f(x)|< .(1) One may readily verify that iffandgare continuous functions onD then the functionsf+g,fgandf.gIf in additionare continuous. gis everywhere nonzero thenf /gis continuous.
A Lines 1, 2, and 25 illustrate some important properties of LT X control sequences E A All LT X control sequences begin with a\. E A LT X control sequences encloserequiredparameters with curly brackets. E A X control sequenceThe LT \begin{}is always matched with an\end{}control E sequence later in the document.
Optionalparameters are usually included in square brackets prior torequired parameters.
A Every LT X document must begin with a E
\documentclass{}
statementandcontaina
\begin{document}
and
4
A COMPILING A LT X DOCUMENT E
\end{document}
statement.
6
A The\documentclass{}statement allows you to specify the type of LT X doc E ument you wish to create. Parameters for this control sequence include
articlefor articles in scientific journals, presentations, short reports, pro gram documentation, invitations, ... reportfor longer reports containing several chapters, small books, PhD theses, ... bookfor real books slidesYou might want toThe class uses big sans serif letters. for slides. consider using FoilT X or the excellent Prospect package instead. E
A Coding Mathematical Formulae in L T X E A An important control sequence is the $ , which is used to activate LT X’s math mode. E A Math mode is a special environment inside LT X where whitepaces aren’t recognized, E 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 LT X automat E ically numbers each equation, and that numbering may be suppressed by using * (see lines 1618).
4
A Compiling a LT X Document E Open a blank document in your favorite editor and input your text along with A the appropriate LT X code. Both WinEdt and Emacs require your document E to be saved with a “.tex” suffix.
4
A COMPILING A LT X DOCUMENT E
7
In WinEdt, select AccessoriesTeXify . This will open a terminal where your A LT X code will be compiled. If your code is errorfree, the terminal window E A should close, and WinEdt will automatically display the “.dvi” file LT X gen E erated in the viewer Yap. During the compilation process, WinEdt generates the following files on< f ile >.tex
< f ile >This a backup copy of.tex.bak : ile >< f .tex, serves no real purpose, and may deleted with impunity. A < f ile >This file is the output from a successful LT X compilation..dvi : E Use this file to make sure the document is correctly formatted and to print drafts. This file may also be deleted with impugnity,unlessyou want to generate a pdf file.
7 A in Emacs , select CommandLaTeX. If you haven’t saved your LT X file, E Emacs will prompt you to save your document. Emacs will then compile your A document using LT X. If Emacs doesn’t report any compilation errors, select E CommandView to view your< f ile >Like WinEdt, Emacs always.dvi file. generates a backup file (designated< f ile >.tex˜), as well as aile >< f .dvi if A the LT X compilation was successful. Feel free to delete either, although the E < f ile >.dvi file should be kept if you intend to generate a pdf document.
8 eeRd(nemmocareneG)dldfapte.e
In WinEdt, choose AccessoriesPDFA terminal willPDF TeXify. open where your pdf file will be compiled. If there are no errors, this terminal window should close automatically and< f ile >.pdf file should now exist in the same directory asile >< f command.tex . Note: this compiles your document using MiKTeXbeforecreating the pdf file, so you 9 don’t need to execute “TeXify” before “PDF TeXify” . In Emacs, choose CommandLaTeX PDF. Emacs will attempt to com pile your pdf file and report the result. If successful,ile >< f .pdf file should now exist in the same directory asile >< f .tex .
7 Assuming the Auctex package is also installed. 8 Why do this? While most computers do not have a program installed able to read “.dvi” files, 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 Reader’s 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 T X document regularly, using “PDF TeXify” E can waste a lot of time.
5
A TROUBLESHOOTING YOUR LT X DOCUMENT E
8
A Compiling LT X Remotely E A Unfortunately, most computer owners are not enlightened LT X users. As such, you E A might find yourself sitting in front of a computer without a LT X compiler. Happily, E 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 LT X compiler. Here’s what to do: E 1. Log onto either your U of M account (login.itd.umich.edu) or your Eco nomics Account (econstat1.econ.lsa.umich.edu) using the SSH protocol.
2. Enterpico <file>.texto either create a new file called<file>.texor open <file>.tex(If you already started writing in a text editor on the local machine, simply upload the file 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 LT X program and exit your file editor. At the prompt, typelatex E A <file>.texIf you receive no errors, thisX program. to compile your LT E statement should have produced<file>.dvi. Typedvipdf <file>.dvito generate a pdf file from<file>.dvi.
4. Download the pdf file and check for formatting errors.
5. (Optional) Repeat.
Admittedly, the above procedure is not very efficient; uploading and downloading files 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 file you compiled without having to download it to your computer. For more information regarding X, seeComputer Networking for Michigan Economists, available on the Department’s website.
A 5 Troubleshooting Your LT X Document E A From time to time, you will try to compile your LT X document only to find that the E WinEdt terminal window doesnothappily disappear, or Emacs returns a compilation A error. DON’T PANIC! you have simply made a coding error. Sometimes, the LT X E compiler will offer 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 find your error. Here are a few troubleshooting tips:
A Compile your LT X documents early and often. Not only will this enable you E to spot formatting errors quickly, it will help give a general sense of where the errors actually are.
6
6
ADDING FUNCTIONALITY
Make sure you have employed matching $ signs when invoking math mode.
9
Make sure all of your control sequences begin with a\, and that control se quences have matching curly brackets{}. Furthermore, make sure that you have spelled your control sequences correctly.
Some control sequences may only be used in specific 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 LT X E A installation, from time to time you may have to install additional LT X packages E 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 “LT X endnotes” E would reveal which style files need to be downloaded. A Unfortunately, installing additional LT X style files an be a frustrating process. E Here ae some instructions for installing new packages on different platforms:
6.1 MikTeX Start the MikTeX package manager by clicking on
StartAll ProgramsMikTeXMikTeX Package Manager
It will take a few moments to load all available packages. If you are asked to configure 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 field 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.
7
A LT X AND STATISTICAL PACKAGES E
10
6.2 Tetex on IFS A Tetex is the version of LT X installed on many *nix machines, including most of E Michigan’s servers. If you are working on one of these machines, chances are you don’t have permission to add new packages to the base Tetex installation. Instead, A you will need to create a local LT X repository. Here is how you do it: E 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 LT X package(s), and follow the installa E tion instructions. Typically, all you should have to do is save the package in the “tex” directory.
4. create a backup copy of the “.cshrc” file (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
6.atthecommandlien,typetexhash.
directory>/:
for additional information on how to install packages, go to http://www.tex.ac.uk/cgibin/texfaq2html?label=instpackagesand http://www.tex.ac.uk/cgibin/texfaq2html?label=wherefilesfor instructions on on how and where to install new packages.
A 7 LT X and Statistical Packages E A Another great feature of LT X is that some of the more prominently used statistical E packages in Economics will output information that can be easily placed into your 10 A A LT X documents. The following programs support LT X formatting E E StataMycontains some excellent commands for formatting output. : Stata personal favorites aresutex, which transforms the output from the summarize A command into a LT X table, andouttex, which does the same thing assutexbut E for regression output. A slightly more supped up version ofsutexcalledest2tex 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 instal lation, they are easily installed usingfindit <command name>, where<command 10 Again, this isn’t a complete list. A Google search on a particular package should tell you what is available, though.
8
A LT X WYSIWYG FRONTENDS E
11
name>is the name of the stata command you want to install. A complete list of A LT X extensions as well as a plethora of useful Stata material is available from E http://www.ats.ucla.edu/stat/stata/.
Matlabpossesses the excellent: Matlab LAT EX(S) command which returns A the LT X representation of the symbolic expressionS. Typehelp latexat E the matlab prompt for further information.
A Sas: Sas’s Output Delivery System (ODS) can create LT Xreadable output E 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 8 LT X WYSIWYG frontends E A Although LT X is a powerful typsetting tool, many people find it’s learning curve a E A bit too steep. One solution is to use a LT X WYSIWYG frontend. The WYSIWYG E A frontends have two distinct advantages over compiling your own LT X documents E they allow you to use easy pulldown menus to insert lists, tables, equations, etc.
they allow you to view your document’s format without having to compile your .texfile.
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 won’t matter, but if you drastically change the document’s 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 LT X control sequences. E As you might expect, these WYSIWYG frontends come in free and commercial flavors. Documentation and installation instructions for the freely availableLyXmay be found athttp://www.lyx.orgcommercially available. The Scientific Word may be purchased fromhttp://www.mackichan.com.
A 9 Formatting your Thesis Using LT X E A One benefit of using LT X is the ability to easily format your dissertation according E A to the myriad of arcane rules necessary for graduation. LT X style files that provide E these formats may be found at
  • Univers Univers
  • Ebooks Ebooks
  • Livres audio Livres audio
  • Presse Presse
  • Podcasts Podcasts
  • BD BD
  • Documents Documents