Practical LaTeX guide

General information on TeX and LaTeX can be found, e.g., from the TeX Users Group's home pages http://www.tug.org/. Up to 1994 the latest LaTeX definition had version number 2.09 (this version originally appeared already 1986 and was revised several times), and it has not been updated ever since. From 1994 the new completely revised and internationalized LaTeX system has had the provisional name LaTeX2e (the 'e' meaning epsilon). It will eventually be replaced by LaTeX3. In the following the name LaTeX is supposed to refer to LaTeX2e. The old LaTeX2.09 should not be used any more!.

Contents:
1. Installation of the LaTeX system
2. MiKTeX options
3. Short LaTeX guide and other literature
4. Structure of LaTeX document
5. Preamble
6. Body
7. LaTeX versus pdfLaTeX
8. Including EPS graphics in LaTeX documents
9. Including PDF graphics in pdfLaTeX documents
10. How do I make good Postscript (PS) documents?
11. How do I make good PDF documents?
12. Printing of LaTeX documents
13. Model template for exercises
14. Happy LaTeXing!
Corrections

  1. Installation of the LaTeX system.
    1. TeX and LaTeX programs.
      For the MS Windows platform the most recommendable LaTeX system is MiKTeX. This is particularly easy to install. Properties: 1. MiKTeX is completely free. 2. From version 2.1 there is an extremely useful update utility by which new packages from the CTAN archives (e.g., ftp://ftp.dante.de/tex-archive/ or ftp://ftp.funet.fi/pub/TeX/tex-archive/) can be automatically downloaded and installed. 3. MiKTeX comes with postscript cm fonts and also with the European EC fonts. 4. It has a metafont utility for generating the missing fonts on fly. 5. MiKTeX offers 3 installation options: small, large and total set. They use, respectively, about 100 MB, 200 MB, or 500 MB of disk space (after installation and after all fonts have been created). Warning: the package management system is horribly slow (perhaps due to the slowness of Windows disk management), so grab a magazine for the installation, for it takes about 20 minutes.

      On MacOS X I have found TeXShop to be a good frontend for TeTeX. Of course you can also use just TeTeX in the console after installing it with e.g. Fink.

      Open source distributions (Linux, *BSD) usually contain a TeX/LaTeX system installation option. Often the program used is TeTeX. The resulting environment is accessed through the standard command-line interface.
    2. Front ends (shells) for MiKTeX.
      MiKTeX does not have an included text editor for the preparation of LaTeX documents. Any text editor can be used for this purpose, and a number of them are listed in http://home.arcor.de/itsfd/texwin.htm. (A classic example is the completely free and easily configurable editor TeXShell, but so far it has had the problem of not tolerating unix-type linefeeds, which makes life difficult, if files are to be shared or transfered between the Windows and unix worlds.)

      After considering the pluses and minuses, our Department recently acquired a site license for the shareware program WinEdt, which is nearly an ideal front end for the underlying MiKTeX system. For instance, it has easy-to-use toolbar buttons for all commands needed in the document preparation.
    3. Other programs.
      The two other necessary programs are (the AFPL) Ghostscript and (the Adobe) Acrobat Reader, which both are free. To view postscript files the GSview program is invaluable. Thus, altogether, a complete Windows LaTeX document preparation system is comprised of the following programs: MiKTeX, WinEdt, AFPL Ghostscript, GSview, and Acrobat Reader. Their present version numbers are, respectively, 2.1, 5.3, 7.04, 4.2, and 5, and the installation is straightforward. (Other alternatives naturally also exist and may have virtues of their own).

      Since some of the MiKTeX utilities need Ghostscript, it is advisable to modify the path such that the directory containing the file 'gswin32c.exe' is on the path (with the present version the default directory is C:\gs\gs7.04\bin). If WinEdt is used to launch those utilities, this can be (hopefully) avoided by executing the 'Run Startup Macro' from WinEdt's 'Macros' menu, which searches for the Windows registry.

      The final practical advice is thus as follows: (a) install Acrobat Reader, (b) install Ghostscript, (c) install Ghostview, (d) install MiKTeX v2.1, (e) install WinEdt v5.3, (f) launch WinEdt and run 'Run Startup Macro'. (If new versions of Ghostscript etc are installed afterwards, run again the WinEdt Startup Macro).
    4. Configuring the right options.
      MiKTeX: After installation, launch 'MiKTeX Options' and check first the page 'Languages'. Mark all the languages you ever think to need in the documents. On the page 'Packages' you can specify the location from where new packages are downloaded, e.g., from a chosen CTAN archive in the internet, or from a local CDROM. As an exercise, find the package 'eurosym' from the Finnish CTAN server ftp.funet.fi, and download it (this provides the new Euro currency symbol € and the documentation for its use. NB: if you did not see the Euro symbol here, update your www browser). Finally, go to page 'General', refresh the filename database and update format files.
      (NB: Package 'eurosym' does not contain postscript descriptions for the Euro symbol. The package 'eurosans' uses Adobe's postscript fonts, but cannot be installed as easily, see the instructions).

      TeTeX: For Finnish hyphenation launch texconfig in a console after installation. Select Hyphenation, and then Latex. Find the string "finnish" in the text. The line is usually commented out; uncomment it. Save and exit.

    5. Short LaTeX guide and other literature.
      An excellent introduction to LaTeX is provided by the "LaTeX2e in 95 (87) minutes" guide of Tobias Oetiker. This is available in the web in several languages, e.g., in English (see directory ftp://ftp.funet.fi/pub/TeX/tex-archive/info/lshort/english/, which contains the documents 'lshort.pdf' and 'lshort.ps'), and in Finnish (slightly older but useful version, directory ftp://ftp.funet.fi/pub/TeX/tex-archive/info/lshort/finnish/).

      These short guides concentrate on the most essential and frequently needed features which may be difficult to locate from the more thorough presentations.

      Of the more comprehensive LaTeX guides the following could be mentioned:
      1. A Guide to LaTeX by Helmut Kopka and Patrick W. Daly (3rd edition, Addison Wesley 1999) (600 pages).
      2. The LaTex Companions: Basic, Advanced, Graphics, Web by Leslie Lamport, Michel Goossens, Frank Mittelbach, Sebastian Rahtz, and Alexander Samarin (Addison Wesley 2001) (1184 pages, the new "bible" which combines the authors' earlier published separate books in a single boxed set, expensive. This is brand new, and presumably mainly intended for reference only, but it is so far unknown whether the various volumes have been updated).

    6. Structure of LaTeX document.
      The main file of a LaTeX document looks like follows:
      	\documentclass[options]{classname}
      	..
      	..
      	\begin{document}
      	..
      	..
      	\end{document}
      
      (Sometimes there may be plain TeX instructions even before the '\documentclass' command). The first slot is a header called the preamble, containing possible additional definitions and extensions to the basic classname style. The most frequently used classnames are book, article, report, and slides, and typical options are 11pt, 12pt, a4paper, and twoside. The second slot contains the body of the document.

    7. Preamble.
      The empty preamble is often sufficient for documents written in English language and containing no pictures. In most environments English is the default language, and the texts are written using the ASCII character encoding.

      If, however, documents in other languages are to be produced, or pictures of various kind to be embedded, there are packages that can do the tricks. Some of the most useful are listed below.

      \usepackage[latin1]{inputenc}
      The option 'latin1' means the ISO 8859-1 (Latin-1) standard for the character encoding of the input text. This contains most of the European accented characters such as ä, ö, é, è etc. This option is good for texts written in the Windows and unix environments, although for Windows an even better option would be 'ansinew'.
      \usepackage[finnish]{babel}
      This produces a Finnish document where all the keywords such as chapter, index, and figure caption names are in Finnish, and hyphenation follows the Finnish hyphenation rules. If several languages are needed in one document (e.g., to properly hyphenate a lengthy quotation in foreign language), the structure '\usepackage[german,swedish,finnish]{babel}' can be used. In this case the last language becomes the default for the document.
      \usepackage[T1]{fontenc}
      The LaTeX documents normally use the old computer modern (cm) fonts in the so-called Old TeX (OT1) encoding. The character tables of these fonts do not contain the European accented characters, and therefore the hyphenation of words with accented letters in European languages remains deficient. Option T1 in this command means that the new TeX encoding scheme (T1) is employed, and the document uses the European EC (or ec) fonts, which contain accented letters in their character tables. Using this command in the preamble makes European hyphenations work perfectly (but for exceptionally difficult words). Hyphenation can be tested with the command '\showhyphens{wordtobehyphenated, anothersuchword, ...}' in the body of the document. After typesetting, read the file 'myfile.log' (if the original main tex file is 'myfile.tex') to see the suggested hyphenation.
      \usepackage{ae,aecompl} A useful alternative to the T1 fontenc, see section 10!
      \usepackage{amsbsy,amssymb}
      Note that several packages can be loaded by one command! 'amsbsy' is a very useful package allowing bold mathematical symbols to be used with the command '\boldsymbol{...}' in the math environment. Example: 'ak' is written as 'a_{\boldsymbol{k}}'. 'amssymb' is a package providing a huge set of symbols due to the American Mathematical Society (AMS; see the references).
      \usepackage{graphicx}
      This package is the best when graphics from picture files should be included in the document. It is explained in more detail below.
      \usepackage{feynmf}
      This is a utility for automatic generation of Feynman graphs in a LaTeX document. This package is not included in the small MiKTeX set; it has to be downloaded and installed (exercise: do it!). Its use is explained in the accompanying documentation file (manual.ps.gz).

    8. Body.
      The document is written in the body part of the main file. There is no point in giving detailed instructions here; a very good starting point is the free 95 minute manual of Oetiker. To those who have used LaTeX2.09 just a couple of remarks:

      Please don't use the old font commands such as '\rm', '\em', '\bf', '\tt' etc. Although they still may work in LaTeX2e, it is better to use the new LaTeX2e font commands. The above cases become, respectively, '\textrm{text}', '\emph{text}', '\textbf{text}', '\texttt{text}'. In WinEdt the enclosed text is nicely shown in the style implied by the command.

      Also, forget everything you have learnt from LaTeX2.09 about placing graphics in the documents. Memorize the new very simple conventions which are (to some extent) explained below!

    9. LaTeX versus pdfLaTeX.
      In addition to the standard LaTeX format there exist plenty of other less standard format specifications. Very noteworthy new formats are the pdfTeX and the associated pdfLaTeX formats. They are very convenient to create documents, which may contain hypertext references and which are saved in the PDF (Adobe's portable document format) form.

      In WinEdt there are toolbar buttons both for the normal LaTeX and also for the pdfLaTeX typesetting. In well-administered Linux/unix systems the commands are, respectively,
      	latex myfile[.tex]
      	pdflatex myfile[.tex]
      
      LaTeX typesetting produces an intermediate DVI file, which can be viewed with a dvi preview program, e.g., in Windows with Yap ('yet another previewer'; comes with MiKTeX), or in unix with xdvi. pdfLaTeX typesetting produces directly the PDF file, which can be viewed by Acrobat Reader. To take real advantage of the pdfLaTeX format one can utilize the 'hyperref' package to include hypertext links of various kinds (this will not be elaborated here). There are also differences in including pictures in the two formats, see below.

    10. Including EPS graphics in LaTeX documents.
      Programs such as Macromedia Freehand, Adobe Illustrator, and CorelDRAW can be used to draw graphics which can be exported as encapsulated postscript (eps) files. To include such files in the LaTeX document insert the command
      	\usepackage{graphicx}
      
      in the preamble, and to place the picture in the document use, e.g., the following command:
      	\includegraphics{myfig.eps}
      
      This command places the picture in its default size in the current position just as a large letter. To change the size and orientation of the picture one can use the commands:
      	\resizebox{x-length}{y-length}{...}
      	\scalebox{x-scale}[y-scale]{...}
      	\rotatebox{angle}{...}
      
      If one of the lengths in '\resizebox' is given as !, the picture is proportionally scaled according to the other length. In '\scalebox' the y-scale is optional and can be left out in which case the x-scale applies to both directions. In the dotted boxes there can be anything, e.g., arbitrary text or nested commands such as
      	\rotatebox{-37}{\resizebox{27mm}{!}{\includegraphics{myfig.eps}}}
      
      With the graphicx package, the picture-manipulating commands may also be combined, e.g., as in
      	\includegraphics[width=27mm, angle=-37]{myfig.eps}
      
      The options are processed from left to right.

    11. Including PDF graphics in pdfLaTeX documents.
      If pdfLaTeX is used, the format does not accept eps figures. The figures must be given as pdf files. If eps files already exist, the pdf forms can be easily created using the console (terminal) command
      	epstopdf myfig.eps
      
      in both the Windows and the Linux/unix platforms (in the appropriate folder). (With WinEdt, the console window in the appropriate directory is easily opened from a toolbar button.) This command knows how to cut the picture along the bounding box of the eps figure. When all the pictures are in pdf form, the figures are included in the pdfLaTeX document precisely in the same way as in the previous section, except that the figure name is of the form myfig.pdf. Thus, in particular, the preamble should contain the command '\usepackage{graphicx}'.

      (On the other hand, if the postscript document already exists, it can be converted into a pdf document without using pdfLaTeX, see 10-11.)

    12. How do I make good Postscript (PS) documents?
      By 'good' we mean fully scalable, consisting only of objects given in the postscript outline description. Such a document can be viewed and printed in any size without loss of smoothness of the contours.

      A document saved as a postscript file, say myfile.ps, can be printed easily and quickly by postscript printers. However, even if the file is a PS or EPS file, it may include printable objects which are given in bitmap description. E.g., bitmap pictures can be embedded in a PS file, but the size of the file then becomes often very large. A PS document may also contain bitmap fonts. Such files don't look good when viewed with GSview, and the corresponding PDF files, converted from the PS files, don't look good in the Acrobat Reader.

      The default font in LaTeX is the computer modern (cm) font. American Mathematical Society (AMS) has offered to the public the postscript descriptions for these fonts by agreement with the manufacturer, BlueSky Research. This is very fortunate, and therefore all normal LaTeX documents may enjoy full scalability, if properly typeset. With the MiKTeX/WinEdt combination, the PS file is produced from the DVI file by activating the 'dvi->ps' button in the toolbar of WinEdt. From the small options window choose the option '-Ppdf'; this tells the dvips program to search and use postscript fonts. In a Linux/unix system, similarly, the dvips program should be used as
      	dvips -Ppdf ... myfile.dvi
      
      Here the dots signify other possible options (for dvips there are quite a lot of them!). (Technically, the dvips program then reads the additional configuration file 'config.pdf', if such exists. This file contains instructions to use postscript fonts).

      The cm fonts do not allow perfect hyphenation of words with accented characters. As mentioned in section 5, the EC fonts are better in this respect, but unfortunately there are no freeware postscript definitions available for them so far (however, see corrections in the end!). Therefore, if the command '\usepackage[T1]{fontenc}' is used in the preamble, the resulting PS document uses bitmap fonts (this would be the case also with the cm fonts, if dvips were invoked without the '-Ppdf' option). While waiting for the postscript EC fonts to be given from heaven, there is an intermediate solution in the form of the 'ae' package due to Lars Engebretsen (ae standing for 'almost European'). This package advices LaTeX to use 'ae' fonts which are actually combined from the standard cm characters and their accent signs. (This technique is apparently similar to what was used in the old multilingual MLTeX, which contained TeX primitives for character composition). This package (together with the complementary 'aecompl') has been included in the standard LaTeX distribution since ca. 1999.

      Thus, one should replace the T1 fontenc package command by
      	\usepackage{ae,aecompl}
      
      to produce good PS output.

    13. How do I make good PDF documents?
      There are at least three different ways to produce good PDF documents.
      1. Directly from dvi file (recommended).
        In WinEdt there is a button 'dvi->pdf' (also as the item 'dvi2pdf' in the 'Accessories' menu) which builds the pdf file directly from the dvi file, using proper postscript font descriptions. With the present version of MiKTeX this command works even if the possible pictures are eps files instead of pdf files. This action launches the MiKTeX executable 'dvipdfm.exe', which, again, depends on the Ghostscript executable 'gswin32c.exe'. If WinEdt is used to perform the conversion, the path to the Ghostscript program is made known to WinEdt by running the 'Run Startup Macro' from the 'Macros' menu (see item 1c).

        Without WinEdt the conversion can be done in the command window with the command
        	dvipdfm myfile.dvi
        
      2. From ps file.
        The ps file can converted into a pdf file by using GSview, menu 'File', action 'Convert...', device 'pdfwrite' (the GSview interface program actually again uses the Ghostscript executable gswin32c.exe). Thus, if a good PS document has been done according to the guidelines given in the previous section, one can use GSview to do the conversion.

        The conversion can also be done by launching the 'ps2pdf' command from the Accessories menu of WinEdt; there is also a button 'ps->pdf' in the toolbar, which does the same.

        In a Linux/unix machine, the command might be something like
        	gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=myfile.pdf myfile.ps &
        
        unless a direct 'ps2pdf' or 'pstopdf' command has been defined.
      3. Using pdfLaTeX.
        Yet another way to create good PDF output is to use pdfLaTeX from the start. Then, the possible pictures must be pdf files, as explained in section 9. There will be no intermediate dvi file, the pdf file is created directly.

    14. Printing of LaTeX documents.
      With the MiKTeX system it is not advisable to try to print directly from the Yap browser program. The main obstacle is that Yap cannot print pages with included eps figures. Also, Yap creates a huge intermediate bitmapped file which is dumped to the printer, whether a postscript printer or any other. This slows down radically the printing of postscript files with postscript printers.

      To print the document, one should use the created postscript or PDF document instead. For ps files, use GSview, and from the 'Print...' menu choose an appropriate 'Print Method': 'Postscript Printer' to dump the ps file to the postscript printer, or 'Windows GDI printer' to print with a non-postscript (such as inkjet) printer using Windows printer drivers.

      Acrobat Reader can be conveniently used to print the PDF file with any printer.

    15. Model template for exercises.
      Below is a Finnish example LaTeX file, which loads a number of useful packages in the preamble. To experiment with it, you can download the file from xtemplate.tex, and the eps figure from tigger.eps. (The resulting pdf file xtemplate.pdf can also be viewed here. It was generated by the MiKTeX dvipdfm program. It can be clearly seen that the Euro symbol is a bitmapped glyph).
      	% Tiedosto xtemplate.tex, malli vaikkapa harjoitustehtäväpapereille
      	% Huomaa että prosenttimerkin jälkeinen rivin osa on kommenttia
      	%
      	\documentclass[12pt,a4paper]{article}
      	\usepackage[latin1]{inputenc}
      	\usepackage[finnish]{babel}
      	\usepackage{ae,aecompl,amsbsy,amssymb,eurosym}
      	\usepackage{graphicx}
      	\begin{document}
      
      	\noindent
      	\textsc{Helsingin yliopisto} \hspace{\stretch{1}}
      	\textsc{Fysikaalisten tieteiden laitos}
      
      	\begin{center}
      	{\large \textbf{Approksimatiivisen fysiikan harjoitus no. 2, kevät 2002}} \\
      	\textbf{Palautetaan viimeistään Ke 9.1.2002 klo 15}
      	\end{center}
      
      	\begin{enumerate}
      	\item
      	Ensimmäinen harjoitus: vääntele tiikeriä
      
      	\scalebox{0.4}{\includegraphics{tigger.eps}}
      	\hspace{\stretch{1}}
      	\raisebox{1.5cm}{%
      	\scalebox{0.5}[0.25]{\rotatebox{-37}{\includegraphics{tigger.eps}}}
      	}
      
      	\item
      	Toinen harjoitus: \EUR{25} = 25 \euro\ = 25 euroa.
      
      	{\footnotesize Footnote-koossa: 25 \euro.}
      
      	\item
      	Kolmas harjoitus: tutki suomalaisen tavutuksen erikoisuuksia ja
      	lue myös tiedosto \texttt{xtemplate.log}:
      
      	laktoosi-intoleranssi, laktoosi"-intoleranssi, kaivosaukko,
      	kaivos\-aukko, hääyöaie.
      
      	Huomaa että suomalaisessa babel-dokumentissa lainausmerkillä on
      	erikoismerkitys. Tekstissä lainausmerkki pitää merkitä kahdella
      	peräkkäisellä heittomerkillä:\ ''lainaus'' (tai ``lainaus'').
      
      	\showhyphens{laktoosi-intoleranssi, laktoosi"-intoleranssi,
      	kaivosaukko, kaivos\-aukko, hääyöaie}
      
      	\item
      	Vielä yksi... Muunna esimerkiksi kuva tigger.eps pdf-tiedostoksi
      	ja prosessoi tämä harjoitus pdf\,\LaTeX :lla.
      
      	\end{enumerate}
      	\end{document}
      

    16. Happy LaTeXing!
      With the properly installed WinEdt/MiKTeX program set (La)TeXing becomes very easy! You just write the LaTeX document, and press (1) the LaTeX button on the WinEdt toolbar, (2a) the dvi->ps button, and (3a) the ps->pdf button. After each phase, the results can be seen as (1) dvi, (2a) ps, or (3a) pdf documents by pressing the buttons (1) 'DVI preview' (Yap), (2a) 'GSview', or (3a) 'Acrobat Reader' buttons, respectively. Or, if a ps file is not needed, (2b) press the dvi->pdf button to produce directly the pdf file.

      If errors occur, much can be learned from the log file (press the 'LOG' button!). Also, there is an inverse search option in the Yap preview program. It is activated from the 'View', 'Options..', 'Inverse Search' menu page, from which WinEdt can be chosen as the default editor.

      Happy LaTeXing!
    Corrections.
    1. Free postscript descriptions for the EC fonts actually do exist! There are two quite recent alternative sets in the CTAN archive folder '/fonts/ps-type1/', see, e.g., ftp://ftp.funet.fi/pub/TeX/CTAN/fonts/ps-type1/. Of these Martti Nikunen (Dept of Mathematics) recommends the "cm-super" fonts due to Vladimir Volovich (Nov 2001). Unfortunately MiKTeX does not yet support these fonts; thus they cannot be directly installed from 'MiKTeX Options'. The fonts require about 56 MB of disk space (or perhaps even more than 100 MB, if also the afm files were downloaded for the purpose of being able to use the Yap preview!). Detailed installation instructions into MiKTeX will not be given here. (In fact, the cm-super fonts may not yet be very economically encoded. Thus they produce typically much larger ps files than obtained by using the normal postscript cm or ae fonts). For nearly all purposes the use of the 'ae' and 'aecompl' packages is quite sufficient.
    2. New updates to the programs (Ghostscript, GSview, MiKTeX, WinEdt and Acrobat Reader) appear quite frequently. The reader should be warned, since the present page may not always be quite up to date.

    Jouko Arponen, with some minor modifications by Jussi Lehtola. Updated 4.8.2004 (with thanks to Martti Nikunen for several corrections).

    BeginningBeginning Theory homeTheory home