A Brief Introduction to TeX and LaTeX
for the
University of Utah SIAM Student Chapter Meeting
Tuesday 13 November 2018
by
Nelson H. F. Beebe
University of Utah
Department of Mathematics, 110 LCB
155 S 1400 E RM 233
Salt Lake City, UT 84112-0090
USA
E-mail: beebe@math.utah.edu, beebe@acm.org, beebe@computer.org
Web: http://www.math.utah.edu/~beebe
Tel: +1 801 581 5254
FAX: +1 801 581 4148

Last updates: Wed Nov 21 11:23:15 2018 … Fri May 21 11:18:43 2021 … Thu Dec 14 06:16:34 2023 Valid HTML 4.0! Valid CSS!

Table of contents

Abstract

This document, and its accompanying lecture, presents some of the background of the TeX and LaTeX typesetting systems, then shows outlines of simple, moderate, and complex documents, with a goal of taking a beginner far enough to be able to prepare articles, reports, and books, and optional indexes and bibliographies therein. It gives pointers to extensive online resources throughout the document, and lists important reference books in a final section.

The TeX typesetting system

TeX (pronounced techhh), and its companion, the METAFONT font design system, were designed and programmed by Donald Knuth at Stanford University, with some help from his students, from 1977 to 1982; some work continued to about 1992.

TeX and METAFONT are remarkable pieces of software that remain in use 40 years after they were first conceived, and because of the care given to their design, they run on computers as small as watches and mobile devices, through tablets, laptops, and desktops, up to supercomputers. On all systems, they produce identical output with respect to fonts, line breaking, and page breaking.

TeX and METAFONT are copyrighted, but are freely available for both private and commercial use. Many large publishers use TeX behind the scenes for preparation of books and journals. The annual TeX Live releases provide TeX and METAFONT, and much else, as easy-to-install downloadable ISO images for most popular platforms. Many O/S distributions also offer similar software bundles in their package systems.

There are several national / language / regional groups devoted to the support, distribution, and use of TeX and METAFONT, most notably, the international TeX User Group (TUG), with a Web site at http://www.tug.org/ . Our Department of Mathematics hosts the master North American mirror of the Comprehensive TeX Archive Network (CTAN) at http://tug.ctan.org and TeX Live at http://www.math.utah.edu/pub/texlive-utah-2018/ .

TeX's view of the typesetting problem is to reduce the task to putting words into boxes whose dimensions are determined by those of character glyphs in the current font, and kerning information that sometimes adjusts interletter spacing (for example, AW usually has tighter spacing than AM), and then those boxes are separated with flexible horizontal space, called glue. The paragraph-breaking algorithm then finds optimal places to break lines to satisfy default, or user-specified, constraints. The lines are assembled into a page galley, and when the page is filled up, an output routine is automatically invoked to decide where to break the page, a process that can introduce additional vertical spacing to fill up an underfull page, or can output the page, with some lines left over for the next page.

The boxes-and-glue model, global line breaking and page breaking algorithms, and powerful multilingual hyphenation, distinguish TeX from all other document formatting and typesetting systems, many of which place lines on a fixed grid, and do line breaking only locally.

The user interfaces to TeX and LaTeX have changed relatively little since they were first designed, and it is rare for changes to introduce incompatibilities. Thus, documents written decades ago can still be typeset without changes; that feature is of utmost importance for many documents, especially in academia and for publishers. In short, TeX and LaTeX are well suited for production of archival documents.

TeX and METAFONT are extraordinarily reliable programs, and their bug history is reflected in the number of fractional digits in their current version numbers: 3.14159265 and 2.7182818 respectively, or 8 and 7 bugs since March 1990, with fixes applied in 1991, 1992, 1995, 1996, 2002, 2003, 2008, and 2014.

Importantly, TeX has a powerful, albeit somewhat unusual, command language that enables extensive customizations of its behavior, as we illustrate in the rest of this document.

LaTeX document preparation system

While TeX provides superb document typesetting, many of its controls are at a deeper level than most users are interested in. Consequently, in the mid-1980s, Leslie Lamport (then at SRI near Stanford) designed the LaTeX (pronounced La-Techhh or Lah-Techhh or Lay-Techhh, but never L. A. Techhhh) document preparation system to allow authors to describe their documents in terms of higher-level concepts such as document classes, font and style packages, sectioning commands (part, chapter, section, subsection, subsubsection, paragraph, and subparagraph), figures, tables, math displays, and so on.

Donald Knuth won the ACM Turing Award in 1974, and Leslie Lamport won it in 2013. In both cases, the award is for their fundamental research in areas other than TeX and METAFONT.

The goal of LaTeX is that authors should be able to write their documents in terms of common logical elements, such as equations, figures, front matter, index entries, literature citations, sectional commands, tables, and so on, all of which are independent of the typeset appearance of the document. It is the job of document classes, packages, and styles to turn logical elements into particular typeset appearances, and most LaTeX users never need to implement, or modify, those complex software systems.

Importantly, typographic objects, such as sections, equations, figures, and tables can be automatically numbered, and with suitable symbolic labels, can be cross referenced elsewhere in the document.

Because TeX and LaTeX files contain only ordinary printable text, they can be processed with numerous software tools, including editors, e-mail systems, spell checkers, and text filters.

Remember: LaTeX markup indicates what things are, not what they look like when typeset. If you find yourself creating input that reflects visual appearance, you are probably doing something undesirable, or just plain wrong.

TeX's input and output

TeX normally reads a single input file, say, mydoc.tex, but that file can include other input files. Its output is normally a pair of files: a .log file that summarizes typesetting progress and records error and warning messages, and a .dvi (DeVice Independent) file that is a compact representation of typesetting decisions, most of which are of the flavor move to this point on the page, and display this string. The files are related with a common basename, here, mydoc, that is available in TeX as the control word \jobname.

TeX has commands for reading and writing named files, so in more complex cases, more output files can be produced, such as for a table of contents, a list of figures, and data for preparing a document bibliography and index.

The .dvi file cannot be output or viewed without translation to the requirements of some particular device, such as a workstation window, or a printer page. Thus, helper programs, such as dvialw and dvips (for PostScript output), dvipdfm (for PDF output), and xdvi (for X Window System workstation displays), are generally required after a successful TeX run.

TeX knows nothing about character glyph shapes, only their measurements, called metrics. Consequently, it does not read font files, but only .tfm (TeX Font Metric) files. LaTeX additionally reads .fd (Font Descriptor) files that are needed to support font families of various sizes and shapes.

Document indexing

Although TeX can write out phrases and their page numbers to a raw data file, it cannot itself turn that data into a sorted index, with duplicates eliminated, and consecutive page numbers elided. A separate program, such as makeindex or xindy, handles that complex task, outputting a formatted index file that can be read by TeX on a subsequent run to typeset the index.

Bibliographies

As with indexes, TeX does not itself produce references to bibliographic data that usually appear in a sorted list at the end of the document, or rarely, chapter. Instead, it must write citation requests and other information to an output file that another program, such as BibTeX, reads, then finds the needed citations, and prepares a sorted list of references formatted according to a user-chosen style. On a subsequent run, TeX can then include a suitable marker at the point of the citation, and typeset the bibliography, usually near the document end.

Graphics in figures

TeX itself contains little support for incorporating graphics files into a document: instead, it provides an escape mechanism that permits the name of a graphics file in any of several supported formats to be written to the output .dvi file, and the DVI translator program must then insert the graphic in the output display.

Extended TeX's

Because the source code for TeX is freely available, its author expected that some people would modify it for additional typographical features. Among the several such examples are these:

Warning: Because of the complexity of some of the world's writing systems, Unicode fonts require special handling by a software layer provided by the operating system. Document formatters then do not work a character at a time, but instead, they pass a word to the Unicode software layer, and get back a description of the box that holds that word, along with the details of glyph placement and linking within the word. All text display on that operating system should then produce the same output words, but because the Unicode software layer was developed independently for Apple, Microsoft, and Unix systems, there is no guarantee that the returned word dimensions are identical across those three families. That in turn means that TeX is likely to produce different line and page breaking for the same input document, unlike its behavior with other fonts.

TeX commands

All TeX commands are visible in the input stream, using only ordinary printable characters, so documents always consist of a mixture of commands to be acted on, and text to be typeset.

TeX has a powerful mechanism for classifying input characters into different types of commands, such as begin command, begin/end group, and begin/end math, based on their category codes. Few users ever change the default codes, so for most purposes, here are the default characters that are assigned each of the 16 codes:

Except in special verbatim mode, single newlines and multiple spaces are treated as a single space, and two or more consecutive newlines are treated as a paragraph break. In math mode, spaces are ignored entirely, so you can sprinkle them judiciously to make your input more readable, without worrying about the many fine details of mathematical typesetting.

Spaces after control words (but not control symbols) are ignored, so you generally need to terminate them with punctuation, or an empty group, or else put them in a group: \TeX, \LaTeX{}, or {\TeX}.

Here is an example of a small fragment of TeX input:

    The integral of the sine of $x$ is the negative of the
    cosine of $x$: $\int \sin x \, dx = -\cos x$.

Most of that input is just ordinary text, but the variable `x' is typeset in math mode, which in English-language typography chooses a math italic font. The larger block of math mode produces an integral sign, the word `sin' in roman text, a math italic `x', a bit of extra horizontal space, the differential quantity `dx' in math italic, an equals sign, the word `cos' in roman, and finally, a math italic `x'. Notice that the markup is close to how a mathematician would read the math text aloud, and TeX automatically handles the conventional font changes.

If the dollar-sign delimiters on the equation are doubled, then TeX switches from in-line math mode to display math mode, centering the contents, and setting math symbols in the slightly large display size. You can see an example here.

TeX ignores text from a comment character through the end of line, and all leading space on the next line. Thus, if you write

    abc%
       def

then TeX sees the word abcdef.

It is important to understand TeX's handling of spaces and comments: far too many macro packages have been written in inscrutable code because the authors failed to appreciate that readability is more important than saving microseconds of time scanning macro text.

Recommendation: Users of some desktop word processors are conditioned to think that a paragraph should be written as one line. TeX's error messages report line numbers, and it can be quite hard to find an error if the offending line is thousands of characters long. Turn on automatic line breaking, if your text editor supports it, and keep lines short in your input file: 40 to 60 characters are reasonable limits. That is also helpful if you wish to print your input file: long lines otherwise disappear off the edge of the page. This author's texpretty utility can reformat problem files for improved readability.

