Google

Go to the first, previous, next, last section, table of contents.

Special sorts of typesetting

Drawing with TeX

There are many packages to do pictures in (La)TeX itself (rather than importing graphics created externally), ranging from simple use of LaTeX picture environment, through enhancements like epic, to sophisticated (but slow) drawing with PicTeX. Depending on your type of drawing, and setup, four systems should be at the top of your list to look at:

  1. graphics/pstricks; this gives you access to all the power of PostScript from TeX itself, by sophisticated use of \specials. You need a decent DVI to PostScript driver (like dvips), but the results are worth it. The well-documented package gives you not only low-level drawing commands (and full colour) like lines, circles, shapes at arbitrary coordinates, but also high-level macros for framing text, drawing trees and matrices, 3D effects, and more.
  2. MetaPost; you liked METAFONT, but never got to grips with font files? Try MetaPost - all the power of METAFONT, but it generates PostScript figures. Knuth uses it for all his work...
  3. Mfpic; you liked METAFONT, but can't understand the language? The package (graphics/mfpic) makes up METAFONT code for you within using familiar-looking TeX macros. Not quite the full power of METAFONT, but a friendlier interface.
  4. You liked PicTeX but don't have enough memory or time? Look at Eitan Gurari's macros/generic/dratex, which is as powerful as most other TeX drawing packages, but is an entirely new implementation, which is not as hard on memory, is much more readable (and is fully documented).

Double-spaced documents in LaTeX

Are you producing a thesis, and trying to obey regulations that were drafted in the typewriter era? Or are you producing copy for a journal that insists on double spacing for the submitted articles?

LaTeX is a typesetting system, so the appropriate design conventions are for ``real books''. If your requirement is from thesis regulations, find whoever is responsible for the regulations, and try to get the wording changed to cater for typeset theses (e.g., to say ``if using a typesetting system, aim to make your thesis look like a well-designed book''). (If your requirement is from a journal, you're probably even less likely to be able to get the rules changed, of course.)

If you fail to convince your officials, or want some inter-line space for copy-editing:

  • Try changing \baselinestretch: \renewcommand{\baselinestretch}{1.2} may be enough to give officials the impression you've kept to their regulations. Don't try changing \baselineskip: its value is reset at any size-changing command.
  • Alternatively, use a line-spacing package. The best for current is macros/latex/contrib/supported/setspace/setspace.sty

Formatting a thesis in LaTeX

Thesis styles are usually very specific to your University, so it's usually not profitable to ask around for a package outside your own University. Since many Universities (in their eccentric way) still require double-spacing, you may care to refer to the question on double-spacing. If you want to write your own, a good place to start is the University of California style (available as macros/latex/contrib/supported/ucthesis), but it's not worth going to a lot of trouble. (If officials won't allow standard typographic conventions, you won't be able to produce an aesthetically pleasing document anyway!)

Flowing text around figures in LaTeX

There are several LaTeX packages that purport to do this, but they all have their limitations because the TeX machine isn't really designed to solve this sort of problem. Piet van Oostrum has conducted a survey of the available packages; he recommends:

picins
picins.sty is part of a large package (systems/msdos/picins/picins.zip) that allows inclusion of pictures (e.g., with shadow boxes, various MS-DOS formats, etc.). The command is:

\parpic(width,height)(x-off,y-off)[Options][Position]{Picture}
Paragraph text

All parameters except the Picture are optional. The picture can be positioned left or right, boxed with a rectangle, oval, shadowbox, dashed box, and a caption can be given which will be included in the list of figures.

Unfortunately (for those of us whose understanding of German is not good), the documentation is in German. Piet van Oostrum has written an English summary macros/latex209/contrib/picins/picins.txt

floatflt
macros/latex/contrib/other/floatflt is an improved version (for LaTeX2e) of floatfig.sty, and its syntax is:
\begin{floatingfigure}[options]{width of figure}
   figure contents
\end{floatingfigure}

There is a (more or less similar) floatingtable environment.

The tables or figures can be set left or right, or alternating on even/odd pages in a double-sided document.

The package works with the multicol package, but doesn't work well in the neighbourhood of list environments (unless you change your LaTeX document).

wrapfig
macros/latex/contrib/other/misc/wrapfig.sty has syntax:
\begin{wrapfigure}[height of figure in lines]{l|r}[overhang]{width}
  figure, caption, etc.
\end{wrapfigure}

The syntax of the wraptable environment is similar.

Height can be omitted, in which case it will be calculated by the package; the package will use the greater of the specified and the actual width. The {l,r,etc.} parameter can also be specified as i(nside) or o(utside) for two-sided documents, and uppercase can be used to indicate that the picture should float. The overhang allows the figure to be moved into the margin. The figure or table will entered into the list of figures or tables if you use the \caption command.

The environments do not work within list environments that end before the figure or table has finished, but can be used in a parbox or minipage, and in twocolumn format.

Alternative head- and footlines in LaTeX

The standard LaTeX document classes define a small set of `page styles' which (in effect) specify head- and footlines for your document. The set defined is very restricted, but LaTeX is capable of much more; people occasionally set about employing LaTeX facilities to do the job, but that's quite unnecessary - Piet van Oostrum has already done the work.

The package is found in directory macros/latex/contrib/supported/fancyhdr and provides simple mechanisms for defining pretty much every head- or footline variation you could want; the directory also contains some (rather good) documentation and one or two smaller packages. Fancyhdr also deals with the tedious behaviour of the standard styles with initial pages, by enabling you to define different page styles for initial and for body pages.

Including a file in verbatim in LaTeX

A good way is to use Rainer Schöpf's verbatim.sty, which provides a command \verbatiminput that takes a file name as argument. This package is available as part of macros/latex/required/tools

Another way is to use the alltt environment, which requires alltt.sty (which is now part of LaTeX). alltt interprets its contents `mostly' verbatim, but executes any TeX commands it finds: so one can say:

  \begin{alltt}
  \input{verb.txt}
  \end{alltt}

of course, this is little use for inputting (La)TeX source code...

The moreverb package (macros/latex/contrib/supported/moreverb) extends the facilities of verbatim package), providing a listing environment and a \listinginput command, which line-number the text of the file.

