Eric Partlo edited Chapter_4_SpecialitiesWhen_putting_together__.html  about 8 years ago

Commit id: a6fd05fb6488c6194b6304d751d7c7ee44df50ad

deletions | additions      

       

Chapter 4 - Specialities
When putting together a large document, LaTeX will help with some special features like index generation, bibliography management, and other things.  A much more complete description of specialities and enhancements possible with LaTeX can be found in the LaTeX Manual and The LaTeX Companion.
Leslie Lamport. L A TEX: A Document Preparation System. Addison-
Wesley, Reading, Massachusetts, second edition, 1994, ISBN 0-201-
52983-1.

Frank Mittelbach, Michel Goossens, Johannes Braams, David Carlisle,
Chris Rowley. The L A TEX Companion, (2nd Edition). Addison-Wesley,
Reading, Massachusetts, 2004, ISBN 0-201-36299-6.

4.1 Including Encapsulated PostScript
LaTeX provides the basic facilities to work with floating bodies, such as images or graphics, with the figure and table environments.  There are several ways to generate the actual graphics with basic LaTeX or LaTeX extension package.  A much easier way to get graphics into a document is to generate them with a specialised software package and then include the finished graphics in the document.  LaTeX packages offer many ways to do this through Encapsulated PostScript (EPS) graphics, because it is quite easy to do and widely used.  

When working on a system with a PostScript printer available for output and with the graphicx package installed, use the following step by step guide to include a picture into your document:
  1. Export the picture from your graphics program to EPS format
  2. Load the graphicx package in the preamble of the input file with \usepackage[driver]{graphicx} where driver is the name of your "dvi to PostScript" converter program
  3. \includegraphics[key=value,...]{file} The optional parameter accepts a comma separated list of keys and associated values.  The keys can be used to alter the width, height, and rotation of the included graphic.  

4.2 Bibliography
Produce a bibliography with the thebibliography environment.  Each entry starts with \bibitem[label]{marker}
The marker is then used to cite the book, article or paper within the document. \cite{marker}

For larger projects, you might want to check out the BibTeX program.  BibTeX is included with most TeX distributions.  It allows you to maintain a bibliographic database and then extract the references relevant to things you cited in your paper.  

4.3 Indexing
A very useful feature of many books is their index.  With LaTeX and the support program makeindex, an index can be generated quite easily.  

To enable their indexing feature of LaTeX, the makeidx package must be loaded in the preamble with \usepackage{makeidx} and the special indexing commands must be enabled by putting the \makeindex command in the preamble.  The content of the index is specified with \index{key@formatted_entry}

When the input file is processed with LaTeX, each \index command writes an appropriate index entry, together with the current page number, to a special file.  The file has the same name as the LaTeX input file, but a different extension (.dix).  This .idx file can then be processed with the makeindex program: makeindex filename

The makeindex program generates a sorted index with the same base file name, but this time with the extension .ind.

4.2 Fancy Headers
The tricky problem when customising headers and footers is to get things like running section and chapter names in there.  LaTeX accomplishes this with a two-stage approach.  In the header and footer definition, you use the commands \rightmark and \leftmark to represent the current section and chapter heading, respectively.  The values of these two commands are overwritten whenever a chapter or section command is processed.  

4.5 The Verbatim Package
The verbatim package is basically a re-implementation of the verbatim environment that works around some of the limitations of the original verbatim environment.  The verbatim package provides the \verbatiminput{filename} command, which allows you to include raw ASCII text into your document as if it were inside a verbatim environment.

4.6 Installing Extra Packages
Most LaTeX installations come with a large set of pre-installed style packages, but many more are available on the net.  The main place to look for style packages on the Internet is CTAN http://www.ctan.org  Packages such as geometry, hyphenate, and many others are typically made up of two files: a file with the extension .ins and another with the extension .dtx

