Eric Partlo edited Chapter_4_SpecialitiesWhen_putting_together__.html  about 8 years ago

Commit id: 7d16827265765a744dd9a4b2f267b4f1c6d5eef0

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
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
Messages like the following:
! pdfTeX warning (ext4): destination with the same identifier (name{page.1}) has been already used, duplicate ignored
appear when a counter gets reinitialized, for example by using the command \mainmatter provided by the book document class.  It resets the page number counter to 1 prior to the first chapter of the book.  But as the preface of the book also has a page number 1 all links to "page 1" would not be unique anymore, hence the notice that "duplicate has been ignored."

4.7.6 Problems with Bookmarks
The text displayed by bookmarks does not always look like you expect it to look.  Because bookmarks are "just text", fewer characters are available for bookmarks than for normal LaTeX text.  Hyperref will normally notice such problems and put up a warning: Package hyperref Warning: Token not allowed in a PDFDocEncoded string: 

Work around this problem by providing a text string for the bookmarks, which replaces the offending text: \texorpdfstring{TeX text}{Bookmark Text}

Math expressions are a prime candidate for this kind of problem:
\section{\texorpdfstring{$E=mc^2$}%{E = mc ** 2}} 
which turns \section{$E=mc^2$} to "E = mc ** 2" in the bookmark area.

If you write your document in Unicode and use the unicode option for the hyperrf package to use Unicode characters in bookmarks, this will give you a much larger selection of characters to pick from when using \texorpdfstring.

4.7.7 Source Compatibility Between LaTeX and pdfLaTeX
Ideally your document would compile equally well with LaTeX and pdfLaTeX.  The main problem in this respect is the inclusion of graphics.  The simple solution is to systematically drop the file extension from \includegraphics commands.  They will then automatically look for a file of a suitable format in the current directory.  All you have to do is create appropriate version of the graphics files.  LaTeX will look for .eps, and pdfLaTeX will try to include a file extension .png, .pdf, .jpg, or .mps.  

Note that in recent TeX distributions (like TeXLive, MacTeX and MiKTeX), the normal TeX program is actually pdfTeX and it will automatically switch between producing pdf and dvi according to the name it is called with: use the pdflatex command to get pdf output and latex for normal dvi output.

4.8 Working with XeLaTeX
Most of the things said about pdfLaTeX are valid for XeLaTeX

4.8.1 The Fonts
In addition to the normal tfm based fonts, XeLaTeX is able to use any font known to the operating system.  When the font is using OpenType technology you have access to many features which required switching to a separate font or using virtual fonts in the past.  

Where to I get OpenType fonts?
If yo uhave TeXLive installed, you already have some at .../texmf-dist/fonts/opentype, just install them in your operating system.  This collection does not include DejaVu, which is available at http://dejavu-fonts.org

Entering Unicode Characters
The number of characters in a font has grown but the number of keys on a regular keyboard has not.  So, how do I enter non-ASCII characters?  If you write a large amount of text in a foreign language, you can install a keyboard for that language and print out the character positions.  Some environments (X Window System) offer many methods to enter non-ASCII characters.

4.8.2 Compatibility Between XeLaTeX and pdfLaTeX
There are a few things that are different between XeLaTeX and pdfLaTeX
  • A XeLaTeX document has to be written in Unicode (UTF-8) while pdfLaTeX may use different input encoding
  • The microtype packages does not work with XeLaTeX yet, support for character protrusion is already under development
  • Everything font related has to be reviewed

4.9 Creating Presentations

 Presentations
You can present the results of your scientific work on a blackboard, with transparencies, or directly from your laptop using some presentation software.

pdfLaTeX combined with the beamer class allows you to create presentations in PDF, looking much like something you might be able to generate with LibreOffice or PowerPoint if you had a very good day, but much more portable because PDF readers are available on many more systems.  

One of the advantages of the beamer class is the it produces PDF file that is directly usable without first going through a PostScript stage like prosper or requiring additional post processing like presentations created with the ppower4 package.

With the beamer class you can produce several versions (modes) of your document from the same input file.  The input file may contain special instructions for the different modes in angular brackets.  The following modes are available:
  • beamer: for the presentation PDF
  • trans: for transparencies
  • handout: for the printed version