The fancyvrb package (macros/latex/contrib/supported/fancyvrb) offers configurable implementations of everything verbatim and moreverb have, and more besides. It is nowadays the package of choice for the discerning typesetter of verbatim text, but its wealth of facilities makes it a complex beast and study of the documentation is strongly advised.

Including line numbers in typeset output

For general numbering of lines, there are two packages for use with LaTeX, macros/latex/contrib/supported/lineno (which permits labels attached to individual lines of typeset output) and macros/latex/contrib/supported/numline/numline.sty

Both of these packages play fast and loose with the LaTeX output routine, which can cause problems: the user should beware\dots

If the requirement is for numbering verbatim text, the macros/latex/contrib/supported/moreverb or macros/latex/contrib/supported/fancyvrb packages (see including files in verbatim) may be used.

One common use of line numbers is in critical editions of texts, and for this the edmac package (macros/plain/contrib/edmac) offers comprehensive support.

Generating an index in (La)TeX

Making an index is not trivial; what to index, and how to index it, is difficult to decide, and uniform implementation is difficult to achieve. You will need to mark all items to be indexed in your text (typically with \index commands).

It is not practical to sort a large index within TeX, so a post-processing program is used to sort the output of one TeX run, to be included into the document at the next run.

The following programs are available:

makeindex
for LaTeX under Unix (but runs under other OSs without changes). Available in indexing/makeindex; a version for the Macintosh is available as systems/mac/macmakeindex.sit, and ones for MS-DOS are part of the emTeX and gTeX distributions (the emTeX version also runs under OS/2).

The Makeindex documentation is a good source of information on how to create your own index. Makeindex can be used with some TeX macro packages other than LaTeX, such as Eplain, and \TeXsis{}, nonfree/macros/texsis (whose macros, nonfree/macros/texsis/index/index.tex, can be used independently with plain).

idxtex
for LaTeX under VMS. Available (together with a glossary-maker called glotex) in indexing/glo+idxtex
texindex
A witty little shell/sed-script-based utility for LaTeX under Unix. Available from support/texindex

There are other programs called texindex, notably one that comes with the Texinfo distribution.

xindy
a recent development, designed for wide-ranging flexibility (including support for multilingual indexes), based on Common Lisp. The system is available on CTAN (support/xindy), but is more easily accessed from a web browser via http://www.iti.informatik.th-darmstadt.de/xindy/ since the distribution contains several different implementations.

Typesetting URLs

URLs tend to be very long, and contain characters that would naturally prevent them being hyphenated even if they weren't typically set in \ttfamily, verbatim. Therefore, without special treatment, they often produce wildly overfull \hboxes, and their typeset representation is awful.