Once you have copied the package files onto your machine, you still have to process them in a way that:
  1. tells your TeX distribution about the new style package
    1. Run LaTeX on the .ins file, this will extract a .sty file
    2. Move the .sty file to a place where your distribution can find it
    3. Refresh your distribution's file-name database.  The command depends on the LaTeX distribution you use: texlive - texhash, maktexlsr, initexmf --update-fndb
  2. gives you the documentation
    1. Run LaTeX on the .dtx file.  This will generate a .dvi file
    2. Check to see if LaTeX has produced a .idx file among the various files you now have
    3. In order to generate the index, type the following: makeindex -s gind.ist [name] (where name stands for the main-file name without any extension)
    4. Run LaTeX on the .dtx file
    5. Last but not least, make a .ps or .pdf file to increase your reading pleasure

4.7 Working with pdfLaTeX
Most web pages you find today are written in HTML.  This format has two significant disadvantages when writing scientific documents:
  1. Including mathematical formulae into HTML documents is not generally supported.  While there is a standard for it, most browsers used today do not support it, or lack the required fonts.
  2. Printing HTML documents is possible, but the results vary widely between platforms and browsers.  The results are miles removed from the quality we have come to expect in the LaTeX world.
4.7.1 PDF Documents for the Web
The creation of a PDF file from LaTeX source is very simple, thanks to pdfTEX which produces PDF output where normal TEX produces DVI.  There is also a pdfLaTeX, which produces PDF output from LaTeX sources.

To produce a PDF instead of DVI, it is sufficient to replace the command latex file.tex by pdflatex file.tex.  

4.7.2 The Fonts
pdfLaTeX can deal with all sorts of fonts (PK bitmaps, TrueType, PostScript type 1...) but the normal LaTeX font format, the bitmap PK fonts produce very ugly results when the document is displayed with Acrobat Reader.  The Type 1 font set most widely used today is called Latin Modern (LM).  

Two ready-made font sets are available for this purpose: pxfonts, which is based on Palatino as its main text body font, and the txfonts package, which is based on Times.  To use them it is sufficient to put the following lines into the preamble of your document:
\usepackage[T1]{fontenc}
\usepackage{pxfonts}

4.7.3 Using Graphics
Including graphics into a document works best with the graphicx package: \usepackage{xcolor, graphicx}
The bad news is that graphics in Encapsulated PostScript format do not work with pdfLaTeX.  If you don't define a file extension in the \includegraphics command, graphicx will go looking for a new suitable file on its own, depending on the setting of the driver option.  For pdftex this formats .png, .pdf, .jpg, and .mps but not .eps.

4.7.4 Hypertext Links

 Links
The hyperref package will take care of turning all internal references of your document into hyperlinks.  For this to work properly some magic is necessary, so you have to put \usepackage[pdftex]{hyperref} as the last command into the preamble of your document.  Many options are available to customize the behavior of the hyperref package:
  • either as a comma separated list after the pdftex option \usepackage[pdftex]{hyperref}
  • or on individual lines with the command \hypersetup{options}
The only required option is pdftex; the others are optional and allow you to change the default behavior of hyperref.  In the following list the default values are written in an upright font.

If you are happy with the defaults, use \usepackage[pdftex]{hyperref}
To have the bookmark list open and links in colour (the =true values are optional): \usepackage[pdftex,bookmarks,colorlinks]{hyperref}

In addition to the automatic hyperlinks for cross references, it is possible to embed explicit links using \href{url}{text}
The \href{http://www.ctan.org}{CTAN} website.

If the destination of the link is not a URL but a local file, use the \href command without the 'http://' bit: The complete document is \href{manual.pdf}{here}
The author of an article might want her readers to easily send email messages by using the \href command inside the \author command on the title page of the document:
\author{Mary Oetiker $<$\href{mailto:[email protected]}%{[email protected]}$>$

Note the email address is not only in the link but also on the page itself.  The link \href{mailto:[email protected]}{Mary Oetiker} would work will within Acrobat, but once the page is printed the email address would not be visible anymore.

4.7.5 Problems with Links