Because of the category code interpretation, there are 10 characters that need special handling if you want them to be typeset as themselves: & $ # % _ { } ^ ~ \. The first seven of them can be made ordinary characters with backslashed input like this: \& \$ \# \% \_ \{ \}. The remaining three must be handled differently, because their backslashed forms have different meanings. In LaTeX, you can write them as \verb=^=, \verb=~=, and \backslash.

Sample LaTeX documents

Here is a short LaTeX document:

    \documentclass{article}
    \begin{document}
    This is a \LaTeX{} document, not a plain \TeX{} document.
    \end{document}

Notice the use of two control words to typeset the traditional logos for LaTeX and TeX. We can typeset it and view it on a Unix workstation screen in any of several ways:

    % latex simple.ltx
    % xdvi simple.dvi                # or evince simple.dvi

    % latex simple.ltx
    % dvips simple.dvi
    % evince simple.ps               # or ghostview simple.ps

    % latex simple.ltx
    % dvips simple.dvi
    % convert simple.ps simple.pdf   # or ps2pdf simple.ps simple.pdf
    % evince simple.pdf

    % latex simple.ltx
    % dvipdfm simple.dvi
    % evince simple.pdf

    % pdflatex simple.ltx
    % evince simple.pdf

Its output looks like this.

Here is another sample, this time with control sequences that supply accents on the following letter:

    \documentclass{article}
    \begin{document}

    We can get e-acute with \verb=\'e=: \'e.

    We can get o-grave with \verb=\`o=: \'o.

    We can get dotless-i-circumflex with \verb=\^\i=: \^\i.

    We can get a long Hungarian accent with \verb=Erd\H{o}s=:
    Erd\H{o}s.  Hungarian also has a short accent,
    \verb=E{\"o}tv{\"o}s=: E{\"o}tv{\"o}s.

    The input \verb=\~n= produces the Spanish letter \~n.

    Danish and Norwegian have three extra letters at
    the end of their alphabets: \verb=\ae=, \verb=\o=,
    \verb=\aa=: \ae, \o, \aa.   They also can indicate
    a stressed e as with an acute accent \verb=\'e=: \'e.

    Swedish also has three extra letters, but their order
    and glyphs differ: \verb=\aa=, \verb=\"a=, \verb=\"o=:
    \aa, \"a, \"o.

    French has several accented vowels, plus the c-cedilla,
    \verb=\c{c}=, \c{c}, pronounced like s, and rarely,
    the o-e ligature, \verb=\oe=, \oe.  They are not separate
    letters, but dictionaries prescribe their sorting order.

    German uses umlauts: \verb=\"a=, \verb=\"o=, \verb=\"u=:
    \"a, \"o, \"u, but they are not considered extra letters
    in the alphabet.   German also has the es-tzet, or
    scharfe-ess: \verb=\ss= for \ss.  When input or output
    devices lack the glyphs for those characters, German
    permits them to be written as digraphs: ae, oe, ue, and ss.

    \end{document}

Its output looks like this.

Here is the outline of a longer document, followed by a description of its contents:

    \documentclass{report}

    %%% ====================================================================
    %%% The preamble begins here, and no typesetting is permitted

    \usepackage{makeidx}
    \usepackage{microtype}
    \usepackage{tgbonum}

    \makeindex

    \title
    {%
          My first report
          \protect \footnote{Research supported under
                             federal grant WM-2017-193b.}
    }

    \author
    {%
        Jane Doe                                     \\[1ex]
        \small Department of \TeX{}nical Typesetting \\
        \small Podunk Technical College              \\
        \small Greater Podunk, Western Magnulia
    }

    \date
    {%
        23 October 2018                              \\
        Revision 2.3                                 \\
        Technical Report PTC\#2018-17
    }

    %%% The preamble ends here
    %%% ====================================================================

    \begin{document}

    %%% Typesetting begins here

    \maketitle

    \pagenumbering{roman}

    \tableofcontents

    \begin{abstract}
        This document shows the basic elements of a technical
        report, including a bibliography and a subject index.
    \end{abstract}

    \pagenumbering{arabic}

    \chapter{The first}

    \emph{The \TeX{}book} \cite{Knuth:1984:TB}%
    \index{Knuth, Donald Ervin}
    is a critical resource for \TeX{} wizards,
    and \emph{The Advanced {\TeX}book}
    \cite{Salomon:1995:AT}%
    \index{Salomon, David}
    has even more wizardry, especially about
    \TeX{} output routines.

    \section{A section}

    Blah blah.

    \section{Another section}

    Blah blah.

    \chapter{The second}

    ...

    \chapter{The third}

    ...

    \bibliographystyle{plain}
    \bibliography{\jobname,mypapers,myrefs}

    \printindex

    \end{document}

Its output looks like this.

LaTeX enforces the rule that no typesetting can be done in the document preamble, which is the input stream up to the \begin{document} command.

The makeidx package defines a few commands needed for document indexing, but indexing does not happen unless the command \makeindex is used. That is a legacy of the early days of TeX, when computers were more than 1000 times slower than current ones, and time saving was more important then. Today, an entire book of prose can be typeset in a fraction of a second.

The tgbonum package changes the document typeface to a member of the TeX Gyre family; look in the TeX Live path texmf-dist/doc/fonts/tex-gyre for documentation.

The microtype package provides access to typographic enhancements in PDFTeX.

The \author, \date, and \title commands do not cause typesetting: they merely save their argument values for later use by the \maketitle command.

There is some logical markup perversion here, because the simple LaTeX report style does not provide separate front-matter markup commands for addresses, report numbers, and grant acknowledgements. An institutional report class or style would likely do so to ensure uniformity in a report series. It could even generate additional output files with title-page data that could later be automatically incorporated into an annual report for the institution, as well as reports to granting agencies of work done with their support.

The \protect command prevents expansion of the following command as the argument is collected: it disappears in the saved title text, so when \maketitle is executed, a footnote marker is attached to the title, and the footnote text is displayed at the bottom of the page.

Explicit line breaks are indicated by the \\ control symbols; they take an optional bracketed argument that supplies the amount of additional vertical space before the next line. Horizontal and vertical spacing requests should be extremely rare in user documents; the peculiar layout of a title page is an exceptional case where such adjustments might be desirable. Empty lines provide paragraph breaks, so explicit \par commands should be rare. Similarly, forced line breaks with \\ (except in tabular displays) and \newline, and forced page breaks with \clearpage, \cleardoublepage, and \newpage should seldom be used.

The comment percent that follows an open brace at end of line is a subtle but important feature: it ensures that the braced contents do not begin with a space. TeX commands can be programmed to discard such leading space in their arguments, with a low-level \unskip command, but that is seldom the case.

Here is how you might typeset and view that document:

    % pdflatex  report.ltx
    % bibtex    report
    % makeindex report
    % pdflatex  report.ltx
    % pdflatex  report.ltx
    % evince    report.pdf

Notice that LaTeX is invoked three times before internal consistency is reached. On its first run, neither the bibliography nor the index files exist, and the \cite{} commands have unknown arguments, so they are programmed to typeset something like [?].

LaTeX writes an auxiliary file, \jobname.aux, to record information that it needs on subsequent runs.

BibTeX reads the auxiliary file to find the name of the requested bibliography style, and the list of database files that contain entries that describe the publications. They are recorded like this in the .aux file:

    \citation{Knuth:1984:TB}
    \citation{Salomon:1995:AT}
    \bibstyle{plain}
    \bibdata{report,mypapers,myrefs}
    \bibcite{Knuth:1984:TB}{1}
    \bibcite{Salomon:1995:AT}{2}

Here is what part of myrefs.bib looks like:

    @String{pub-AW                  = "Ad{\-d}i{\-s}on-Wes{\-l}ey"}
    @String{pub-AW:adr              = "Reading, MA, USA"}

    @Book{Knuth:1984:TB,
      author =       "Donald E. Knuth",
      title =        "The {\TeX}book",
      publisher =    pub-AW,
      address =      pub-AW:adr,
      pages =        "ix + 483",
      year =         "1984",
      ISBN =         "0-201-13448-9",
      ISBN-13 =      "978-0-201-13448-3",
      LCCN =         "Z253.4.T47 K58 1984",
      bibdate =      "Wed Dec 15 10:37:34 1993",
      bibsource =    "http://www.math.utah.edu/pub/tex/bib/master.bib",
      acknowledgement = ack-nhfb,
    }

BibTeX finds all of the cited reference entries, then sorts and formats their data according to the requested style, and outputs formatted reference list items in the \jobname.bbl file for TeX or LaTeX to read on the next run. Here is what a portion of that file looks like:

    \begin{thebibliography}{1}

    \bibitem{Knuth:1984:TB}
    Donald~E. Knuth.
    \newblock {\em The {\TeX}book}.
    \newblock Ad{\-d}i{\-s}on-Wes{\-l}ey, Reading, MA, USA, 1984.

    ...

    \end{thebibliography}

You can learn much more about BibTeX here.

The LaTeX \index commands write their arguments and the current page number to the \jobname.idx file. For this document, that file is short:

    \indexentry{Knuth, Donald Ervin}{1}
    \indexentry{Salomon, David}{1}

MakeIndex reads that file, and sorts and formats its entries according to the requested style (here, the default), and produces a LaTeX input file, \jobname.ind that looks like this:

    \begin{theindex}

      \item Knuth, Donald Ervin, 1

      \indexspace

      \item Salomon, David, 1

    \end{theindex}

Now that the bibliography and index files are available, LaTeX can typeset them on the next run, but because those files are not read until near the end of the document, the citation labels remain unknown earlier in the document. Their values are finally written to a new version of the \jobname.aux file, and thus, a third run of LaTeX is needed to completely resolve the literature citations.

Recommendation: In practice, index entries, literature citations, and reference lists do not matter much while the document is being created or revised, so most users would normally just run LaTeX alone to see the effects of their changes. The complete set of tools for typesetting, bibliographies, and indexing should be run again to make the final version of the report for distribution to others.

Although for small and simple documents, you might get by with running the programs manually, no one else knows how to do so, so you should always encapsulate the required steps in an associated shell script, or better, in a Unix Makefile, where you can supply not only the needed steps, but also the dependencies of created files on other files.

Journal articles sometimes engender debates, or have subsequent addenda, comments, corrigenda, and errata. BibTeX databases should therefore incorporate cross references between entries, so an author can cite just the main paper, but the bibliography then automatically includes those related papers. BibTeX reads each input file just once, so getting cross references consistent in your typeset document may take one or more pairs of BiBTeX and LaTeX runs. Once again, a command script or a Makefile is the proper way to guarantee consistent typesetting.

There is much more to say about technical writing and typesetting with LaTeX: see this author's Typesetting and Writing Hints for Theses and Dissertations .

TeX dimensions

When lengths are specified in document commands, TeX allows you to suffix numbers with a two-letter code for the units:

Some of those are conventional in the imperial and metric systems of measurements, and others are traditional in English and European continental typography. For example, documents are commonly printed with 10pt type on a 12pt baseline, and mechanical typewriters usually printed six lines per vertical inch, or nearly 1pc per line.

TeX's DVI output allows page-image scaling, but not all dimensions should necessarily scale: ones that relate to measurements on physical devices, such as paper sizes, should not. TeX therefore allows you to insert the keyword true between a number and its unit, as in 210 true mm or 210truemm.

The scaled point is unique to TeX, and is a consequence of a design choice inside the TeX program that all dimensions are represented internally in scaled points. That means that they can be interpreted as integer values in scaled points, or as fixed-point numbers in points, with a 16-bit fraction (because 216 = 65536). A scaled point is smaller than the wavelength of visible light, so you cannot see an object of such a tiny size. However, it is sometimes useful when you want a minuscule, but nonzero, dimension: 1sp does the trick.

A consequence of TeX's representation of fixed-point numbers, and its choice of using the high-order bit following the sign bit as an overflow indicator, is that on computers with a 32-bit integer word, which is common today, there are 14 bits available for the integer part of a fixed-point number, so on most computers, TeX's largest dimension is 1sp under 214 points, which is about 5.75 meters, or 18.89 feet. That is large enough for most typesetting purposes, except possibly for highway billboards, where enlargement of a smaller image would likely be used anyway. TeX makes that size available with the dimension command \maxdimen.

Although it is uncommon to do so, except possibly in the document preamble, or inside style files, you can use dimensions in LaTeX like this:

    \setlength   {\parskip}    {0.25pc}
    \setlength   {\textwidth}  {11cm}
    \setlength   {\textheight} {8in}
    \addtolength {\footskip}   {25pt}

Some measurements in TeX are for glue, or in LaTeX terminology, rubber space. They are like dimensions, but stored in different internal registers in TeX that hold a base dimension, plus two other dimensions, for stretch and shrink. Here are examples:

    \setlength {\parskip} {1pc plus 3pt minus 1pt}
    \setlength {\parskip} {10pt plus 4pt}
    \setlength {\parskip} {12pt minus 3pt}

Flexible glue is commonly used in TeX to improve line breaking and page breaking, and most measurements that would correspond to space on the page are specified with glue units, rather than dimension units.

Besides the nine units that relate to absolute measurements, TeX has two additional dimensions that are frequently useful, because they are relative to the current font size: 1em is about the width of the letter m, and 1ex is about the height of a lowercase x. They are usually employed for horizontal and vertical measurements respectively, but can be used in either context.

TeX supplies two convenient commands for generating small amounts of horizontal space: \quad and \qquad. The first is a fixed space of about 1em, and the second is twice that size. In a math display, they might be used to separate an equation from a comment about the equation.

You can see examples of em, ex, and quad spacing here.

Figures, tables, and floats

In traditional typesetting, supplementary data are often supplied in typeset material that need not be displayed at its point of reference. Such data include figures, tables, appendices, reference lists, and even out-of-document links to Web sites.

Figures and tables in LaTeX are a class of objects that are called floats, because they can be moved automatically from the current page to later pages, if that proves typographically convenient. Float contents cannot be split across page boundaries. The input order of each type of float is preserved in the output, although whether a figure or a table is output next depends on the available space on the page. Figure and table environments need not be graphical objects or tabular displays, but they usually are. There is some limited control in their placement with bracketed optional arguments: ! for really here, h for close to here, b for bottom of this, or a later, page, t for top of this, or a later, page, and p for a separate page of one or more floats.

Although it is rare to do so, you can influence LaTeX's float placement decisions by tweaking the values of these float style parameters, as discussed on pages 199–200 of Lamport's book:

    bottomnumber        \bottomfraction     \dbltopfraction     \textfloatsep
    dbltopnumber        \dblfloatpagefracti \floatpagefraction  \textfraction
    topnumber           \dblfloatsep        \floatsep           \topfraction
    totalnumber         \dbltextfloatsep    \intextsep

Recommendation: Because a tiny change at the start of a chapter can alter line and page breaks through the rest of the chapter, fiddling with float parameter values and float placement while your document is being written is generally a waste of your time. Wait until your document is almost ready for publication, with all text frozen, then fine tune your float positioning as needed, with the goal of placing them as close to their point of first reference as possible for the convenience of your readers. For two-sided printing, such placement should consider even-odd (left-right) facing page pairs. If your LaTeX files are to be submitted to a journal or book publisher for typesetting by their production staff, their fonts and page layout are likely to differ from yours, so let them deal with float placement. [Incidentally, that is why journals often require that all figures be collected at the end of author-supplied documents.]

In English-language typography, the convention is that tables have captions at the top, and figures at the bottom. LaTeX does not do that for you: instead, you must issue commands in a suitable order:

    \begin{figure}[b]
        \begin{picture}
            ...
        \end{picture}
        \caption[Optional, but desirable, short caption]
                {Long caption with complete sentences.}
    \end{figure}

    \begin{table}[t]
        \caption[Optional, but desirable, short caption]
                {Long caption with complete sentences.}
        \begin{tabular}{...}
            ...
        \end{tabular}
    \end{table}

The \caption command increments the float counter, and the float environment can therefore contain multiple graphical or tabular displays, each with its own caption. Unless they are rather short, you probably want them on a separate page, thereby ensuring that they appear together.

    \begin{figure}[p]
        \begin{picture}
            ...
        \end{picture}
        \caption[Optional, but desirable, short caption]
                {Long caption with complete sentences.}

        \begin{picture}
            ...
        \end{picture}
        \caption[Optional, but desirable, short caption]
                {Long caption with complete sentences.}
    \end{figure}

    \begin{table}[p]
        \caption[Optional, but desirable, short caption]
                {Long caption with complete sentences.}
        \begin{tabular}{...}
            ...
        \end{tabular}

        \caption[Optional, but desirable, short caption]
                {Long caption with complete sentences.}
        \begin{tabular}{...}
            ...
        \end{tabular}
    \end{table}

Because the \caption macro changes the float counter, you must take care to place a LaTeX \label command after the caption, like this:

    \includegraphics[scale = 0.5]{fruits}
    \caption{Common temperate-zone fruits.}
    \label{common-fruits}

You can then reference the figure elsewhere in your document like this:

    Figure~\ref{common-fruits} shows common fruits.

It is sometimes useful to have other kinds of floats, but standard LaTeX does not supply a general float mechanism. Fortunately, the float package has been written to remedy that design deficiency. This author has used it to provide a float environment for display of computer programs.

Font style changes

Typesetting systems and document formatters generally have a repertoire of at least several font styles and sizes, often taken from a selected font family. They may include weights (condensed, light, medium, normal, bold, heavy, …) and styles (fixed-width (or monospace, or typewriter), italic, roman, sans serif, slanted, small caps, upright, …). Standard LaTeX provides access to a subset of those choices, and if a particular style or weight is not available, it issues a warning and continues with a possibly suitable default. Thus, you might be able to get bold, bold italic, and italic in one family, but bold italic may be missing from another.

Here are the standard low-level TeX commands for choosing a font style:

Once issued, those commands apply until the end of the document, or the end of the current group, whichever comes first. Thus, when you use them, you must almost always do so in a braced group, like this:

    This is {\bf boldface text} and this is {\it italic text}.

There is a small typographic nicety that you need to pay attention to: when the font style changes from italic or slanted to an upright style, the spacing at the change point may be visually too tight, and in some fonts, the characters at the boundary may overlap slightly. Thus, it is conventional for such fonts to include an italic correction with the TeX control symbol \/. You need it everywhere, except when the next character is a period or a comma: both are low enough that the leaning preceding character cannot overlap that punctuation.

    This is {\it italic text\/} in a sentence.
    This is {\em emphasized text\/} and this is {\sl slanted
    text\/} and for each, an italic correction is required.

    This is {\it italic text}, this is {\em emphasized text},
    this is {\sl slanted text}, and no italic correction is
    needed for any of them.

The italic style should almost never be specified: use the emphasized style instead, so as to avoid introducing unwarranted knowledge of the current font.

LaTeX introduces additional style changing commands beyond those supplied by TeX:

Their style changes apply only to their arguments, making the change clearly limited.

LaTeX also has additional global font-style changing commands that apply to end of group, or end of document:

Font sizes

For most documents, you should expect that your chosen document class is defined by a competent, or expert, typographer, and that suitable font sizes are chosen to make an attractive document. Thus, changing font sizes inside a document should be rare.

You can, however, select a prevailing font size at the start of your document, like this:

    \documentclass        {article}     % default 10pt size

    \documentclass [10pt] {article}     % 10pt size

    \documentclass [11pt] {article}     % 11pt size

    \documentclass [12pt] {article}     % 12pt size

No other sizes are offered by the original LaTeX article, book, and report document classes. Fortunately, extended classes (extarticle, extbook, and extreport) were added in the mid-1990s. They offer point sizes 8, 9, 10, 11, 12, 14, 17, and 20. The smaller sizes might be desirable for lengthy handbooks, and the larger ones for children learning to read, and for people with impaired vision.

LaTeX supplies the following commands for varying the font size in a text region of your document, from smallest to largest: \tiny, \scriptsize, \footnotesize, \small, \normalsize, \large, \Large, \LARGE, \huge, and \Huge. There are separate commands for controlling size in math displays: \scriptscriptstyle, \scriptstyle, \textstyle, and \displaystyle.

The actual sizes that they select depend on the default size specified in the \documentclass command, and also on the font family chosen in a \usepackage command. You can see a test of those sizes here. That output records the height of a capital letter, and the height and depth of a strut, which typically is the same as that of an open or close parenthesis in most fonts.

Font packages

When TeX was first designed, it was soon discovered that fonts for typesetting devices were largely unavailable: none was free, and most required expensive licenses for each of several sizes and styles. Worse, the mathematical character repertoire was nonexistent, or sharply limited, for most font families, and sometimes, font publishers would not even release glyph dimensions that are critically needed by typesetting algorithms. Font file data formats were also often secret and proprietary, making them unusable without possibly illegal decoding and reverse engineering. Thus, METAFONT had to be designed and implemented, and then a large family of fonts developed to handle the needs of mathematical and scientific typesetting.

The initial METAFONT font family is called Computer Modern, and it is based on a venerable typeface from the 19th Century, Linotype Modern 8A, that was used in previous editions of Donald Knuth's books. It is the default font family in TeX and almost all of its extensions, and Volume E, Computer Modern Typefaces, of Donald Knuth's book series Computers and Typesetting is devoted to a description and display of its design.

As computers became more accessible to ordinary people, the font market enlarged dramatically, with price reductions, expansion of the glyph and style repertoires, and publishing of glyph dimensions. Several font designers have released fonts that are free for the public to use without cost, and there are support packages in LaTeX for many of the important ones. Try one of these in a \usepackage{...} command in your document preamble:

    basker         DejaVuSans     newcent        tgpagella
    bookman        fourier        noto           tgschola
    chancery       helvet         palatino       tgtermes
    charter        mathpazo       tgadventor     times
    concrete       libertine      tgbonum        utopia
    courier        lmodern        tgcursor

You can find all of those, and many more, in A Font Family Sampler. That document discusses important issues in choosing a font, and provides samples of fixed-width, math, and text fonts.

There is an extensive discussion of free fonts for LaTeX, with display samples, in The LaTeX Font Catalogue.

If you decide to use a commercial font package, read its license carefully. Some permit further use in documents published as printed books or on the Web, and others may require additional license fees for print publication, and forbid electronic or Web use altogether. Most are issued to a single person for use on a single computer, which is why we cannot offer access to commercial fonts to all of our users.

User-defined commands and environments

Most authors soon find that particular phrases, or typographic displays, occur repeatedly in their documents. It is then worthwhile to define new commands or environments for private use that ensure consistency, make it easy to change their typeset appearance, and provide additional capabilities, such as coloring and indexing, that would be tedious and error prone to do manually.

The simplest command definitions just provide short names for longer phrases, and lettercase in control words is significant:

    \newcommand {\gng}   {gnats and gnus}
    \newcommand {\IBM}   {IBM Corporation}
    \newcommand {\NYSE}  {New York Stock Exchange%
                          \index{New York Stock Exchange (NYSE)}}
    \newcommand {\USDoE} {United States Department of Energy}

Should you accidentally use the name of an existing TeX or LaTeX command, \newcommand rejects your request, and reports an error. You then need to decide whether to rename your command, or force replacement of an existing one, which you can do with \renewcommand, like this:

    \newcommand   {\gng}   {gnats and gnus}
    ...
    \renewcommand {\gng}   {gnats\index{gnat} and gnus\index{gnu}}

We can easily arrange for the first use of a command to display a full definition, with index entries, but then redefine itself to ensure that all subsequent invocations produce only the abbreviation, and at the same time, index every such use:

    \newcommand {\USDoD}
        {%
            United States Department of Defense (USDoD)%
            \index{USDoD|see United States Department of Defense (USDoD)}%
            \index{United States Department of Defense (USDoD)}%
            \renewcommand {\USDoD}{USDoD%
                                   \index{United States Department of
                                          Defense (USDoD)}}
        }

Often, you want to ensure identical treatment of varying phrases. You then need a way to get the phrase automatically inserted into the command expansion. Here are some examples:

    \newcommand {\binom}     [2] {\left(\begin{array}{c}{#1}\\{#2}\end{array}\right)}
    \newcommand {\bioname}   [1] {{{\em #1}}}
    \newcommand {\booktitle} [1] {{{\em #1}}}
    \newcommand {\discard}   [1] {}
    \newcommand {\pkg}       [1] {{{\tt #1}}}

You can have up to nine arguments, referred to as #1 through #9, in the expansion text. It is not required that you refer to all of them in the definition, but you must supply exactly the bracketed number of arguments when you use the command. Those arguments can be used multiple times in the expansion, if needed.

Our \discard command never references its argument, and expands to nothing. Such tricks are handy when you want to disable a command entirely.

Similarly, you can define your own environments, such as these modifications of a predefined environment:

    \newenvironment   {bolditemize} {\begin{itemize}\bf}
                                    {\end{itemize}}
    ...
    \renewenvironment {bolditemize} {\begin{itemize}\bf \large}
                                    {\end{itemize}}
    ...

You can see examples of typesetting with those environments here.

Centering

It is common to center figures, tables, and tabular displays on the page, but LaTeX does not do that automatically. There are three ways to do so:

    \begin{figure}
        \centerline{\includegraphics[...]{...}}
        \caption[...]{...}
    \end{figure}

    \begin{figure}
        {%
            \centering
            \includegraphics[...]{...}
        }
        \caption[...]{...}
    \end{figure}

    \begin{figure}
        \begin{center}
            \includegraphics[...]{...}
        \end{center}
        \caption[...]{...}
    \end{figure}

The first is appropriate for a single line, or box of text, and here produces the same output as the second. The third is different, however, because the center environment is implemented internally as a list environment, and that always produces a bit of extra vertical space before and after the list.

The centering commands produce a surprise when the typeset object is wider than \textwidth: they then place the object flush left, and protruding into the right margin. Tables that are somewhat wider than the normal text are not a serious problem, as long as they do not get too close to the inner or outer page edges, where they would be hard to read. This author solved that problem long ago like this:

    \usepackage{widecenter}
    ...
    \begin{widecenter}
        ...
    \end{widecenter}

The widecenter environment centers its contents on the text width, protruding equally into both margins. Its style file is available here.

Left and right alignment

Hot-lead typesetters traditionally aligned text on both margins, because lead slugs for each glyph were placed in rows on a matrix, and then each row was adjusted by inserting thin shims to spread out words to fit. Consequently, readers of typeset material have come to expect such alignment, even when there is no technological reason to do so.

TeX normally produces uniform left and right margins, but is sometimes desirable to align text to the left or the right, with the opposite margin ragged. There are environments and commands for doing so in LaTeX:

    \textbf{This is normal text:}

    \sample

    \textbf{This is {\tt flushleft} text:}

    \begin{flushleft}
        \sample
    \end{flushleft}

    \textbf{This is {\tt flushright} text:}

    \begin{flushright}
        \sample
    \end{flushright}

    \textbf{This is {\tt raggedright} text:}

    {%
        \raggedright
        \sample
        \par
    }

    \textbf{This is {\tt raggedleft} text:}

    {%
        \raggedleft
        \sample
        \par
    }

You can see the typeset output here. Notice in the output that there is extra vertical spacing when the environments are used.

In the input, a \par command is needed in the last two cases to force a paragraph break. That is because TeX does not break lines until the paragraph ends.

Here is a short example, taken from a book by this author, to typeset epigraphs — short quotations — at the start of chapters:

    %%% Usage: \begin{epigraph} text \end{epigraph}
    \newenvironment{epigraph}%
    {%
        \begin{flushright}%
            \index{epigraph}%
            \small
            \scshape
    }
    {%
        \end{flushright}
    }

    \begin{epigraph}
        Many pitfalls await a systems programmer who    \\
        attempts to implement basic function routines   \\
        using information gleaned from a calculus text. \\[1ex]
        --- W. J. Cody, Jr. and W. Waite%
        \index{Cody, Jr., William J.}%
        \index{Waite, William}
        (1980).
    \end{epigraph}

Tabular displays

Relations between objects are often best displayed in a grid of cells supplied by the tabular environment. It takes an argument that defines the number of cells per row, and their alignment: c (centered), l (left aligned), r (right aligned), and p (paragraph of text). The cells in a row are separated by &, and rows are separated by \\ control symbols. Here are two examples:

    \begin{tabular}{cccc}
        1 & 2 & 3 & 4 \\
        5 & 6 & 7 & 8 \\
        9
    \end{tabular}

    \begin{tabular}{lrrr}
        \hline
        \textbf{Item}      & \textbf{Quantity} &
        \textbf{Unit cost} & \textbf{Total cost}         \\
        \hline
            Gnat & 30,000 & \$0.01    & \$300            \\
            Gnu  &     20 & \$750.00  & \$15,000         \\
        \hline
    \end{tabular}

You can see the typeset output from that document fragment here.

The optional \hline commands supply a thin horizontal rule that fills a row with an implicit line break.

Rows do not need to be filled with cells; omitted ones are treated as empty.

Each cell has its own typographic group, so font and color changes apply only to that cell, and thus must be repeated if needed in other cells.

Tabular displays are frequently wrapped in a center environment, like this:

    \begin{center}
        \begin{tabular}{...}
            ...
        \end{tabular}
    \end{center}

Extra packages and options can supply things like vertically aligned decimal points, colored cells, and cells that span multiple columns or rows, but such features are beyond the scope of this document. See a later section for suggestions.

Graphics inclusions

Because TeX does not supply any graphics capabilities, and LaTeX has only the picture environment whose primary use today is easy positioning of objects in a display, inclusion of graphics files requires a special package, and an understanding on the part of the user of what graphics formats can be used with a particular extension of TeX.

    \usepackage {graphicx}
    ...
    \centerline{\includegraphics[width = 0.5\textwidth]
                                {mypicture.jpg}}

Notice that we specified the picture width as a fraction of the text width: that is almost always a better choice than forcing a particular size.

For DVI-producing versions of TeX, the only commonly supported graphics file format is PostScript, and TeX reads the file just until it finds a special comment of the form

    %%BoundingBox: 50 75 600 400

The units are PostScript points, which TeX calls big points: 72 bp = 1 inch. The four integers are the lower-left and upper-right corner coordinates of the smallest rectangle that encloses the image, measured in a right-handed Cartesian coordinate system with the origin (0,0) at the lower-left corner.

LaTeX needs those dimensions, and any optional rotation, scaling, width, or height requests, so that it can include instructions in the output to tell the DVI translator how to place, and optionally clip, the image to fit in a box of the desired size. The PostScript file must use only a language subset that is called Encapsulated PostScript, and excludes three dozen PostScript operators that fiddle with the page scaling, rotation, translation, and output. Here is a table of the forbidden operators:

    banddevice              nulldevice              setoverprint
    clear                   quit                    setpagedevice
    cleardictstack          renderbands             setscreen
    copypage                setblackgeneration      setshared
    erasepage               setcolorrendering       setsmoothness
    executive               setcolorscreen          settransfer
    exitserver              setcolortransfer        setundercolorremoval
    framedevice             setflat                 startjob
    grestoreall             setglobal               statusdict
    initclip                setgstate               undefinefont
    initgraphics            sethalftone             undefineresource
    initmatrix              setmatrix               userdict

Perhaps surprisingly, the PostScript showpage operator is absent from that list; it displays the current page on the output device. The reason that it is permitted is that it is almost always present, so software that includes PostScript files is expected to temporarily redefine it to a no-op.

For PDF-producing versions of TeX, PostScript graphics files cannot be supported, because PDF is a nonprogrammable page description language, whereas PostScript is a full programming language with variables, functions, conditionals, loops, and I/O operators. Instead, you can use graphics files in bitmap formats (JBIG2, JPEG, and PNG), or one-page PDF files. The utilities convert and sam2p can convert between a variety of bitmap formats. Their simplest use requires only specification of suitable file types for input (first) and output (second) files:

    % convert myphoto.jpg myphoto.png
    % sam2p   myphoto.jpg myphoto.jbig2

Multipage PDF files can be included via additional commands supplied by the pdfpages package. We exploit that feature to allow inclusion of published papers as chapters of dissertations and theses; see our Web site for examples.

The \includegraphics command detects which flavor of extended TeX engine is underneath, and automatically searches for files that match the supported graphics file types, so you should always omit the file extension:

    \includegraphics[width = 0.5\textwidth]{mypicture}

You can then arrange to have two versions of your image file, one in PostScript (mypicture.eps), and one in another format, such as mypicture.pdf or mypicture.png. Unless you are dealing with photographic images, you should avoid bitmap formats, because they fix the picture resolution; PostScript and PDF both support scaleable image descriptions.

Bitmap files have another serious problem: most use lossy compression algorithms that sacrifice image quality to reduce filesystem space. In the case of line drawings, the data loss introduces unwanted visual artifacts near the lines.

There is also support for Scaleable Vector Graphics (SVG) files, but processing is a bit more complex; consult the documentation for the svg package, a copy of which is available here.

Recommendation: In order to ensure portability of your documents across diverse operating systems and filesystems, please restrict your filename characters to ASCII letters, digits, hyphen, underscore, and at most a single period. Never use any of the 10 characters that have special significance to TeX, and never use spaces in filenames. Also, while relative pathnames to files in directories below the current one are perfectly okay, as in

    \includegraphics{images/mypicture}

never use absolute pathnames to files elsewhere in the filesystem, such as

    \includegraphics{/home/doe/research/2018/images/mypicture} % NOOOOOO ....

because that ties your document to just one computer system.

Although Microsoft Windows normally separates directory names with backslashes, you can use a slash in pathnames, so relative paths with slashes work on all common operating systems.

Some filesystems represent filenames case independently, while others (like Unix) are case sensitive, and still others are case preserving, but case ignoring (like Microsoft Windows, and some Apple Macintosh filesystems). The safest approach is to name your files in a single lettercase — lower —, and ensure that references to them in your documents are spelled identically.

Historical note: Older filesystems often severely limited the format and length of filenames, such as the 6 + 3 or 8 + 3 rules that permitted up to 6 or 8 alphanumerics for the basename, a single period, and up to 3 alphanumerics for the extension or type. However, by about the year 2000, most operating systems had added support for much longer filenames, and relaxed the syntax restrictions.

Recommendation: Each document deserves its own filesystem directory, and it should be possible to transfer that directory contents to any other operating system on any other computer in the world, and still have it be typesettable by TeX without modification of any file.

Common historical filesystems differ on how lines are terminated: some older O/Ses, and Microsoft ones, use the CR LF pair. Unix uses just LF, while older Apple filesystems used only CR. PostScript was designed to recognize all three, but TeX originally was not. Fortunately, that problem has long since been repaired by system-dependent changes to TeX that are permitted by its license.

Verbatim displays

Documents that deal with computer input and output often require the ability to typeset arbitrary characters, without having to protect the 10 characters that cause special handling by TeX, and, in particular, without collapsing consecutive spaces to a single space, as TeX normally does as it reads its input stream.

LaTeX provides two common ways of typesetting such text verbatim, a short command form for inline use, and an environment for multiline display:

    \verb=a b c=

    \verb=http://www.math.utah.edu/~beebe/=

    \verb*=Enter your guess: =

    \begin{verbatim}
    #include <stddef.h>
    #include <stdio.h>

    int
    main(void)
    {
        static double x = 0.125;

        (void)printf("x = %.3f = %a\n", x, x);
        (void)printf("x = %.3f = %.6a\n", x, x);

        return (EXIT_SUCCESS);
    }
    \end{verbatim}

    \begin{verbatim*}
    #include <stddef.h>
    #include <stdio.h>

    int
    main(void)
    {
        static double x = 0.125;

        (void)printf("x = %.3f = %a\n", x, x);
        (void)printf("x = %.3f = %.6a\n", x, x);

        return (EXIT_SUCCESS);
    }
    \end{verbatim*}

You can see the typeset output of those examples here.

The starred form of the command displays each space as a lowered half box, and is useful when you want to emphasize the presence of spaces. The verbatim* environment also makes all spaces visible, but it is unlikely to be needed, except possibly for display of historic punched-card input, or perhaps for code in the Python language, where leading space is significant.

The argument of the \verb and \verb* commands is delimited by an identical punctuation character. We use an equals sign in the examples in this document, but at-sign, minus, plus, underscore, and vertical bar are also reasonable delimiter characters that are unlikely to be needed in most verbatim text.

When LaTeX begins to process a verbatim command, it temporarily changes the category codes of all characters except the outer delimiter character, and then collects, and typesets, the argument in the current fixed-width font. Similarly, in the verbatim environment, it just chugs along typesetting characters, and newlines, literally, until it comes to the magic string \end{verbatim}, which causes restoration of category codes to their values at entry to the verbatim text, and returns to normal typesetting. TeX ignores spaces after control words, but this may be the sole exception in all of TeX where no space is permitted between the command \end and the argument string {verbatim}.

The character-code changes that are required for TeX to handle verbatim text mean that it is impossible to have such text in arguments to other commands. If you need such things, you have to work around the restriction by minor rewriting:

    \section{The \verb=\caption= command}           % ERRONEOUS!

    \section{The {\tt \backslash caption} command}  % OKAY!

One important caveat for verbatim text input is that TeX does not treat a horizontal tab (HT) as you would expect: the usual convention in editing and printing is that a tab causes filling with one or more spaces up through the next character column that is a multiple of 8. Instead, TeX just discards the tab as unrepresentable, thereby destroying the display of your nicely lined-up source code. To fix that, you need to expand all tabs in verbatim displays to spaces. In the emacs text editor, you can mark a region of text, then run the command M-x untabify. Alternatively, you can filter your LaTeX file with the Unix expand utility to convert all tabs to the correct sequences of spaces:

    % mv myfile.ltx myfile.ltx-tabs
    % expand myfile.ltx-tabs > myfile.ltx

You might sometimes want to typeset entire computer files as verbatim text, and with optional line numbering or coloring. The basic LaTeX commands cannot do that, but additional commands supplied by the fancyvrb package support those features.

Related packages for typesetting computer files include listings and tgrind.

Documents like this one have frequent references to filenames, e-mail addresses, and Internet URLs (Uniform Resource Locators). The best way to handle them in LaTeX is to use the url package. You can then write LaTeX input like this:

    My e-mail address is \url{beebe@math.utah.edu}.

    My Web site is \url{http://www.math.utah.edu/~beebe}.

    This file is called \url{index.html}.

The arguments are then set in the current fixed-width font, and importantly, can be broken at line boundaries at user-selectable punctuation characters, without introducing a final hyphen that would corrupt the meaning of the argument, which is automatically hyperlinked if the hyperref package has been included.

Math typesetting

This is a huge area that can take an entire book to cover, so we can only give a few examples here. TeX has named symbols for Greek letters (\alpha, \beta, \gamma, … \Chi, \Psi, \Omega, but only for those that have different letter shapes than their Latin descendants), blackboard bold letters, calligraphic letters, fraktur letters, one Hebrew letter (\aleph), integrals and sums (\int and \sum), partial derivatives (\partial), and numerous operators and symbols little seen outside of specialized areas of mathematics. It also has arrows of many kinds, commutative diagrams, continued fractions, normal fractions (\frac{a}{b}), matrices, vectors, and so on.

Inline math text is generated with either LaTeX \( ... \) or TeX $ ... $ markup. If that math material would extend into the margin, TeX makes an attempt to break it at a suitable place.

Display math text is centered on a line by itself, without any equation number, and is generated with LaTeX \[ ... \] or \begin{displaymath} ... \end{displaymath}, or with TeX $$ ... $$. To get a numbered equation, use LaTeX's \begin{equation} ... \end{equation}. However, TeX never breaks such displays across lines if they are too long to fit, on the grounds that mathematics typesetting is hard, and a computer program's choice of line breaks may be inferior to a human's.

A math display is normally considered part of the preceding paragraph, so there should not be a paragraph break from an empty line before it. To keep your input legible, just use an empty comment line to make it easy to see, like this:

    This is a displayed equation:
    %
    \begin{displaymath}
        a = \sqrt{b + c} / \sqrt[3]{\alpha + \beta + \gamma}
    \end{displaymath}
    %
    We continue our remarks in the same paragraph.

Each math display is expected to contain only one line. To get multiline math displays, you need different LaTeX environments: eqnarray (numbered) or eqnarray* (unnumbered). They behave like a three-column tabular environment, with two & separators in each row, and with rows separated by \\ control symbols.

Here are some famous formulas from Albert Einstein's special relativity, the roots of a quadratic equation, the Euler relation, the Taylor series of the exponential function, and some properties of the tangent function:

    \begin{eqnarray*}
        E                            &=& m c^2                                   \\
        x                            &=& \frac{-b \pm \sqrt{b^2 - 4 a c}}{2a}    \\
        e^{i \pi} + 1                &=& 0                                       \\
        e^x                          &=& \sum_{k = 0}^\infty x^n / n!            \\
        \int \tan x \, dx            &=& -\ln(\cos x)                            \\
        \int_0^{\pi/4} \tan x \, dx  &=& \ln(2) / 2                              \\
        \int_0^{\pi/2} \tan x \, dx  &=& \infty                                  \\
        \tan x                       &=& 0 + \frac{x}
                                             {1 + \frac{x^2}
                                                        {-3 + \frac{x^2}
                                                                  {5 + \ldots}}} \\[1ex]
        \tan x                       &=& 0 + \frac{x}
                                             {\displaystyle 1 + \frac{x^2}
                                                        {\displaystyle -3 + \frac{x^2}
                                                                  {\displaystyle 5 + \ldots}}}
    \end{eqnarray*}

You can see an enlarged typeset version of that display here.

Warning: The spacing around the central column of the eqnarray environment is now considered suboptimal, and the restriction to three cells per row is often too limiting, but its implementation is forever frozen because it is in wide use in millions of documents. Modern practice is to avoid that environment entirely, and instead, use the align (numbered) and align* (unnumbered) environments supplied by the amsmath package.

The align environment does not require that you declare the number of alignment points for multicolumn output: just put an ampersand at each such point. Here are some examples of its use:

    \usepackage{amsmath}

    ...

    This is a numbered display:
    %
    \begin{align}
        a &= b         \\
          &= c + d     \\
          &= e + f + g
    \end{align}

    Here is its unnumbered companion:
    %
    \begin{align*}
        a &= b         \\
          &= c + d     \\
          &= e + f + g
    \end{align*}

    Here is an example of multiple alignment points:
    %
    \begin{align*}
        a &= b         & &< A     & & \ll B                 \\
          &= c + d     & &> C + D & & \gg \gamma + \delta   \\
          &= e + f + g
    \end{align*}

You find typeset output for several of those examples here.

When multiline displays contain more than one equation, punctuate them like an inline list, with separating commas, and a final period. With continued right-hand sides, only the last one merits punctuation:

    \begin{align*}
        a &= b, \\
        c &= d, \\
        e &= f, \\
        g &= h.
    \end{align}

    \begin{align*}
        a &= b  \\
          &= c  \\
          &= d, \\
        e &= f, \\
        g &= h.
    \end{align*}

The align environment makes it easy to add comments in math displays, similar to the practices in computer programming:

    \newcommand {\mathcomment} [1] {\qquad \mbox{\footnotesize \textsl {#1}}}

    ...

    Here is a display decorated with right-aligned comments:

    \begin{align*}
        a &= b          & \mathcomment{same as $b$}      \\
          &= c          & \mathcomment{also same as $c$} \\
          &= d,         & \mathcomment{and $d$ too}      \\
        e &= f,         & \mathcomment{same as $f$}      \\
        g &= h.         & \mathcomment{same as $g$}
    \end{align*}

    Here is the same display, but decorated with left-aligned comments:

    \begin{align*}
        a &= b          & & \mathcomment{same as $b$}      \\
          &= c          & & \mathcomment{also same as $c$} \\
          &= d,         & & \mathcomment{and $d$ too}      \\
        e &= f,         & & \mathcomment{same as $f$}      \\
        g &= h.         & & \mathcomment{same as $g$}
    \end{align*}

Recommendation: Technical documents are often complex, and it helps the reader if you reduce clutter. Thus, avoid numbering math displays that you never cross reference.

Fixing overfull boxes

TeX diagnoses horizontal and vertical boxes that are too big to fit in their alloted space. You might find it helpful to insert these two lines into your document preamble, and then swap their order as desired:

    \overfullrule = 0pt                 % do not show overfull boxes
    \overfullrule = 100pt               % make overfull boxes really visible!

If you prefer to remain in LaTeX syntax, write instead

    \setlength {\overfullrule}   {0pt}  % do not show overfull boxes
    \setlength {\overfullrule} {100pt}  % make overfull boxes really visible!

The first is the default value. The second produces a 100pt-wide black rule in the right margin of any line that is overfull, that is, protrudes into the margin. That action makes problem lines easily visible in a document viewer. It is your job to fix such problems, which can be done in several ways:

Page layout and document printing

Most users should be satisfied with the default page layout defined by their chosen document class. Nevertheless, there are situations where tweaks to various layout parameters are needed. They are all dimension values, so you can set them in LaTeX with code like this: \setlength {\parindent} {10pt}. Rather than tabulate them here, it is better to look at their use in the page images in this file.

One point that sometimes causes confusion, and document portability problems, is the physical paper size. Countries differ in their preferred office paper sizes, but two common choices are European A4 (210mm wide by 297mm high, or about 8.27 by 11.69 inches, or about 595.28 by 841.89 big points), and US A or letter (8.5 by 11 inches, or 215.9 by 279.4 millimeters, or 612 by 792 big points). Standard document classes are defined with sufficient page margins to allow printing on either of those sizes, but sometimes, users modify page layouts so that they work only with one of those.

Standard LaTeX classes have options for choosing one of a few different paper sizes and orientations, as in these examples:

    \documentclass [letterpaper]           {article}
    \documentclass [a4paper]               {article}
    \documentclass [landscape, legalpaper] {article}

They also set dimensional values \paperwidth and \paperheight. Most documents, however, should never use paper-related options, and instead should rely on the document class and TeX installation defaults.

While TeX itself knows nothing about paper sizes, several software tools that are included in TeX and METAFONT distributions do, but incompatibly so. Thus, it is not easy to manually find the several configuration files that need adjustments to change your default paper size. Fortunately, with TeX Live distributions, it is easy to switch:

    % man tlmgr                # view tlmgr manual pages
    % tlmgr paper a4
    % tlmgr paper letter

    ## If your system does not have tlmgr, try this for a personal change:
    % texconfig paper letter

    ## or this for a system-wide change:
    # texconfig-sys paper letter

Here is a list of the configuration files that are changed by those commands in a TeX Live 2018 installation tree:

    texmf-config/dvipdfmx/dvipdfmx.cfg
    texmf-config/dvips/config/config.ps
    texmf-config/psutils/paper.cfg
    texmf-config/tex/context/user/cont-sys.tex
    texmf-config/tex/generic/config/pdftexconfig.tex
    texmf-config/xdvi/XDvi

You can find what the default paper types are, and where they are set, in your TeX Live installation with a command like this (pathnames are site dependent):

    % tlmgr paper
    Current context paper size (from /usr/local/texlive/2021/texmf-config/tex/context/user/cont-sys.tex): letter
    Current dvipdfmx paper size (from /usr/local/texlive/2021/texmf-config/dvipdfmx/dvipdfmx.cfg): letter
    Current dvips paper size (from /usr/local/texlive/2021/texmf-config/dvips/config/config.ps): letter
    Current pdftex paper size (from /usr/local/texlive/2021/texmf-config/tex/generic/tex-ini-files/pdftexconfig.tex): letter
    Current psutils paper size (from /usr/local/texlive/2021/texmf-config/psutils/paper.cfg): letter
    Current xdvi paper size (from /usr/local/texlive/2021/texmf-config/xdvi/XDvi): letter

Including those files, more than 50 *.fmt files might be regenerated. They contain binary dumps of TeX's memory after large macro packages have been loaded, and are used to speedup subsequent typesetting runs. In TeX Live, you can manually force the regeneration of those files like this:

    % fmtutil-sys --all

Tests on various systems with vendor-supplied TeX installations turn up an additional level of complexity: whether new format files are generated by that command is controlled by lines in the file fmtutil.cnf somewhere inside the installation tree. This author had to uncomment the pdflatex and pdftex lines in that file before running fmtutil-sys.

On Debian and Ubuntu systems, which have the apt tool for software package management, the proper way to change paper sizes for all software on the system, including programs that are unrelated to TeX, is to run one of these commands:

    # paperconfig -p a4
    # paperconfig -p letter

The short file /etc/papersize records the current size. To restrict the changes just to TeXware, instead run one of these:

    # tl-paper set all a4
    # tl-paper set all letter

If you install a separate TeX Live distribution, you also need to run the tlmgr commands described earlier.

There are several other O/S distributions, even ones outside the GNU/Linux family, that use Debian-style packaging, but they lack full support for paper management. On those, you likely also need to run tlmgr, tl-paper, texconfig, and fmtutil-sys. Those tools handle only TeXware; paper sizes assumed by other programs may require detective work, and manual changes, on your part.

Because some distributions of TeX and METAFONT do not supply a simple way to change paper sizes, you might have to do the job manually. Here is a difference listing made after having saved the previous configuration files in a temporary directory, and then changing paper sizes:

    % diff -r /var/tmp/texmf-config texmf-config

    % diff -r /var/tmp/texmf-config/dvipdfmx/dvipdfmx.cfg texmf-config/dvipdfmx/dvipdfmx.cfg
    39c39
    < p a4
    ---
    > p letter

    % diff -r /var/tmp/texmf-config/dvips/config/config.ps texmf-config/dvips/config/config.ps
    63a64,71
    > @ letter 8.5in 11in
    > @+ ! %%DocumentPaperSizes: Letter
    > @+ %%BeginPaperSize: Letter
    > @+ /setpagedevice where
    > @+  { pop << /PageSize [612 792] >> setpagedevice }
    > @+  { /letter where { pop letter } if }
    > @+ ifelse
    > @+ %%EndPaperSize
    74,81d81
    < @ letter 8.5in 11in
    < @+ ! %%DocumentPaperSizes: Letter
    < @+ %%BeginPaperSize: Letter
    < @+ /setpagedevice where
    < @+  { pop << /PageSize [612 792] >> setpagedevice }
    < @+  { /letter where { pop letter } if }
    < @+ ifelse
    < @+ %%EndPaperSize
    Only in texmf-config: ls-R

    % diff -r /var/tmp/texmf-config/psutils/paper.cfg texmf-config/psutils/paper.cfg
    2c2
    < p a4
    ---
    > p letter

    % diff -r /var/tmp/texmf-config/tex/context/user/cont-sys.tex texmf-config/tex/context/user/cont-sys.tex
    186c186
    < \setuppapersize[a4][a4]
    ---
    > \setuppapersize[letter][letter]

    % diff -r /var/tmp/texmf-config/tex/generic/config/pdftexconfig.tex texmf-config/tex/generic/config/pdftexconfig.tex
    9,10c9,10
    < \pdfpageheight       = 297 true mm
    < \pdfpagewidth        = 210 true mm
    ---
    > \pdfpageheight       = 11 true in
    > \pdfpagewidth        = 8.5 true in
    Only in texmf-config: web2c

    % diff -r /var/tmp/texmf-config/xdvi/XDvi texmf-config/xdvi/XDvi
    24c24
    < *paper: a4
    ---
    > *paper: letter

PDF files generally contain a paper size specification, which you can see via a document-properties display in a PDF viewer, or on the command line like this:

    % pdfinfo weinberg-2005-em.pdf
    Title:          Einstein's Mistakes
    Subject:        Articles
    Keywords:       Physics Today November 2005, page 31-35
    Author:         Steven Weinberg
    Creator:        PScript5.dll Version 5.2.2
    Producer:       Acrobat Distiller 6.0 (Windows)
    CreationDate:   Wed Oct 12 12:05:33 2005
    ModDate:        Thu Nov  3 10:05:17 2005
    Tagged:         no
    Form:           AcroForm
    Pages:          5
    Encrypted:      yes (print:yes copy:no change:no addNotes:no)
    Page size:      648 x 756 pts (rotated 0 degrees)
    File size:      332318 bytes
    Optimized:      yes
    PDF version:    1.5

Notice that the Page size value (given in PostScript points, or TeX big points) differs from both A and A4 sizes. Printing devices vary in their handling of nondefault paper sizes. Some simply refuse to print the document, while others can be configured to use a nearby size. When a document cannot be printed, the printer may pause for human intervention, even though other jobs in the printer input queue could be printed without problems. The only way to successfully print such a document may then be through a PDF viewer that allows a choice of output paper size, and optionally, scaling of the text. Paper sizes for journal articles and books vary widely, so you will soon encounter that printing problem.

Advice: When \documentclass paper options are used, they affect the computation of page margins and text area dimensions, but they do not change the paper sizes that PDFTeX records in the PDF file; instead, those values are taken from a local configuration file. Thus, you need to do something like this to produce A4 documents at a site where US A format is the default:

    \documentclass [a4paper] {article}
    \pdfpageheight = 29.7 true cm
    \pdfpagewidth  = 21 true cm

If you still want to be able to produce DVI output, you need to check that those variables already exist, like this:

    \documentclass [a4paper] {article}
    \ifx \undefined \pdfpageheight
    \else
        \pdfpageheight = 29.7 true cm
        \pdfpagewidth  = 21 true cm
    \fi

Clearly, such additional low-level code belongs in a private style file, instead of in the document file itself.

Here is another way to achieve the same goal:

    \documentclass [a4paper] {article}
    \usepackage    [a4paper] {geometry}

The problem is that the geometry package is complex, and its use might affect other parts of your document. You should avoid it, if two simple assignments can do precisely what you want.

Popular LaTeX packages

TeX and METAFONT installations are generally accompanied by a considerable suite of companion software tools and class and style files. The TeX Live 2018 distribution contains 175,000+ files in 13,300+ directories, includes 5,100+ packages, and 7200+ PDF documentation files, and occupies about 9GB of filesystem space. There are nearly two million lines in style files, and about a half million lines in class files. Even large books, like the famous three-volume LaTeX Companion book series, can only discuss a few hundred packages. Apart from the font packages discussed in links from a previous section, here are some more that this author has found useful across numerous articles, reports, and books, and you may as well (run the command texdoc pkgname to find documentation for a particular package):

amsfonts American Mathematical Society (AMS) extended font collections, especially for mathematical text, including medium and bold series, Cyrillic, caps and small caps, Euler fonts
amsmath TeX commands and environments for fancy mathematical typesetting as required by AMS publications
amssymb TeX command names for AMS math symbols
amsthm Extensions of LaTeX's \newtheorem environment
array New implementation of LaTeX array and tabular environments with extended features
beamer Support for fancy lecture slides
authidx Support for author/editor indexes of bibliographic data; requires a helper program, authidx.awk (author contributed)
calligra Extended calligraphic fonts, including coverage of lowercase letters
color Support for background and foreground colors
coloralias Support for defining aliases for named colors (author contributed)
colortbl Support for cell, row, and column coloring in tabular display
dcolumn Support for tabular data aligned on decimal points
fancyvrb Enhanced verbatim environments with coloring, file inclusion, and optional line numbering
fontenc Support for dealing with the historical mess of dozens of incompatible character encodings on computers around the world, now all subsumed into Unicode
graphicx Support for graphics file inclusion, with optional scaling and rotation
hhmm Support for typesetting current time in hours and minutes (author contributed)
hyperref Support for hypertext links in PDF output
keyname Support for typesetting oval boxes around computer keyboard keynames (author contributed)
listings Support for typesetting computer programs in 100+ programming languages with highlighted keywords; its documentation also describes several other similar packages
longtable Support for tabular data that can be automatically split at page boundaries, with optional header and footer text on successive pages (see also supertabular)
luximono Support for an alternative, compact, and readable fixed-width font that may provide a better solution for display of computer input and output than the default typewriter font
makeidx Commands for document indexing and index printing
microtype Access to microtypographic extensions of PDFTeX, providing improvements in line breaking, and reduced hyphenation, over TeX's already superb algorithms
namelist Support for aligned named items in lists, as an alternative to the LaTeX description environment (author contributed)
multicol Enhanced multicolumn typesetting, including switching between single and multicolumn displays on the same page, and improved balancing of multicolumn material
nimbusmononarrow Support for an alternative, compact, and readable fixed-width font, available in four different weights
pifont Support for special characters available in some PostScript fonts
rgb Support for all of the 650+ color names from the X11 Window System (author contributed)
supertabular Support for tabular data that can be automatically split at page boundaries, with optional header and footer text on successive pages (see also longtable)
tgrind Support for typesetting computer programs with bold keywords, preserving indentation of tabs and spaces (also needs tgrindex.tex and tgrindmac.tex)
url Handling of filenames, URLs, and e-mail addresses, including support for hypertext links in PDF output
varioref Support for automatic addition of page numbers in LaTeX cross references [strongly recommended as a service to your readers]
widecenter Support for centering of more-than-page-wide displays (author contributed)
xcolor Extended support for color shades, tints, and tones

Low-level hacking

LaTeX is designed to isolate the document author from most of the low-level details of the TeX engine. However, with a few exceptions, most plain TeX commands remain accessible in LaTeX, but if you use them, you do so at your own risk: a future release of LaTeX could break your code.

An exception to that recommendation is LaTeX class and style files, because they are often implemented using a considerable amount of plain TeX: it would be impossible to write the LaTeX system in LaTeX itself!

Here is one example where we redefine a LaTeX command to add color to its argument:

    \usepackage{color}

    ...

    \newcommand   {\mytitle} [1] {\centerline{\Large #1}}

    ...

    \let \oldmytitle = \mytitle
    \renewcommand {\mytitle} [1] {\oldmytitle{{\color{red}#1}}}

The TeX \let command saves the original command definition under a different name that then behaves identically to the original. We then redefine the original command to wrap its argument in color, and pass that argument to the saved command.

Of course, in that example, you know what the original command does, because you wrote it yourself. However, the same trick works for many LaTeX commands defined in classes or packages, where you almost certainly want to avoid knowing anything at all about the internals of the command implementation.

Here is another example: you want to completely disable the uppercasing of text, such as LaTeX does for running page headers. A little digging in style files shows that LaTeX uses an undocumented internal macro named \MakeUppercase that takes a single argument. You can turn it into a no-op with either of these definitions:

    \let \MakeUppercase = \relax

    \renewcommand {\MakeUppercase} [1] {#1}

The TeX \relax command consumes no argument, and does nothing, but is useful when you want that inaction to be a macro.

One place where LaTeX users are likely to need \relax or an empty brace group, {}, is in tabular displays where the next line begins with a left bracket. TeX skips intervening space between a command and its first argument, and between its arguments, so that left bracket would be interpreted as the start of an optional dimension argument. Here is an example:

    \begin{tabular}{ll}
     \{ braced value \}      & mandatory TeX or LaTeX argument             \\ \relax
     [ bracketed value ]     & optional LaTeX argument                     \\
     ( parenthesized value ) & rare, and special, mandatory LaTeX argument \\
     \verb=\somename=        & macro used as single TeX or LaTeX argument
    \end{tabular}

Advice: TeX macros can have complex definitions that require special patterns in their use; such macros cannot be created in standard LaTeX markup, so \let is generally preferred over \newcommand for saving command definitions.

TeX's arithmetic

Documents rarely require user-visible numerical computations for typesetting, but it is sometimes useful to be able to do that. TeX's low-level integer and fixed-point arithmetic is peculiar, and deals with 256 (32768 in extended TeX's) integer count registers, dimension registers, skip (glue) registers, and muglue (math glue) registers. The first 10 count registers are used to track composite page numbers. TeX does not handle numeric expressions that are common in most programming languages, but instead has operations like these:

    \count254 = 100
    \count255 = 25
    \showthe  \count255                   % reports 25
    \advance  \count255 by 25
    \showthe  \count255                   % reports 50
    \advance  \count255 by \count254
    \showthe  \count255                   % reports 150
    \multiply \count255 by 10
    \showthe  \count255                   % reports 1500
    \divide   \count255 by 30
    \showthe  \count255                   % reports 50

    \dimen0 = 12pt
    \multiply \dimen0 by 10
    \showthe  \dimen0                     % reports 120pt

    \dimen1 = 3.5\dimen0
    \showthe  \dimen1                     % reports 420pt

    \skip0 = 12pt plus 3pt minus 3pt
    \dimen0 = \skip0                      % drop stretch and shrink
    \showthe  \dimen0                     % reports 12pt

    \multiply \skip0 by 10
    \showthe  \skip0                      % reports 120pt plus 30pt minus 30pt
    \advance  \skip0 by 500pt
    \showthe  \skip0                      % reports 620pt plus 30pt minus 30pt

    \skip1 = 2.5\skip0
    \showthe  \skip1                      % reports 1550pt (stretch and shrink lost)

    \skip1 = \skip0
    \advance \skip1 by \skip0
    \showthe  \skip1                      % reports 1240pt plus 60pt minus 60pt

    \advance  \skip0 by 0pt plus -30pt minus -30pt
    \showthe  \skip0                      % reports 620pt

    \count255 = \skip0                    % convert to integer scaled points
    \showthe  \count255                   % reports 40632320 (620 * 65536)

    \dimen0   = \count255 sp
    \showthe  \dimen0                     % reports 620pt

Notice that dimensions and glue can be defined as scaled values of other registers, but scaling loses glue stretch and shrink components, while addition and multiplication preserve them.

In any arithmetic system, it is important to understand the behavior when results are too big to represent, that is, when they overflow. Here are some examples:

    \count255 = \maxdimen
    \showthe  \count255                   % reports 1073741823
    \advance  \count255 by \count255
    \showthe  \count255                   % reports 2147483646
    \advance  \count255 by \count255      % cause overflow
    \showthe  \count255                   % reports -4 (WHOOPS: uncaught overflow!)

    \count255 = \maxdimen
    \multiply \count255 by 4              % fails with message: ! Arithmetic overflow
    \showthe  \count255                   % reports 1073741823 (unchanged)

Thus, TeX detects overflow on multiplication, but not on addition! When this author reported that flaw, TeX's author replied that there were too many places in the program where addition and subtraction happen, and chose not to add overflow checks in those cases. However, he did so for multiplication.

The LaTeX calc package was developed in the late 1990s to make coding of arithmetic expressions more compact and traditional. More recently, the trig package makes trigonometric functions accessible, and, in a tour-de-force, the apnum package supplies arbitrary-precision decimal arithmetic and several elementary functions!

How TeX finds files

Most users of TeX and LaTeX never have to do anything special to ensure that files named by filename alone, with no path component, are found. As with many other current and historical software systems that might need files provided by either the user, or by the operating-system package system, TeXware and METAFONTware support numerous search paths supplied in environment variables that can be customized by users. The most common such variable is TEXINPUTS, and at this author's site, its current value can be found like this:

    % env | grep TEXINPUTS
    TEXINPUTS=.:/usr/uumath/texlive/2018/texmf-local//:/usr/uumath/texlive/2018/texmf-extra//:

Its value is a colon-separated list, and here, it means that TeX looks first in the current directory (dot), then in all directories starting at /usr/uumath/texlive/2018/texmf-local, then in all directories starting at /usr/uumath/texlive/2018/texmf-extra. The doubled slashes request subdirectory searching; were they absent, TeX would look only in the specified directories.

Subdirectory searching can be expensive, so TeX installations normally supply a special cache file in search-path directories that lists all of the files below that directory. That file is called ls-R. If the requested file is not found in the cache, then TeX searches that directory tree recursively. If the doubled slashes are replaced by doubled exclamation points, then only the cache file is used.

As a special convenience to users, if a search path begins or ends with a colon, then the installation default search path for that variable is implicitly inserted in its place. Thus, to get a private location searched before the installation-defined path, you could set the variable like this:

    # csh and tcsh C-shell family syntax:
    % setenv TEXINPUTS  .:$HOME/tex/mymacros:

    # ash, bash, dash, ksh, sh, zsh, ... Bourne-shell family syntax:
    $ TEXINPUTS=.:$HOME/tex/mymacros:
    $ export TEXINPUTS

There is more to TeX path searching than we describe here; for details, run the command texdoc texlive. That important document is available in about ten languages, so texdoc texlive-ru would display the Russian-language version.

That document also describes a useful command tool for exploring TeX's search-path algorithm, which is particularly useful when you are customizing search paths and want to ensure that the correct file is found. Here is an example:

    % kpsewhich article.cls
    /usr/uumath/texlive/2018/texmf-dist/tex/latex/base/article.cls

You can also find the values of search-path variables that might not be set in the environment, but are determined by local run-time defaults:

    % kpsewhich --var-value TEXINPUTS
    .:/usr/uumath/texlive/2018/texmf-local//:/usr/uumath/texlive/2018/texmf-extra//:

To find out which file types and environment variables are known to your TeX installation, run commands like these::

    % kpsewhich -help-formats
    [long output]

    % kpsewhich -help-formats | grep TEXINPUTS
    graphic/figure:  .eps .epsi  [variables: TEXPICTS TEXINPUTS]
    tex: .tex  .sty .cls .fd .aux .bbl .def .clo .ldf  [variables: TEXINPUTS]

Warning: One thing to be aware of with both cache files and recursive directory searching is that the order in which files are found is system dependent. It is most definitely not lexicographic order in general. Thus, if two or more files in a directory tree have the same name, but different contents, you cannot predict which one is found. TeX distributions normally try to avoid duplicate filenames when those files are expected to be read by TeX. The TeX .log file always records full pathnames of each file that it reads, so you can easily verify that it found the expected instance. If it did not, redefine the search path variable.

More software for TeX, METAFONT, BibTeX, and Emacs

The binary executables directories in TeX Live distributions supply a large number of tools that users have found convenient to have on all platforms. The tool count has grown from about 250 in 2003 to almost 450 in 2018. Feel free to browse around, like this:

    % which tex
    /usr/uumath/texlive/2018/bin/x86_64-linux-centos-7/tex

    % ls /usr/uumath/texlive/2018/bin/x86_64-linux-centos-7 | less
    [long list to page through]

In addition, in our standard local installation directories, /usr/local/bin or /usr/uumath/bin, we supply several thousand more executables that support our users. Among the TeX-related ones are chktex, detex, lacheck, and texpretty.

This author has long been a software developer and supporter of BibTeX and bibliographic databases. Among the many related tools on our systems are bibcheck, bibclean, bibdup, bibextract, bibjoin, biblabel, biblex, biborder, bibparse, bibsearch, bibsort, bibsplit, bibsql, bibtosql, bibunlex, cattobib, chkdelim, citesub, doi-to-bibtex, dw, myspell, ref2bib, and scholar. He has developed more than 400 programs that support conversion of publisher Web metadata to BibTeX, plus several extended BibTeX styles that provide richer bibliographic information, and more than 950 functions for the emacs text editor. Feel free to communicate with him if such software could be useful to you.

Customizing TeXware limits

Most users of TeX and LaTeX never encounter a TeX capacity exceeded message. Nevertheless, large documents sometimes require bigger internal tables. Originally, their sizes were compiled into the software, which meant that large documents might have to be produced in several parts. Work by this author, Karl Berry, and other members of the TeX Live team has largely eliminated compile-time table sizes in TeXware and MFware, in favor of dynamically allocated tables whose sizes are set in default, and optional user-supplied, configuration files named texmf.cnf. In TeX Live 2018, the default file is found in the directory texmf-dist/web2c, and it contains documentation comments before each customizable value.

You can supply personal settings in a private file, texmf.cnf, in the directory with your big document. For example, this author deals with large bibliography files using assignments like these:

    hash_size.bibtex   =   50000
    max_cites.bibtex   =   20000
    max_strings.bibtex = 2048000

There is no need to duplicate the default settings, because they are read before your customizations.

Updating TeX Live

The annual TeX Live releases have proven to be reliable software distributions, and many users who install them on personal machines may not even update them yearly. Nevertheless, even though TeX and METAFONT can be viewed as essentially bug free, the same may not be true for the hundreds of other programs that come with TeX Live. Also, package development is active, and there are frequent updates. You might therefore decide that you always want to have the `latest stuff', in which case, you need to know how to install updates.