There are two approaches to this problem:

  • macros/latex/contrib/other/misc/path.sty, which defines a \path command. The command defines each potential break character as a \discretionary, and offers the user the opportunity of specifying a personal list of potential break characters. Its chief disadvantage is fragility in the LaTeX context.
  • macros/latex/contrib/other/misc/url.sty, which defines an \url command (among others, including its own \path command). The command gives each potential break character a maths-mode `personality', and then sets the URL itself in the user's choice of font, in maths mode. It can produce (LaTeX-style) `robust' commands (see use of \protect) for use within moving arguments. Note that, because the operation is conducted in maths mode, spaces within the URL argument are ignored unless special steps are taken.

The author of this answer prefers the (rather newer) url.sty; both packages work equally well with plain TeX (though of course, the fancy LaTeX facilities of url.sty don't have much place there).

Citing URLs with BibTeX

There is no citation type for URLs, per se, in the standard BibTeX styles, though Oren Patashnik (the author of BibTeX) is considering developing one such for use with the long-awaited BibTeX version 1.0.

The actual information that need be available in a citation of an URL is discussed at some length in the publicly available on-line extracts of ISO 690-2, available via http://www.nlc-bnc.ca/iso/tc46sc9/standard/690-2e.htm; the techniques below do not satisfy all the requirements of ISO 690-2, but they offer a solution that is at least available to users of today's tools.

Until the new version arrives, the simplest technique is to use the howpublished field of the standard styles' @misc function. Of course, the strictures about typesetting URLs still apply, so the entry will look like:

  @misc{...,
    ...,
    howpublished = "\url{http://...}"
  }

Another possibility is that some conventionally-published paper, technical report (or even book) is also available on the Web. In such cases, a useful technique is something like:

  @techreport{...,
    ...,
    note = "Also available as \url{http://...}"
  }

There is good reason to use macros/latex/contrib/other/misc/url.sty in this context, since (by default) it ignores spaces in its argument. BibTeX has a habit of splitting lines it considers excessively long, and if there are no space characters for it to use as `natural' breakpoints, BibTeX will insert a comment (`\textpercent') character ... which is an acceptable character in an URL, so that \url will typeset it. The way around the problem is to insert odd spaces inside the URL itself in the .bib file, to enable BibTeX to make reasonable decisions about breaking the line.

Using BibTeX with plain TeX

The file macros/eplain/btxmac.tex contains macros and documentation for using BibTeX with plain TeX, either directly or with Eplain. See the use of BibTeX for more information about BibTeX itself.

Typesetting music in TeX

A powerful package which allows the typesetting of polyphonic and other multiple-stave music is MusicTeX, written by Daniel Taupin (taupin@rsovax.lps.u-psud.fr). It is available in macros/musictex

In the recent past, Daniel (as well as with various other people, notably Ross Mitchell and Andreas Egler) have been working on a development of MusicTeX, known as MusiXTeX. MusiXTeX is a three-pass system (with a processor program that computes values for the element spacing in the music), and achieves finer control than is possible in the unmodified TeX-based mechanism that MusicTeX uses. Daniel Taupin and Andreas Egler are pursuing distinct versions of MusiXTeX; they are available, respectively, from macros/musixtex/taupin and macros/musixtex/egler

Digital music fans can typeset notation for their efforts by using midi2tex, which translates MIDI data files into MusicTeX source code. It is available from support/midi2tex

A rather simpler notation than MusicTeX is supported by abc2mtex; this is a package designed to notate tunes stored in an ASCII format (abc notation). It was designed primarily for folk and traditional tunes of Western European origin (such as Irish, English and Scottish) which can be written on one stave in standard classical notation. However, it should be extendable to many other types of music. It is available from support/abc2mtex

There is a mailing list for discussion of typesetting music in TeX. To subscribe, send mail to mutex-request@stolaf.edu containing the word `subscribe' in the body.

Drawing Feynman diagrams in LaTeX

Michael Levine's macro package for drawing Feynman diagrams in LaTeX is available in macros/latex209/contrib/feynman

Another possibility is Thorsten Ohl's macros/latex/contrib/supported/feynmf, that works in combination with METAFONT (or MetaPost). The feynmf or feynmp package reads a description of the diagram written in TeX, and writes out code. METAFONT (or MetaPost) can then produce a font (or PostScript file) for use in a subsequent LaTeX run. For new users, who have access to MetaPost, the PostScript version is probably the better route, for document portability and other reasons.


Go to the first, previous, next, last section, table of contents.