The first step is to choose a suitable package repository mirror. The master TeX Live site now resides in Paris, France, but there are numerous mirrors around the world that you can find listed here. That site can also alert you to problems at your chosen mirror, because it reports their status. Rarely, a mirror site may experience hardware or network problems that take it offline for an extended period, leaving it somewhat stale when it returns to service. In most cases, all should be well within a day or two.

This author's site at the University of Utah is the master North American mirror, and if that is suitably close to you network-wise, then you can make it your default source like this:

    % tlmgr option repository http://ctan.math.utah.edu/tex-archive/systems/texlive/tlnet

You could revert to the Paris repository like this:

    % tlmgr option repository http://mirror.ctan.org/systems/texlive/tlnet

Updating is now a simple two-step process. The first step installs any updates for the package-management system itself, and the second updates everything else:

    % tlmgr update --self
    % tlmgr update --all

Books about TeX and LaTeX

This author keeps an extensive BibTeX bibliography of books and other publications about TeX and METAFONT here. It records more than 300 such books.

The standard reference for TeX is Donald Knuth's The TeXbook, the first of the five-volume Computers & Typesetting series.

The standard reference for LaTeX is the second edition of Leslie Lamport's LaTeX: a Document Preparation System: User's Guide and Reference Manual . However, it was written before many support packages had been written, and does not cover them at all.

Three supplementary volumes have been produced by members of the LaTeX team, in various languages and editions: The LaTeX Companion, The LaTeX Graphics Companion, and The LaTeX Web Companion: integrating TeX, HTML and XML. A new edition of the first of those may be available by late 2019.

For a student on a low budget who just wants one book, the Kopka & Daley books called Guide to LaTeX: Tools and Techniques for Computer Typesetting, available in German and English editions, are a good start. They cover core LaTeX, and a small set of useful LaTeX packages.

Mathematicians and scientists should also get the most recent edition of George Grätzer's excellent More Math Into LaTeX. It is a treasure trove for typesetting complex mathematical displays.

Several LaTeX packages support the preparation of lectures slides and Herbert Voß's book Presentations with LaTeX is a useful guide.

Finally, you really do need an authoritative writing style guide. There are several such books, listed in the Handbooks on writing section of this author's Typesetting and Writing Hints for Theses and Dissertations .