\input texinfo @c $Id: latex2e.texi 1141 2023-01-10 23:19:31Z karl $ @comment %**start of header (This is for running Texinfo on a region.) @setfilename latex2e.info @set UPDATED January 2023 @include common.texi @settitle @LaTeX{}2e unofficial reference manual (@value{UPDATED}) @comment %**end of header (This is for running Texinfo on a region.) @c latex 2.09 commands should all be present now, @c xx but latex2e stuff is missing. @c xx random list of a few of the missing items is at the end of this file @c xx read through latex2e news for things to update. @c @c xx ctan, distributions, components of TeX @c xx classes and packages: required, additional, useful; oberdiek; fonts @c xx merge permuted-index @c xx merge latex-manual from savannah @c xx merge display style math @c xx systematically check stated math atom type vs. fontdef.dtx etc. @c xx check recent ltnews for (lots of) changes @c xx \write of non-ASCII chars (vincent mail of 14 Mar 2020 21:39:41) @c xx \nonstopmode etc., if they are officially supported by LaTeX? @c xx LaTeX defines \do at \begin{document} even though it is not documented @c xx JH explain nfss somewhere @c xx JH expand BiBTeX @c xx JH expand theorem, AMS math @c xx JH something on code listings @c xx JH ligatures @c @c xx \NewCommandCopy et al. (Brian Dunn, 21 Dec 2021 06:50:17). @c @c xx The typeset source2e has an index with all kernel @c xx commands, though some are internal and shouldn't be included. @c xx classes.dtx et al. define additional commands. @c xx See also http://ctan.org/pkg/macros2e. @c @c xx All the special characters should be definitively described. @copying This document is an unofficial reference manual for @LaTeX{}, a document preparation system, version of @value{UPDATED}. This manual was originally translated from @file{LATEX.HLP} v1.0a in the VMS Help Library. The pre-translation version was written by George@tie{}D. Greenwade of Sam Houston State University. The @LaTeX{}@tie{}2.09 version was written by Stephen Gilmore. The @LaTeX{}2e version was adapted from this by Torsten Martinsen. Karl Berry made further updates and additions, and gratefully acknowledges using @cite{Hypertext Help with @LaTeX{}}, by Sheldon Green, and @cite{@LaTeX{} Command Summary} (for @LaTeX{}@tie{}2.09) by L.@tie{}Botway and C.@tie{}Biemesderfer (published by the @TeX{} Users Group as @cite{@TeX{}niques} number 10), as reference material. We also gratefully acknowledge additional material appearing in latex2e-reference by Martin Herbert Dietze. (From these references no text was directly copied.) Copyright 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 Karl Berry.@* Copyright 1988, 1994, 2007 Stephen Gilmore.@* Copyright 1994, 1995, 1996 Torsten Martinsen. @comment start of License Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. @ignore Permission is granted to process this file through TeX and print the results, provided the printed document carries copying permission notice identical to this one except for the removal of this paragraph (this paragraph not being relevant to the printed manual). @end ignore Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions. @comment end of License @end copying @c Merge into one index (arbitrarily chosen to be the concept index). @syncodeindex fn cp @dircategory TeX @direntry * LaTeX2e: (latex2e). Unofficial LaTeX reference manual. @end direntry @tex \global\hbadness=4444 % don't complain much @end tex @microtype on @html

This is an unofficial reference manual for LaTeX. See below for the Table of Contents. If you want a tutorial then please instead visit learnlatex.org or this list.

This manual has two versions. One has separate web pages for each section or subsection. It's also available as a single web page and as a pdf. Note that there is also a separately-maintained French edition.

This document is not official. It has not been reviewed by the LaTeX maintainers. Our goal is to cover all (non-private) LaTeX commands. Your comments and contributions, including bug reports, are very welcome. See our project page for more, including license information and information on how you can contribute to this manual as well as mirror it.

@end html @titlepage @title @LaTeX{}2e: An unofficial reference manual @subtitle @value{UPDATED} @author @url{@value{LTXREFMAN_HOME_PAGE}} @page @vskip 0pt plus 1filll @insertcopying @end titlepage @shortcontents @contents @c Best Effort Symbol @iftex @macro visiblespace @tex% {@tt@char`@ }% @end tex@c @end macro @macro BES {utf8,math} @math{\math\} @end macro @macro BESU {utf8,math} @code{@backslashchar{}\math\} @end macro @end iftex @ifnottex @macro visiblespace @w{ } @end macro @macro BES {utf8,math} @U{\utf8\} @end macro @macro BESU {utf8,math} @U{\utf8\} @end macro @end ifnottex @macro EnvIndex {env} @findex @r{environment}, @code{\env\} @findex @code{\env\} @r{environment} @end macro @macro PkgIndex {pkg} @cindex @r{package}, @code{\pkg\} @cindex @code{\pkg\} @r{package} @end macro @set NotInPlainTeX Not available in plain @TeX{}. @set NeedsAMSSymb @value{NotInPlainTeX} In @LaTeX{} you need to load the @package{amssymb} package. @set NeedsSTIX @value{NotInPlainTeX} In @LaTeX{} you need to load the @file{stix} package. @ifnottex @node Top @top @LaTeX{}2e: An unofficial reference manual This document is an unofficial reference manual (version of @value{UPDATED}) for @LaTeX{}2e, a document preparation system. @end ifnottex @menu * About this document:: Bug reporting, etc. * Overview:: What is @LaTeX{}? * Document classes:: Some of the various classes available. * Fonts:: Italic, bold, typewriter, etc. * Layout:: Controlling the page layout. * Sectioning:: Parts, Chapters, Sections, etc. * Cross references:: Automatic referencing. * Environments:: Such as enumerate & itemize. * Line breaking:: Influencing line breaks. * Page breaking:: Influencing page breaks. * Footnotes:: How to produce footnotes. * Definitions:: Define your own commands, etc. * Counters:: Internal counters used by @LaTeX{}. * Lengths:: The length commands. * Making paragraphs:: Paragraph commands. * Math formulas:: How to create mathematical formulas. * Modes:: Paragraph, Math or LR modes. * Page styles:: Various styles of page layout. * Spaces:: Horizontal and vertical space. * Boxes:: Making boxes. * Color:: Defining and using colors. * Graphics:: Importing graphics from outside @LaTeX{}. * Special insertions:: Inserting reserved and special characters. * Splitting the input:: Dealing with big files by splitting. * Front/back matter:: Tables of contents, glossaries, indexes. * Letters:: The @code{letter} class. * Input/output:: User interaction. * Command line interface:: Common command-line options. * Document templates:: Starter templates for various document classes. * Index:: General index. @end menu @node About this document @chapter About this document @cindex home page for manual This is an unofficial reference manual for the @LaTeX{}2e document preparation system, which is a macro package for the @TeX{} typesetting program (@pxref{Overview}). This document's home page is @url{@value{LTXREFMAN_HOME_PAGE}}; it has separate web pages for each topic. Alternatively. @url{https://latexref.xyz/dev/latex2e.html} has the entire document on a single page. For other output formats, the sources, and plenty more information, see @url{https://latexref.xyz/dev/}. @cindex @LaTeX{} vs.@: @LaTeX{}2e In this document, we will mostly just use `@LaTeX{}' rather than `@LaTeX{}2e', since the previous version of @LaTeX{}@tie{}(2.09) was frozen decades ago. @cindex unofficial nature of this manual @cindex @LaTeX{} Project team @findex @email{@value{LTXREFMAN_BUGS}} @r{email address} @LaTeX{} is maintained by a group of volunteers (@url{https://latex-project.org}). The official documentation written by the @LaTeX{} project is available from their web site. The present document is completely unofficial and has not been written or reviewed by the @LaTeX{} maintainers. @cindex bug reporting @cindex reporting bugs Do not send bug reports or anything else about this document to them. Instead, please send all comments to @email{@value{LTXREFMAN_BUGS}}. This document is a reference, not a tutorial. There is a vast array of other information available about @LaTeX{}, at all levels. Here are a few introductions. @table @url @item https://ctan.org/pkg/latex-doc-ptr @findex latex-doc-ptr @r{document} Two pages of recommended references to @LaTeX{} documentation. @item https://ctan.org/pkg/first-latex-doc @findex first-latex-doc @r{document} Writing your first document, with a bit of both text and math. @item https://ctan.org/pkg/lshort @findex lshort @r{document} A longer introduction to @LaTeX{}, translated to many languages. @item https://tug.org/begin.html Introduction to the @TeX{} system, including @LaTeX{}, with further references. @end table @node Overview @chapter Overview of @LaTeX{} @cindex overview of @LaTeX{} @cindex basics of @LaTeX{} @cindex Knuth, Donald E. @cindex Lamport, Leslie @cindex @LaTeX{} overview @LaTeX{} is a system for typesetting documents. It was originally created by Leslie Lamport in 1984, but has been maintained by a group of volunteers for many years now (@url{https://latex-project.org}). It is widely used, particularly but not exclusively for mathematical and technical documents. @cindex UTF-8, default @LaTeX{} input encoding A @LaTeX{} user writes an input file containing text to be typeset along with interspersed commands. The default encoding for the text is UTF-8 (as of 2018). The commands specify, for example, how the text should be formatted. @LaTeX{} is implemented as a set of related so-called ``macros'' which use Donald@tie{}E. Knuth's @TeX{} typesetting program or one of its derivatives, collectively known as ``engines''. Thus, the user produces output, typically PDF, by giving the input file to a @TeX{} engine. (The following sections describe all this in more detail.) The term @LaTeX{} is also sometimes used to mean the language in which the input document is marked up, that is, to mean the set of commands available to a @LaTeX{} user. @cindex Lamport @TeX{} @cindex pronunciation The name @LaTeX{} is short for ``Lamport @TeX{}''. It is pronounced LAH-teck or LAY-teck, or sometimes LAY-tecks. Inside a document, produce the logo with @code{\LaTeX}. Where use of the logo is not sensible, such as in plain text, write it as @samp{LaTeX}. @menu * Starting and ending:: The standard beginning and end of a document. * Output files:: Files produced. * @TeX{} engines:: Programs that can compile @TeX{} and @LaTeX{}. * @LaTeX{} command syntax:: General syntax of @LaTeX{} commands. * Environment:: An area of the source with distinct behavior. * CTAN:: Our repository. @end menu @node Starting and ending @section Starting and ending @anchor{Starting & ending}@c old name @cindex starting and ending @cindex ending and starting @cindex hello, world @LaTeX{} files have a simple global structure, with a standard beginning and ending. This is a small example. @example \documentclass@{article@} \begin@{document@} Hello, \LaTeX\ world. \end@{document@} @end example @noindent Every @LaTeX{} document has a @code{\begin@{document@}} line and an @code{\end@{document@}} line. @cindex document class, defined @noindent Here, the @samp{article} is the @dfn{document class}. It is implemented in a file @file{article.cls}. You can use any document class on your system. A few document classes are defined by @LaTeX{} itself, and vast array of others are widely available. @xref{Document classes}. @cindex preamble, defined You can include other @LaTeX{} commands between the @code{\documentclass} and the @code{\begin@{document@}} commands. This area is called the @dfn{preamble}. The @code{\begin@{document@}}, @code{\end@{document@}} pair defines an @cindex environment @dfn{environment}; the @samp{document} environment (and no others) is required in all @LaTeX{} documents (@pxref{document}). @LaTeX{} make available to you many environments that are documented here (@pxref{Environments}). Many more are available to you from external packages, most importantly those available at CTAN (@pxref{CTAN}). The following sections discuss how to produce PDF or other output from a @LaTeX{} input file. @node Output files @section Output files @LaTeX{} produces a main output file and at least two auxiliary files. The main output file's name ends in either @file{.dvi} or @file{.pdf}. @table @code @item .dvi @findex .dvi @r{file} @findex latex @r{command} @findex xdvi @r{command} @findex dvips @r{command} @findex dvipdfmx @r{command} @findex dvitype @r{command} @anchor{output files dvi} If @LaTeX{} is invoked with the system command @command{latex} then it produces a DeVice Independent file, with extension @file{.dvi}. You can view this file with a command such as @command{xdvi}, or convert it to a PostScript @code{.ps} file with @command{dvips} or to a Portable Document Format @code{.pdf} file with @command{dvipdfmx}. The contents of the file can be dumped in human-readable form with @command{dvitype}. A vast array of other DVI utility programs are available (@url{https://mirror.ctan.org/dviware}). @item .pdf @findex .pdf @r{file} @cindex pdf@TeX{} @findex pdflatex @r{command} @anchor{output files pdf} If @LaTeX{} is invoked via the system command @command{pdflatex}, among other commands (@pxref{@TeX{} engines}), then the main output is a Portable Document Format (PDF) file. Typically this is a self-contained file, with all fonts and images included. @end table @LaTeX{} always produces at least two additional files. @table @code @item .log @cindex transcript file @cindex log file @findex .log @r{file} @anchor{output files log} This transcript file contains summary information such as a list of loaded packages. It also includes diagnostic messages and perhaps additional information for any errors. @item .aux @cindex auxiliary file @findex .aux @r{file} @cindex cross references, resolving @cindex forward references, resolving @cindex references, resolving forward @anchor{output files aux} Auxiliary information is used by @LaTeX{} for things such as cross references. For example, the first time that @LaTeX{} finds a forward reference---a cross reference to something that has not yet appeared in the source---it will appear in the output as a doubled question mark @code{??}. When the referred-to spot does eventually appear in the source then @LaTeX{} writes its location information to this @code{.aux} file. On the next invocation, @LaTeX{} reads the location information from this file and uses it to resolve the reference, replacing the double question mark with the remembered location. @end table @findex .lof @r{file} @cindex list of figures file @findex .lot @r{file} @cindex list of tables file @findex .toc @r{file} @cindex table of contents file @cindex contents file @LaTeX{} may produce yet more files, characterized by the filename ending. These include a @code{.lof} file that is used to make a list of figures, a @code{.lot} file used to make a list of tables, and a @code{.toc} file used to make a table of contents (@pxref{Table of contents etc.}). A particular class may create others; the list is open-ended. @node @TeX{} engines @section @TeX{} engines @cindex engines, @TeX{} @cindex implementations of @TeX{} @cindex UTF-8, engine support for @cindex Unicode input, native @cindex TrueType fonts @cindex OpenType fonts @cindex @TeX{} format (@code{.fmt}) files @cindex @LaTeX{} format (@code{.fmt}) files @cindex format files, @TeX{} @findex .fmt @r{file} @LaTeX{} is a large set of commands that is executed by a @TeX{} program (@pxref{Overview}). Such a set of commands is called a @dfn{format}, and is embodied in a binary @code{.fmt} file, which can be read much more quickly than the corresponding @TeX{} source. This section gives a terse overview of the @TeX{} programs that are commonly available (see also @ref{Command line interface}). @ftable @code @item latex @itemx pdflatex @findex etex @r{command} @cindex pdf@TeX{} engine @cindex e-@TeX{} @anchor{tex engines latex} In @TeX{} Live (@url{https://tug.org/texlive}), if @LaTeX{} is invoked via either the system command @command{latex} or @command{pdflatex}, then the pdf@TeX{} engine is run (@url{https://ctan.org/pkg/pdftex}). When invoked as @command{latex}, the main output is a @file{.dvi} file; as @command{pdflatex}, the main output is a @file{.pdf} file. pdf@TeX{} incorporates the e-@TeX{} extensions to Knuth's original program (@url{https://ctan.org/pkg/etex}), including additional programming features and bi-directional typesetting, and has plenty of extensions of its own. e-@TeX{} is available on its own as the system command @command{etex}, but this is plain @TeX{} (and produces @file{.dvi}). In other @TeX{} distributions, @command{latex} may invoke e-@TeX{} rather than pdf@TeX{}. In any case, the e-@TeX{} extensions can be assumed to be available in @LaTeX{}. @item lualatex @cindex Lua@TeX{} @anchor{tex engines lualatex} If @LaTeX{} is invoked via the system command @command{lualatex}, the Lua@TeX{} engine is run (@url{https://ctan.org/pkg/luatex}). This program allows code written in the scripting language Lua (@url{http://luatex.org}) to interact with @TeX{}'s typesetting. Lua@TeX{} handles UTF-8 Unicode input natively, can handle OpenType and TrueType fonts, and produces a @file{.pdf} file by default. There is also @command{dvilualatex} to produce a @file{.dvi} file. @item xelatex @cindex Xe@TeX{} @findex .xdv @r{file} @findex xdvipdfmx @anchor{tex engines xelatex} If @LaTeX{} is invoked with the system command @command{xelatex}, the Xe@TeX{} engine is run (@url{https://tug.org/xetex}). Like Lua@TeX{}, Xe@TeX{} natively supports UTF-8 Unicode and TrueType and OpenType fonts, though the implementation is completely different, mainly using external libraries instead of internal code. Xe@TeX{} produces a @file{.pdf} file as output; it does not support DVI output. Internally, Xe@TeX{} creates an @code{.xdv} file, a variant of DVI, and translates that to PDF using the (@code{x})@code{dvipdfmx} program, but this process is automatic. The @code{.xdv} file is only useful for debugging. @item platex @itemx uplatex These commands provide significant additional support for Japanese and other languages; the @code{u} variant supports Unicode. See @url{https://ctan.org/pkg/ptex} and @url{https://ctan.org/pkg/uptex}. @end ftable As of 2019, there is a companion @code{-dev} command and format for all of the above: @ftable @code @item dvilualatex-dev @itemx latex-dev @itemx lualatex-dev @itemx pdflatex-dev @itemx platex-dev @itemx uplatex-dev @itemx xelatex-dev @cindex release candidates @cindex prerelease testing These are candidates for an upcoming @LaTeX{} release. The main purpose is to find and address compatibility problems before an official release. These @code{-dev} formats make it easy for anyone to help test documents and code: you can run, say, @code{pdflatex-dev} instead of @code{pdflatex}, without changing anything else in your environment. Indeed, it is easiest and most helpful to always run the @code{-dev} versions instead of bothering to switch back and forth. During quiet times after a release, the commands will be equivalent. These are not daily snapshots or untested development code. They undergo the same extensive regression testing by the @LaTeX{} team before being released. For more information, see ``The @LaTeX{} release workflow and the @LaTeX{} @code{dev} formats'' by Frank Mittelbach, @cite{TUGboat} 40:2, @url{https://tug.org/TUGboat/tb40-2/tb125mitt-dev.pdf}. @end ftable @node @LaTeX{} command syntax @section @LaTeX{} command syntax @cindex command syntax @findex \ @r{character starting commands} @findex [...] @r{(for optional arguments)} @findex @{...@} @r{(for required arguments)} In the @LaTeX{} input file, a command name starts with a backslash character, @code{\}. The name itself then consists of either (a)@tie{}a string of letters or (b)@tie{}a single non-letter. @LaTeX{} commands names are case sensitive so that @code{\pagebreak} differs from @code{\Pagebreak} (the latter is not a standard command). Most command names are lowercase, but in any event you must enter all commands in the same case as they are defined. A command may be followed by zero, one, or more arguments. These arguments may be either required or optional. Required arguments are contained in curly braces, @code{@{...@}}. Optional arguments are contained in square brackets, @code{[...]}. Generally, but not universally, if the command accepts an optional argument, it comes first, before any required arguments. Inside of an optional argument, to use the character close square bracket@tie{}(@code{]}) hide it inside curly braces, as in@tie{}@code{\item[closing bracket @{]@}]}. Similarly, if an optional argument comes last, with no required argument after it, then to make the first character of the following text be an open square bracket, hide it inside curly braces. @LaTeX{} has the convention that some commands have a @code{*} form that is related to the form without a @code{*}, such as @code{\chapter} and @code{\chapter*}. The exact difference in behavior varies from command to command. This manual describes all accepted options and @code{*}-forms for the commands it covers (barring unintentional omissions, a.k.a.@: bugs). @PkgIndex{expl3} @PkgIndex{xparse} @cindex @LaTeX{}3 syntax As of the 2020-10-01 release of @LaTeX{}, the @package{expl3} and @package{xparse} packages are part of the @LaTeX{}2e format. They provide a completely different underlying programming language syntax. We won't try to cover them in this document; see the related package documentation and other @LaTeX{} manuals. @node Environment @section Environment Synopsis: @example \begin@{@var{environment-name}@} ... \end@{@var{environment-name}@} @end example An @dfn{environment} is an area of @LaTeX{} source, inside of which there is a distinct behavior. For instance, for poetry in @LaTeX{} put the lines between @code{\begin@{verse@}} and @code{\end@{verse@}}. @example \begin@{verse@} There once was a man from Nantucket \\ ... \end@{verse@} @end example @xref{Environments}, for a list of environments. Particularly notable is that every @LaTeX{} document must have a @code{document} environment, a @code{\begin@{document@} ... \end@{document@}} pair. The @var{environment-name} at the beginning must exactly match that at the end. This includes the case where @var{environment-name} ends in a star@tie{}(@code{*}); both the @code{\begin} and @code{\end} texts must include the star. Environments may have arguments, including optional arguments. This example produces a table. The first argument is optional (and causes the table to be aligned on its top row) while the second argument is required (it specifies the formatting of columns). @example \begin@{tabular@}[t]@{r|l@} ... rows of table ... \end@{tabular@} @end example @node CTAN @section CTAN: The Comprehensive @TeX{} Archive Network @cindex CTAN The Comprehensive @TeX{} Archive Network, CTAN, is the @TeX{} and @LaTeX{} community's repository of free material. It is a set of Internet sites around the world that offer material related to @LaTeX{} for download. Visit CTAN on the web at @url{https://ctan.org}. This material is organized into packages, discrete bundles that typically offer some coherent functionality and are maintained by one person or a small number of people. For instance, many publishers have a package that allows authors to format papers to that publisher's specifications. In addition to the massive holdings, the @code{ctan.org} web site offers features such as search by name or by functionality. @cindex DANTE e.V. CTAN is not a single host, but instead is a set of hosts, one of which is the so-called ``master''. The master host actively manages the material, for instance, by accepting uploads of new or updated packages. For many years, it has been hosted by the German @TeX{} group, DANTE e.V. @cindex mirrors of CTAN Other sites around the world help out by mirroring, that is, automatically syncing their collections with the master site and then in turn making their copies publicly available. This gives users close to their location better access and relieves the load on the master site. The list of mirrors is at @url{https://ctan.org/mirrors}. @node Document classes @chapter Document classes @cindex document classes @cindex classes of documents @findex \documentclass The document's overall class is defined with this command, which is normally the first command in a @LaTeX{} source file. @example \documentclass[@var{options}]@{@var{class}@} @end example @findex article @r{class} @findex report @r{class} @findex book @r{class} @findex letter @r{class} @findex slides @r{class} The following document @var{class} names are built into @LaTeX{}. (Many other document classes are available as separate packages; @pxref{Overview}.) @table @code @item article @anchor{document classes article} For a journal article, a presentation, and miscellaneous general use. @item book @anchor{document classes book} Full-length books, including chapters and possibly including front matter, such as a preface, and back matter, such as an appendix (@pxref{Front/back matter}). @item letter @anchor{document classes letter} Mail, optionally including mailing labels (@pxref{Letters}). @item report @anchor{document classes report} For documents of length between an @code{article} and a @code{book}, such as technical reports or theses, which may contain several chapters. @item slides @anchor{document classes slides} For slide presentations---rarely used nowadays. The @package{beamer} package is perhaps the most prevalent (@url{https://ctan.org/pkg/beamer}). @xref{beamer template}, for a small template for a beamer document. @end table Standard @var{options} are described in the next section. @menu * Document class options:: Global options. * Additional packages:: Bring in packages. * Class and package construction:: Create new classes and packages. @end menu @node Document class options @section Document class options @cindex document class options @cindex options, document class @cindex class options @cindex global options You can specify @dfn{global options} or @dfn{class options} to the @code{\documentclass} command by enclosing them in square brackets. To specify more than one @var{option}, separate them with a comma. @example \documentclass[@var{option1},@var{option2},...]@{@var{class}@} @end example Here is the list of the standard class options. @findex 10pt @r{option} @findex 11pt @r{option} @findex 12pt @r{option} All of the standard classes except @code{slides} accept the following options for selecting the typeface size (default is @code{10pt}): @example 10pt 11pt 12pt @end example @findex a4paper @r{option} @findex a5paper @r{option} @findex b5paper @r{option} @findex executivepaper @r{option} @findex legalpaper @r{option} @findex letterpaper @r{option} All of the standard classes accept these options for selecting the paper size (these show height by width): @table @code @item a4paper 210 by 297@dmn{mm} (about 8.25 by 11.75@tie{}inches) @item a5paper 148 by 210@dmn{mm} (about 5.8 by 8.3@tie{}inches) @item b5paper 176 by 250@dmn{mm} (about 6.9 by 9.8@tie{}inches) @item executivepaper 7.25 by 10.5@tie{}inches @item legalpaper 8.5 by 14@tie{}inches @item letterpaper 8.5 by 11@tie{}inches (the default) @end table @findex \pdfpagewidth @findex \pdfpageheight @PkgIndex{geometry} When using one of the engines pdf@LaTeX{}, Lua@LaTeX{}, or Xe@LaTeX{} (@pxref{@TeX{} engines}), options other than @code{letterpaper} set the print area but you must also set the physical paper size. One way to do that is to put @code{\pdfpagewidth=\paperwidth} and @code{\pdfpageheight=\paperheight} in your document's preamble. @PkgIndex{geometry} The @package{geometry} package provides flexible ways of setting the print area and physical page size. @findex draft @r{option} @findex final @r{option} @findex fleqn @r{option} @findex landscape @r{option} @findex leqno @r{option} @findex openbib @r{option} @findex titlepage @r{option} @findex notitlepage @r{option} Miscellaneous other options: @table @code @item draft @itemx final @cindex black boxes, omitting Mark (@code{draft}) or do not mark (@code{final}) overfull boxes with a black box in the margin; default is @code{final}. @item fleqn @cindex flush left equations @cindex centered equations @cindex equations, flush left vs.@: centered Put displayed formulas flush left; default is centered. @item landscape @cindex landscape orientation @cindex portrait orientation Selects landscape format; default is portrait. @item leqno @cindex left-hand equation numbers @cindex right-hand equation numbers @cindex equation numbers, left vs.@: right Put equation numbers on the left side of equations; default is the right side. @item openbib @cindex bibliography format, open Use ``open'' bibliography format. @item titlepage @itemx notitlepage @cindex title page, separate or run-in Specifies whether there is a separate page for the title information and for the abstract also, if there is one. The default for the @code{report} class is @code{titlepage}, for the other classes it is @code{notitlepage}. @end table The following options are not available with the @code{slides} class. @findex onecolumn @r{option} @findex twocolumn @r{option} @findex oneside @r{option} @findex twoside @r{option} @findex openright @r{option} @findex openany @r{option} @table @code @item onecolumn @itemx twocolumn Typeset in one or two columns; default is @code{onecolumn}. @item oneside @itemx twoside @findex \evensidemargin @findex \oddsidemargin @c xx TODO re-align on the French version which is more accurate. Selects one- or two-sided layout; default is @code{oneside}, except that in the @code{book} class the default is @code{twoside}. For one-sided printing, the text is centered on the page. For two-sided printing, the @code{\evensidemargin} (@code{\oddsidemargin}) parameter determines the distance on even (odd) numbered pages between the left side of the page and the text's left margin, with @code{\oddsidemargin} being 40% of the difference between @code{\paperwidth} and @code{\textwidth}, and @code{\evensidemargin} is the remainder. @item openright @itemx openany Determines if a chapter should start on a right-hand page; default is @code{openright} for @code{book}, and @code{openany} for @code{report}. @end table @findex clock @r{option to @code{slides} class} The @code{slides} class offers the option @code{clock} for printing the time at the bottom of each note. @node Additional packages @section Additional packages @cindex loading additional packages @cindex packages, loading additional @cindex additional packages, loading @findex \usepackage Load a package @var{pkg}, with the package options given in the comma-separated list @var{options}, as here. @example \usepackage[@var{options}]@{@var{pkg}@}. @end example To specify more than one package you can separate them with a comma, as in @code{\usepackage@{@var{pkg1},@var{pkg2},...@}}, or use multiple @code{\usepackage} commands. @cindex global options @cindex options, global Any options given in the @code{\documentclass} command that are unknown to the selected document class are passed on to the packages loaded with @code{\usepackage}. @node Class and package construction @section Class and package construction @cindex document class commands @cindex commands, document class @cindex new class commands You can create new document classes and new packages. For instance, if your memos must satisfy some local requirements, such as a standard header for each page, then you could create a new class @code{smcmemo.cls} and begin your documents with @code{\documentclass@{smcmemo@}}. What separates a package from a document class is that the commands in a package are useful across classes while those in a document class are specific to that class. Thus, a command to set page headers is for a package while a command to make the page headers say @code{Memo from the SMC Math Department} is for a class. @cindex class and package difference @cindex difference between class and package Inside of a class or package file you can use the at-sign @code{@@} as a character in command names without having to surround the code containing that command with @code{\makeatletter} and @code{\makeatother}. @xref{\makeatletter & \makeatother}. This allow you to create commands that users will not accidentally redefine. Another technique is to preface class- or package-specific commands with some string to prevent your class or package from interfering with others. For instance, the class @code{smcmemo} might have commands @code{\smc@@tolist}, @code{\smc@@fromlist}, etc. @menu * Class and package structure:: Layout of the file. * Class and package commands:: List of commands. @end menu @node Class and package structure @subsection Class and package structure @cindex class and package structure @cindex class file layout @cindex package file layout @cindex options, document class @cindex options, package @cindex class options @cindex package options A class file or package file typically has four parts. @enumerate @item In the @dfn{identification part}, the file says that it is a @LaTeX{} package or class and describes itself, using the @code{\NeedsTeXFormat} and @code{\ProvidesClass} or @code{\ProvidesPackage} commands. @item The @dfn{preliminary declarations part} declares some commands and can also load other files. Usually these commands will be those needed for the code used in the next part. For example, an @code{smcmemo} class might be called with an option to read in a file with a list of people for the to-head, as @code{\documentclass[mathto]@{smcmemo@}}, and therefore needs to define a command @code{\newcommand@{\setto@}[1]@{\def\@@tolist@{#1@}@}} used in that file. @item In the @dfn{handle options part} the class or package declares and processes its options. Class options allow a user to start their document as @code{\documentclass[@var{option list}]@{@var{class name}@}}, to modify the behavior of the class. An example is when you declare @code{\documentclass[11pt]@{article@}} to set the default document font size. @item Finally, in the @dfn{more declarations part} the class or package usually does most of its work: declaring new variables, commands and fonts, and loading other files. @end enumerate Here is a starting class file, which should be saved as @file{stub.cls} where @LaTeX{} can find it, for example in the same directory as the @file{.tex} file. @example \NeedsTeXFormat@{LaTeX2e@} \ProvidesClass@{stub@}[2017/07/06 stub to start building classes from] \DeclareOption*@{\PassOptionsToClass@{\CurrentOption@}@{article@}@} \ProcessOptions\relax \LoadClass@{article@} @end example @cindex class file example @noindent It identifies itself, handles the class options via the default of passing them all to the @code{article} class, and then loads the @code{article} class to provide the basis for this class's code. For more, see the official guide for class and package writers, the Class Guide, at @url{https://www.latex-project.org/help/documentation/clsguide.pdf} (much of the descriptions here derive from this document), or the tutorial @url{https://www.tug.org/TUGboat/tb26-3/tb84heff.pdf}. @node Class and package commands @subsection Class and package commands @cindex class and package commands @cindex commands, class and package These are the commands designed to help writers of classes or packages. @table @code @item \AtBeginDvi@{specials@} @findex \AtBeginDvi Save in a box register things that are written to the @file{.dvi} file at the beginning of the shipout of the first page of the document. @item \AtEndOfClass@{@var{code}@} @itemx \AtEndOfPackage@{@var{code}@} @findex \AtEndOfClass @findex \AtEndOfPackage Hook to insert @var{code} to be executed when @LaTeX{} finishes processing the current class or package. You can use these hooks multiple times; the @code{code} will be executed in the order that you called it. See also @ref{\AtBeginDocument}. @item \CheckCommand@{@var{cmd}@}[@var{num}][@var{default}]@{@var{definition}@} @itemx \CheckCommand*@{@var{cmd}@}[@var{num}][@var{default}]@{@var{definition}@} @findex \CheckCommand @findex \CheckCommand* @cindex new command, checking Like @code{\newcommand} (@pxref{\newcommand & \renewcommand}) but does not define @var{cmd}; instead it checks that the current definition of @var{cmd} is exactly as given by @var{definition} and is or is not @cindex long command @dfn{long} as expected. A long command is a command that accepts @code{\par} within an argument. The @var{cmd} command is expected to be long with the unstarred version of @code{\CheckCommand}. Raises an error when the check fails. This allows you to check before you start redefining @code{cmd} yourself that no other package has already redefined this command. @item \ClassError@{@var{class name}@}@{@var{error text}@}@{@var{help text}@} @itemx \ClassWarning@{@var{class name}@}@{@var{warning text}@} @itemx \ClassWarningNoLine@{@var{class name}@}@{@var{warning text}@} @itemx \ClassInfo@{@var{class name}@}@{@var{info text}@} @itemx \ClassInfoNoLine@{@var{class name}@}@{@var{info text}@} @itemx \PackageError@{@var{package name}@}@{@var{error text}@}@{@var{help text}@} @itemx \PackageWarning@{@var{package name}@}@{@var{warning text}@} @itemx \PackageWarningNoLine@{@var{package name}@}@{@var{warning text}@} @itemx \PackageInfo@{@var{package name}@}@{@var{info text}@} @itemx \PackageInfoNoLine@{@var{package name}@}@{@var{info text}@} @findex \ClassError @findex \PackageError @findex \ClassWarning @findex \PackageWarning @findex \ClassWarningNoLine @findex \PackageWarningNoLine @findex \ClassInfo @findex \PackageInfo @findex \ClassInfoNoLine @findex \PackageInfoNoLine Produce an error message, or warning or informational messages. For @code{\ClassError} and @code{\PackageError} the message is @var{error text}, followed by @TeX{}'s @code{?} error prompt. If the user then asks for help by typing @code{h}, they see the @var{help text}. The four warning commands are similar except that they write @var{warning text} on the screen with no error prompt. The four info commands write @var{info text} only in the transcript file. The @code{NoLine} versions do not show the number of the line generating the message, while the other versions do show that number. To format the messages, including the @var{help text}: use @code{\protect} to stop a command from expanding, get a line break with @code{\MessageBreak}, and get a space with @code{\space} when a space character does not allow it, like after a command. Note that @LaTeX{} appends a period to the messages. @item \CurrentOption @findex \CurrentOption Expands to the name of the currently-being-processed option. Can only be used within the @var{code} argument of either @code{\DeclareOption} or @code{\DeclareOption*}. @item \DeclareOption@{@var{option}@}@{@var{code}@} @itemx \DeclareOption*@{@var{code}@} @findex \DeclareOption @findex \DeclareOption* @cindex class options @cindex package options @cindex options, class @cindex options, package Make an option available to a user to invoke in their @code{\documentclass} command. For example, the @code{smcmemo} class could have an option @code{\documentclass[logo]@{smcmemo@}} allowing users to put the institutional logo on the first page. The class file must contain @code{\DeclareOption@{logo@}@{@var{code}@}} (and later, @code{\ProcessOptions}). If you request an option that has not been declared, by default this will produce a warning like @code{Unused global option(s): [badoption].} Change this behavior with the starred version @code{\DeclareOption*@{@var{code}@}}. For example, many classes extend an existing class, using a command such as @code{\LoadClass@{article@}}, and for passing extra options to the underlying class use code such as this. @example \DeclareOption*@{% \PassOptionsToClass@{\CurrentOption@}@{article@}% @} @end example Another example is that the class @code{smcmemo} may allow users to keep lists of memo recipients in external files. Then the user could invoke @code{\documentclass[math]@{smcmemo@}} and it will read the file @code{math.memo}. This code handles the file if it exists and otherwise passes the option to the @code{article} class. @example \DeclareOption*@{\InputIfFileExists@{\CurrentOption.memo@}@{@}@{% \PassOptionsToClass@{\CurrentOption@}@{article@}@}@} @end example @item \DeclareRobustCommand@{@var{cmd}@}[@var{num}][@var{default}]@{@var{definition}@} @item* \DeclareRobustCommand*@{@var{cmd}@}[@var{num}][@var{default}]@{@var{definition}@} @findex \DeclareRobustCommand @findex \DeclareRobustCommand* @cindex new command, definition Like @code{\newcommand} and @code{\newcommand*} (@pxref{\newcommand & \renewcommand}) but these declare a robust command, even if some code within the @var{definition} is fragile. (For a discussion of robust and fragile commands @pxref{\protect}.) Use this command to define new robust commands or to redefine existing commands and make them robust. Unlike @code{\newcommand} these do not give an error if macro @var{cmd} already exists; instead, a log message is put into the transcript file if a command is redefined. Commands defined this way are a bit less efficient than those defined using @code{\newcommand} so unless the command's data is fragile and the command is used within a moving argument, use @code{\newcommand}. @PkgIndex{etoolbox} The @package{etoolbox} package offers the commands @code{\newrobustcmd}, @code{\newrobustcmd*}, as well as the commands @code{\renewrobustcmd}, @code{\renewrobustcmd*}, and the commands @code{\providerobustcmd}, and @code{\providerobustcmd*}. These are similar to @code{\newcommand}, @code{\newcommand*}, @code{\renewcommand}, @code{\renewcommand*}, @code{\providecommand}, and @code{\providecommand*}, but define a robust @var{cmd} with two advantages as compared to @code{\DeclareRobustCommand}: @enumerate @item They use the low-level e-@TeX{} protection mechanism rather than the higher level @LaTeX{} @code{\protect} mechanism, so they do not incur the slight loss of performance mentioned above, and @item They make the same distinction between @code{\new@dots{}}, @code{\renew@dots{}}, and @code{\provide@dots{}}, as the standard commands, so they do not just make a log message when you redefine @var{cmd} that already exists, in that case you need to use either @code{\renew@dots{}} or @code{\provide@dots{}} or you get an error. @end enumerate @item \IfFileExists@{@var{filename}@}@{@var{true code}@}@{@var{false code}@} @itemx \InputIfFileExists@{@var{filename}@}@{@var{true code}@}@{@var{false code}@} @findex \IfFileExists @findex \InputIfFileExists Execute @var{true code} if @LaTeX{} finds the file @file{@var{file name}} or @var{false code} otherwise. In the first case it executing @var{true code} and then inputs the file. Thus the command @example \IfFileExists@{img.pdf@}@{% \includegraphics@{img.pdf@}@}@{\typeout@{!! img.pdf not found@} @end example @noindent will include the graphic @file{img.pdf} if it is found and otherwise give a warning. This command looks for the file in all search paths that @LaTeX{} uses, not only in the current directory. To look only in the current directory do something like @code{\IfFileExists@{./filename@}@{@var{true code}@}@{@var{false code}@}}. If you ask for a filename without a @code{.tex} extension then @LaTeX{} will first look for the file by appending the @code{.tex}; for more on how @LaTeX{} handles file extensions see @ref{\input}. @item \LoadClass[@var{options list}]@{@var{class name}@}[@var{release date}] @itemx \LoadClassWithOptions@{@var{class name}@}[@var{release date}] @findex \LoadClass @findex \LoadClassWithOptions Load a class, as with @code{\documentclass[@var{options list}]@{@var{class name}@}[@var{release info}]}. An example is @code{\LoadClass[twoside]@{article@}}. The @var{options list}, if present, is a comma-separated list. The @var{release date} is optional. If present it must have the form @var{YYYY/MM/DD}. @c BTW, there are at-macros documented in macros2e.pdf to check the version @c and do some actions conditionnally on version later or not to some @c date. If you request a @var{release date} and the date of the package installed on your system is earlier, then you get a warning on the screen and in the log like this. @example You have requested, on input line 4, version `2038/01/19' of document class article, but only version `2014/09/29 v1.4h Standard LaTeX document class' is available. @end example The command version @code{\LoadClassWithOptions} uses the list of options for the current class. This means it ignores any options passed to it via @code{\PassOptionsToClass}. This is a convenience command that lets you build classes on existing ones, such as the standard @code{article} class, without having to track which options were passed. @item \ExecuteOptions@{@var{options-list}@} @findex \ExecuteOptions For each option @var{option} in the @var{options-list}, in order, this command executes the command @code{\ds@@@var{option}}. If this command is not defined then that option is silently ignored. It can be used to provide a default option list before @code{\ProcessOptions}. For example, if in a class file you want the default to be 11pt fonts then you could specify @code{\ExecuteOptions@{11pt@}\ProcessOptions\relax}. @item \NeedsTeXFormat@{@var{format}@}[@var{format date}] @findex \NeedsTeXFormat Specifies the format that this class must be run under. Often issued as the first line of a class file, and most often used as: @code{\NeedsTeXFormat@{LaTeX2e@}}. When a document using that class is processed, the format name given here must match the format that is actually being run (including that the @var{format} string is case sensitive). If it does not match then execution stops with an error like @samp{This file needs format `LaTeX2e' but this is `xxx'.} To specify a version of the format that you know to have certain features, include the optional @var{format date} on which those features were implemented. If present it must be in the form @code{YYYY/MM/DD}. If the format version installed on your system is earlier than @var{format date} then you get a warning like this. @example You have requested release `2038/01/20' of LaTeX, but only release `2016/02/01' is available. @end example @item \OptionNotUsed @findex \OptionNotUsed Adds the current option to the list of unused options. Can only be used within the @var{code} argument of either @code{\DeclareOption} or @code{\DeclareOption*}. @c I cannot reproduce this behavior as it is documented in clsguide. @c In the absence of a @code{\DeclareOption*} declaration, @LaTeX{} issues @c on the console a warning like @code{LaTeX Warning: Unused global @c option(s): [unusedoption].} with the list of not-used options when it @c reaches @code{\begin@{document@}}. @item \PassOptionsToClass@{@var{option list}@}@{@var{class name}@} @itemx \PassOptionsToPackage@{@var{option list}@}@{@var{package name}@} @findex \PassOptionsToClass @findex \PassOptionsToPackage Adds the options in the comma-separated list @var{option list} to the options used by any future @code{\RequirePackage} or @code{\usepackage} command for package @var{package name} or the class @var{class name}. The reason for these commands is: you may load a package any number of times with no options but if you want options then you may only supply them when you first load the package. Loading a package with options more than once will get you an error like @code{Option clash for package foo.} (@LaTeX{} throws an error even if there is no conflict between the options.) If your own code is bringing in a package twice then you can collapse that to once, for example replacing the two @code{\RequirePackage[landscape]@{geometry@}} and @code{\RequirePackage[margins=1in]@{geometry@}} with the single command @code{\RequirePackage[landscape,margins=1in]@{geometry@}}. However, imagine that you are loading @file{firstpkg} and inside that package it loads @file{secondpkg}, and you need the second package to be loaded with option @code{draft}. Then before doing the first package you must queue up the options for the second package, like this. @example \PassOptionsToPackage@{draft@}@{secondpkg@} \RequirePackage@{firstpkg@} @end example @noindent (If @code{firstpkg.sty} loads an option in conflict with what you want then you may have to alter its source.) These commands are useful for general users as well as class and package writers. For instance, suppose a user wants to load the @code{graphicx} package with the option @code{draft} and also wants to use a class @code{foo} that loads the @code{graphicx} package, but without that option. The user could start their @LaTeX{} file with @code{\PassOptionsToPackage@{draft@}@{graphicx@}\documentclass@{foo@}}. @item \ProcessOptions @itemx \ProcessOptions*@var{\@@options} @findex \ProcessOptions @findex \ProcessOptions* Execute the code for each option that the user has invoked. Include it in the class file as @code{\ProcessOptions\relax} (because of the existence of the starred command). Options come in two types. @dfn{Local options} have been specified for this particular package in the @var{options} argument of @code{\PassOptionsToPackage@{@var{options}@}}, @code{\usepackage[@var{options}]}, or @code{\RequirePackage[@var{options}]}. @dfn{Global options} are those given by the class user in @code{\documentclass[@var{options}]} (If an option is specified both locally and globally then it is local.) When @code{\ProcessOptions} is called for a package @file{pkg.sty}, the following happens: @enumerate @item For each option @var{option} so far declared with @code{\DeclareOption}, it looks to see if that option is either a global or a local option for @code{pkg}. If so then it executes the declared code. This is done in the order in which these options were given in @file{pkg.sty}. @item For each remaining local option, it executes the command @code{\ds@@}@var{option} if it has been defined somewhere (other than by a @code{\DeclareOption}); otherwise, it executes the default option code given in @code{\DeclareOption*}. If no default option code has been declared then it gives an error message. This is done in the order in which these options were specified. @end enumerate When @code{\ProcessOptions} is called for a class it works in the same way except that all options are local, and the default @var{code} for @code{\DeclareOption*} is @code{\OptionNotUsed} rather than an error. The starred version @code{\ProcessOptions*} executes the options in the order specified in the calling commands, rather than in the order of declaration in the class or package. For a package this means that the global options are processed first. @item \ProvidesClass@{@var{class name}@}[@var{release date} @var{brief additional information}] @itemx \ProvidesClass@{@var{class name}@}[@var{release date}] @itemx \ProvidesPackage@{@var{package name}@}[@var{release date} @var{brief additional information}] @itemx \ProvidesPackage@{@var{package name}@}[@var{release date}] @findex \ProvidesClass @findex \ProvidesPackage Identifies the class or package, printing a message to the screen and the log file. When you load a class or package, for example with @code{\documentclass@{smcmemo@}} or @code{\usepackage@{test@}}, @LaTeX{} inputs a file. If the name of the file does not match the class or package name declared in it then you get a warning. Thus, if you invoke @code{\documentclass@{smcmemo@}}, and the file @file{smcmemo.cls} has the statement @code{\ProvidesClass@{xxx@}} then you get a warning like @code{You have requested document class `smcmemo', but the document class provides 'xxx'.} This warning does not prevent @LaTeX{} from processing the rest of the class file normally. If you include the optional argument then you must include a date, before any spaces, of the form @code{YYYY/MM/DD}. The rest of the optional argument is free-form, although it traditionally identifies the class, and is written to the screen during compilation and to the log file. Thus, if your file @file{smcmemo.cls} contains the line @code{\ProvidesClass@{smcmemo@}[2008/06/01 v1.0 SMC memo class]} and your document's first line is @code{\documentclass@{smcmemo@}} then you will see @code{Document Class: smcmemo 2008/06/01 v1.0 SMC memo class}. The date in the optional argument allows class and package users to ask to be warned if the version of the class or package is earlier than @var{release date}. For instance, a user could enter @code{\documentclass@{smcmemo@}[2018/10/12]} or @code{\usepackage@{foo@}[[2017/07/07]]} to require a class or package with certain features by specifying that it must be released no earlier than the given date. (Although, in practice package users only rarely include a date, and class users almost never do.) @item \ProvidesFile@{@var{filename}@}[@var{additional information}] @findex \ProvidesFile Declare a file other than the main class and package files, such as configuration files or font definition files. Put this command in that file and you get in the log a string like @code{File: test.config 2017/10/12 config file for test.cls} for @var{filename} equal to @samp{test.config} and @var{additional information} equal to @samp{2017/10/12 config file for test.cls}. @item \RequirePackage[@var{option list}]@{@var{package name}@}[@var{release date}] @itemx \RequirePackageWithOptions@{@var{package name}@}[@var{release date}] @findex \RequirePackage @findex \RequirePackageWithOptions Load a package, like the command @code{\usepackage} (@pxref{Additional packages}). The @LaTeX{} development team strongly recommends use of these commands over Plain@tie{}@TeX{}'s @code{\input}; see the Class Guide. An example is @code{\RequirePackage[landscape,margin=1in]@{geometry@}}. The @var{option list}, if present, is a comma-separated list. The @var{release date}, if present, must have the form @var{YYYY/MM/DD}. If the release date of the package as installed on your system is earlier than @var{release date} then you get a warning like @code{You have requested, on input line 9, version `2017/07/03' of package jhtest, but only version `2000/01/01' is available}. The @code{\RequirePackageWithOptions} version uses the list of options for the current class. This means it ignores any options passed to it via @code{\PassOptionsToClass}. This is a convenience command to allow easily building classes on existing ones without having to track which options were passed. The difference between @code{\usepackage} and @code{\RequirePackage} is small. The @code{\usepackage} command is intended for the document file while @code{\RequirePackage} is intended for package and class files. Thus, using @code{\usepackage} before the @code{\documentclass} command causes @LaTeX{} to give error like @code{\usepackage before \documentclass}, but you can use @code{\RequirePackage} there. @end table @node Fonts @chapter Fonts @anchor{Typefaces}@c old name @cindex typefaces @cindex fonts @LaTeX{} comes with powerful font capacities. For one thing, its New Font Selection Scheme allows you to work easily with the font families in your document (for instance, see@tie{}@ref{Font styles}). And, @LaTeX{} documents can use most fonts that are available today, including versions of Times Roman, Helvetica, Courier, etc. (Note, though, that many fonts do not have support for mathematics.) The first typeface in the @TeX{} world was the Computer Modern family, developed by Donald Knuth. It is the default for @LaTeX{} documents and is still the most widely used. But changing to another font often only involves a few commands. For instance, putting the following in your preamble gives you a Palatino-like font, which is handsome and more readable online than many other fonts, while still allowing you to typeset mathematics. (This example is from Michael Sharpe, @url{https://math.ucsd.edu/~msharpe/RcntFnts.pdf}.) @example \usepackage[osf]@{newpxtext@} % osf for text, not math \usepackage@{cabin@} % sans serif \usepackage[varqu,varl]@{inconsolata@} % sans serif typewriter \usepackage[bigdelims,vvarbb]@{newpxmath@} % bb from STIX \usepackage[cal=boondoxo]@{mathalfa@} % mathcal @end example @noindent In addition, the @command{xelatex} or @command{lualatex} engines allow you to use any fonts on your system that are in OpenType or TrueType format (@pxref{@TeX{} engines}). The @LaTeX{} Font Catalogue (@url{https://tug.org/FontCatalogue}) shows font sample graphics and copy-and-pasteable source to use many fonts, including many with support for mathematics. It aims to cover all Latin alphabet free fonts available for easy use with @LaTeX{}. More information is also available from the @TeX{} Users Group, at @url{https://www.tug.org/fonts/}. @menu * fontenc package:: Encoding of the font. * Font styles:: Select roman, italics, etc. * Font sizes:: Select point size. * Low-level font commands:: Select encoding, family, series, shape. @end menu @node fontenc package @section @code{fontenc} package @cindex font encoding @cindex UTF-8, font support for @cindex T1 @cindex OT1 @findex fontenc Synopsis: @example \usepackage[@var{font_encoding}]@{fontenc@} @end example or @example \usepackage[@var{font_encoding1}, @var{font_encoding2}, ...]@{fontenc@} @end example Specify the font encodings. A font encoding is a mapping of the character codes to the font glyphs that are used to typeset your output. @PkgIndex{fontspec} This package only applies if you use the @code{pdflatex} engine (@pxref{@TeX{} engines}). If you use the @command{xelatex} or @command{lualatex} engine then instead use the @package{fontspec} package. @TeX{}'s original font family, Computer Modern, has a limited character set. For instance, to make common accented characters you must use @code{\accent} (@pxref{\accent}) but this disables hyphenation. @TeX{} users have agreed on a number of standards to access the larger sets of characters provided by modern fonts. If you are using @command{pdflatex} then put this in the preamble @example \usepackage[T1]@{fontenc@} @end example @noindent gives you support for the most widespread European languages, including French, German, Italian, Polish, and others. In particular, if you have words with accented letters then @LaTeX{} will hyphenate them and your output can be copied and pasted. (The optional second line allows you to directly enter accented characters into your source file.) @PkgIndex{lmodern} @PkgIndex{cm-super} If you are using an encoding such as @code{T1} and the characters appear blurry or do not magnify well then your fonts may be bitmapped, sometimes called raster or Type@tie{}3. You want vector fonts. Use a package such as @package{lmodern} or @package{cm-super} to get a font that extends @LaTeX{}'s default using vector fonts. For each @var{font_encoding} given as an option but not already declared, this package loads the encoding definition files, named @file{@var{font_encoding}enc.def}. It also sets @code{\encodingdefault} to be the last encoding in the option list. These are the common values for @var{font_encoding}. @table @code @item OT1 The original encoding for @TeX{}. Limited to mostly English characters. @item OMS, OML Math symbols and math letters encoding. @item T1 @TeX{} text extended. Sometimes called the Cork encoding for the Users Group meeting where it was developed. Gives access to most European accented characters. The most common option for this package. @item TS1 Text Companion encoding. @end table @noindent @LaTeX{}'s default is to load @code{OML}, @code{T1}, @code{OT1}, and then @code{OMS}, and set the default to @code{OT1}. Even if you do not use accented letters, you may need to specify a font encoding if your font requires it. If you use @code{T1}@tie{}encoded fonts other than the default Computer Modern family then you may need to load the package that selects your fonts before loading @file{fontenc}, to prevent the system from loading any @code{T1}@tie{}encoded fonts from the default. The @LaTeX{} team reserve encoding names starting with: @samp{T} for the standard text encodings with 256 characters, @samp{TS} for symbols that extend the corresponding T encodings, @samp{X} for test encodings, @samp{M} for standard math encodings with 256 characters, @samp{A} for special applications, @samp{OT} for standard text encodings with 128 characters, and @samp{OM} for standard math encodings with 128 characters (@samp{O} stands for @samp{obsolete}). This package provides a number of commands, detailed below. Many of them are encoding-specific, so if you have defined a command that works for one encoding but the current encoding is different then the command is not in effect. @menu * \DeclareFontEncoding:: Define an encoding. * \DeclareTextAccent:: Define an accent in the encoding. * \DeclareTextAccentDefault:: Fallback for using an accent in the encoding. * \DeclareTextCommand & \ProvideTextCommand:: New encoding-specific command. * \DeclareTextCommandDefault & \ProvideTextCommandDefault:: Fallback for encoding-specific commands. * \DeclareTextComposite:: Directly access an accented glyph, in the encoding. * \DeclareTextCompositeCommand:: Run code in slot, in the encoding. * \DeclareTextSymbol:: Define a symbol in the encoding. * \DeclareTextSymbolDefault:: Fallback for a symbol in the encoding. * \LastDeclaredEncoding:: Save most recently declared encoding. * \UseTextSymbol & \UseTextAccent:: Temporarily switch to another encoding. @end menu @node \DeclareFontEncoding @subsection @code{\DeclareFontEncoding} @cindex font encoding, declaring @cindex encoding, font @cindex accents, defining @findex \DeclareFontEncoding Synopsis: @example \DeclareFontEncoding@{@var{encoding}@}@{@var{text-settings}@}@{@var{math-settings}@} @end example Declare the font encoding @var{encoding}. It also saves the value of @var{encoding} in @code{\LastDeclaredEncoding} (@pxref{\LastDeclaredEncoding}). The file @file{t1enc.def} contains this line (followed by many others). @example \DeclareFontEncoding@{T1@}@{@}@{@} @end example The @var{text-settings} are the commands that @LaTeX{} will run every time it switches from one encoding to another with the @code{\selectfont} and @code{\fontencoding} commands. The @var{math-settings} are the commands that @LaTeX{} will use whenever the font is accessed as a math alphabet. @LaTeX{} ignores any space characters inside @var{text-settings} and @var{math-settings}, to prevent unintended spaces in the output. If you invent an encoding you should pick a two or three letter name starting with @samp{L} for @samp{local}, or @samp{E} for @samp{experimental}. Note that output encoding files may be read several times by @LaTeX{} so using, e.g., @code{\newcommand} may cause an error. In addition, such files should contain @code{\ProvidesFile} line (@pxref{Class and package commands}). Note also that you should use the @code{\...Default} commands only in a package, not in the encoding definition files, since those files should only contain declarations specific to that encoding. @node \DeclareTextAccent @subsection @code{\DeclareTextAccent} @cindex font encoding @cindex accents, defining @findex \DeclareTextAccent Synopsis: @example \DeclareTextAccent@{@var{cmd}@}@{@var{encoding}@}@{@var{slot}@} @end example Define an accent, to be put on top of other glyphs, in the encoding @var{encoding} at the location @var{slot}. @cindex slot, font A @dfn{slot} is the number identifying a glyph within a font. This line from @file{t1enc.def} declares that to make a circumflex accent as in @code{\^A}, the system will put the accent in slot@tie{}2 over the @samp{A} character, which is represented in ASCII as@tie{}65. (This holds unless there is a relevant @code{DeclareTextComposite} or @code{\DeclareTextCompositeCommand} declaration; @pxref{\DeclareTextComposite}.) @example \DeclareTextAccent@{\^@}@{T1@}@{2@} @end example If @var{cmd} has already been defined then @code{\DeclareTextAccent} does not give an error but it does log the redefinition in the transcript file. @node \DeclareTextAccentDefault @subsection @code{\DeclareTextAccentDefault} @cindex accents, defining @findex \DeclareTextAccent @findex \DeclareTextAccentDefault Synopsis: @example \DeclareTextAccentDefault@{\@var{cmd}@}@{@var{encoding}@} @end example If there is an encoding-specific accent command \@var{cmd} but there is no associated @code{\DeclareTextAccent} for that encoding then this command will pick up the slack, by saying to use it as described for @var{encoding}. For example, to make the encoding @code{OT1} be the default encoding for the accent @code{\"}, declare this. @example \DeclareTextAccentDefault@{\"@}@{OT1@} @end example @noindent If you issue a @code{\"} when the current encoding does not have a definition for that accent then @LaTeX{} will use the definition from @code{OT1} That is, this command is equivalent to this call (@pxref{\UseTextSymbol & \UseTextAccent}). @example \DeclareTextCommandDefault[1]@{\@var{cmd}@} @{\UseTextAccent@{@var{encoding}@}@{\@var{cmd}@}@{#1@}@} @end example Note that @code{\DeclareTextAccentDefault} works for any one-argument @file{fontenc} command, not just the accent command. @node \DeclareTextCommand & \ProvideTextCommand @subsection @code{\DeclareTextCommand} & @code{\ProvideTextCommand} @anchor{\DeclareTextCommand} @anchor{\ProvideTextCommand} @findex \DeclareTextCommand @findex \ProvideTextCommand Synopsis, one of: @example \DeclareTextCommand@{\@var{cmd}@}@{@var{encoding}@}@{@var{defn}@} \DeclareTextCommand@{\@var{cmd}@}@{@var{encoding}@}[@var{nargs}]@{@var{defn@}} \DeclareTextCommand@{\@var{cmd}@}@{@var{encoding}@}[@var{nargs}][@var{optargdefault}]@{@var{defn}@} @end example or one of: @example \ProvideTextCommand@{\@var{cmd}@}@{@var{encoding}@}@{@var{defn}@} \ProvideTextCommand@{\@var{cmd}@}@{@var{encoding}@}[@var{nargs}]@{@var{defn}@} \ProvideTextCommand@{\@var{cmd}@}@{@var{encoding}@}[@var{nargs}][@var{optargdefault}]@{@var{defn}@} @end example Define the command @code{\@var{cmd}}, which will be specific to one encoding. The command name @var{cmd} must be preceded by a backslash, @code{\}. These commands can only appear in the preamble. Redefining \@var{cmd} does not cause an error. The defined command will be robust even if the code in @var{defn} is fragile (@pxref{\protect}). For example, the file @file{t1enc.def} contains this line. @example \DeclareTextCommand@{\textperthousand@}@{T1@}@{\%\char 24 @} @end example With that, you can express parts per thousand. @example \usepackage[T1]@{fontenc@} % in preamble ... Legal limit is \( 0.8 \)\textperthousand. @end example @noindent If you change the font encoding to @code{OT1} then you get an error like @samp{LaTeX Error: Command \textperthousand unavailable in encoding OT1}. @findex \DeclareTextSymbol The @code{\ProvideTextCommand} variant does the same, except that it does nothing if @code{\@var{cmd}} is already defined. The @code{\DeclareTextSymbol} command is faster than this one for simple slot-to-glyph association (@pxref{\DeclareTextSymbol}) The optional @var{nargs} and @var{optargdefault} arguments play the same role here as in @code{\newcommand} (@pxref{\newcommand & \renewcommand}). Briefly, @var{nargs} is an integer from 0 to 9 specifying the number of arguments that the defined command @code{\@var{cmd}} takes. This number includes any optional argument. Omitting this argument is the same as specifying 0, meaning that @code{\@var{cmd}} will have no arguments. And, if @var{optargdefault} is present then the first argument of @code{\@var{cmd}} is optional, with default value @var{optargdefault} (which may be the empty string). If @var{optargdefault} is not present then @code{\@var{cmd}} does not take an optional argument. @node \DeclareTextCommandDefault & \ProvideTextCommandDefault @subsection @code{\DeclareTextCommandDefault} & @code{\ProvideTextCommandDefault } @anchor{\DeclareTextCommandDefault} @anchor{\ProvideTextCommandDefault} @findex \DeclareTextCommandDefault @findex \ProvideTextCommandDefault Synopsis: @example \DeclareTextCommandDefault@{\@var{cmd}@}@{@var{defn}@} @end example or: @example \ProvideTextCommandDefault@{\@var{cmd}@}@{@var{defn}@} @end example Give a default definition for @code{\@var{cmd}}, for when that command is not defined in the encoding currently in force. This default should only use encodings known to be available. This makes @code{\copyright} available. @example \DeclareTextCommandDefault@{\copyright@}@{\textcircled@{c@}@} @end example @noindent It uses only an encoding (OMS) that is always available. The @code{\DeclareTextCommandDefault} should not occur in the encoding definition files since those files should declare only commands for use when you select that encoding. It should instead be in a package. As with the related non-default commands, the @code{\ProvideTextCommandDefault} has exactly the same behavior as @code{\DeclareTextCommandDefault} except that it does nothing if @code{\@var{cmd}} is already defined (@pxref{\DeclareTextCommand & \ProvideTextCommand}). So, packages can use it to provide fallbacks that other packages can improve upon. @node \DeclareTextComposite @subsection @code{\DeclareTextComposite} @cindex accents, defining @findex \DeclareTextComposite Synopsis: @example \DeclareTextComposite@{\@var{cmd}@}@{@var{encoding}@}@{@var{simple_object}@}@{@var{slot}@} @end example Access an accented glyph directly, that is, without having to put an accent over a separate character. This line from @file{t1enc.def} means that @code{\^o} will cause @LaTeX{} to typeset lowercase@tie{}@samp{o} by taking the character directly from slot 224 in the font. @example \DeclareTextComposite@{\^@}@{T1@}@{o@}@{244@} @end example @xref{fontenc package}, for a list of common encodings. The @var{simple_object} should be a single character or a single command. The @var{slot} argument is usually a positive integer represented in decimal (although octal or hexadecimal are possible). Normally \@var{cmd} has already been declared for this encoding, either with @code{\DeclareTextAccent} or with a one-argument @code{\DeclareTextCommand}. In @file{t1enc.def}, the above line follows the @code{\DeclareTextAccent@{\^@}@{T1@}@{2@}} command. @node \DeclareTextCompositeCommand @subsection @code{\DeclareTextCompositeCommand} @cindex accents, defining @findex \DeclareTextCompositeCommand Synopsis: @example \DeclareTextCompositeCommand@{\@var{cmd}@}@{@var{encoding}@}@{@var{arg}@}@{@var{code}@} @end example A more general version of @code{\DeclareTextComposite} that runs arbitrary code with @code{\@var{cmd}}. This allows accents on @samp{i} to act like accents on dotless@tie{}i, @code{\i}. @example \DeclareTextCompositeCommand@{\'@}@{OT1@}@{i@}@{\'\i@} @end example @xref{fontenc package}, for a list of common encodings. Normally @code{\@var{cmd}} will have already been declared with @code{\DeclareTextAccent} or as a one argument @code{\DeclareTextCommand}. @node \DeclareTextSymbol @subsection @code{\DeclareTextSymbol} @cindex symbol, defining @findex \DeclareTextSymbol Synopsis: @example \DeclareTextSymbol@{\@var{cmd}@}@{@var{encoding}@}@{@var{slot}@} @end example Define a symbol in the encoding @var{encoding} at the location @var{slot}. Symbols defined in this way are for use in text, not mathematics. For example, this line from @file{t1enc.def} declares the number of the glyph to use for @BES{00AB,\hbox{\guillemotleft}}, the left guillemet. @example \DeclareTextSymbol@{\guillemotleft@}@{T1@}@{19@} @end example @noindent The command @code{\DeclareTextCommand@{\guillemotleft@}@{T1@}@{\char 19@}} has the same effect but is slower (@pxref{\DeclareTextCommand & \ProvideTextCommand}). @xref{fontenc package}, for a list of common encodings. The @var{slot} can be specified in decimal, or octal (as in @code{'023}), or hexadecimal (as in @code{"13}), although decimal has the advantage that single quote or double quote could be redefined by another package. If @code{\@var{cmd}} has already been defined then @code{\DeclareTextSymbol} does not give an error but it does log the redefinition in the transcript file. @node \DeclareTextSymbolDefault @subsection @code{\DeclareTextSymbolDefault} @cindex accents, defining @findex \DeclareTextSymbol @findex \DeclareTextSymbolDefault Synopsis: @example \DeclareTextSymbolDefault@{\@var{cmd}@}@{@var{encoding}@} @end example If there is an encoding-specific symbol command @code{\@var{cmd}} but there is no associated @code{\DeclareTextSymbol} for that encoding, then this command will pick up the slack, by saying to get the symbol as described for @var{encoding}. For example, to declare that if the current encoding has no meaning for @code{\textdollar} then use the one from @code{OT1}, declare this. @example \DeclareTextSymbolDefault@{\textdollar@}@{OT1@} @end example That is, this command is equivalent to this call (@pxref{\UseTextSymbol & \UseTextAccent}). @example \DeclareTextCommandDefault@{\@var{cmd}@} @{\UseTextSymbol@{@var{encoding}@}@{\@var{cmd}@}@} @end example Note that @code{\DeclareTextSymbolDefault} can be used to define a default for any zero-argument @file{fontenc} command. @node \LastDeclaredEncoding @subsection @code{\LastDeclaredEncoding} @findex \LastDeclaredEncoding Synopsis: @example \LastDeclaredEncoding @end example Get the name of the most recently declared encoding. The @code{\DeclareFontEncoding} command stores the name so that it can be retrieved with this command (@pxref{\DeclareFontEncoding}). This relies on @code{\LastDeclaredEncoding} rather than give the name of the encoding explicitly. @example \DeclareFontEncoding@{JH1@}@{@}@{@} \DeclareTextAccent@{\'@}@{\LastDeclaredEncoding@}@{0@} @end example @node \UseTextSymbol & \UseTextAccent @subsection @code{\UseTextSymbol} & @code{\UseTextAccent} @anchor{\UseTextSymbol} @anchor{\UseTextAccent} @findex \UseTextSymbol @findex \UseTextAccent Synopsis: @example \UseTextSymbol@{@var{encoding}@}@{\@var{cmd}@} @end example or: @example \UseTextAccent@{@var{encoding}@}@{\@var{cmd}@}@{@var{text}@} @end example Use a symbol or accent not from the current encoding. In general, to use a @file{fontenc} command in an encoding where it is not defined, and if the command has no arguments, then you can use it like this: @example \UseTextSymbol@{OT1@}@{\ss@} @end example @noindent which is equivalent to this (note the outer braces form a group, so @LaTeX{} reverts back to the prior encoding after the @code{\ss}): @example @{\fontencoding@{OT1@}\selectfont\ss@} @end example Similarly, to use a @file{fontenc} command in an encoding where it is not defined, and if the command has one argument, you can use it like this: @example \UseTextAccent@{OT1@}@{\'@}@{a@} @end example @noindent which is equivalent to this (again note the outer braces forming a group): @example @{fontencoding@{OT1@}\selectfont\'@{\fontencoding@{@var{enc_in_use}@}\selectfont a@}@} @end example @noindent Here, @var{enc_in_use} is the encoding in force before this sequence of commands, so that @samp{a} is typeset using the current encoding and only the accent is taken from @code{OT1}. @node Font styles @section Font styles @cindex font styles @cindex type styles @cindex styles of text The following type style commands are supported by @LaTeX{}. @cindex declaration form of font style commands In the table below the listed commands, the @code{\text...} commands, are used with an argument as in @code{\textit@{@var{text}@}}. This is the preferred form. But shown after it in parenthesis is the corresponding @dfn{declaration form}, which is often useful. This form takes no arguments, as in @code{@{\itshape @var{text}@}}. The scope of the declaration form lasts until the next type style command or the end of the current group. In addition, each has an environment form such as @code{\begin@{itshape@}...\end@{itshape@}}, which we'll describe further at the end of the section. These commands, in any of the three forms, are cumulative; for instance you can get bold sans serif by saying either of @code{\sffamily\bfseries} or @code{\bfseries\sffamily}. @anchor{\nocorrlist} @anchor{\nocorr} @findex \nocorrlist @findex \nocorr One advantage of these commands is that they automatically insert italic corrections if needed (@pxref{\/}). Specifically, they insert the italic correction unless the following character is in the list @code{\nocorrlist}, which by default consists of period and comma. To suppress the automatic insertion of italic correction, use @code{\nocorr} at the start or end of the command argument, such as @code{\textit@{\nocorr text@}} or @code{\textsc@{text \nocorr@}}. @table @code @item \textrm (\rmfamily) @findex \textrm @findex \rmfamily Roman. @item \textit (\itshape) @findex \textit @findex \itshape Italics. @item \textmd (\mdseries) @findex \textmd @findex \mdseries Medium weight (default). @item \textbf (\bfseries) @findex \textbf @findex \bfseries Boldface. @item \textup (\upshape) @findex \textup @findex \upshape Upright (default). @item \textsl (\slshape) @findex \textsl @findex \slshape Slanted. @item \textsf (\sffamily) @findex \textsf @findex \sffamily Sans serif. @item \textsc (\scshape) @findex \textsc @findex \scshape Small caps. @item \texttt (\ttfamily) @findex \texttt @findex \ttfamily Typewriter. @item \textnormal (\normalfont) @findex \textnormal @findex \normalfont Main document font. @end table @cindex emphasis @findex \emph Although it also changes fonts, the @code{\emph@{@var{text}@}} command is semantic, for @var{text} to be emphasized, and should not be used as a substitute for @code{\textit}. For example, @code{\emph@{@var{start text} \emph@{@var{middle text}@} @var{end text}@}} will result in the @var{start text} and @var{end text} in italics, but @var{middle text} will be in roman. @LaTeX{} also provides the following commands, which unconditionally switch to the given style, that is, are @emph{not} cumulative. They are used as declarations: @code{@{\@var{cmd}...@}} instead of @code{\@var{cmd}@{...@}}. (The unconditional commands below are an older version of font switching. The earlier commands are an improvement in most circumstances. But sometimes an unconditional font switch is what is needed.) @ftable @code @item \bf @cindex bold font Switch to bold face. @item \cal @cindex script letters for math @cindex calligraphic letters for math Switch to calligraphic letters for math. @item \it @cindex italic font Italics. @item \rm @cindex roman font Roman. @item \sc @cindex small caps font Small caps. @item \sf @cindex sans serif font Sans serif. @item \sl @cindex slanted font @cindex oblique font Slanted (oblique). @item \tt @cindex typewriter font @cindex monospace font @cindex fixed-width font Typewriter (monospace, fixed-width). @end ftable The @code{\em} command is the unconditional version of @code{\emph}. The following commands are for use in math mode. They are not cumulative, so @code{\mathbf@{\mathit@{@var{symbol}@}@}} does not create a boldface and italic @var{symbol}; instead, it will just be in italics. This is because typically math symbols need consistent typographic treatment, regardless of the surrounding environment. @table @code @item \mathrm @findex \mathrm Roman, for use in math mode. @item \mathbf @findex \mathbf Boldface, for use in math mode. @item \mathsf @findex \mathsf Sans serif, for use in math mode. @item \mathtt @findex \mathtt Typewriter, for use in math mode. @item \mathit @itemx (\mit) Italics, for use in math mode. @item \mathnormal @findex \mathnormal For use in math mode, e.g., inside another type style declaration. @item \mathcal @findex \mathcal Calligraphic letters, for use in math mode. @end table @anchor{\mathversion} @findex \mathversion @cindex math, bold @cindex bold math In addition, the command @code{\mathversion@{bold@}} can be used for switching to bold letters and symbols in formulas. @code{\mathversion@{normal@}} restores the default. @anchor{\oldstylenums} @findex \oldstylenums @cindex numerals, old-style @cindex old-style numerals @cindex lining numerals Finally, the command @code{\oldstylenums@{@var{numerals}@}} will typeset so-called ``old-style'' numerals, which have differing heights and depths (and sometimes widths) from the standard ``lining'' numerals, which all have the same height as uppercase letters. @LaTeX{}'s default fonts support this, and will respect @code{\textbf} (but not other styles; there are no italic old-style numerals in Computer Modern). Many other fonts have old-style numerals also; sometimes package options are provided to make them the default. FAQ entry: @url{https://www.texfaq.org/FAQ-osf}. @node Font sizes @section Font sizes @cindex font sizes @cindex typeface sizes @cindex sizes of text The following standard type size commands are supported by @LaTeX{}. The table shows the command name and the corresponding actual font size used (in points) with the @samp{10pt}, @samp{11pt}, and @samp{12pt} document size options, respectively (@pxref{Document class options}). @findex \tiny @findex \scriptsize @findex \footnotesize @findex \small @findex \normalsize @findex \large @findex \Large @findex \LARGE @findex \huge @findex \Huge @multitable {@code{\normalsize} (default)@ @ } {24.88@ @ } {24.88@ @ } {24.88} @headitem Command @tab @code{10pt} @tab @code{11pt} @tab @code{12pt} @item @code{\tiny} @tab 5 @tab 6 @tab 6 @item @code{\scriptsize} @tab 7 @tab 8 @tab 8 @item @code{\footnotesize} @tab 8 @tab 9 @tab 10 @item @code{\small} @tab 9 @tab 10 @tab 10.95 @item @code{\normalsize} (default) @tab 10 @tab 10.95 @tab 12 @item @code{\large} @tab 12 @tab 12 @tab 14.4 @item @code{\Large} @tab 14.4 @tab 14.4 @tab 17.28 @item @code{\LARGE} @tab 17.28 @tab 17.28 @tab 20.74 @item @code{\huge} @tab 20.74 @tab 20.74 @tab 24.88 @item @code{\Huge} @tab 24.88 @tab 24.88 @tab 24.88 @end multitable @cindex declaration form of font size commands The commands are listed here in declaration (not environment) form, since that is how they are typically used. For example. @example \begin@{quotation@} \small The Tao that can be named is not the eternal Tao. \end@{quotation@} @end example @noindent Here, the scope of the @code{\small} lasts until the end of the @code{quotation} environment. It would also end at the next type style command or the end of the current group, so you could enclose it in curly braces @code{@{\small This text is typeset in the small font.@}}. Trying to use these commands in math, as with @code{$\small mv^2/2$}, results in @samp{LaTeX Font Warning: Command \small invalid in math mode}, and the font size doesn't change. To work with a too-large formula, often the best option is to use the @code{displaymath} environment (@pxref{Math formulas}), or one of the environments from the @package{amsmath} package. For inline mathematics, such as in a table of formulas, an alternative is something like @code{@{\small $mv^2/2$@}}. (Sometimes @code{\scriptsize} and @code{\scriptstyle} are confused. Both change the font size, but the latter also changes a number of other aspects of how mathematics is typeset. @xref{Math styles}.) @cindex environment form of font size commands An @dfn{environment form} of each of these commands is also defined; for instance, @code{\begin@{tiny@}...\end@{tiny@}}. However, in practice this form can easily lead to unwanted spaces at the beginning and/or end of the environment without careful consideration, so it's generally less error-prone to stick to the declaration form. (Aside: Technically, due to the way @LaTeX{} defines @code{\begin} and @code{\end}, nearly every command that does not take an argument technically has an environment form. But in almost all cases, it would only cause confusion to use it. The reason for mentioning the environment form of the font size declarations specifically is that this particular use is not rare.) @node Low-level font commands @section Low-level font commands @cindex low-level font commands @cindex font commands, low-level These commands are primarily intended for writers of macros and packages. The commands listed here are only a subset of the available ones. @c xx but it should be complete @c xx something about ultimately reading ENCFAM.fd? @table @code @anchor{low level font commands fontencoding} @item \fontencoding@{@var{encoding}@} @findex \fontencoding Select the font encoding, the encoding of the output font. There are a large number of valid encodings. The most common are @code{OT1}, Knuth's original encoding for Computer Modern (the default), and @code{T1}, also known as the Cork encoding, which has support for the accented characters used by the most widespread European languages (German, French, Italian, Polish and others), which allows @TeX{} to hyphenate words containing accented letters. For more, see @url{https://ctan.org/pkg/encguide}. @anchor{low level font commands fontfamily} @item \fontfamily@{@var{family}@} @findex \fontfamily @cindex families, of fonts @cindex font catalogue Select the font family. The web page @url{https://tug.org/FontCatalogue/} provides one way to browse through many of the fonts easily used with @LaTeX{}. Here are examples of some common families. @multitable {font} {Computer Modern Typewriter more space} @item @code{pag} @tab Avant Garde @item @code{fvs} @tab Bitstream Vera Sans @item @code{pbk} @tab Bookman @item @code{bch} @tab Charter @item @code{ccr} @tab Computer Concrete @item @code{cmr} @tab Computer Modern @item @code{cmss} @tab Computer Modern Sans Serif @item @code{cmtt} @tab Computer Modern Typewriter @item @code{pcr} @tab Courier @item @code{phv} @tab Helvetica @item @code{fi4} @tab Inconsolata @item @code{lmr} @tab Latin Modern @item @code{lmss} @tab Latin Modern Sans @item @code{lmtt} @tab Latin Modern Typewriter @item @code{pnc} @tab New Century Schoolbook @item @code{ppl} @tab Palatino @item @code{ptm} @tab Times @item @code{uncl} @tab Uncial @item @code{put} @tab Utopia @item @code{pzc} @tab Zapf Chancery @end multitable @anchor{low level font commands fontseries} @item \fontseries@{@var{series}@} @findex \fontseries @cindex series, of fonts Select the font series. A @dfn{series} combines a @dfn{weight} and a @dfn{width}. Typically, a font supports only a few of the possible combinations. Some common combined series values include: @multitable {xx} {Medium (normal)xx} @item @code{m} @tab Medium (normal) @item @code{b} @tab Bold @item @code{c} @tab Condensed @item @code{bc} @tab Bold condensed @item @code{bx} @tab Bold extended @end multitable @cindex weights, of fonts The possible values for weight, individually, are: @multitable {xx} {Medium (normal) xx} @item @code{ul} @tab Ultra light @item @code{el} @tab Extra light @item @code{l} @tab Light @item @code{sl} @tab Semi light @item @code{m} @tab Medium (normal) @item @code{sb} @tab Semi bold @item @code{b} @tab Bold @item @code{eb} @tab Extra bold @item @code{ub} @tab Ultra bold @end multitable @cindex widths, of fonts The possible values for width, individually, are (the meaning and relationship of these terms varies with individual typefaces): @multitable {xx} {Ultra condensed} @item @code{uc} @tab Ultra condensed @item @code{ec} @tab Extra condensed @item @code{c} @tab Condensed @item @code{sc} @tab Semi condensed @item @code{m} @tab Medium @item @code{sx} @tab Semi expanded @item @code{x} @tab Expanded @item @code{ex} @tab Extra expanded @item @code{ux} @tab Ultra expanded @end multitable When forming the @var{series} string from the weight and width, drop the @code{m} that stands for medium weight or medium width, unless both weight and width are @code{m}, in which case use just one (@samp{@code{m}}). @anchor{low level font commands fontshape} @item \fontshape@{@var{shape}@} @findex \fontshape @cindex shapes, of fonts Select font shape. Valid shapes are: @multitable {xx} {Slanted (oblique)xx} @item @code{n} @tab Upright (normal) @item @code{it} @tab Italic @item @code{sl} @tab Slanted (oblique) @item @code{sc} @tab Small caps @item @code{ui} @tab Upright italics @item @code{ol} @tab Outline @end multitable The two last shapes are not available for most font families, and small caps are often missing as well. @anchor{low level font commands fontsize} @item \fontsize@{@var{size}@}@{@var{skip}@} @findex \fontsize @cindex font size @findex \baselineskip Set the font size and the line spacing. The unit of both parameters defaults to points (@code{pt}). The line spacing is the nominal vertical space between lines, baseline to baseline. It is stored in the parameter @code{\baselineskip}. The default @code{\baselineskip} for the Computer Modern typeface is 1.2 times the @code{\fontsize}. Changing @code{\baselineskip} directly is inadvisable since its value is reset every time a size change happens; instead use @code{\baselinestretch}. (@pxref{\baselineskip & \baselinestretch}). @anchor{low level font commands linespread} @item \linespread@{@var{factor}@} @findex \linespread Equivalent to @code{\renewcommand@{\baselinestretch@}@{@var{factor}@}}, and therefore must be followed by @code{\selectfont} to have any effect. Best specified in the preamble. @xref{\baselineskip & \baselinestretch}, for using @package{setspace} package instead. @anchor{low level font commands selectfont} @item \selectfont @findex \selectfont The effects of the font commands described above do not happen until @code{\selectfont} is called, as in @code{\fontfamily@{@var{familyname}@}\selectfont}. It is often useful to put this in a macro:@* @code{\newcommand*@{\myfont@}@{\fontfamily@{@var{familyname}@}\selectfont@}}@* (@pxref{\newcommand & \renewcommand}). @anchor{low level font commands usefont} @item \usefont@{@var{enc}@}@{@var{family}@}@{@var{series}@}@{@var{shape}@} @findex \usefont The same as invoking @code{\fontencoding}, @code{\fontfamily}, @code{\fontseries} and @code{\fontshape} with the given parameters, followed by @code{\selectfont}. For example: @example \usefont@{ot1@}@{cmr@}@{m@}@{n@} @end example @end table @node Layout @chapter Layout @cindex layout commands Commands for controlling the general page layout. @menu * \onecolumn:: Use one-column layout. * \twocolumn:: Use two-column layout. * \flushbottom:: Make all text pages the same height. * \raggedbottom:: Allow text pages of differing height. * Page layout parameters:: @code{\headheight} @code{\footskip}. * \baselineskip & \baselinestretch:: Space between lines. * Floats:: Figures, tables, etc. @end menu @node \onecolumn @section @code{\onecolumn} @findex \onecolumn @cindex one-column output Synopsis: @example \onecolumn @end example Start a new page and produce single-column output. If the document is given the class option @code{onecolumn} then this is the default behavior (@pxref{Document class options}). This command is fragile (@pxref{\protect}). @node \twocolumn @section @code{\twocolumn} @findex \twocolumn @cindex multicolumn text @cindex two-column output Synopses: @example \twocolumn \twocolumn[@var{prelim one column text}] @end example Start a new page and produce two-column output. If the document is given the class option @code{twocolumn} then this is the default (@pxref{Document class options}). This command is fragile (@pxref{\protect}). If the optional @var{prelim one column text} argument is present, it is typeset in one-column mode before the two-column typesetting starts. These parameters control typesetting in two-column output: @ftable @code @item \columnsep @anchor{twocolumn columnsep} The distance between columns. The default is 35pt. Change it with a command such as @code{\setlength@{\columnsep@}@{40pt@}}. You must change it before the two column mode starts; in the preamble is a good place. @item \columnseprule @anchor{twocolumn columnseprule} The width of the rule between columns. The default is 0pt, meaning that there is no rule. Otherwise, the rule appears halfway between the two columns. Change it with a command such as @code{\setlength@{\columnseprule@}@{0.4pt@}}, before the two-column mode starts. @item \columnwidth @anchor{twocolumn columnwidth} The width of a single column. In one-column mode this is equal to @code{\textwidth}. In two-column mode by default @LaTeX{} sets the width of each of the two columns, @code{\columnwidth}, to be half of @code{\textwidth} minus @code{\columnsep}. @end ftable In a two-column document, the starred environments @code{table*} and @code{figure*} are two columns wide, whereas the unstarred environments @code{table} and @code{figure} take up only one column (@pxref{figure} and @pxref{table}). @LaTeX{} places starred floats at the top of a page. The following parameters control float behavior of two-column output. @ftable @code @anchor{twocolumn dbltopfraction} @item \dbltopfraction The maximum fraction at the top of a two-column page that may be occupied by two-column wide floats. The default is 0.7, meaning that the height of a @code{table*} or @code{figure*} environment must not exceed @code{0.7\textheight}. If the height of your starred float environment exceeds this then you can take one of the following actions to prevent it from floating all the way to the back of the document: @itemize @bullet @item Use the @code{[tp]} location specifier to tell @LaTeX{} to try to put the bulky float on a page by itself, as well as at the top of a page. @item Use the @code{[t!]} location specifier to override the effect of @code{\dbltopfraction} for this particular float. @item Increase the value of @code{\dbltopfraction} to a suitably large number, to avoid going to float pages so soon. @end itemize You can redefine it, as with @code{\renewcommand@{\dbltopfraction@}@{0.9@}}. @item \dblfloatpagefraction @anchor{twocolumn dblfloatpagefraction} For a float page of two-column wide floats, this is the minimum fraction that must be occupied by floats, limiting the amount of blank space. @LaTeX{}'s default is @code{0.5}. Change it with @code{\renewcommand}. @item \dblfloatsep @anchor{twocolumn dblfloatsep} On a float page of two-column wide floats, this length is the distance between floats, at both the top and bottom of the page. The default is @code{12pt plus2pt minus2pt} for a document set at @code{10pt} or @code{11pt}, and @code{14pt plus2pt minus4pt} for a document set at @code{12pt}. @item \dbltextfloatsep @anchor{twocolumn dbltextfloatsep} This length is the distance between a multi-column float at the top or bottom of a page and the main text. The default is @code{20pt plus2pt minus4pt}. @item \dbltopnumber @anchor{twocolumn dbltopnumber} On a float page of two-column wide floats, this counter gives the maximum number of floats allowed at the top of the page. The @LaTeX{} default is @code{2}. @end ftable @c From egreg at http://tex.stackexchange.com/a/142232/339 This example uses @code{\twocolumn}'s optional argument of to create a title that spans the two-column article: @example \documentclass[twocolumn]@{article@} \newcommand@{\authormark@}[1]@{\textsuperscript@{#1@}@} \begin@{document@} \twocolumn[@{% inside this optional argument goes one-column text \centering \LARGE The Title \\[1.5em] \large Author One\authormark@{1@}, Author Two\authormark@{2@}, Author Three\authormark@{1@} \\[1em] \normalsize \begin@{tabular@}@{p@{.2\textwidth@}@@@{\hspace@{2em@}@}p@{.2\textwidth@}@} \authormark@{1@}Department one &\authormark@{2@}Department two \\ School one &School two \end@{tabular@}\\[3em] % space below title part @}] Two column text here. @end example @node \flushbottom @section @code{\flushbottom} @findex \flushbottom Make all pages in the document after this declaration have the same height, by stretching the vertical space where necessary to fill out the page. This is most often used when making two-sided documents since the differences in facing pages can be glaring. If @TeX{} cannot satisfactorily stretch the vertical space in a page then you get a message like @samp{Underfull \vbox (badness 10000) has occurred while \output is active}. If you get that, one option is to change to @code{\raggedbottom} (@pxref{\raggedbottom}). Alternatively, you can adjust the @code{textheight} to make compatible pages, or you can add some vertical stretch glue between lines or between paragraphs, as in @code{\setlength@{\parskip@}@{0ex plus0.1ex@}}. Your last option is to, in a final editing stage, adjust the height of individual pages (@pxref{\enlargethispage}). The @code{\flushbottom} state is the default only if you select the @code{twocolumn} document class option (@pxref{Document class options}), and for indexes made using @code{makeidx}. @node \raggedbottom @section @code{\raggedbottom} @findex \raggedbottom @cindex stretch, omitting vertical Make all later pages the natural height of the material on that page; no rubber vertical lengths will be stretched. Thus, in a two-sided document the facing pages may be different heights. This command can go at any point in the document body. @xref{\flushbottom}. This is the default unless you select the @code{twocolumn} document class option (@pxref{Document class options}). @node Page layout parameters @section Page layout parameters @cindex page layout parameters @cindex parameters, page layout @cindex layout, page parameters for @cindex header, parameters for @cindex footer, parameters for @cindex running header and footer @ftable @code @item \columnsep @itemx \columnseprule @itemx \columnwidth @findex \columnsep @findex \columnseprule @findex \columnwidth @anchor{page layout parameters columnsep} @anchor{page layout parameters columnseprule} @anchor{page layout parameters columnwidth} The distance between the two columns, the width of a rule between the columns, and the width of the columns, when the document class option @code{twocolumn} is in effect (@pxref{Document class options}). @xref{\twocolumn}. @item \headheight @findex \headheight @anchor{page layout parameters headheight} Height of the box that contains the running head. The default in the @code{article}, @code{report}, and @code{book} classes is @samp{12pt}, at all type sizes. @item \headsep @findex \headsep @anchor{page layout parameters headsep} Vertical distance between the bottom of the header line and the top of the main text. The default in the @code{article} and @code{report} classes is @samp{25pt}. In the @code{book} class the default is: if the document is set at 10pt then it is @samp{0.25in}, and at 11pt or 12pt it is @samp{0.275in}. @item \footskip @findex \footskip @anchor{page layout parameters footskip} Distance from the baseline of the last line of text to the baseline of the page footer. The default in the @code{article} and @code{report} classes is @samp{30pt}. In the @code{book} class the default is: when the type size is 10pt the default is @samp{0.35in}, while at 11pt it is @samp{0.38in}, and at 12pt it is @samp{30pt}. @item \linewidth @findex \linewidth @anchor{page layout parameters linewidth} Width of the current line, decreased for each nested @code{list} (@pxref{list}). That is, the nominal value for @code{\linewidth} is to equal @code{\textwidth} but for each nested list the @code{\linewidth} is decreased by the sum of that list's @code{\leftmargin} and @code{\rightmargin} (@pxref{itemize}). @c The default varies with the font size, paper width, two-column mode, @c etc. For an @code{article} document set in 10pt, the default is @c @samp{345pt}, while in two-column mode that becomes @samp{229.5pt}. @item \marginparpush @itemx \marginsep @itemx \marginparwidth @findex \marginparpush @findex \marginsep @findex \marginparwidth @anchor{page layout parameters marginparpush} @anchor{page layout parameters marginsep} @anchor{page layout parameters marginparwidth} The minimum vertical space between two marginal notes, the horizontal space between the text body and the marginal notes, and the horizontal width of the notes. Normally marginal notes appear on the outside of the page, but the declaration @code{\reversemarginpar} changes that (and @code{\normalmarginpar} changes it back). The defaults for @code{\marginparpush} in both @code{book} and @code{article} classes are: @samp{7pt} if the document is set at 12pt, and @samp{5pt} if the document is set at 11pt or 10pt. For @code{\marginsep}, in @code{article} class the default is @samp{10pt} except if the document is set at 10pt and in two-column mode where the default is @samp{11pt}. For @code{\marginsep} in @code{book} class the default is @samp{10pt} in two-column mode and @samp{7pt} in one-column mode. For @code{\marginparwidth} in both @code{book} and @code{article} classes, in two-column mode the default is 60% of @code{\paperwidth @minus{} \textwidth}, while in one-column mode it is 50% of that distance. @item \oddsidemargin @itemx \evensidemargin @findex \oddsidemargin @findex \evensidemargin @anchor{page layout parameters oddsidemargin} @anchor{page layout parameters evensidemargin} @c xx TODO re-align on French version that is more complete/accurate. The @code{\oddsidemargin} length is the extra distance between the left side of the page and the text's left margin, on odd-numbered pages when the document class option @code{twoside} is chosen and on all pages when @code{oneside} is in effect. When @code{twoside} is in effect, on even-numbered pages the extra distance on the left is @code{\evensidemargin}. @LaTeX{}'s default is that @code{\oddsidemargin} is 40% of the difference between @code{\paperwidth} and @code{\textwidth}, and @code{\evensidemargin} is the remainder. @item \paperheight @findex \paperheight @anchor{page layout parameters paperheight} The height of the paper, as distinct from the height of the print area. Normally set with a document class option, as in @code{\documentclass[a4paper]@{article@}} (@pxref{Document class options}). @item \paperwidth @findex \paperwidth @anchor{page layout parameters paperwidth} The width of the paper, as distinct from the width of the print area. Normally set with a document class option, as in @code{\documentclass[a4paper]@{article@}} (@pxref{Document class options}). @item \textheight @findex \textheight @anchor{page layout parameters textheight} The normal vertical height of the page body. If the document is set at a nominal type size of 10pt then for an @code{article} or @code{report} the default is @samp{43\baselineskip}, while for a @code{book} it is @samp{41\baselineskip}. At a type size of 11pt the default is @samp{38\baselineskip} for all document classes. At 12pt it is @samp{36\baselineskip} for all classes. @item \textwidth @findex \textwidth @anchor{page layout parameters textwidth} The full horizontal width of the entire page body. For an @code{article} or @code{report} document, the default is @samp{345pt} when the chosen type size is 10pt, the default is @samp{360pt} at 11pt, and it is @samp{390pt} at 12pt. For a @code{book} document, the default is @samp{4.5in} at a type size of 10pt, and @samp{5in} at 11pt or 12pt. In multi-column output, @code{\textwidth} remains the width of the entire page body, while @code{\columnwidth} is the width of one column (@pxref{\twocolumn}). In lists (@pxref{list}), @code{\textwidth} remains the width of the entire page body (and @code{\columnwidth} the width of the entire column), while @code{\linewidth} may decrease for nested lists. Inside a minipage (@pxref{minipage}) or @code{\parbox} (@pxref{\parbox}), all the width-related parameters are set to the specified width, and revert to their normal values at the end of the @code{minipage} or @code{\parbox}. @item \hsize @findex \hsize @anchor{page layout parameters hsize} This entry is included for completeness: @code{\hsize} is the @TeX{} primitive parameter used when text is broken into lines. It should not be used in normal @LaTeX{} documents. @item \topmargin @findex topmargin @anchor{page layout parameters topmargin} @c xxx TODO re-align on French version that is more accurate. Space between the top of the @TeX{} page (one inch from the top of the paper, by default) and the top of the header. The value is computed based on many other parameters: @code{\paperheight @minus{} 2in @minus{} \headheight @minus{} \headsep @minus{} \textheight @minus{} \footskip}, and then divided by two. @item \topskip @findex \topskip @anchor{page layout parameters topskip} Minimum distance between the top of the page body and the baseline of the first line of text. For the standard classes, the default is the same as the font size, e.g., @samp{10pt} at a type size of 10pt. @end ftable @node \baselineskip & \baselinestretch @section @code{\baselineskip} & @code{\baselinestretch} @anchor{\baselineskip} @anchor{\baselinestretch} @findex \baselineskip @findex \baselinestretch @findex \linespread @cindex space between lines @cindex interline space @cindex leading @cindex double spacing The @code{\baselineskip} is a rubber length (@pxref{Lengths}). It gives the @dfn{leading}, the normal distance between lines in a paragraph, from baseline to baseline. Ordinarily document authors do not directly change @code{\baselineskip} while writing. Instead, it is set by the low level font selection command @code{\fontsize} (@pxref{low level font commands fontsize}). The @code{\baselineskip}'s value is reset every time a font change happens and so any direct change to @code{\baselineskip} would vanish the next time there was a font switch. For how to influence line spacing, see the discussion of @code{\baselinestretch} below. Usually, a font's size and baseline skip is assigned by the font designer. These numbers are nominal in the sense that if, for instance, a font's style file has the command @code{\fontsize@{10pt@}@{12pt@}} then that does not mean that the characters in the font are 10@dmn{pt} tall; for instance, parentheses and accented capitals may be taller. Nor does it mean that if the lines are spaced less than 12@dmn{pt} apart then they risk touching. Rather these numbers are typographic judgements. (Often, the @code{\baselineskip} is about twenty percent larger than the font size.) @c adapted from FAQ The @code{\baselineskip} is not a property of each line but of the entire paragraph. As a result, large text in the middle of a paragraph, such as a single @code{@{\Huge Q@}}, will be squashed into its line. @TeX{} will make sure it doesn't scrape up against the line above but won't change the @code{\baselineskip} for that one line to make extra room above. For the fix, use a @code{\strut} (@pxref{\strut}). The value of @code{\baselineskip} that @TeX{} uses for the paragraph is the value in effect at the blank line or command that ends the paragraph unit. So if a document contains this paragraph then its lines will be scrunched together, compared to lines in surrounding paragraphs. @c Adapted from B Beeton's "Lapses in TeX" TB 42:1 p 13. @example Many people see a page break between text and a displayed equation as bad style, so in effect the display is part of the paragraph. Because this display is in footnotesize, the entire paragraph has the baseline spacing matching that size. @{\footnotesize $$a+b = c$$@} @end example @findex \lineskip @findex \lineskiplimit @findex \prevdepth The process for making paragraphs is that when a new line is added, if the depth of the previous line plus the height of the new line is less than @code{\baselineskip} then @TeX{} inserts vertical glue to make up the difference. There are two fine points. The first is that if the lines would be too close together, closer than @code{\lineskiplimit}, then @TeX{} instead uses @code{\lineskip} as the interline glue. The second is that @TeX{} doesn't actually use the depth of the previous line. Instead it uses @code{\prevdepth}, which usually contains that depth. But at the beginning of the paragraph (or any vertical list) or just after a rule, @code{\prevdepth} has the value -1000@dmn{pt} and this special value tells @TeX{} not to insert any interline glue at the paragraph start. In the standard classes @code{\lineskiplimit} is 0@dmn{pt} and @code{\lineskip} is 1@dmn{pt}. By the prior paragraph then, the distance between lines can approach zero but if it becomes zero (or less than zero) then the lines jump to 1@dmn{pt} apart. Sometimes authors must, for editing purposes, put the document in double space or one-and-a-half space. The right way to influence the interline distance is via @code{\baselinestretch}. It scales @code{\baselineskip}, and has a default value of 1.0. It is a command, not a length, and does not take effect until a font change happens, so set the scale factor like this: @code{\renewcommand@{\baselinestretch@}@{1.5@}\selectfont}. The most straightforward way to change the line spacing for an entire document is to put @code{\linespread@{@var{factor}@}} in the preamble. For double spacing, take @var{factor} to be 1.6 and for one-and-a-half spacing use 1.3. These numbers are rough: for instance, since the @code{\baselineskip} is about 1.2 times the font size, multiplying by 1.6 gives a baseline skip to font size ratio of about 2. (The @code{\linespread} command is defined as @code{\renewcommand@{\baselinestretch@}@{@var{factor}@}} so it also won't take effect until a font setting happens. But that always takes place at the start of a document, so there you don't need to follow it with @code{\selectfont}.) @PkgIndex{setspace} A simpler approach is the @package{setspace} package. The basic example: @example \usepackage@{setspace@} \doublespacing % or \onehalfspacing for 1.5 @end example @noindent In the preamble these will start the document off with that sizing. But you can also use these declarations in the document body to change the spacing from that point forward, and consequently there is @code{\singlespacing} to return the spacing to normal. In the document body, a better practice than using the declarations is to use environments, such as @code{\begin@{doublespace@} ... \end@{doublespace@}}. The package also has commands to do arbitrary spacing: @code{\setstretch@{@var{factor}@}} and @code{\begin@{spacing@}@{@var{factor}@} ... \end@{spacing@}}. This package also keeps the line spacing single-spaced in places where that is typically desirable, such as footnotes and figure captions. See the package documentation. @node Floats @section Floats Some typographic elements, such as figures and tables, cannot be broken across pages. They must be typeset outside of the normal flow of text, for instance floating to the top of a later page. @LaTeX{} can have a number of different classes of floating material. The default is the two classes, @code{figure} (@pxref{figure}) and @code{table} (@pxref{table}), but you can create a new class with the package @package{float}. Within any one float class @LaTeX{} always respects the order, so that the first figure in a document source must be typeset before the second figure. However, @LaTeX{} may mix the classes, so it can happen that while the first table appears in the source before the first figure, it appears in the output after it. The placement of floats is subject to parameters, given below, that limit the number of floats that can appear at the top of a page, and the bottom, etc. If so many floats are queued that the limits prevent them all from fitting on a page then @LaTeX{} places what it can and defers the rest to the next page. In this way, floats may end up being typeset far from their place in the source. In particular, a float that is big may migrate to the end of the document. In which event, because all floats in a class must appear in sequential order, every following float in that class also appears at the end. @cindex placement of floats @cindex specifier, float placement In addition to changing the parameters, for each float you can tweak where the float placement algorithm tries to place it by using its @var{placement} argument. The possible values are a sequence of the letters below. The default for both @code{figure} and @code{table}, in both @code{article} and @code{book} classes, is @code{tbp}. @table @code @item t (Top)---at the top of a text page. @item b (Bottom)---at the bottom of a text page. (However, @code{b} is not allowed for full-width floats (@code{figure*}) with double-column output. To ameliorate this, use the @file{stfloats} or @file{dblfloatfix} package, but see the discussion at caveats in the FAQ: @url{https://www.texfaq.org/FAQ-2colfloat}. @item h (Here)---at the position in the text where the @code{figure} environment appears. However, @code{h} is not allowed by itself; @code{t} is automatically added. @cindex here, putting floats @PkgIndex{float} To absolutely force a float to appear ``here'', you can @code{\usepackage@{float@}} and use the @code{H} specifier which it defines. For further discussion, see the FAQ entry at @url{https://www.texfaq.org/FAQ-figurehere}. @item p @cindex float page (Page of floats)---on a separate @dfn{float page}, which is a page containing no text, only floats. @item ! Used in addition to one of the above; for this float only, @LaTeX{} ignores the restrictions on both the number of floats that can appear and the relative amounts of float and non-float text on the page. The @code{!} specifier does @emph{not} mean ``put the float here''; see above. @end table Note: the order in which letters appear in the @var{placement} argument does not change the order in which @LaTeX{} tries to place the float; for instance, @code{btp} has the same effect as @code{tbp}. All that @var{placement} does is that if a letter is not present then the algorithm does not try that location. Thus, @LaTeX{}'s default of @code{tbp} is to try every location except placing the float where it occurs in the source. To prevent @LaTeX{} from moving floats to the end of the document or a chapter you can use a @code{\clearpage} command to start a new page and insert all pending floats. If a pagebreak is undesirable then you can use the @file{afterpage} package and issue @code{\afterpage@{\clearpage@}}. This will wait until the current page is finished and then flush all outstanding floats. @PkgIndex{flafter} @LaTeX{} can typeset a float before where it appears in the source (although on the same output page) if there is a @code{t} specifier in the @var{placement} parameter. If this is not desired, and deleting the @code{t} is not acceptable as it keeps the float from being placed at the top of the next page, then you can prevent it by either using the @package{flafter} package or using the command @findex \suppressfloats @code{\suppressfloats[t]}, which causes floats for the top position on this page to moved to the next page. Parameters relating to fractions of pages occupied by float and non-float text (change them with @code{\renewcommand@{@var{parameter}@}@{@var{decimal between 0 and 1}@}}): @ftable @code @item \bottomfraction @findex \bottomfraction @anchor{floats bottomfraction} The maximum fraction of the page allowed to be occupied by floats at the bottom; default @samp{.3}. @item \floatpagefraction @findex \floatpagefraction @anchor{floats floatpagefraction} The minimum fraction of a float page that must be occupied by floats; default @samp{.5}. @item \textfraction @findex \textfraction @anchor{floats textfraction} Minimum fraction of a page that must be text; if floats take up too much space to preserve this much text, floats will be moved to a different page. The default is @samp{.2}. @item \topfraction @findex \topfraction @anchor{floats topfraction} Maximum fraction at the top of a page that may be occupied before floats; default @samp{.7}. @end ftable Parameters relating to vertical space around floats (change them with a command of the form @code{\setlength@{@var{parameter}@}@{@var{length expression}@}}): @ftable @code @item \floatsep @findex \floatsep @anchor{floats floatsep} Space between floats at the top or bottom of a page; default @samp{12pt plus2pt minus2pt}. @item \intextsep @findex \intextsep @anchor{floats intextsep} Space above and below a float in the middle of the main text; default @samp{12pt plus2pt minus2pt} for 10 point and 11 point documents, and @samp{14pt plus4pt minus4pt} for 12 point documents. @item \textfloatsep @findex \textfloatsep @anchor{floats textfloatsep} Space between the last (first) float at the top (bottom) of a page; default @samp{20pt plus2pt minus4pt}. @end ftable Counters relating to the number of floats on a page (change them with a command of the form @code{\setcounter@{@var{ctrname}@}@{@var{natural number}@}}): @ftable @code @item bottomnumber @findex bottomnumber @anchor{floats bottomnumber} Maximum number of floats that can appear at the bottom of a text page; default 1. @item dbltopnumber @findex dbltopnumber @anchor{floats dbltopnumber} Maximum number of full-sized floats that can appear at the top of a two-column page; default 2. @item topnumber @findex topnumber @anchor{floats topnumber} Maximum number of floats that can appear at the top of a text page; default 2. @item totalnumber @findex totalnumber @anchor{floats totalnumber} Maximum number of floats that can appear on a text page; default 3. @end ftable The principal @TeX{}@tie{}FAQ entry relating to floats @url{https://www.texfaq.org/FAQ-floats} contains suggestions for relaxing @LaTeX{}'s default parameters to reduce the problem of floats being pushed to the end. A full explanation of the float placement algorithm is in Frank Mittelbach's article ``How to influence the position of float environments like figure and table in @LaTeX{}?'' (@url{https://www.latex-project.org/publications/2014-FMi-TUB-tb111mitt-float-placement.pdf}). @menu * \caption:: Make a caption for a floating environment. @end menu @node \caption @subsection @code{\caption} @findex \caption @cindex captions Synopsis: @example \caption@{@var{caption-text}@} @end example @noindent or @example \caption[@var{short-caption-text}]@{@var{caption-text}@} @end example Make a caption for a floating environment, such as a @code{figure} or @code{table} environment (@pxref{figure} or @ref{table}). In this example, @LaTeX{} places a caption below the vertical blank space that is left by the author for the later inclusion of a picture. @example \begin@{figure@} \vspace*@{1cm@} \caption@{Alonzo Cushing, Battery A, 4th US Artillery.@} \label@{fig:CushingPic@} \end@{figure@} @end example @noindent The @code{\caption} command will label the @var{caption-text} with something like @samp{Figure@tie{}1:} for an article or @samp{Figure@tie{}1.1:} for a book. The text is centered if it is shorter than the text width, or set as an unindented paragraph if it takes more than one line. In addition to placing the @var{caption-text} in the output, the @code{\caption} command also saves that information for use in a list of figures or list of tables (@pxref{Table of contents etc.}). Here the @code{\caption} command uses the optional @var{short-caption-text}, so that the shorter text appears in the list of tables, rather than the longer @var{caption-text}. @example \begin@{table@} \centering \begin@{tabular@}@{|*@{3@}@{c@}|@} \hline 4 &9 &2 \\ 3 &5 &7 \\ 8 &1 &6 \\ \hline \end@{tabular@} \caption[\textit@{Lo Shu@} magic square]@{% The \textit@{Lo Shu@} magic square, which is unique among squares of order three up to rotation and reflection.@} \label@{tab:LoShu@} \end@{table@} @end example @noindent @LaTeX{} will label the @var{caption-text} with something like @samp{Table@tie{}1:} for an article or @samp{Table@tie{}1.1:} for a book. The caption can appear at the top of the @code{figure} or @code{table}. For instance, that would happen in the prior example by putting the @code{\caption} between the @code{\centering} and the @code{\begin@{tabular@}}. Different floating environments are numbered separately, by default. It is @code{\caption} that updates the counter, and so any @code{\label} must come after the @code{\caption}. The counter for the @code{figure} environment is named @code{figure}, and similarly the counter for the @code{table} environment is @code{table}. The text that will be put in the list of figures or list of tables is moving argument. If you get the @LaTeX{} error @samp{! Argument of \@@caption has an extra @}} then you must put @code{\protect} in front of any fragile commands. @xref{\protect}. @PkgIndex{caption} The @package{caption} package has many options to adjust how the caption appears, for example changing the font size, making the caption be hanging text rather than set as a paragraph, or making the caption always set as a paragraph rather than centered when it is short. @node Sectioning @chapter Sectioning @cindex sectioning commands @cindex part @cindex chapter @cindex section @cindex subsection @cindex subsubsection @cindex paragraph @cindex subparagraph @findex \part @findex \chapter @findex \section @findex \subsection @findex \subsubsection @findex \paragraph @findex \subparagraph Structure your text into divisions: parts, chapters, sections, etc. All sectioning commands have the same form, one of: @example @var{sectioning-command}@{@var{title}@} @var{sectioning-command}*@{@var{title}@} @var{sectioning-command}[@var{toc-title}]@{@var{title}@} @end example @noindent For instance, declare the start of a subsection as with @code{\subsection@{Motivation@}}. The table has each @var{sectioning-command} in @LaTeX{}. All are available in all of @LaTeX{}'s standard document classes @code{book}, @code{report}, and@tie{}@code{article}, except that @code{\chapter} is not available in @code{article}. @multitable @columnfractions .25 .25 .40 @headitem Sectioning unit @tab Command @tab Level @item Part @tab @code{\part} @tab -1 (@code{book}, @code{report}), 0 (@code{article}) @item Chapter @tab @code{\chapter} @tab 0 @item Section @tab @code{\section} @tab 1 @item Subsection @tab @code{\subsection} @tab 2 @item Subsubsection @tab @code{\subsubsection} @tab 3 @item Paragraph @tab @code{\paragraph} @tab 4 @item Subparagraph @tab @code{\subparagraph} @tab 5 @end multitable @cindex @code{*}-form of sectioning commands All these commands have a @code{*}-form that prints @var{title} as usual but does not number it and does not make an entry in the table of contents. An example of using this is for an appendix in an @code{article}. The input @code{\appendix\section@{Appendix@}} gives the output @samp{A Appendix} (@pxref{\appendix}). You can lose the numbering@tie{}@samp{A} by instead entering @code{\section*@{Appendix@}} (articles often omit a table of contents and have simple page headers so the other differences from the @code{\section} command may not matter). The section title @var{title} provides the heading in the main text, but it may also appear in the table of contents and in the running head or foot (@pxref{Page styles}). You may not want the same text in these places as in the main text. All of these commands have an optional argument @var{toc-title} for these other places. The level number in the table above determines which sectional units are numbered, and which appear in the table of contents. If the sectioning command's @var{level} is less than or equal to the value of the counter @code{secnumdepth} then the titles for this sectioning command will be numbered (@pxref{Sectioning/secnumdepth}). And, if @var{level} is less than or equal to the value of the counter @code{tocdepth} then the table of contents will have an entry for this sectioning unit (@pxref{Sectioning/tocdepth}). @LaTeX{} expects that before you have a @code{\subsection} you will have a @code{\section} and, in a @code{book} class document, that before a @code{\section} you will have a @code{\chapter}. Otherwise you can get something like a subsection numbered @samp{3.0.1}. @PkgIndex{titlesec} @LaTeX{} lets you change the appearance of the sectional units. As a simple example, you can change the section numbering to uppercase letters with this (in the preamble):@* @code{\renewcommand\thesection@{\Alph@{section@}@}} . (@xref{\alph \Alph \arabic \roman \Roman \fnsymbol}.) CTAN has many packages that make this adjustment easier, notably @package{titlesec}. Two counters relate to the appearance of headings made by sectioning commands. @ftable @code @item secnumdepth @findex secnumdepth @r{counter} @cindex section numbers, printing @anchor{sectioning secnumdepth} @anchor{Sectioning/secnumdepth} Controls which sectioning unit are numbered. Setting the counter with @code{\setcounter@{secnumdepth@}@{@var{level}@}} will suppress numbering of sectioning at any depth greater than @var{level} (@pxref{\setcounter}). See the above table for the level numbers. For instance, if the @code{secnumdepth} is 1 in an @code{article} then a @code{\section@{Introduction@}} command will produce output like @samp{1 Introduction} while @code{\subsection@{Discussion@}} will produce output like @samp{Discussion}, without the number. @LaTeX{}'s default @code{secnumdepth} is@tie{}3 in @file{article} class and @tie{}2 in the @file{book} and @file{report} classes. @item tocdepth @findex tocdepth @r{counter} @cindex table of contents, sectioning numbers printed @anchor{sectioning tocdepth} @anchor{Sectioning/tocdepth} Controls which sectioning units are listed in the table of contents. The setting @code{\setcounter@{tocdepth@}@{@var{level}@}} makes the sectioning units at @var{level} be the smallest ones listed (@pxref{\setcounter}). See the above table for the level numbers. For instance, if @code{tocdepth} is@tie{}1 then the table of contents will list sections but not subsections. @LaTeX{}'s default @code{tocdepth} is@tie{}3 in @file{article} class and @tie{}2 in the @file{book} and @file{report} classes. @end ftable @menu * \part:: Start a part. * \chapter:: Start a chapter. * \section:: Start a section. * \subsection:: Start a subsection. * \subsubsection & \paragraph & \subparagraph:: Lower divisions. * \appendix:: Start appendices. * \frontmatter & \mainmatter & \backmatter:: The three parts of a book. * \@@startsection:: Sectional unit headings. @end menu @node \part @section @code{\part} @findex \part @cindex part @cindex sectioning, part Synopsis, one of: @example \part@{@var{title}@} \part*@{@var{title}@} \part[@var{toc-title}]@{@var{title}@} @end example Start a document part. The standard @LaTeX{} classes @code{book}, @code{report}, and @code{article}, all have this command. This produces a document part, in a book. @example \part@{VOLUME I \\ PERSONAL MEMOIRS OF U.\ S.\ GRANT@} \chapter@{ANCESTRY--BIRTH--BOYHOOD.@} My family is American, and has been for generations, in all its branches, direct and collateral. @end example In each standard class the @code{\part} command outputs a part number such as @samp{Part I}, alone on its line, in boldface, and in large type. Then @LaTeX{} outputs @var{title}, also alone on its line, in bold and in even larger type. In class @code{book}, the @LaTeX{} default puts each part alone on its own page. If the book is two-sided then @LaTeX{} will skip a page if needed to have the new part on an odd-numbered page. In @code{report} it is again alone on a page, but @LaTeX{} won't force it onto an odd-numbered page. In an @code{article} @LaTeX{} does not put it on a fresh page, but instead outputs the part number and part title onto the main document page. The @code{*}@tie{}form shows @var{title} but it does not show the part number, does not increment the @code{part} counter, and produces no table of contents entry. The optional argument @var{toc-title} will appear as the part title in the table of contents (@pxref{Table of contents etc.}) and in running headers (@pxref{Page styles}). If it is not present then @var{title} will be there. This example puts a line break in @var{title} but omits the break in the table of contents. @example \part[Up from the bottom; my life]@{Up from the bottom\\ my life@} @end example For determining which sectional units are numbered and which appear in the table of contents, the level number of a part is@tie{}-1 (@pxref{Sectioning/secnumdepth}, and @ref{Sectioning/tocdepth}). @PkgIndex{indentfirst} In the class @code{article}, if a paragraph immediately follows the part title then it is not indented. To get an indent you can use the package @package{indentfirst}. @PkgIndex{titlesec} One package to change the behavior of @code{\part} is @package{titlesec}. See its documentation on CTAN. @node \chapter @section @code{\chapter} @findex \chapter @cindex chapter Synopsis, one of: @example \chapter@{@var{title}@} \chapter*@{@var{title}@} \chapter[@var{toc-title}]@{@var{title}@} @end example Start a chapter. The standard @LaTeX{} classes @code{book} and @code{report} have this command but @code{article} does not. This produces a chapter. @example \chapter@{Loomings@} Call me Ishmael. Some years ago---never mind how long precisely---having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. @end example The @LaTeX{} default starts each chapter on a fresh page, an odd-numbered page if the document is two-sided. It produces a chapter number such as @samp{Chapter 1} in large boldface type (the size is @code{\huge}). It then puts @var{title} on a fresh line, in boldface type that is still larger (size @code{\Huge}). It also increments the @code{chapter} counter, adds an entry to the table of contents (@pxref{Table of contents etc.}), and sets the running header information (@pxref{Page styles}). The @code{*}@tie{}form shows @var{title} on a fresh line, in boldface. But it does not show the chapter number, does not increment the @code{chapter} counter, produces no table of contents entry, and does not affect the running header. (If you use the page style @code{headings} in a two-sided document then the header will be from the prior chapter.) This example illustrates. @example \chapter*@{Preamble@} @end example The optional argument @var{toc-title} will appear as the chapter title in the table of contents (@pxref{Table of contents etc.}) and in running headers (@pxref{Page styles}). If it is not present then @var{title} will be there. This shows the full name in the chapter title, @example \chapter[Weyl]@{Hermann Klaus Hugo (Peter) Weyl (1885--1955)@} @end example @noindent but only @samp{Weyl} on the contents page. This puts a line break in the title but that doesn't work well with running headers so it omits the break in the contents @example \chapter[Given it all; my story]@{Given it all\\ my story@} @end example For determining which sectional units are numbered and which appear in the table of contents, the level number of a chapter is@tie{}0 (@pxref{Sectioning/secnumdepth} and @pxref{Sectioning/tocdepth}). @PkgIndex{indentfirst} The paragraph that follows the chapter title is not indented, as is a standard typographical practice. To get an indent use the package @package{indentfirst}. You can change what is shown for the chapter number. To change it to something like @samp{Lecture 1}, put in the preamble either @code{\renewcommand@{\chaptername@}@{Lecture@}} or this (@pxref{\makeatletter & \makeatother}). @example \makeatletter \renewcommand@{\@@chapapp@}@{Lecture@} \makeatother @end example @PkgIndex{babel} @noindent To make this change because of the primary language for the document, see the package @package{babel}. In a two-sided document @LaTeX{} puts a chapter on odd-numbered page, if necessary leaving an even-numbered page that is blank except for any running headers. To make that page completely blank, see@tie{}@ref{\clearpage & \cleardoublepage}. @PkgIndex{titlesec} To change the behavior of the @code{\chapter} command, you can copy its definition from the @LaTeX{} format file and make adjustments. But there are also many packages on CTAN that address this. One is @package{titlesec}. See its documentation, but the example below gives a sense of what it can do. @example \usepackage@{titlesec@} % in preamble \titleformat@{\chapter@} @{\Huge\bfseries@} % format of title @{@} % label, such as 1.2 for a subsection @{0pt@} % length of separation between label and title @{@} % before-code hook @end example @noindent This omits the chapter number @samp{Chapter 1} from the page but unlike @code{\chapter*} it keeps the chapter in the table of contents and the running headers. @node \section @section @code{\section} @findex \section @cindex section Synopsis, one of: @example \section@{@var{title}@} \section*@{@var{title}@} \section[@var{toc-title}]@{@var{title}@} @end example Start a section. The standard @LaTeX{} classes @code{article}, @code{book}, and @code{report} all have this command. This produces a section. @example In this Part we tend to be more interested in the function, in the input-output behavior, than in the details of implementing that behavior. \section@{Turing machines@} Despite this desire to downplay implementation, we follow the approach of A~Turing that the first step toward defining the set of computable functions is to reflect on the details of what mechanisms can do. @end example For the standard @LaTeX{} classes @code{book} and @code{report} the default output is like @samp{1.2 @var{title}} (for chapter@tie{}1, section@tie{}2), alone on its line and flush left, in boldface and a larger type (the type size is @code{\Large}). The same holds in @code{article} except that there are no chapters in that class so it looks like @samp{2 @var{title}}. The @code{*}@tie{}form shows @var{title}. But it does not show the section number, does not increment the @code{section} counter, produces no table of contents entry, and does not affect the running header. (If you use the page style @code{headings} in a two-sided document then the header will be from the prior section.) The optional argument @var{toc-title} will appear as the section title in the table of contents (@pxref{Table of contents etc.}) and in running headers (@pxref{Page styles}). If it is not present then @var{title} will be there. This shows the full name in the title of the section: @example \section[Elizabeth~II]@{Elizabeth the Second, by the Grace of God of the United Kingdom, Canada and Her other Realms and Territories Queen, Head of the Commonwealth, Defender of the Faith.@} @end example @noindent but only @samp{Elizabeth II} on the contents page and in the headers. This has a line break in @var{title} but that does not work with headers so it is omitted from the contents and headers. @example \section[Truth is, I cheated; my life story]@{Truth is, I cheated\\my life story@} @end example For determining which sectional units are numbered and which appear in the table of contents, the level number of a section is@tie{}1 (@pxref{Sectioning/secnumdepth} and @pxref{Sectioning/tocdepth}). @PkgIndex{indentfirst} The paragraph that follows the section title is not indented, as is a standard typographical practice. One way to get an indent is to use the package @package{indentfirst}. @PkgIndex{titlesec} In general, to change the behavior of the @code{\section} command, there are a number of options. One is the @code{\@@startsection} command (@pxref{\@@startsection}). There are also many packages on CTAN that address this, including @package{titlesec}. See the documentation but the example below gives a sense of what they can do. @c credit: egreg https://groups.google.com/forum/#!topic/comp.text.tex/tvc8oM5P4y4 @example \usepackage@{titlesec@} % in preamble \titleformat@{\section@} @{\normalfont\Large\bfseries@} % format of title @{\makebox[1pc][r]@{\thesection\hspace@{1pc@}@}@} % label @{0pt@} % length of separation between label and title @{@} % before-code hook \titlespacing*@{\section@} @{-1pc@}@{18pt@}@{10pt@}[10pc] @end example @noindent That puts the section number in the margin. @node \subsection @section @code{\subsection} @findex \subsection @cindex subsection Synopsis, one of: @example \subsection@{@var{title}@} \subsection*@{@var{title}@} \subsection[@var{toc-title}]@{@var{title}@} @end example Start a subsection. The standard @LaTeX{} classes @code{article}, @code{book}, and @code{report} all have this command. This produces a subsection. @example We will show that there are more functions than Turing machines and that therefore some functions have no associated machine. \subsection@{Cardinality@} We will begin with two paradoxes that dramatize the challenge to our intuition posed by comparing the sizes of infinite sets. @end example For the standard @LaTeX{} classes @code{book} and @code{report} the default output is like @samp{1.2.3 @var{title}} (for chapter@tie{}1, section@tie{}2, subsection@tie{}3), alone on its line and flush left, in boldface and a larger type (the type size is @code{\large}). The same holds in @code{article} except that there are no chapters in that class so it looks like @samp{2.3 @var{title}}. The @code{*}@tie{}form shows @var{title}. But it does not show the subsection number, does not increment the @code{subsection} counter, and produces no table of contents entry. The optional argument @var{toc-title} will appear as the subsection title in the table of contents (@pxref{Table of contents etc.}). If it is not present then @var{title} will be there. This shows the full text in the title of the subsection: @example \subsection[$\alpha,\beta,\gamma$ paper]@{\textit@{The Origin of Chemical Elements@} by R.A.~Alpher, H.~Bethe, and G.~Gamow@} @end example @noindent but only @samp{@BES{03B1,\alpha},@BES{03B2,\beta},@BES{03B3,\gamma} paper} on the contents page. For determining which sectional units are numbered and which appear in the table of contents, the level number of a subsection is@tie{}2 (@pxref{Sectioning/secnumdepth} and @pxref{Sectioning/tocdepth}). @PkgIndex{indentfirst} The paragraph that follows the subsection title is not indented, as is a standard typographical practice. One way to get an indent is to use the package @package{indentfirst}. @PkgIndex{titlesec} There are a number of ways to change the behavior of the @code{\subsection} command. One is the @code{\@@startsection} command (@pxref{\@@startsection}). There are also many packages on CTAN that address this, including @package{titlesec}. See the documentation but the example below gives a sense of what they can do. @example \usepackage@{titlesec@} % in preamble \titleformat@{\subsection@}[runin] @{\normalfont\normalsize\bfseries@} % format of the title @{\thesubsection@} % label @{0.6em@} % space between label and title @{@} % before-code hook @end example @noindent That puts the subsection number and @var{title} in the first line of text. @node \subsubsection & \paragraph & \subparagraph @section @code{\subsubsection}, @code{\paragraph}, @code{\subparagraph} @anchor{\subsubsection} @findex \subsubsection @cindex subsubsection @c @anchor{\paragraph} @findex \paragraph @cindex paragraph @c @anchor{\subparagraph} @findex \subparagraph @cindex subparagraph Synopsis, one of: @example \subsubsection@{@var{title}@} \subsubsection*@{@var{title}@} \subsubsection[@var{toc-title}]@{@var{title}@} @end example @noindent or one of: @example \paragraph@{@var{title}@} \paragraph*@{@var{title}@} \paragraph[@var{toc-title}]@{@var{title}@} @end example @noindent or one of: @example \subparagraph@{@var{title}@} \subparagraph*@{@var{title}@} \subparagraph[@var{toc-title}]@{@var{title}@} @end example Start a subsubsection, paragraph, or subparagraph. The standard @LaTeX{} classes @code{article}, @code{book}, and @code{report} all have these commands, although they are not commonly used. This produces a subsubsection. @example \subsubsection@{Piston ring compressors: structural performance@} Provide exterior/interior wall cladding assemblies capable of withstanding the effects of load and stresses from consumer-grade gasoline engine piston rings. @end example The default output of each of the three does not change over the standard @LaTeX{} classes @code{article}, @code{book}, and @code{report}. For @code{\subsubsection} the @var{title} is alone on its line, in boldface and normal size type. For @code{\paragraph} the @var{title} is inline with the text, not indented, in boldface and normal size type. For @code{\subparagraph} the @var{title} is inline with the text, with a paragraph indent, in boldface and normal size type (Because an @code{article} has no chapters its subsubsections are numbered and so it looks like @samp{1.2.3 @var{title}}, for section@tie{}1, subsection@tie{}2, and subsubsection@tie{}3. The other two divisions are not numbered.) The @code{*}@tie{}form shows @var{title}. But it does not increment the associated counter and produces no table of contents entry (and does not show the number for @code{\subsubsection}). The optional argument @var{toc-title} will appear as the division title in the table of contents (@pxref{Table of contents etc.}). If it is not present then @var{title} will be there. For determining which sectional units are numbered and which appear in the table of contents, the level number of a subsubsection is@tie{}3, of a paragraph is@tie{}4, and of a subparagraph is@tie{}5 (@pxref{Sectioning/secnumdepth} and @pxref{Sectioning/tocdepth}). @PkgIndex{indentfirst} The paragraph that follows the subsubsection title is not indented, as is a standard typographical practice. One way to get an indent is to use the package @package{indentfirst}. @PkgIndex{titlesec} There are a number of ways to change the behavior of the these commands. One is the @code{\@@startsection} command (@pxref{\@@startsection}). There are also many packages on CTAN that address this, including @package{titlesec}. See the documentation on CTAN. @node \appendix @section @code{\appendix} @findex \appendix @cindex appendix @cindex appendices Synopsis: @example \appendix @end example This does not directly produce any output. But in a @code{book} or @code{report} document it declares that subsequent @code{\chapter} commands start an appendix. In an article it does the same, for @code{\section} commands. It also resets the @code{chapter} and @code{section} counters to@tie{}0 in a book or report, and in an article resets the @code{section} and @code{subsection} counters. In this book @example \chapter@{One@} ... \chapter@{Two@} ... ... \appendix \chapter@{Three@} ... \chapter@{Four@} ... @end example @noindent the first two will generate output numbered @samp{Chapter 1} and @samp{Chapter 2}. After the @code{\appendix} the numbering will be @samp{Appendix A} and @samp{Appendix B}. @xref{Larger book template}, for another example. @PkgIndex{appendix} The @package{appendix} package adds the command @code{\appendixpage} to put a separate @samp{Appendices} in the document body before the first appendix, and the command @code{\addappheadtotoc} to do the same in the table of contents. You can reset the name @samp{Appendices} with a command like @code{\renewcommand@{\appendixname@}@{Specification@}}, as well as a number of other features. See the documentation on CTAN. @node \frontmatter & \mainmatter & \backmatter @section @code{\frontmatter}, @code{\mainmatter}, @code{\backmatter} @anchor{\frontmatter} @findex \frontmatter @cindex book, front matter @cindex front matter of a book @c @anchor{\mainmatter} @findex \mainmatter @cindex book, main matter @cindex main matter of a book @c @anchor{\backmatter} @findex \backmatter @cindex book, back matter @cindex book, end matter @cindex back matter of a book @cindex end matter of a book Synopsis, one or more of: @example \frontmatter ... \mainmatter ... \backmatter ... @end example Format a @code{book} class document differently according to which part of the document is being produced. All three commands are optional. Traditionally, a book's front matter contains such things as the title page, an abstract, a table of contents, a preface, a list of notations, a list of figures, and a list of tables. (Some of these front matter pages, such as the title page, are traditionally not numbered.) The back matter may contain such things as a glossary, notes, a bibliography, and an index. The @code{\frontmatter} command makes the pages numbered in lowercase roman, and makes chapters not numbered, although each chapter's title appears in the table of contents; if you use other sectioning commands here, use the @code{*}-version (@pxref{Sectioning}). The @code{\mainmatter} command changes the behavior back to the expected version, and resets the page number. The @code{\backmatter} command leaves the page numbering alone but switches the chapters back to being not numbered. @xref{Larger book template}, for an example using these three commands. @node \@@startsection @section @code{\@@startsection}, typesetting sectional unit headings @findex \@@startsection @cindex section, redefining Synopsis: @example \@@startsection@{@var{name}@}@{@var{level}@}@{@var{indent}@}@{@var{beforeskip}@}@{@var{afterskip}@}@{@var{style}@} @end example Used to help redefine the behavior of commands that start sectioning divisions such as @code{\section} or @code{\subsection}. Note that the @package{titlesec} package makes manipulation of sectioning easier. Further, while most requirements for sectioning commands can be satisfied with @code{\@@startsection}, some cannot. For instance, in the standard @LaTeX{} @code{book} and @code{report} classes the commands @code{\chapter} and @code{\report} are not constructed in this way. To make such a command you may want to use the @code{\secdef} command. @c xx define, and make a cross reference to, secdef. Technically, @code{\@@startsection} has the form @example \@@startsection@{@var{name}@} @{@var{level}@} @{@var{indent}@} @{@var{beforeskip}@} @{@var{afterskip}@} @{@var{style}@}*[@var{toctitle}]@{@var{title}@} @end example @noindent so that issuing @example \renewcommand@{\section@}@{\@@startsection@{@var{name}@} @{@var{level}@} @{@var{indent}@} @{@var{beforeskip}@} @{@var{afterskip}@} @{@var{style}@}@} @end example @noindent redefines @code{\section} while keeping its standard calling form @code{\section*[@var{toctitle}]@{@var{title}@}} (in which, for reminder, the star@tie{}@code{*} is optional). @xref{Sectioning}. This implies that when you write a command like @code{\renewcommand@{\section@}@{...@}}, the @code{\@@startsection@{...@}} must come last in the definition. See the examples below. @table @var @item name @anchor{startsection name} @anchor{\@@startsection/name} Name of the counter used to number the sectioning header. This counter must be defined separately. Most commonly this is either @code{section}, @code{subsection}, or @code{paragraph}. Although in those cases the counter name is the same as the sectioning command itself, you don't have to use the same name. Then @code{\the}@var{name} displays the title number and @code{\}@var{name}@code{mark} is for the page headers. See the third example below. @item level @anchor{startsection level} @anchor{\@@startsection/level} An integer giving the depth of the sectioning command. @xref{Sectioning}, for the list of standard level numbers. If @var{level} is less than or equal to the value of the counter @code{secnumdepth} then titles for this sectioning command will be numbered (@pxref{Sectioning/secnumdepth}). For instance, if @code{secnumdepth} is 1 in an @code{article} then the command @code{\section@{Introduction@}} will produce output like ``1 Introduction'' while @code{\subsection@{Discussion@}} will produce output like ``Discussion'', without the number prefix. If @var{level} is less than or equal to the value of the counter @var{tocdepth} then the table of contents will have an entry for this sectioning unit (@pxref{Sectioning/tocdepth}). For instance, in an @code{article}, if @var{tocdepth} is 1 then the table of contents will list sections but not subsections. @item indent @anchor{startsection indent} @anchor{\@@startsection/indent} A length giving the indentation of all of the title lines with respect to the left margin. To have the title flush with the margin use @code{0pt}. A negative indentation such as @code{-\parindent} will move the title into the left margin. @item beforeskip @anchor{startsection beforeskip} @anchor{\@@startsection/beforeskip} The absolute value of this length is the amount of vertical space that is inserted before this sectioning unit's title. This space will be discarded if the sectioning unit happens to start at the beginning of a page. If this number is negative then the first paragraph following the header is not indented, if it is non-negative then the first paragraph is indented. (Note that the negative of @code{1pt plus 2pt minus 3pt} is @code{-1pt plus -2pt minus -3pt}.) For example, if @var{beforeskip} is @code{-3.5ex plus -1ex minus -0.2ex} then to start the new sectioning unit, @LaTeX{} will add about 3.5 times the height of a letter x in vertical space, and the first paragraph in the section will not be indented. Using a rubber length, with @code{plus} and @code{minus}, is good practice here since it gives @LaTeX{} more flexibility in making up the page (@pxref{Lengths}). The full accounting of the vertical space between the baseline of the line prior to this sectioning unit's header and the baseline of the header is that it is the sum of the @code{\parskip} of the text font, the @code{\baselineskip} of the title font, and the absolute value of the @var{beforeskip}. This space is typically rubber so it may stretch or shrink. (If the sectioning unit starts on a fresh page so that the vertical space is discarded then the baseline of the header text will be where @LaTeX{} would put the baseline of the first text line on that page.) @item afterskip @anchor{startsection afterskip} @anchor{\@@startsection/afterskip} This is a length. If @var{afterskip} is non-negative then this is the vertical space inserted after the sectioning unit's title header. If it is negative then the title header becomes a run-in header, so that it becomes part of the next paragraph. In this case the absolute value of the length gives the horizontal space between the end of the title and the beginning of the following paragraph. (Note that the negative of @code{1pt plus 2pt minus 3pt} is @code{-1pt plus -2pt minus -3pt}.) As with @var{beforeskip}, using a rubber length, with @code{plus} and @code{minus} components, is good practice here since it gives @LaTeX{} more flexibility in putting together the page. If @code{afterskip} is non-negative then the full accounting of the vertical space between the baseline of the sectioning unit's header and the baseline of the first line of the following paragraph is that it is the sum of the @code{\parskip} of the title font, the @code{\baselineskip} of the text font, and the value of @var{after}. That space is typically rubber so it may stretch or shrink. (Note that because the sign of @code{afterskip} changes the sectioning unit header's from standalone to run-in, you cannot use a negative @code{afterskip} to cancel part of the @code{\parskip}.) @item style @anchor{startsection style} @anchor{\@@startsection/style} Controls the styling of the title. See the examples below. Typical commands to use here are @code{\centering}, @code{\raggedright}, @code{\normalfont}, @code{\hrule}, or @code{\newpage}. The last command in @var{style} may be one that takes one argument, such as @code{\MakeUppercase} or @code{\fbox} that takes one argument. The section title will be supplied as the argument to this command. For instance, setting @var{style} to @code{\bfseries\MakeUppercase} would produce titles that are bold and uppercase. @end table These are @LaTeX{}'s defaults for the first three sectioning units that are defined with @code{\@@startsection}, for the @file{article}, @file{book}, and @file{report} classes. @itemize @item For @code{section}: @var{level} is 1, @var{indent} is 0@dmn{pt}, @var{beforeskip} is @code{-3.5ex plus -1ex minus -0.2ex}, @var{afterskip} is @code{2.3ex plus 0.2ex}, and @var{style} is @code{\normalfont\Large\bfseries}. @item For @code{subsection}: @var{level} is 2, @var{indent} is 0@dmn{pt}, @var{beforeskip} is @code{-3.25ex plus -1ex minus @w{-0.2ex}}, @var{afterskip} is @code{1.5ex plus 0.2ex}, and @var{style} is @code{\normalfont\large\bfseries}. @item @raggedright For @code{subsubsection}: @var{level} is 3, @var{indent} is 0@dmn{pt}, @var{beforeskip} is @code{-3.25ex plus -1ex minus -0.2ex}, @var{afterskip} is @code{1.5ex plus 0.2ex}, and @var{style} is @code{\normalfont\normalsize\bfseries}. @end raggedright @end itemize Some examples follow. These go either in a package or class file or in the preamble of a @LaTeX{} document. If you put them in the preamble they must go between a @code{\makeatletter} command and a @code{\makeatother}. (Probably the error message @code{You can't use `\spacefactor' in vertical mode.} means that you forgot this.) @xref{\makeatletter & \makeatother}. This will put section titles in large boldface type, centered. It says @code{\renewcommand} because @LaTeX{}'s standard classes have already defined a @code{\section}. For the same reason it does not define a @code{section} counter, or the commands @code{\thesection} and @code{\l@@section}. @example \renewcommand\section@{% \@@startsection@{section@}% @ref{\@@startsection/name,@var{name},@var{name}} @{1@}% @ref{\@@startsection/level,@var{level},@var{level}} @{0pt@}% @ref{\@@startsection/indent,@var{indent},@var{indent}} @{-3.5ex plus -1ex minus -.2ex@}% @ref{\@@startsection/beforeskip,@var{beforeskip},@var{beforeskip}} @{2.3ex plus.2ex@}% @ref{\@@startsection/afterskip,@var{afterskip},@var{afterskip}} @{\centering\normalfont\Large\bfseries@}% @ref{\@@startsection/style,@var{style},@var{style}} @} @end example This will put @code{subsection} titles in small caps type, inline with the paragraph. @example \renewcommand\subsection@{% \@@startsection@{subsection@}% @ref{\@@startsection/name,@var{name},@var{name}} @{2@}% @ref{\@@startsection/level,@var{level},@var{level}} @{0em@}% @ref{\@@startsection/indent,@var{indent},@var{indent}} @{-1ex plus 0.1ex minus -0.05ex@}% @ref{\@@startsection/beforeskip,@var{beforeskip},@var{beforeskip}} @{-1em plus 0.2em@}% @ref{\@@startsection/afterskip,@var{afterskip},@var{afterskip}} @{\scshape@}% @ref{\@@startsection/style,@var{style},@var{style}} @} @end example The prior examples redefined existing sectional unit title commands. This defines a new one, illustrating the needed counter and macros to display that counter. @c From https://groups.google.com/forum/#!searchin/comp.text.tex/startsection%7Csort:relevance/comp.text.tex/sB-nTS-oL08/ZZeKYdG0llMJ @example \setcounter@{secnumdepth@}@{6@}% show counters this far down \newcounter@{subsubparagraph@}[subparagraph]% counter for numbering \renewcommand@{\thesubsubparagraph@}% how to display @{\thesubparagraph.\@@arabic\c@@subsubparagraph@}% numbering \newcommand@{\subsubparagraph@}@{\@@startsection @{subsubparagraph@}% @{6@}% @{0em@}% @{\baselineskip@}% @{0.5\baselineskip@}% @{\normalfont\normalsize@}@} \newcommand*\l@@subsubparagraph@{\@@dottedtocline@{6@}@{10em@}@{5em@}@}% for toc \newcommand@{\subsubparagraphmark@}[1]@{@}% for page headers @end example @node Cross references @chapter Cross references @cindex cross references @cindex label We often want something like @samp{See Theorem~31}. But by-hand typing the 31 is poor practice. Instead you should write a @dfn{label} such as @code{\label@{eq:GreensThm@}} and then @dfn{reference} it, as with @code{See equation~\ref@{eq:GreensThm@}}. @LaTeX{} will automatically work out the number, put it into the output, and will change that number later if needed. @example We will see this with Theorem~\ref@{th:GreensThm@}. % forward reference ... \begin@{theorem@} \label@{th:GreensThm@} ... \end@{theorem@} ... See Theorem~\ref@{th:GreensThm@} on page~\pageref@{th:GreensThm@}. @end example @LaTeX{} tracks cross reference information in a file having the extension @file{.aux} and with the same base name as the file containing the @code{\label}. So if @code{\label} is in @file{calculus.tex} then the information is in @file{calculus.aux}. @LaTeX{} puts the information in that file every time it runs across a @code{\label}. @cindex forward reference @cindex reference, forward The behavior described in the prior paragraph results in a quirk that happens when your document has a @dfn{forward reference}, a @code{\ref} that appears before the associated @code{\label}. If this is the first time that you are compiling the document then you will get @samp{LaTeX Warning: Label(s) may have changed. Rerun to get cross references right} and in the output the forward reference will appear as two question marks@tie{}@samp{??}, in boldface. A similar thing happens if you change some things so the references changes; you get the same warning and the output contains the old reference information. In both cases, resolve this by compiling the document a second time. @PkgIndex{cleveref} The @package{cleveref} package enhances @LaTeX{}'s cross referencing features. You can arrange that if you enter @code{\begin@{thm@}\label@{th:Nerode@}...\end@{thm@}} then @code{\cref@{th:Nerode@}} will output @samp{Theorem 3.21}, without you having to enter the ``Theorem.'' @menu * \label:: Assign a symbolic name to a piece of text. * \pageref:: Refer to a page number. * \ref:: Refer to a section, figure or similar. * xr package:: References from another document. @end menu @node \label @section @code{\label} @findex \label Synopsis: @example \label@{@var{key}@} @end example Assign a reference number to @var{key}. In ordinary text @code{\label@{@var{key}@}} assigns to @var{key} the number of the current sectional unit. Inside an environment with numbering, such as a @code{table} or @code{theorem} environment, @code{\label@{@var{key}@}} assigns to @var{key} the number of that environment. Retrieve the assigned number with the @code{\ref@{@var{key}@}} command (@pxref{\ref}). A key name can consist of any sequence of letters, digits, or common punctuation characters. Upper and lowercase letters are distinguished, as usual. A common convention is to use labels consisting of a prefix and a suffix separated by a colon or period. Thus, @code{\label@{fig:Post@}} is a label for a figure with a portrait of Emil Post. This helps to avoid accidentally creating two labels with the same name, and makes your source more readable. Some commonly-used prefixes: @table @code @item ch for chapters @item sec @itemx subsec for lower-level sectioning commands @item fig for figures @item tab for tables @item eq for equations @end table In the auxiliary file the reference information is kept as the text of a command of the form @code{\newlabel@{@var{label}@}@{@{@var{currentlabel}@}@{@var{pagenumber}@}@}}. Here @var{currentlabel} is the current value of the macro @code{\@@currentlabel} that is usually updated whenever you call @code{\refstepcounter@{@var{counter}@}}. Below, the key @code{sec:test} will get the number of the current section and the key @code{fig:test} will get the number of the figure. (Incidentally, put labels after captions in figures and tables.) @example \section@{section name@} \label@{sec:test@} This is Section~\ref@{sec:test@}. \begin@{figure@} ... \caption@{caption text@} \label@{fig:test@} \end@{figure@} See Figure~\ref@{fig:test@}. @end example @node \pageref @section @code{\pageref} @findex \pageref @cindex cross referencing with page number @cindex page number, cross referencing Synopsis: @example \pageref@{@var{key}@} @end example Produce the page number of the place in the text where the corresponding @code{\label}@{@var{key}@} command appears. If there is no @code{\label@{@var{key}@}} then you get something like @samp{LaTeX Warning: Reference `th:GrensThm' on page 1 undefined on input line 11.} Below, the @code{\label@{eq:main@}} is used both for the formula number and for the page number. (Note that the two references are forward references so this document would need to be compiled twice to resolve those.) @example The main result is formula~\ref@{eq:main@} on page~\pageref@{eq:main@}. ... \begin@{equation@} \label@{eq:main@} \mathbf@{P@}=\mathbf@{NP@} \end@{equation@} @end example @node \ref @section @code{\ref} @findex \ref @cindex cross referencing, symbolic @cindex section number, cross referencing @cindex equation number, cross referencing @cindex figure number, cross referencing @cindex footnote number, cross referencing Synopsis: @example \ref@{@var{key}@} @end example Produces the number of the sectional unit, equation, footnote, figure, @dots{}, of the corresponding @code{\label} command (@pxref{\label}). It does not produce any text, such as the word `Section' or `Figure', just the bare number itself. If there is no @code{\label@{@var{key}@}} then you get something like @samp{LaTeX Warning: Reference `th:GrensThm' on page 1 undefined on input line 11.} In this example the @code{\ref@{popular@}} produces @samp{2}. Note that it is a forward reference since it comes before @code{\label@{popular@}} so this document would have to be compiled twice. @example The most widely-used format is item number~\ref@{popular@}. \begin@{enumerate@} \item Plain \TeX \item \label@{popular@} \LaTeX \item Con\TeX t \end@{enumerate@} @end example @PkgIndex{cleveref} The @package{cleveref} package includes text such as @samp{Theorem} in the reference. See the documentation on CTAN. @node xr package @section @package{xr} package @PkgIndex{xr} @PkgIndex{xr-hyper} @findex \externaldocument @cindex cross referencing, across documents Synopsis: @example \usepackage@{xr@} \externaldocument@{@var{document-basename}@} @end example @noindent or @example \usepackage@{xr@} \externaldocument[@var{reference-prefix}]@{@var{document-basename}@} @end example Make cross references to the external document @file{@var{document-basename}.tex}. Here is an example. If @file{lectures.tex} has this in the preamble @example \usepackage@{xr@} \externaldocument@{exercises@} \externaldocument[H-]@{hints@} \externaldocument@{answers@} @end example @noindent then it can use cross reference labels from the other three documents. Suppose that @file{exercises.tex} has an enumerated list containing this, @example \item \label@{exer:EulersThm@} What if every vertex has odd degree? @end example @noindent and @file{hints.tex} has an enumerated list with this, @example \item \label@{exer:EulersThm@} Distinguish the case of two vertices. @end example @noindent and @file{answers.tex} has an enumerated list with this, @example \item \label@{ans:EulersThm@} There is no Euler path, except if there are exactly two vertices. @end example After compiling the exercises, hints, and answers documents, entering this in the body of @file{lectures.tex} will result in the lectures getting the reference numbers used in the other documents. @example See Exercise~\ref@{exer:EulersThm@}, with Hint~\ref@{H-exer:EulersThm@}. The solution is Answer~\ref@{ans:EulersThm@}. @end example The prefix @code{H-} for the reference from the hints file is needed because the label in the hints file is the same as the label in the exercises file. Without that prefix, both references would get the number from the later file. Note: if the document uses the @package{hyperref} package then in place of @package{xr}, put @code{\usepackage@{xr-hyper@}} before the @code{\usepackage@{hyperref@}}. Also, if any of the multiple documents uses @package{hyperref} then they all must use it. @node Environments @chapter Environments @cindex environments @findex \begin @findex \end @LaTeX{} provides many environments for delimiting certain behavior. An environment begins with @code{\begin} and ends with @code{\end}, like this: @example \begin@{@var{environment-name}@} ... \end@{@var{environment-name}@} @end example The @var{environment-name} at the beginning must exactly match that at the end. For instance, the input @code{\begin@{table*@}...\end@{table@}} will cause an error like: @samp{! LaTeX Error: \begin@{table*@} on input line 5 ended by \end@{table@}.} @cindex group, and environments Environments are executed within a group. @menu * abstract:: Produce an abstract. * array:: Math arrays. * center:: Centered lines. * description:: Labelled lists. * displaymath:: Formulas that appear on their own line. * document:: Enclose the whole document. * enumerate:: Numbered lists. * eqnarray:: Sequences of aligned equations. * equation:: Displayed equation. * figure:: Floating figures. * filecontents:: Writing multiple files from the source. * flushleft:: Flushed left lines. * flushright:: Flushed right lines. * itemize:: Bulleted lists. * letter:: Letters. * list:: Generic list environment. * math:: In-line math. * minipage:: Miniature page. * picture:: Picture with text, arrows, lines and circles. * quotation & quote:: Include a quotation. * tabbing:: Align text arbitrarily. * table:: Floating tables. * tabular:: Align text in columns. * thebibliography:: Bibliography or reference list. * theorem:: Theorems, lemmas, etc. * titlepage:: For hand crafted title pages. * verbatim:: Simulating typed input. * verse:: For poetry and other things. @end menu @node abstract @section @code{abstract} @EnvIndex{abstract} @cindex abstracts Synopsis: @example \begin@{abstract@} ... \end@{abstract@} @end example Produce an abstract, possibly of multiple paragraphs. This environment is only defined in the @code{article} and @code{report} document classes (@pxref{Document classes}). Using the example below in the @code{article} class produces a displayed paragraph. Document class option @code{titlepage} causes the abstract to be on a separate page (@pxref{Document class options}); this is the default only in the @code{report} class. @example \begin@{abstract@} We compare all known accounts of the proposal made by Porter Alexander to Robert E Lee at the Appomattox Court House that the army continue in a guerrilla war, which Lee refused. \end@{abstract@} @end example @PkgIndex{abstract} The next example produces a one column abstract in a two column document (for a more flexible solution, use the package @package{abstract}). @c Adopted from http://www.tex.ac.uk/FAQ-onecolabs.html @example \documentclass[twocolumn]@{article@} ... \begin@{document@} \title@{Babe Ruth as Cultural Progenitor: a Atavistic Approach@} \author@{Smith \\ Jones \\ Robinson\thanks@{Railroad tracking grant.@}@} \twocolumn[ \begin@{@@twocolumnfalse@} \maketitle \begin@{abstract@} Ruth was not just the Sultan of Swat, he was the entire swat team. \end@{abstract@} \end@{@@twocolumnfalse@} ] @{ % by-hand insert a footnote at page bottom \renewcommand@{\thefootnote@}@{\fnsymbol@{footnote@}@} \footnotetext[1]@{Thanks for all the fish.@} @} @end example @node array @section @code{array} @EnvIndex{array} @cindex arrays, math Synopsis: @example \begin@{array@}@{@var{cols}@} @var{column 1 entry} &@var{column 2 entry} ... &@var{column n entry} \\ ... \end@{array@} @end example @noindent or: @example \begin@{array@}[@var{pos}]@{@var{cols}@} @var{column 1 entry} &@var{column 2 entry} ... &@var{column n entry} \\ ... \end@{array@} @end example Produce a mathematical array. This environment can only be used in math mode (@pxref{Modes}), and normally appears within a displayed mathematics environment such as @code{equation} (@pxref{equation}). Inside of each row the column entries are separated by an ampersand, (@code{&}). Rows are terminated with double-backslashes (@pxref{\\}). This example shows a three by three array. @example \begin@{equation*@} \chi(x) = \left| % vertical bar fence \begin@{array@}@{ccc@} x-a &-b &-c \\ -d &x-e &-f \\ -g &-h &x-i \end@{array@} \right| \end@{equation*@} @end example The required argument @var{cols} describes the number of columns, their alignment, and the formatting of the intercolumn regions. For instance, @code{\begin@{array@}@{rcl@}...\end@{array@}} gives three columns: the first flush right, the second centered, and the third flush left. See @ref{tabular} for the complete description of @var{cols} and of the other common features of the two environments, including the optional @var{pos} argument. There are two ways that @code{array} diverges from @code{tabular}. The first is that @code{array} entries are typeset in math mode, in textstyle (@pxref{Math styles}) except if the @var{cols} definition specifies the column with @code{p@{...@}}, which causes the entry to be typeset in text mode. The second is that, instead of @code{tabular}'s parameter @code{\tabcolsep}, @LaTeX{}'s intercolumn space in an @code{array} is governed by @findex \arraycolsep @code{\arraycolsep}, which gives half the width between columns. The default for this is @samp{5pt} so that between two columns comes 10@dmn{pt} of space. @PkgIndex{amsmath} To obtain arrays with braces the standard is to use the @package{amsmath} package. It comes with environments @code{pmatrix} for an array surrounded by parentheses@tie{}@code{(...)}, @code{bmatrix} for an array surrounded by square brackets@tie{}@code{[...]}, @code{Bmatrix} for an array surrounded by curly braces@tie{}@code{@{...@}}, @code{vmatrix} for an array surrounded by vertical bars@tie{}@code{|...|}, and @code{Vmatrix} for an array surrounded by double vertical bars@tie{}@code{||...||}, along with a number of other array constructs. @PkgIndex{amsmath} The next example uses the @package{amsmath} package. @example \usepackage@{amsmath@} % in preamble \begin@{equation@} \begin@{vmatrix@}@{cc@} % array with vert lines a &b \\ c &d \end@{vmatrix@}=ad-bc \end@{equation@} @end example @PkgIndex{array} @PkgIndex{dcolumn} There are many packages concerning arrays. The @package{array} package has many useful extensions, including more column types. The @package{dcolumn} package adds a column type to center on a decimal point. For both see the documentation on CTAN. @node center @section @code{center} @EnvIndex{center} @cindex centering text, environment for Synopsis: @example \begin@{center@} @var{line1} \\ @var{line2} \\ ... \end@{center@} @end example Create a new paragraph consisting of a sequence of lines that are centered within the left and right margins. Use double-backslash, @code{\\}, to get a line break (@pxref{\\}). @findex \\ @r{(for @code{center})} If some text is too long to fit on a line then @LaTeX{} will insert line breaks that avoid hyphenation and avoid stretching or shrinking any interword space. This environment inserts space above and below the text body. See @ref{\centering} to avoid such space, for example inside a @code{figure} environment. This example produces three centered lines. There is extra vertical space between the last two lines. @example \begin@{center@} A Thesis Submitted in Partial Fufillment \\ of the Requirements of \\[0.5ex] the School of Environmental Engineering \end@{center@} @end example In this example, depending on the page's line width, @LaTeX{} may choose a line break for the part before the double backslash. If so, it will center each of the two lines and if not it will center the single line. Then @LaTeX{} will break at the double backslash, and will center the ending. @example \begin@{center@} My father considered that anyone who went to chapel and didn't drink alcohol was not to be tolerated.\\ I grew up in that belief. ---Richard Burton \end@{center@} @end example A double backslash after the final line is optional. If present it doesn't add any vertical space. In a two-column document the text is centered in a column, not in the entire page. @menu * \centering:: Declaration form of the @code{center} environment. @end menu @node \centering @subsection @code{\centering} @findex \centering @cindex centering text, declaration for Synopsis: @example @{\centering ... @} @end example @noindent or @example \begin@{group@} \centering ... \end@{group@} @end example Center the material in its scope. It is most often used inside an environment such as @code{figure}, or in a @code{parbox}. This example's @code{\centering} declaration causes the graphic to be horizontally centered. @example \begin@{figure@} \centering \includegraphics[width=0.6\textwidth]@{ctan_lion.png@} \caption@{CTAN Lion@} \label@{fig:CTANLion@} \end@{figure@} @end example @noindent The scope of this @code{\centering} ends with the @code{\end@{figure@}}. Unlike the @code{center} environment, the @code{\centering} command does not add vertical space above and below the text. That's its advantage in the above example; there is not an excess of space. It also does not start a new paragraph; it simply changes how @LaTeX{} formats paragraph units. If @code{ww @{\centering xx \\ yy@} zz} is surrounded by blank lines then @LaTeX{} will create a paragraph whose first line @samp{ww xx} is centered and whose second line, not centered, contains @samp{yy zz}. Usually what is desired is for the scope of the declaration to contain a blank line or the @code{\end} command of an environment such as @code{figure} or @code{table} that ends the paragraph unit. Thus, if @code{@{\centering xx \\ yy\par@} zz} is surrounded by blank lines then it makes a new paragraph with two centered lines @samp{xx} and @samp{yy}, followed by a new paragraph with @samp{zz} that is formatted as usual. @node description @section @code{description} @EnvIndex{description} @cindex labelled lists, creating @cindex description lists, creating Synopsis: @example \begin@{description@} \item[@var{label of first item}] @var{text of first item} \item[@var{label of second item}] @var{text of second item} ... \end@{description@} @end example Environment to make a list of labeled items. Each item's @var{label} is typeset in bold and is flush left, so that long labels continue into the first line of the item text. There must be at least one item; having none causes the @LaTeX{} error @samp{Something's wrong--perhaps a missing \item}. This example shows the environment used for a sequence of definitions. @example \begin@{description@} \item[lama] A priest. \item[llama] A beast. \end@{description@} @end example @noindent The labels @samp{lama} and @samp{llama} are output in boldface, with the left edge on the left margin. @findex \item Start list items with the @code{\item} command (@pxref{\item}). Use the optional labels, as in @code{\item[Main point]}, because there is no sensible default. Following the @code{\item} is optional text, which may contain multiple paragraphs. @cindex bold typewriter, avoiding @cindex typewriter labels in lists Since the labels are in bold style, if the label text calls for a font change given in argument style (see @ref{Font styles}) then it will come out bold. For instance, if the label text calls for typewriter with @code{\item[\texttt@{label text@}]} then it will appear in bold typewriter, if that is available. The simplest way around this, in this example to get non-bold typewriter, is to use declarative style: @code{\item[@{\tt label text@}]}. Similarly, get the standard roman font with @code{\item[@{\rm label text@}]}. For other major @LaTeX{} labelled list environments, see @ref{itemize} and @ref{enumerate}. Unlike those environments, nesting @code{description} environments does not change the default label; it is boldface and flush left at all levels. For information about list layout parameters, including the default values, and for information about customizing list layout, see @ref{list}. The package @package{enumitem} is useful for customizing lists. This example changes the description labels to small caps. @example \renewcommand@{\descriptionlabel@}[1]@{% @{\hspace@{\labelsep@}\textsc@{#1@}@}@} @end example @node displaymath @section @code{displaymath} @c http://tex.stackexchange.com/questions/40492/what-are-the-differences-between-align-equation-and-displaymath @EnvIndex{displaymath} Synopsis: @example \begin@{displaymath@} @var{mathematical text} \end@{displaymath@} @end example Environment to typeset the @var{mathematical text} on its own line, in display style and centered. To make the text be flush-left use the global option @code{fleqn}; see @ref{Document class options}. In the @code{displaymath} environment no equation number is added to the math text. One way to get an equation number is to use the @code{equation} environment (@pxref{equation}). @LaTeX{} will not break the @var{math text} across lines. @PkgIndex{amsmath} Note that the @package{amsmath} package has significantly more extensive displayed equation facilities. For example, there are a number of ways in that package for having math text broken across lines. @findex \[...\] @r{display math} The construct @code{\[@var{math}\]} is a synonym for the environment @code{\begin@{displaymath@} @var{math} \end@{displaymath@}} but the latter is easier to work with in the source; for instance, searching for a square bracket may get false positives but the word @code{displaymath} will likely be unique. @findex $$...$$ @r{plain @TeX{} display math} (Aside: The construct @code{$$@var{math}$$} from Plain@tie{}@TeX{} is sometimes mistakenly used as a synonym for @code{displaymath}. It is not a synonym, and is not officially supported in @LaTeX{} at all; @code{$$} doesn't support the @code{fleqn} option (@pxref{Document class options}), has different vertical spacing, and doesn't perform consistency checks.) The output from this example is centered and alone on its line. @example \begin@{displaymath@} \int_1^2 x^2\,dx=7/3 \end@{displaymath@} @end example @noindent Also, the integral sign is larger than the inline version @code{\( \int_1^2 x^2\,dx=7/3 \)} produces. @node document @section @code{document} @EnvIndex{document} The @code{document} environment encloses the entire body of a document. It is required in every @LaTeX{} document. @xref{Starting and ending}. @menu * \AtBeginDocument:: Hook for commands at the start of the document. * \AtEndDocument:: Hook for commands at the end of the document. @end menu @node \AtBeginDocument @subsection @code{\AtBeginDocument} @findex \AtBeginDocument @cindex beginning of document hook Synopsis: @example \AtBeginDocument@{@var{code}@} @end example Save @var{code} and execute it when @code{\begin@{document@}} is executed, at the very end of the preamble. The code is executed after the font selection tables have been set up, so the normal font for the document is the current font. However, the code is executed as part of the preamble so you cannot do any typesetting with it. You can issue this command more than once; the successive code lines will be executed in the order that you gave them. @node \AtEndDocument @subsection @code{\AtEndDocument} @findex \AtEndDocument @cindex end of document hook Synopsis: @example \AtEndDocument@{@var{code}@} @end example Save @var{code} and execute it near the end of the document. Specifically, it is executed when @code{\end@{document@}} is executed, before the final page is finished and before any leftover floating environments are processed. If you want some of the code to be executed after these two processes then include a @code{\clearpage} at the appropriate point in @var{code}. You can issue this command more than once; the successive code lines will be executed in the order that you gave them. @node enumerate @section @code{enumerate} @EnvIndex{enumerate} @cindex lists of items, numbered Synopsis: @example \begin@{enumerate@} \item[@var{optional label of first item}] @var{text of first item} \item[@var{optional label of second item}] @var{text of second item} ... \end@{enumerate@} @end example Environment to produce a numbered list of items. The format of the label numbering depends on the nesting level of this environment; see below. The default top-level numbering is @samp{1.}, @samp{2.}, etc. Each @code{enumerate} list environment must have at least one item; having none causes the @LaTeX{} error @samp{Something's wrong--perhaps a missing \item}. This example gives the first two finishers in the 1908 Olympic marathon. As a top-level list the labels would come out as @samp{1.} and @samp{2.}. @example \begin@{enumerate@} \item Johnny Hayes (USA) \item Charles Hefferon (RSA) \end@{enumerate@} @end example @findex \item Start list items with the @code{\item} command (@pxref{\item}). If you give @code{\item} an optional argument by following it with square brackets, as in @code{\item[Interstitial label]}, then the next item will continue the interrupted sequence (@pxref{\item}). That is, you will get labels like @samp{1.}, then @samp{Interstitial label}, then @samp{2.}. Following the @code{\item} is optional text, which may contain multiple paragraphs. Enumerations may be nested within other @code{enumerate} environments, or within any paragraph-making environment such as @code{itemize} (@pxref{itemize}), up to four levels deep. This gives @LaTeX{}'s default for the format at each nesting level, where 1 is the top level, the outermost level. @enumerate @item arabic number followed by a period: @samp{1.}, @samp{2.},@tie{}@dots{} @item lowercase letter inside parentheses: @samp{(a)}, @samp{(b)}@tie{}@dots{} @item lowercase roman numeral followed by a period: @samp{i.}, @samp{ii.},@tie{}@dots{} @item uppercase letter followed by a period: @samp{A.}, @samp{B.},@tie{}@dots{} @end enumerate @findex \enumi @findex \enumii @findex \enumiii @findex \enumiv @anchor{enumerate enumi} @anchor{enumerate enumii} @anchor{enumerate enumiii} @anchor{enumerate enumiv} The @code{enumerate} environment uses the counters @code{\enumi} through @code{\enumiv} (@pxref{Counters}). For other major @LaTeX{} labeled list environments, see @ref{description} and @ref{itemize}. For information about list layout parameters, including the default values, and for information about customizing list layout, see @ref{list}. The package @package{enumitem} is useful for customizing lists. @findex \labelenumi @findex \labelenumii @findex \labelenumiii @findex \labelenumiv @anchor{enumerate labelenumi} @anchor{enumerate labelenumii} @anchor{enumerate labelenumiii} @anchor{enumerate labelenumiv} To change the format of the label use @code{\renewcommand} (@pxref{\newcommand & \renewcommand}) on the commands @code{\labelenumi} through @code{\labelenumiv}. For instance, this first level list will be labelled with uppercase letters, in boldface, and without a trailing period. @findex \Alph @r{example} @example \renewcommand@{\labelenumi@}@{\textbf@{\Alph@{enumi@}@}@} \begin@{enumerate@} \item Shows as boldface A \item Shows as boldface B \end@{enumerate@} @end example For a list of counter-labeling commands see @ref{\alph \Alph \arabic \roman \Roman \fnsymbol}. @node eqnarray @section @code{eqnarray} @EnvIndex{eqnarray} @cindex equations, aligning @cindex aligning equations @cindex align @r{environment, from @package{amsmath}} @cindex amsmath @r{package, replacing @code{eqnarray}} @cindex Madsen, Lars The @code{eqnarray} environment is obsolete. It has infelicities, including spacing that is inconsistent with other mathematics elements. (See ``Avoid eqnarray!''@: by Lars Madsen @url{https://tug.org/TUGboat/tb33-1/tb103madsen.pdf}). New documents should include the @package{amsmath} package and use the displayed mathematics environments provided there, such as the @code{align} environment. We include a description only for completeness and for working with old documents. Synopsis: @example \begin@{eqnarray@} @var{first formula left} &@var{first formula middle} &@var{first formula right} \\ ... \end@{eqnarray@} @end example @noindent or @example \begin@{eqnarray*@} @var{first formula left} &@var{first formula middle} &@var{first formula right} \\ ... \end@{eqnarray*@} @end example @findex \\ @r{(for @code{eqnarray})} Display a sequence of equations or inequalities. The left and right sides are typeset in display mode, while the middle is typeset in text mode. It is similar to a three-column @code{array} environment, with items within a row separated by an ampersand@tie{}(@code{&}), and with rows separated by double backslash@tie{} @code{\\}). @findex \\* @r{(for @code{eqnarray})} The starred form of line break (@code{\\*}) can also be used to separate equations, and will disallow a page break there (@pxref{\\}). @findex \nonumber @cindex equation numbers, omitting The unstarred form @code{eqnarray} places an equation number on every line (using the @code{equation} counter), unless that line contains a @code{\nonumber} command. The starred form @code{eqnarray*} omits equation numbering, while otherwise being the same. @findex \lefteqn The command @code{\lefteqn} is used for splitting long formulas across lines. It typesets its argument in display style flush left in a box of zero width. This example shows three lines. The first two lines make an inequality, while the third line has not entry on the left side. @example \begin@{eqnarray*@} \lefteqn@{x_1+x_2+\cdots+x_n@} \\ &\leq &y_1+y_2+\cdots+y_n \\ &= &z+y_3+\cdots+y_n \end@{eqnarray*@} @end example @node equation @section @code{equation} @EnvIndex{equation} @cindex equations, environment for @cindex formulas, environment for Synopsis: @example \begin@{equation@} @var{mathematical text} \end@{equation@} @end example The same as a @code{displaymath} environment (@pxref{displaymath}) except that @LaTeX{} puts an equation number flush to the right margin. The equation number is generated using the @code{equation} counter. You should have no blank lines between @code{\begin@{equation@}} and @code{\begin@{equation@}}, or @LaTeX{} will tell you that there is a missing dollar sign. @PkgIndex{amsmath} The package @package{amsmath} package has extensive displayed equation facilities. New documents should include this package. @node figure @section @code{figure} @EnvIndex{figure} @cindex inserting figures @cindex figures, inserting Synopsis: @example \begin@{figure@}[@var{placement}] @var{figure body} \caption[@var{loftitle}]@{@var{title}@} % optional \label@{@var{label@}} % optional \end@{figure@} @end example @noindent or: @example \begin@{figure*@}[@var{placement}] @var{figure body} \caption[@var{loftitle}]@{@var{title}@} % optional \label@{@var{label@}} % optional \end@{figure*@} @end example Figures are for material that is not part of the normal text. An example is material that you cannot have split between two pages, such as a graphic. Because of this, @LaTeX{} does not typeset figures in sequence with normal text but instead ``floats'' them to a convenient place, such as the top of a following page (@pxref{Floats}). The @var{figure body} can consist of imported graphics (@pxref{Graphics}), or text, @LaTeX{} commands, etc. It is typeset in a @code{parbox} of width @code{\textwidth}. The possible values of @var{placement} are @code{h} for @samp{here}, @code{t} for @samp{top}, @code{b} for @samp{bottom}, and @code{p} for @samp{on a separate page of floats}. For the effect of these options on the float placement algorithm, see @ref{Floats}. The starred form @code{figure*} is used when a document is in double-column mode (@pxref{\twocolumn}). It produces a figure that spans both columns, at the top of the page. To add the possibility of placing at a page bottom see the discussion of @var{placement} @code{b} in @ref{Floats}. @findex \caption The label is optional; it is used for cross references (@pxref{Cross references}). The optional @code{\caption} command specifies caption text for the figure (@pxref{\caption}). By default it is numbered. If @var{loftitle} is present, it is used in the list of figures instead of @var{title} (@pxref{Table of contents etc.}). This example makes a figure out of a graphic. @LaTeX{} will place that graphic and its caption at the top of a page or, if it is pushed to the end of the document, on a page of floats. @example \usepackage@{graphicx@} % in preamble ... \begin@{figure@}[t] \centering \includegraphics[width=0.5\textwidth]@{CTANlion.png@} \caption@{The CTAN lion, by Duane Bibby@} \end@{figure@} @end example @node filecontents @section @code{filecontents} @EnvIndex{filecontents} @EnvIndex{filecontents*} @cindex external files, writing @cindex writing external files Synopsis: @example \begin@{filecontents@}[@var{option}]@{@var{filename}@} @var{text} \end@{filecontents@} @end example @noindent or @example \begin@{filecontents*@}[@var{option}]@{@var{filename}@} @var{text} \end@{filecontents*@} @end example Create a file named @var{filename} in the current directory (or the output directory, if specified; @pxref{output directory}) and write @var{text} to it. By default, an existing file is not overwritten. The unstarred version of the environment @code{filecontents} prefixes the content of the created file with a header of @TeX{} comments; see the example below. The starred version @code{filecontents*} does not include the header. The possible options are: @table @code @item force @itemx overwrite @cindex @code{force} option for @code{filecontents} @cindex @code{overwrite} option for @code{filecontents} Overwrite an existing file. @item noheader @cindex @code{noheader} option for @code{filecontents} Omit the header. Equivalent to using @code{filecontents*}. @item nosearch @cindex @code{nosearch} option for @code{filecontents} Only check the current directory (and the output directory, if specified) for an existing file, not the entire search path. @end table These options were added in a 2019 release of @LaTeX{}. @cindex self-contained sources @cindex source files, making self-contained This environment can be used anywhere in the preamble, although it often appears before the @code{\documentclass} command. It is commonly used to create a @code{.bib} or other such data file from the main document source, to make the source file self-contained. Similarly, it can be used to create a custom style or class file, again making the source self-contained. For example, this document: @example \documentclass@{article@} \begin@{filecontents@}@{JH.sty@} \newcommand@{\myname@}@{Jim Hef@{@}feron@} \end@{filecontents@} \usepackage@{JH@} \begin@{document@} Article by \myname. \end@{document@} @end example @noindent produces this file @file{JH.sty}: @example %% LaTeX2e file `JH.sty' %% generated by the `filecontents' environment %% from source `test' on 2015/10/12. %% \newcommand@{\myname@}@{Jim Hef@{@}feron@} @end example @node flushleft @section @code{flushleft} @EnvIndex{flushleft} @cindex left-justifying text, environment for @cindex ragged right text, environment for Synopsis: @example \begin@{flushleft@} @var{line1} \\ @var{line2} \\ ... \end@{flushleft@} @end example @findex \\ @r{(for @code{flushleft})} An environment that creates a paragraph whose lines are flush to the left-hand margin, and ragged right. If you have lines that are too long then @LaTeX{} will linebreak them in a way that avoids hyphenation and stretching or shrinking interword spaces. To force a new line use a double backslash, @code{\\}. For the declaration form see@tie{}@ref{\raggedright}. This creates a box of text that is at most 3 inches wide, with the text flush left and ragged right. @example \noindent\begin@{minipage@}@{3in@} \begin@{flushleft@} A long sentence that will be broken by \LaTeX@{@} at a convenient spot. \\ And, a fresh line forced by the double backslash. \end@{flushleft@} \end@{minipage@} @end example @menu * \raggedright:: Declaration form of the @code{flushleft} environment. @end menu @node \raggedright @subsection @code{\raggedright} @findex \raggedright @cindex ragged right text @cindex left-justifying text @cindex justification, ragged right Synopses: @example @{\raggedright ... @} @end example @noindent or @example \begin@{@var{environment}@} \raggedright ... \end@{@var{environment}@} @end example A declaration which causes lines to be flush to the left margin and ragged right. It can be used inside an @var{environment} such as @code{quote} or in a @code{parbox}. For the environment form see@tie{}@ref{flushleft}. Unlike the @code{flushleft} environment, the @code{\raggedright} command does not start a new paragraph; it only changes how @LaTeX{} formats paragraph units. To affect a paragraph unit's format, the scope of the declaration must contain the blank line or @code{\end} command that ends the paragraph unit. Here @code{\raggedright} in each second column keeps @LaTeX{} from doing awkward typesetting to fit the text into the narrow column. Note that @code{\raggedright} is inside the curly braces @code{@{...@}} to delimit its effect. @example \begin@{tabular@}@{rp@{2in@}@} Team alpha &@{\raggedright This team does all the real work.@} \\ Team beta &@{\raggedright This team ensures that the water cooler is never empty.@} \\ \end@{tabular@} @end example @node flushright @section @code{flushright} @EnvIndex{flushright} @cindex ragged left text, environment for @cindex right-justifying text, environment for @example \begin@{flushright@} @var{line1} \\ @var{line2} \\ ... \end@{flushright@} @end example @findex \\ @r{(for @code{flushright})} An environment that creates a paragraph whose lines are flush to the right-hand margin and ragged left. If you have lines that are too long to fit the margins then @LaTeX{} will linebreak them in a way that avoids hyphenation and stretching or shrinking inter-word spaces. To force a new line use a double backslash, @code{\\}. For the declaration form see@tie{}@ref{\raggedleft}. For an example related to this environment, see@tie{}@ref{flushleft}, where one just have mutatis mutandis to replace @code{flushleft} by @code{flushright}. @menu * \raggedleft:: Declaration form of the @code{flushright} environment. @end menu @node \raggedleft @subsection @code{\raggedleft} @findex \raggedleft @cindex ragged left text @cindex justification, ragged left @cindex right-justifying text Synopses: @example @{\raggedleft ... @} @end example @noindent or @example \begin@{@var{environment}@} \raggedleft ... \end@{@var{environment}@} @end example A declaration which causes lines to be flush to the right margin and ragged left. It can be used inside an @var{environment} such as @code{quote} or in a @code{parbox}. For the environment form see@tie{}@ref{flushright}. Unlike the @code{flushright} environment, the @code{\raggedleft} command does not start a new paragraph; it only changes how @LaTeX{} formats paragraph units. To affect a paragraph unit's format, the scope of the declaration must contain the blank line or @code{\end} command that ends the paragraph unit. For an example related to this environment, see@tie{}@ref{\raggedright}, where one just have mutatis mutandis to replace @code{\raggedright} by @code{\raggedleft}. @node itemize @section @code{itemize} @EnvIndex{itemize} @findex \item @cindex lists of items @cindex unordered lists @cindex bulleted lists @cindex bullet lists Synopsis: @example \begin@{itemize@} \item[@var{optional label of first item}] @var{text of first item} \item[@var{optional label of second item}] @var{text of second item} ... \end@{itemize@} @end example Produce an @dfn{unordered list}, sometimes called a bullet list. There must be at least one @code{\item} within the environment; having none causes the @LaTeX{} error @samp{Something's wrong--perhaps a missing \item}. This gives a two-item list. @example \begin@{itemize@} \item Pencil and watercolor sketch by Cassandra \item Rice portrait \end@{itemize@} @end example @noindent With the default locale---without loading e.g.@: @package{babel} package with another language than USenglish---as a top-level list each label would come out as a bullet, @bullet{}. The format of the labeling depends on the nesting level; see below. @findex \item Start list items with the @code{\item} command (@pxref{\item}). If you give @code{\item} an optional argument by following it with square brackets, as in @code{\item[@var{Optional label}]}, then by default @var{Optional label} will appear in bold and be flush right, so it could extend into the left margin. For labels that are flush left see the @ref{description} environment. Following the @code{\item} is the text of the item, which may be empty or contain multiple paragraphs. Unordered lists can be nested within one another, up to four levels deep. They can also be nested within other paragraph-making environments, such as @code{enumerate} (@pxref{enumerate}). @findex \labelitemi @findex \labelitemii @findex \labelitemiii @findex \labelitemiv @anchor{itemize labelitemi} @anchor{itemize labelitemii} @anchor{itemize labelitemiii} @anchor{itemize labelitemiv} The @code{itemize} environment uses the commands @code{\labelitemi} through @code{\labelitemiv} to produce the default label (note the convention of lowercase roman numerals at the end of the command names that signify the nesting level). These are the default marks at each level. @enumerate @item @bullet{} (bullet, from @code{\textbullet}) @item @b{-@w{-}} (bold en-dash, from @code{\normalfont\bfseries\textendash}) @item * (asterisk, from @code{\textasteriskcentered}) @iftex @item @math{\cdot} (vertically centered dot, from @code{\textperiodcentered}) @end iftex @ifnottex @item . (vertically centered dot, rendered here as a period, from @code{\textperiodcentered}) @end ifnottex @end enumerate Change the labels with @code{\renewcommand}. For instance, this makes the first level use diamonds. @example \renewcommand@{\labelitemi@}@{$\diamond$@} @end example @findex \leftmargin @findex \leftmargini @findex \leftmarginii @findex \leftmarginiii @findex \leftmarginiv @findex \leftmarginv @findex \leftmarginvi @anchor{itemize leftmargin} @anchor{itemize leftmargini} @anchor{itemize leftmarginii} @anchor{itemize leftmarginiii} @anchor{itemize leftmarginiv} @anchor{itemize leftmarginv} @anchor{itemize leftmarginvi} The distance between the left margin of the enclosing environment and the left margin of the @code{itemize} list is determined by the parameters @code{\leftmargini} through @code{\leftmarginvi}. (This also uses the convention of using lowercase roman numerals a the end of the command name to denote the nesting level.) The defaults are: @code{2.5em} in level 1 (@code{2em} in two-column mode), @code{2.2em} in level 2, @code{1.87em} in level 3, and @code{1.7em} in level 4, with smaller values for more deeply nested levels. @PkgIndex{enumitem} For other major @LaTeX{} labeled list environments, see @ref{description} and @ref{enumerate}. The @code{itemize}, @code{enumerate} and @code{description} environment use the same list layout parameters. For a description, including the default values, and for information about customizing list layout, see @ref{list}. The package @package{enumitem} is useful for customizing lists. This example greatly reduces the margin space for outermost itemized lists. @example \setlength@{\leftmargini@}@{1.25em@} % default 2.5em @end example @findex \parskip @r{example} Especially for lists with short items, it may be desirable to elide space between items. Here is an example defining an @code{itemize*} environment with no extra spacing between items, or between paragraphs within a single item (@code{\parskip} is not list-specific, @pxref{\parindent & \parskip}): @example \newenvironment@{itemize*@}% @{\begin@{itemize@}% \setlength@{\itemsep@}@{0pt@}% \setlength@{\parsep@}@{0pt@}@}% \setlength@{\parskip@}@{0pt@}@}% @{\end@{itemize@}@} @end example @node letter @section @code{letter} environment: writing letters @EnvIndex{letter} This environment is used for creating letters. @xref{Letters}. @node list @section @code{list} @EnvIndex{list} @cindex lists of items, generic Synopsis: @example \begin@{list@}@{@var{labeling}@}@{@var{spacing}@} \item[@var{optional label of first item}] @var{text of first item} \item[@var{optional label of second item}] @var{text of second item} ... \end@{list@} @end example An environment for constructing lists. Note that this environment does not typically appear in the document body. Most lists created by @LaTeX{} authors are the ones that come standard: the @code{description}, @code{enumerate}, and @code{itemize} environments (@pxref{description}, @ref{enumerate}, and @ref{itemize}). Instead, the @code{list} environment is most often used in macros. For example, many standard @LaTeX{} environments that do not immediately appear to be lists are in fact constructed using @code{list}, including @code{quotation}, @code{quote}, and @code{center} (@pxref{quotation & quote}, @pxref{center}). This uses the @code{list} environment to define a new custom environment. @example \newcounter@{namedlistcounter@} % number the items \newenvironment@{named@} @{\begin@{list@} @{Item~\Roman@{namedlistcounter@}.@} % labeling @{\usecounter@{namedlistcounter@} % set counter \setlength@{\leftmargin@}@{3.5em@}@} % set spacing @} @{\end@{list@}@} \begin@{named@} \item Shows as ``Item~I.'' \item[Special label.] Shows as ``Special label.'' \item Shows as ``Item~II.'' \end@{named@} @end example The mandatory first argument @var{labeling} specifies the default labeling of list items. It can contain text and @LaTeX{} commands, as above where it contains both @samp{Item} and @samp{\Roman@{@dots{}@}}. @LaTeX{} forms the label by putting the @var{labeling} argument in a box of width @code{\labelwidth}. If the label is wider than that, the additional material extends to the right. When making an instance of a @code{list} you can override the default labeling by giving @code{\item} an optional argument by including square braces and the text, as in the above @code{\item[Special label.]}; @pxref{\item}. The mandatory second argument @var{spacing} has a list of commands. This list can be empty. A command that can go in here is @code{\usecounter@{@var{countername}@}} (@pxref{\usecounter}). Use this to tell @LaTeX{} to number the items using the given counter. The counter will be reset to zero each time @LaTeX{} enters the environment, and the counter is incremented by one each time @LaTeX{} encounters an @code{\item} that does not have an optional argument. @findex \makelabel @anchor{list makelabel} Another command that can go in @var{spacing} is @code{\makelabel}, which constructs the label box. By default it puts the contents flush right. Its only argument is the label, which it typesets in LR mode (@pxref{Modes}). One example of changing its definition is that to the above @code{named} example, before the definition of the environment add @code{\newcommand@{\namedmakelabel@}[1]@{\textsc@{#1@}@}}, and between the @code{\setlength} command and the parenthesis that closes the @var{spacing} argument also add @code{\let\makelabel\namedmakelabel}. Then the labels will be typeset in small caps. Similarly, changing the second code line to @code{\let\makelabel\fbox} puts the labels inside a framed box. Another example of the @code{\makelabel} command is below, in the definition of the @code{redlabel} environment. Also often in @var{spacing} are commands to redefine the spacing for the list. Below are the spacing parameters with their default values. (Default values for derived environments such as @code{itemize} can be different than the values shown here.) See also the figure that follows the list. Each is a length (@pxref{Lengths}). The vertical spaces are normally rubber lengths, with @code{plus} and @code{minus} components, to give @TeX{} flexibility in setting the page. Change each with a command such as @code{\setlength@{itemsep@}@{2pt plus1pt minus1pt@}}. For some effects these lengths should be zero or negative. @ftable @code @item \itemindent @anchor{list itemindent} Extra horizontal space indentation, beyond @code{leftmargin}, of the first line each item. Its default value is @code{0pt}. @item \itemsep @anchor{list itemsep} Vertical space between items, beyond the @code{\parsep}. The defaults for the first three levels in @LaTeX{}'s @samp{article}, @samp{book}, and @samp{report} classes at 10 point size are: @code{4pt plus2pt minus1pt}, @code{\parsep} (that is, @code{2pt plus1pt minus1pt}), and @code{\topsep} (that is, @code{2pt plus1pt minus1pt}). The defaults at 11 point are: @code{4.5pt plus2pt minus1pt}, @code{\parsep} (that is, @code{2pt plus1pt minus1pt}), and @code{\topsep} (that is, @code{2pt plus1pt minus1pt}). The defaults at 12 point are: @code{5pt plus2.5pt minus1pt}, @code{\parsep} (that is, @code{2.5pt plus1pt minus1pt}), and @code{\topsep} (that is, @code{2.5pt plus1pt minus1pt}). @item \labelsep @anchor{list labelsep} Horizontal space between the label and text of an item. The default for @LaTeX{}'s @samp{article}, @samp{book}, and @samp{report} classes is @code{0.5em}. @item \labelwidth @anchor{list labelwidth} Horizontal width. The box containing the label is nominally this wide. If @code{\makelabel} returns text that is wider than this then the first line of the item will be indented to make room for this extra material. If @code{\makelabel} returns text of width less than or equal to @code{\labelwidth} then @LaTeX{}'s default is that the label is typeset flush right in a box of this width. The left edge of the label box is @code{\leftmargin}+@code{\itemindent}-@code{\labelsep}-@code{\labelwidth} from the left margin of the enclosing environment. The default for @LaTeX{}'s @samp{article}, @samp{book}, and @samp{report} classes at the top level is @code{\leftmargini}-@code{\labelsep}, (which is @code{2em} in one column mode and @code{1.5em} in two column mode). At the second level it is @code{\leftmarginii}-@code{\labelsep}, and at the third level it is @code{\leftmarginiii}-@code{\labelsep}. These definitions make the label's left edge coincide with the left margin of the enclosing environment. @item \leftmargin @anchor{list leftmargin} Horizontal space between the left margin of the enclosing environment (or the left margin of the page if this is a top-level list), and the left margin of this list. It must be non-negative. In the standard @LaTeX{} document classes, a top-level list has this set to the value of @code{\leftmargini}, while a list that is nested inside a top-level list has this margin set to @code{\leftmarginii}. More deeply nested lists get the values of @code{\leftmarginiii} through @code{\leftmarginvi}. (Nesting greater than level five generates the error message @samp{Too deeply nested}.) The defaults for the first three levels in @LaTeX{}'s @samp{article}, @samp{book}, and @samp{report} classes are: @code{\leftmargini} is @code{2.5em} (in two column mode, @code{2em}), @code{\leftmarginii} is @code{2.2em}, and @code{\leftmarginiii} is @code{1.87em}. @item \listparindent @anchor{list listparindent} Horizontal space of additional line indentation, beyond @code{\leftmargin}, for second and subsequent paragraphs within a list item. A negative value makes this an ``outdent''. Its default value is @code{0pt}. @item \parsep @anchor{list parsep} Vertical space between paragraphs within an item. The defaults for the first three levels in @LaTeX{}'s @samp{article}, @samp{book}, and @samp{report} classes at 10 point size are: @code{4pt plus2pt minus1pt}, @code{2pt plus1pt minus1pt}, and @code{0pt}. The defaults at 11 point size are: @code{4.5pt plus2pt minus1pt}, @code{2pt plus1pt minus1pt}, and @code{0pt}. The defaults at 12 point size are: @code{5pt plus2.5pt minus1pt}, @code{2.5pt plus1pt minus1pt}, and @code{0pt}. @item \partopsep @anchor{list partopsep} Vertical space added, beyond @code{\topsep}+@code{\parskip}, to the top and bottom of the entire environment if the list instance is preceded by a blank line. (A blank line in the @LaTeX{} source before the list changes spacing at both the top and bottom of the list; whether the line following the list is blank does not matter.) The defaults for the first three levels in @LaTeX{}'s @samp{article}, @samp{book}, and @samp{report} classes at 10 point size are: @code{2pt plus1 minus1pt}, @code{2pt plus1pt minus1pt}, and @code{1pt plus0pt minus1pt}. The defaults at 11 point are: @code{3pt plus1pt minus1pt}, @code{3pt plus1pt minus1pt}, and @code{1pt plus0pt minus1pt}). The defaults at 12 point are: @code{3pt plus2pt minus3pt}, @code{3pt plus2pt minus2pt}, and @code{1pt plus0pt minus1pt}. @item \rightmargin @anchor{list rightmargin} Horizontal space between the right margin of the list and the right margin of the enclosing environment. Its default value is @code{0pt}. It must be non-negative. @item \topsep @anchor{list topsep} Vertical space added to both the top and bottom of the list, in addition to @code{\parskip} (@pxref{\parindent & \parskip}). The defaults for the first three levels in @LaTeX{}'s @samp{article}, @samp{book}, and @samp{report} classes at 10 point size are: @code{8pt plus2pt minus4pt}, @code{4pt plus2pt minus1pt}, and @code{2pt plus1pt minus1pt}. The defaults at 11 point are: @code{9pt plus3pt minus5pt}, @code{4.5pt plus2pt minus1pt}, and @code{2pt plus1pt minus1pt}. The defaults at 12 point are: @code{10pt plus4pt minus6pt}, @code{5pt plus2.5pt minus1pt}, and @code{2.5pt plus1pt minus1pt}. @end ftable This shows the horizontal and vertical distances. @float @image{latex2e-figures/list,3.21in,,,.png} @end float The lengths shown are listed below. The key relationship is that the right edge of the bracket for @var{h1} equals the right edge of the bracket for @var{h4}, so that the left edge of the label box is at @var{h3}+@var{h4}-(@var{h0}+@var{h1}). @table @var @item v0 @math{@code{@\topsep} + @code{@\parskip}} if the list environment does not start a new paragraph, and @code{\topsep}+@code{\parskip}+@code{\partopsep} if it does @item v1 @code{\parsep} @item v2 @code{\itemsep}+@code{\parsep} @item v3 Same as @var{v0}. (This space is affected by whether a blank line appears in the source above the environment; whether a blank line appears in the source below the environment does not matter.) @item h0 @code{\labelwidth} @item h1 @code{\labelsep} @item h2 @code{\listparindent} @item h3 @code{\leftmargin} @item h4 @code{\itemindent} @item h5 @code{\rightmargin} @end table The list's left and right margins, shown above as @var{h3} and @var{h5}, are with respect to the ones provided by the surrounding environment, or with respect to the page margins for a top-level list. The line width used for typesetting the list items is @code{\linewidth} (@pxref{Page layout parameters}). For instance, set the list's left margin to be one quarter of the distance between the left and right margins of the enclosing environment with @code{\setlength@{\leftmargin@}@{0.25\linewidth@}}. Page breaking in a list structure is controlled by the three parameters below. For each, the @LaTeX{} default is @code{-\@@lowpenalty}, that is, @code{-51}. Because it is negative, it somewhat encourages a page break at each spot. Change it with, e.g., @code{\@@beginparpenalty=9999}; a value of 10000 prohibits a page break. @ftable @code @item \@@beginparpenalty @anchor{list beginparpenalty} The page breaking penalty for breaking before the list (default @code{-51}). @item \@@itempenalty @anchor{list itempenalty} The page breaking penalty for breaking before a list item (default @code{-51}). @item \@@endparpenalty @anchor{list endparpenalty} The page breaking penalty for breaking after a list (default @code{-51}). @end ftable @PkgIndex{enumitem} The package @package{enumitem} is useful for customizing lists. This example has the labels in red. They are numbered, and the left edge of the label lines up with the left edge of the item text. @xref{\usecounter}. @example \usepackage@{color@} \newcounter@{cnt@} \newcommand@{\makeredlabel@}[1]@{\textcolor@{red@}@{#1.@}@} \newenvironment@{redlabel@} @{\begin@{list@} @{\arabic@{cnt@}@} @{\usecounter@{cnt@} \setlength@{\labelwidth@}@{0em@} \setlength@{\labelsep@}@{0.5em@} \setlength@{\leftmargin@}@{1.5em@} \setlength@{\itemindent@}@{0.5em@} % equals \labelwidth+\labelsep \let\makelabel=\makeredlabel @} @} @{\end@{list@}@} @end example @menu * \item:: An entry in a list. * trivlist:: A restricted form of @code{list}. @end menu @node \item @subsection @code{\item}: An entry in a list Synopsis: @example \item text of item @end example @noindent or @example \item[@var{optional-label}] text of item @end example An entry in a list. The entries are prefixed by a label, whose default depends on the list type. Because the optional label is surrounded by square brackets @samp{[...]}, if you have an item whose text starts with [, you have to hide the bracket inside curly braces, as in: @code{\item @{[@} is an open square bracket}; otherwise, @LaTeX{} will think it marks the start of an optional label. Similarly, if the item does have the optional label and you need a close square bracket inside that label, you must hide it in the same way: @code{\item[Close square bracket, @{]@}]}. @xref{@LaTeX{} command syntax}. In this example the enumerate list has two items that use the default label and one that uses the optional label. @example \begin@{enumerate@} \item Moe \item[sometimes] Shemp \item Larry \end@{enumerate@} @end example The first item is labelled @samp{1.}, the second item is labelled @samp{sometimes}, and the third item is labelled @samp{2.}. Because of the optional label in the second item, the third item is not labelled@tie{}@samp{3.}. @node trivlist @subsection @code{trivlist}: A restricted form of @code{list} Synopsis: @example \begin@{trivlist@} ... \end@{trivlist@} @end example A restricted version of the list environment, in which margins are not indented and an @code{\item} without an optional argument produces no text. It is most often used in macros, to define an environment where the @code{\item} command is part of the environment's definition. For instance, the @code{center} environment is defined essentially like this: @example \newenvironment@{center@} @{\begin@{trivlist@}\centering\item\relax@} @{\end@{trivlist@}@} @end example Using @code{trivlist} in this way allows the macro to inherit some common code: combining vertical space of two adjacent environments; detecting whether the text following the environment should be considered a new paragraph or a continuation of the previous one; adjusting the left and right margins for possible nested list environments. Specifically, @code{trivlist} uses the current values of the list parameters (@pxref{list}), except that @code{\parsep} is set to the value of @code{\parskip}, and @code{\leftmargin}, @code{\labelwidth}, and @code{\itemindent} are set to zero. This example outputs the items as two paragraphs, except that (by default) they have no paragraph indent and are vertically separated. @example \begin@{trivlist@} \item The \textit@{Surprise@} is not old; no one would call her old. \item She has a bluff bow, lovely lines. \end@{trivlist@} @end example @node math @section @code{math} @EnvIndex{math} @cindex inline formulas Synopsis: @example \begin@{math@} @var{math} \end@{math@} @end example @findex $ @r{inline math} @findex \(...\) @r{inline math} The @code{math} environment inserts given @var{math} material within the running text. @code{\(...\)} and @code{$...$} are synonyms. @xref{Math formulas}. @node minipage @section @code{minipage} @EnvIndex{minipage} @cindex minipage, creating a Synopses: @example \begin@{minipage@}@{@var{width}@} @var{contents} \end@{minipage@} @end example @noindent or @example \begin@{minipage@}[@var{position}][@var{height}][@var{inner-pos}]@{@var{width}@} @var{contents} \end@{minipage@} @end example Put @var{contents} into a box that is @var{width} wide. This is like a small version of a page; it can contain its own footnotes, itemized lists, etc. (There are some restrictions, including that it cannot have floats.) This box will not be broken across pages. So @code{minipage} is similar to @code{\parbox} (@pxref{\parbox}) but here you can have paragraphs. This example will be 3@tie{}inches wide, and has two paragraphs. @example \begin@{minipage@}@{3in@} Stephen Kleene was a founder of the Theory of Computation. He was a student of Church, wrote three influential texts, was President of the Association for Symbolic Logic, and won the National Medal of Science. \end@{minipage@} @end example @noindent See below for a discussion of the paragraph indent inside a @code{minipage}. The required argument @var{width} is a rigid length (@pxref{Lengths}). It gives the width of the box into which @var{contents} are typeset. There are three optional arguments, @var{position}, @var{height}, and @var{inner-pos}. You need not include all three. For example, get the default @var{position} and set the @var{height} with @code{\begin@{minipage@}[c][2.54cm]@{\columnwidth@} @var{contents} \end@{minipage@}}. (Get the natural height with an empty argument, @code{[]}.) The optional argument @var{position} governs how the @code{minipage} vertically aligns with the surrounding material. @table @code @item c @c xx Clarify what it means when adjacent text lines do not have aligned @c vertical center with each other (synonym @code{m}) Default. Positions the @code{minipage} so its vertical center lines up with the center of the adjacent text line. @item t @findex \vtop @r{plain @TeX{}} Align the baseline of the top line in the @code{minipage} with the baseline of the surrounding text (plain @TeX{}'s @code{\vtop}). @item b @findex \vbox @r{(plain @TeX{})} Align the baseline of the bottom line in the @code{minipage} with the baseline of the surrounding text (plain @TeX{}'s @code{\vbox}). @end table To see the effects of these, contrast running this @example ---\begin@{minipage@}[c]@{0.25in@} first\\ second\\ third \end@{minipage@} @end example @noindent with the results of changing @code{c} to @code{b} or@tie{}@code{t}. @c xx Clarify what happens if user enter a rubber length instead of a @c rigid length. The optional argument @var{height} is a rigid length (@pxref{Lengths}). It sets the height of the @code{minipage}. You can enter any value larger than, or equal to, or smaller than the @code{minipage}'s natural height and @LaTeX{} will not give an error or warning. You can also set it to a height of zero or a negative value. The final optional argument @var{inner-pos} controls the placement of @var{contents} inside the box. These are the possible values are (the default is the value of @var{position}). @table @code @item t Place @var{contents} at the top of the box. @item c Place it in the vertical center. @item b Place it at the box bottom. @item s Stretch @var{contents} out vertically; it must contain vertically stretchable space. @end table The @var{inner-pos} argument makes sense when the @var{height} option is set to a value larger than the @code{minipage}'s natural height. To see the effect of the options, run this example with the various choices in place of @code{b}. @example Text before \begin@{center@} ---\begin@{minipage@}[c][3in][b]@{0.25\textwidth@} first\\ second\\ third \end@{minipage@} \end@{center@} Text after @end example @cindex indentation of paragraphs, in minipage @cindex paragraph indentation, in minipage @findex \parindent By default paragraphs are not indented in a @code{minipage}. Change that with a command such as @code{\setlength@{\parindent@}@{1pc@}} at the start of @var{contents}. @cindex footnotes in figures @cindex figures, footnotes in Footnotes in a @code{minipage} environment are handled in a way that is particularly useful for putting footnotes in figures or tables. A @code{\footnote} or @code{\footnotetext} command puts the footnote at the bottom of the minipage instead of at the bottom of the page, and it uses the @code{\mpfootnote} counter instead of the ordinary @code{footnote} counter (@pxref{Counters}). This puts the footnote at the bottom of the table, not the bottom of the page. @example \begin@{center@} % center the minipage on the line \begin@{minipage@}@{2.5in@} \begin@{center@} % center the table inside the minipage \begin@{tabular@}@{ll@} \textsc@{Monarch@} &\textsc@{Reign@} \\ \hline Elizabeth II &63 years\footnote@{to date@} \\ Victoria &63 years \\ George III &59 years \end@{tabular@} \end@{center@} \end@{minipage@} \end@{center@} @end example If you nest minipages then there is an oddness when using footnotes. Footnotes appear at the bottom of the text ended by the next @code{\end@{minipage@}} which may not be their logical place. This puts a table containing data side by side with a map graphic. They are vertically centered. @PkgIndex{siunitx} @example % siunitx to have the S column specifier, % which aligns numbers on their decimal point. \usepackage@{siunitx@} \newcommand*@{\vcenteredhbox@}[1]@{\begin@{tabular@}@{@@@{@}c@@@{@}@}#1\end@{tabular@}@} ... \begin@{center@} \vcenteredhbox@{\includegraphics[width=0.3\textwidth]@{nyc.png@}@} \hspace@{0.1\textwidth@} \begin@{minipage@}@{0.5\textwidth@} \begin@{tabular@}@{r|S@} % \multicolumn to remove vertical bar between column headers \multicolumn@{1@}@{r@}@{Borough@} & % braces to prevent siunitx from misinterpreting the % period as a decimal separator @{Pop. (million)@} \\ \hline The Bronx &1.5 \\ Brooklyn &2.6 \\ Manhattan &1.6 \\ Queens &2.3 \\ Staten Island &0.5 \end@{tabular@} \end@{minipage@} \end@{center@} @end example @node picture @section @code{picture} @EnvIndex{picture} @cindex creating pictures @cindex pictures, creating Synopses: @example \begin@{picture@}(@var{width},@var{height}) @var{picture command} \end@{picture@} @end example @noindent or @example \begin@{picture@}(@var{width},@var{height})(@var{xoffset},@var{yoffset}) @var{picture command} \end@{picture@} @end example @noindent Where there may be any number of @var{picture command}'s. An environment to create simple pictures containing lines, arrows, boxes, circles, and text. This environment is not obsolete, but new documents typically use much more powerful graphics creation systems, such as TikZ, PSTricks, MetaPost, or Asymptote. None of these are covered in this document; see CTAN. To start, here's an example showing the parallelogram law for adding vectors. @findex \unitlength @example \setlength@{\unitlength@}@{1cm@} \begin@{picture@}(6,6) % picture box will be 6cm wide by 6cm tall \put(0,0)@{\vector(2,1)@{4@}@} % for every 2 over this vector goes 1 up \put(2,1)@{\makebox(0,0)[l]@{\ first leg@}@} \put(4,2)@{\vector(1,2)@{2@}@} \put(5,4)@{\makebox(0,0)[l]@{\ second leg@}@} \put(0,0)@{\vector(1,1)@{6@}@} \put(3,3)@{\makebox(0,0)[r]@{sum\ @}@} \end@{picture@} @end example The @code{picture} environment has one required argument, a pair of positive real numbers (@var{width},@var{height}). Multiply these by the value @code{\unitlength} to get the nominal size of the output, i.e.@: the space that @LaTeX{} reserves on the output page. This nominal size need not be how large the picture really is; @LaTeX{} will draw things from the picture outside the picture's box. This environment also has an optional argument (@var{xoffset},@var{yoffset}). It is used to shift the origin. Unlike most optional arguments, this one is not contained in square brackets. As with the required argument, it consists of a pair of two real numbers, but these may also be negative or null. Multiply these by @code{\unitlength} to get the coordinates of the point at the lower-left corner of the picture. For example, if @code{\unitlength} has been set to @code{1mm}, the command @example \begin@{picture@}(100,200)(10,20) @end example @noindent produces a box of width 100 millimeters and height 200 millimeters. The picture's origin is the point (10mm,20mm) and so the lower-left corner is there, and the upper-right corner is at (110mm,220mm). When you first draw a picture you typically omit the optional argument, leaving the origin at the lower-left corner. If you then want to modify your picture by shifting everything, you can just add the appropriate optional argument. @cindex position, in picture Each @var{picture command} tells @LaTeX{} where to put something by providing its position. A @dfn{position} is a pair such as @code{(2.4,-5)} giving the x- and y-coordinates. A @dfn{coordinate} is a not a length, it is a real number (it may have a decimal point or a minus sign). It specifies a length in multiples of the unit length @code{\unitlength}, so if @code{\unitlength} has been set to @code{1cm}, then the coordinate @code{2.54} specifies a length of 2.54 centimeters. @LaTeX{}'s default for @code{\unitlength} is @code{1pt}. It is a rigid length (@pxref{Lengths}). Change it with the @code{\setlength} command (@pxref{\setlength}). Make this change only outside of a @code{picture} environment. The @code{picture} environment supports using standard arithmetic expressions as well as numbers. Coordinates are given with respect to an origin, which is by default at the lower-left corner of the picture. Note that when a position appears as an argument, as with @code{\put(1,2)@{...@}}, it is not enclosed in braces since the parentheses serve to delimit the argument. Also, unlike in some computer graphics systems, larger y-coordinates are further up the page, for example, @math{y = 1} is @emph{above} @math{y = 0}. There are four ways to put things in a picture: @code{\put}, @code{\multiput}, @code{\qbezier}, and @code{\graphpaper}. The most often used is @code{\put}. This @example \put(11.3,-0.3)@{...@} @end example @noindent places the object with its reference point at coordinates @math{(11.3,-0.3)}. The reference points for various objects will be described below. @findex LR box The @code{\put} command creates an @dfn{LR box} (@pxref{Modes}). Anything that can go in an @code{\mbox} (@pxref{\mbox & \makebox}) can go in the text argument of the @code{\put} command. The reference point will be the lower left corner of the box. In this picture @example \setlength@{\unitlength@}@{1cm@} ...\begin@{picture@}(1,1) \put(0,0)@{\line(1,0)@{1@}@} \put(0,0)@{\line(1,1)@{1@}@} \end@{picture@} @end example @noindent the three dots are just slightly left of the point of the angle formed by the two lines. (Also, @code{\line(1,1)@{1@}} does not call for a line of length one; rather the line has a change in the x coordinate of 1.) The @code{\multiput}, @code{qbezier}, and @code{graphpaper} commands are described below. You can also use this environment to place arbitrary material at an exact location. For example: @example \usepackage@{color,graphicx@} % in preamble ... \begin@{center@} \setlength@{\unitlength@}@{\textwidth@} \begin@{picture@}(1,1) % leave space, \textwidth wide and tall \put(0,0)@{\includegraphics[width=\textwidth]@{desertedisland.jpg@}@} \put(0.25,0.35)@{\textcolor@{red@}@{X Treasure here@}@} \end@{picture@} \end@{center@} @end example @noindent The red@tie{}X will be precisely a quarter of the @code{\textwidth} from the left margin, and @code{0.35\textwidth} up from the bottom of the picture. Another example of this usage is to put similar code in the page header to get repeat material on each of a document's pages. @menu * \put:: Place an object at a specified place. * \multiput:: Draw multiple instances of an object. * \qbezier:: Draw a quadratic B@'ezier curve. * \graphpaper:: Draw graph paper. * \line:: Draw a straight line. * \linethickness:: Set thickness of horizontal and vertical lines. * \thinlines:: The default line thickness. * \thicklines:: A heavier line thickness. * \circle:: Draw a circle. * \oval:: Draw an oval. * \shortstack:: Make a stack of objects. * \vector:: Draw a line with an arrow. * \makebox (picture):: Draw a box of the specified size. * \framebox (picture):: Draw a box with a frame around it. * \frame:: Draw a frame around an object. * \dashbox:: Draw a dashed box. @end menu @node \put @subsection @code{\put} @findex \put Synopsis: @example \put(@var{xcoord},@var{ycoord})@{@var{content}@} @end example Place @var{content} at the coordinate (@var{xcoord},@var{ycoord}). See the discussion of coordinates and @code{\unitlength} in @ref{picture}. The @var{content} is processed in LR mode (@pxref{Modes}) so it cannot contain line breaks. This includes the text into the @code{picture}. @example \put(4.5,2.5)@{Apply the \textit@{unpoke@} move@} @end example The reference point, the location (4.5,2.5), is the lower left of the text, at the bottom left of the @samp{A}. @node \multiput @subsection @code{\multiput} @findex \multiput Synopsis: @example \multiput(@var{x},@var{y})(@var{delta_x},@var{delta_y})@{@var{num-copies}@}@{@var{obj}@} @end example Copy @var{obj} a total of @var{num-copies} times, with an increment of @var{delta_x,delta_y}. The @var{obj} first appears at position @math{(x,y)}, then at @math{(x+\delta_x,y+\delta_y)}, and so on. This draws a simple grid with every fifth line in bold (see also @ref{\graphpaper}). @example \begin@{picture@}(10,10) \linethickness@{0.05mm@} \multiput(0,0)(1,0)@{10@}@{\line(0,1)@{10@}@} \multiput(0,0)(0,1)@{10@}@{\line(1,0)@{10@}@} \linethickness@{0.5mm@} \multiput(0,0)(5,0)@{3@}@{\line(0,1)@{10@}@} \multiput(0,0)(0,5)@{3@}@{\line(1,0)@{10@}@} \end@{picture@} @end example @node \qbezier @subsection @code{\qbezier} @findex \qbezier Synopsis: @example \qbezier(@var{x1},@var{y1})(@var{x2},@var{y2})(@var{x3},@var{y3}) \qbezier[@var{num}](@var{x1},@var{y1})(@var{x2},@var{y2})(@var{x3},@var{y3}) @end example Draw a quadratic Bezier curve whose control points are given by the three required arguments @code{(@var{x1},@var{y1})}, @code{(@var{x2},@var{y2})}, and @code{(@var{x3},@var{y3})}. That is, the curve runs from @var{(x1,y1)} to @var{(x3,y3)}, is quadratic, and is such that the tangent line at @var{(x1,y1)} passes through @var{(x2,y2)}, as does the tangent line at @var{(x3,y3)}. This draws a curve from the coordinate (1,1) to (1,0). @example \qbezier(1,1)(1.25,0.75)(1,0) @end example @noindent The curve's tangent line at (1,1) contains (1.25,0.75), as does the curve's tangent line at (1,0). The optional argument @var{num} gives the number of calculated intermediate points. The default is to draw a smooth curve whose maximum number of points is @code{\qbeziermax} (change this value with @code{\renewcommand}). This draws a rectangle with a wavy top, using @code{\qbezier} for that curve. @example \begin@{picture@}(8,4) \put(0,0)@{\vector(1,0)@{8@}@} % x axis \put(0,0)@{\vector(0,1)@{4@}@} % y axis \put(2,0)@{\line(0,1)@{3@}@} % left side \put(4,0)@{\line(0,1)@{3.5@}@} % right side \qbezier(2,3)(2.5,2.9)(3,3.25) \qbezier(3,3.25)(3.5,3.6)(4,3.5) \thicklines % below here, lines are twice as thick \put(2,3)@{\line(4,1)@{2@}@} \put(4.5,2.5)@{\framebox@{Trapezoidal Rule@}@} \end@{picture@} @end example @node \graphpaper @subsection @code{\graphpaper} @findex \graphpaper Synopsis: @example \graphpaper(@var{x_init},@var{y_init})(@var{x_dimen},@var{y_dimen}) \graphpaper[@var{spacing}](@var{x_init},@var{y_init})(@var{x_dimen},@var{y_dimen}) @end example @PkgIndex{graphpap} Draw a coordinate grid. Requires the @package{graphpap} package. The grid's origin is @code{(@var{x_init},@var{y_init})}. Grid lines come every @var{spacing} units (the default is 10). The grid extends @var{x_dimen} units to the right and @var{y_dimen} units up. All arguments must be positive integers. This make a grid with seven vertical lines and eleven horizontal lines. @example \usepackage@{graphpap@} % in preamble ... \begin@{picture@}(6,20) % in document body \graphpaper[2](0,0)(12,20) \end@{picture@} @end example @noindent The lines are numbered every ten units. @node \line @subsection @code{\line} @findex \line Synopsis: @example \line(@var{x_run},@var{y_rise})@{@var{travel}@} @end example Draw a line. It slopes such that it vertically rises @var{y_rise} for every horizontal @var{x_run}. The @var{travel} is the total horizontal change---it is not the length of the vector, it is the change in @math{x}. In the special case of vertical lines, where (@var{x_run},@var{y_rise})=(0,1), the @var{travel} gives the change in @math{y}. This draws a line starting at coordinates (1,3). @example \put(1,3)@{\line(2,5)@{4@}@} @end example @noindent For every over 2, this line will go up 5. Because @var{travel} specifies that this goes over 4, it must go up@tie{}10. Thus its endpoint is @math{(1,3)+(4,10)=(5,13)}. In particular, note that @math{@var{travel}=4} is not the length of the line, it is the change in @math{x}. The arguments @var{x_run} and @var{y_rise} are integers that can be positive, negative, or zero. (If both are 0 then @LaTeX{} treats the second as 1.) With @code{\put(@var{x_init},@var{y_init})@{\line(@var{x_run},@var{y_rise})@{@var{travel}@}@}}, if @var{x_run} is negative then the line's ending point has a first coordinate that is less than @var{x_init}. If @var{y_rise} is negative then the line's ending point has a second coordinate that is less than @var{y_init}. If @var{travel} is negative then you get @code{LaTeX Error: Bad \line or \vector argument.} @cindex graphics packages @PkgIndex{pict2e} @PkgIndex{TikZ} @PkgIndex{PSTricks} @PkgIndex{MetaPost} @PkgIndex{Asymptote} Standard @LaTeX{} can only draw lines with a limited range of slopes because these lines are made by putting together line segments from pre-made fonts. The two numbers @var{x_run} and @var{y_rise} must have integer values from @minus{}6 through@tie{}6. Also, they must be relatively prime, so that @var{(x_run,y_rise)} can be (2,1) but not (4,2) (if you choose the latter then instead of lines you get sequences of arrowheads; the solution is to switch to the former). To get lines of arbitrary slope and plenty of other shapes in a system like @code{picture}, see the package @package{pict2e} (@url{https://ctan.org/pkg/pict2e}). Another solution is to use a full-featured graphics system such as TikZ, PSTricks, MetaPost, or Asymptote. @node \linethickness @subsection @code{\linethickness} @findex \linethickness Synopsis: @example \linethickness@{@var{dim}@} @end example Declares the thickness of subsequent horizontal and vertical lines in a picture to be @var{dim}, which must be a positive length (@pxref{Lengths}). It differs from @code{\thinlines} and @code{\thicklines} in that it does not affect the thickness of slanted lines, circles, or ovals (@pxref{\oval}). @node \thinlines @subsection @code{\thinlines} @findex \thinlines Declaration to set the thickness of subsequent lines, circles, and ovals in a picture environment to be 0.4@dmn{pt}. This is the default thickness, so this command is unnecessary unless the thickness has been changed with either @ref{\linethickness} or @ref{\thicklines}. @node \thicklines @subsection @code{\thicklines} @findex \thicklines Declaration to set the thickness of subsequent lines, circles, and ovals in a picture environment to be 0.8@dmn{pt}. See also @ref{\linethickness} and @ref{\thinlines}. This command is illustrated in the Trapezoidal Rule example of @ref{\qbezier}. @node \circle @subsection @code{\circle} @findex \circle Synopsis: @example \circle@{@var{diameter}@} \circle*@{@var{diameter}@} @end example Produces a circle with a diameter as close as possible to the specified one. The @code{*}@tie{}form produces a filled-in circle. This draws a circle of radius 6, centered at @code{(5,7)}. @example \put(5,7)@{\circle@{6@}@} @end example The available radii for @code{\circle} are, in points, the even numbers from 2 to 20, inclusive. For @code{\circle*} they are all the integers from 1 to 15. @node \oval @subsection @code{\oval} @findex \oval Synopsis: @example \oval(@var{width},@var{height}) \oval(@var{width},@var{height})[@var{portion}] @end example Produce a rectangle with rounded corners, hereinafter referred to as an @dfn{oval}. The optional argument @var{portion} allows you to produce only half or a quarter of the oval. For half an oval take @var{portion} to be one of these. @table @code @item t top half @item b bottom half @item r right half @item l left half @end table Produce only one quarter of the oval by setting @var{portion} to @code{tr}, @code{br}, @code{bl}, or @code{tl}. This draws the top half of an oval that is 3 wide and 7 tall. @example \put(5,7)@{\oval(3,7)[t]@} @end example @noindent The (5,7) is the center of the entire oval, not just the center of the top half. These shapes are not ellipses. They are rectangles whose corners are made with quarter circles. These circles have a maximum radius of 20@dmn{pt} (@pxref{\circle} for the sizes). Thus large ovals are just frames with a small amount of corner rounding. @node \shortstack @subsection @code{\shortstack} @findex \shortstack Synopsis: @example \shortstack[@var{position}]@{@var{line 1} \\ ... @} @end example Produce a vertical stack of objects. This labels the @math{y} axis by writing the word @samp{@math{y}} above the word @samp{axis}. @example \setlength@{\unitlength@}@{1cm@} \begin@{picture@}(5,2.5)(-0.75,0) \put(0,0)@{\vector(1,0)@{4@}@} % x axis \put(0,0)@{\vector(0,1)@{2@}@} % y \put(-0.2,2)@{\makebox(0,0)[r]@{\shortstack[r]@{$y$\\ axis@}@}@} \end@{picture@} @end example @noindent For a short stack, the reference point is the lower left of the stack. In the above example the @code{\makebox} (@pxref{\mbox & \makebox}) puts the stack flush right in a zero width box so in total the short stack sits slightly to the left of the @math{y}@tie{}axis. The valid positions are: @table @code @item r Make objects flush right @item l Make objects flush left @item c Center objects (default) @end table @findex \\ @r{(for @code{\shortstack} objects)} Separate objects into lines with @code{\\}. These stacks are short in that, unlike in a @code{tabular} or @code{array} environment, here the rows are not spaced out to be of even baseline skips. Thus, in @code{\shortstack@{X\\o\\o\\X@}} the first and last rows are taller than the middle two, and therefore the baseline skip between the two middle rows is smaller than that between the third and last row. You can adjust row heights and depths either by putting in the usual interline spacing with @code{\shortstack@{X\\ \strut o\\o\\X@}} (@pxref{\strut}), or explicitly, via an zero-width box @code{\shortstack@{X \\ \rule@{0pt@}@{12pt@} o\\o\\X@}} or by using @code{\\}'s optional argument @code{\shortstack@{X\\[2pt] o\\o\\X@}}. The @code{\shortstack} command is also available outside the @code{picture} environment. @node \vector @subsection @code{\vector} @findex \vector Synopsis: @example \vector(@var{x_run},@var{y_rise})@{@var{travel}@} @end example Draw a line ending in an arrow. The slope of that line is: it vertically rises @var{y_rise} for every horizontal @var{x_run}. The @var{travel} is the total horizontal change---it is not the length of the vector, it is the change in @math{x}. In the special case of vertical vectors, if (@var{x_run},@var{y_rise})=(0,1), then @var{travel} gives the change in @math{y}. For an example see @ref{picture}. For elaboration on @var{x_run} and @var{y_rise} see @ref{\line}. As there, the values of @var{x_run} and @var{y_rise} are limited. For @code{\vector} you must chooses integers between @minus{}4 and 4, inclusive. Also, the two you choose must be relatively prime. Thus, @code{\vector(2,1)@{4@}} is acceptable but @code{\vector(4,2)@{4@}} is not (if you use the latter then you get a sequence of arrowheads). @node \makebox (picture) @subsection @code{\makebox} (picture) @findex \makebox @r{(for @code{picture})} Synopsis: @example \makebox(@var{rec-width},@var{rec-height})@{@var{text}@} \makebox(@var{rec-width},@var{rec-height})[@var{position}]@{@var{text}@} @end example Make a box to hold @var{text}. This command fits with the @code{picture} environment, although you can use it outside of there, because @var{rec-width} and @var{rec-height} are numbers specifying distances in terms of the @code{\unitlength} (@pxref{picture}). This command is similar to the normal @code{\makebox} command (@pxref{\mbox & \makebox}) except here that you must specify the width and height. This command is fragile (@pxref{\protect}). This makes a box of length 3.5 times @code{\unitlength} and height 4 times @code{\unitlength}. @example \put(1,2)@{\makebox(3.5,4)@{...@}@} @end example The optional argument @code{@var{position}} specifies where in the box the @var{text} appears. The default is to center it, both horizontally and vertically. To place it somewhere else, use a string with one or two of these letters. @table @code @item t Puts @var{text} the top of the box. @item b Put @var{text} at the bottom. @item l Put @var{text} on the left. @item r Put @var{text} on the right. @end table @node \framebox (picture) @subsection @code{\framebox} (picture) @findex \framebox Synopsis: @example \framebox(@var{rec-width},@var{rec-height})@{@var{text}@} \framebox(@var{rec-width},@var{rec-height})[@var{position}]@{@var{text}@} @end example This is the same as @ref{\makebox (picture)} except that it puts a frame around the outside of the box that it creates. The reference point is the bottom left corner of the frame. This command fits with the @code{picture} environment, although you can use it outside of there, because lengths are numbers specifying the distance in terms of the @code{\unitlength} (@pxref{picture}). This command is fragile (@pxref{\protect}). This example creates a frame 2.5@tie{}inches by 3@tie{}inches and puts the text in the center. @example \setlength@{\unitlength@}@{1in@} \framebox(2.5,3)@{test text@} @end example The required arguments are that the rectangle has overall width @var{rect-width} units and height @var{rect-height} units. The optional argument @var{position} specifies the position of @var{text}; see @ref{\makebox (picture)} for the values that it can take. @findex \fboxrule @findex \fboxsep The rule has thickness @code{\fboxrule} and there is a blank space @code{\fboxsep} between the frame and the contents of the box. For this command, you must specify the @var{width} and @var{height}. If you want to just put a frame around some contents whose dimension is determined in some other way then either use @code{\fbox} (@pxref{\fbox & \framebox}) or @code{\frame} (@pxref{\frame}). @node \frame @subsection @code{\frame} @findex \frame Synopsis: @example \frame@{@var{contents}@} @end example Puts a rectangular frame around @var{contents}. The reference point is the bottom left corner of the frame. In contrast to @code{\framebox} (@pxref{\framebox (picture)}), this command puts no extra space between the frame and the object. It is fragile (@pxref{\protect}). @node \dashbox @subsection @code{\dashbox} @findex \dashbox Synopsis: @example \dashbox@{@var{dash-len}@}(@var{rect-width},@var{rect-height})@{@var{text}@} \dashbox@{@var{dash-len}@}(@var{rect-width},@var{rect-height})[@var{position}]@{@var{text}@} @end example Create a dashed rectangle around @var{text}. This command fits with the @code{picture} environment, although you can use it outside of there, because lengths are numbers specifying the distance in terms of the @code{\unitlength} (@pxref{picture}). The required arguments are: dashes are @var{dash-len} units long, with the same length gap, and the rectangle has overall width @var{rect-width} units and height @var{rect-height} units. The optional argument @var{position} specifies the position of @var{text}; see @ref{\makebox (picture)} for the values that it can take. This shows that you can use non-integer value for @var{dash-len}. @example \put(0,0)@{\dashbox@{0.1@}(5,0.5)@{My hovercraft is full of eels.@}@} @end example @noindent Each dash will be @code{0.1\unitlength} long, the box's width is @code{5\unitlength} and its height is @code{0.5\unitlength}. As in that example, a dashed box looks best when @var{rect-width} and @var{rect-height} are multiples of the @var{dash-len}. @node quotation & quote @section @code{quotation} & @code{quote} @anchor{quotation} @EnvIndex{quotation} @cindex quoted text with paragraph indentation, displaying @cindex displaying quoted text with paragraph indentation @cindex paragraph indentations in quoted text @anchor{quote} @EnvIndex{quote} @cindex quoted text without paragraph indentation, displaying @cindex displaying quoted text without paragraph indentation @cindex paragraph indentations in quoted text, omitting Synopsis: @example \begin@{quotation@} @var{text} \end@{quotation@} @end example @noindent or @example \begin@{quote@} @var{text} \end@{quote@} @end example Include a quotation. Both environments indent margins on both sides by @code{\leftmargin} and the text is right-justified. They differ in how they treat paragraphs. In the @code{quotation} environment, paragraphs are indented by 1.5@dmn{em} and the space between paragraphs is small, @code{0pt plus 1pt}. In the @code{quote} environment, paragraphs are not indented and there is vertical space between paragraphs (it is the rubber length @code{\parsep}). @example \begin@{quotation@} \small\it Four score and seven years ago ... shall not perish from the earth. \hspace@{1em plus 1fill@}---Abraham Lincoln \end@{quotation@} @end example @node tabbing @section @code{tabbing} @c xx TODO align on the French which is more precise and has more illustrative examples. @EnvIndex{tabbing} @cindex tab stops, using @cindex lining text up using tab stops @cindex alignment via tabbing Synopsis: @example \begin@{tabbing@} @var{row1col1} \= @var{row1col2} ... \\ @var{row2col1} \> @var{row2col2} ... \\ ... \end@{tabbing@} @end example Align text in columns, by setting tab stops and tabbing to them much as was done on a typewriter. This is less often used than the environments @code{tabular} (@pxref{tabular}) or @code{array} (@pxref{array}) because in those the width of each column need not be constant and need not be known in advance. This example has a first line where the tab stops are set to explicit widths, ended by a @code{\kill} command (which is described below): @example \begin@{tabbing@} \hspace@{1.2in@}\=\hspace@{1in@}\=\kill Ship \>Guns \>Year \\ \textit@{Sophie@} \>14 \>1800 \\ \textit@{Polychrest@} \>24 \>1803 \\ \textit@{Lively@} \>38 \>1804 \\ \textit@{Surprise@} \>28 \>1805 \\ \end@{tabbing@} @end example Both the @code{tabbing} environment and the more widely-used @code{tabular} environment put text in columns. The most important distinction is that in @code{tabular} the width of columns is determined automatically by @LaTeX{}, while in @code{tabbing} the user sets the tab stops. Another distinction is that @code{tabular} generates a box, but @code{tabbing} can be broken across pages. Finally, while @code{tabular} can be used in any mode, @code{tabbing} can be used only in paragraph mode and it always starts a new paragraph, without indentation. Moreover, as shown in the example above, there is no need to use the starred form of the @code{\hspace} command at the beginning of a tabbed row. The right margin of the @code{tabbing} environment is the end of line, so that the width of the environment is @code{\linewidth}. @cindex row, @r{tabbing} The @code{tabbing} environment contains a sequence of @dfn{tabbed rows}. The first tabbed row begins immediately after @code{\begin@{tabbing@}} and each row ends with @code{\\} or @code{\kill}. The last row may omit the @code{\\} and end with just @code{\end@{tabbing@}}. @cindex pattern, current tab stops, @r{tabbing} At any point the @code{tabbing} environment has a @dfn{current tab stop pattern}, a sequence of @math{@var{n} > 0} tab stops, numbered 0, 1, etc. These create @var{n} corresponding columns. Tab stop@tie{}0 is always the left margin, defined by the enclosing environment. Tab stop number@tie{}@var{i} is set if it is assigned a horizontal position on the page. Tab stop number@tie{}@var{i} can only be set if all the stops 0, @dots{}, @math{i-1} have already been set; normally later stops are to the right of earlier ones. By default any text typeset in a @code{tabbing} environment is typeset ragged right and left-aligned on the current tab stop. Typesetting is done in LR mode (@pxref{Modes}). The following commands can be used inside a @code{tabbing} environment. They are all fragile (@pxref{\protect}). @ftable @code @item \\ @r{(tabbing)} End a tabbed line and typeset it. @item \= @r{(tabbing)} Sets a tab stop at the current position. @item \> @r{(tabbing)} @findex \> Advances to the next tab stop. @item \< Put following text to the left of the local margin (without changing the margin). Can only be used at the start of the line. @item \+ Moves the left margin of the next and all the following commands one tab stop to the right, beginning tabbed line if necessary. @item \- Moves the left margin of the next and all the following commands one tab stop to the left, beginning tabbed line if necessary. @item \' @r{(tabbing)} Moves everything that you have typed so far in the current column, i.e., everything from the most recent @code{\>}, @code{\<}, @code{\'}, @code{\\}, or @code{\kill} command, to the previous column and aligned to the right, flush against the current column's tab stop. @item \` @r{(tabbing)} Allows you to put text flush right against any tab stop, including tab stop@tie{}0. However, it can't move text to the right of the last column because there's no tab stop there. The @code{\`} command moves all the text that follows it, up to the @code{\\} or @code{\end@{tabbing@}} command that ends the line, to the right margin of the @code{tabbing} environment. There must be no @code{\>} or @code{\'} command between the @code{\`} and the @code{\\} or @code{\end@{tabbing@}} command that ends the line. @item \a @r{(tabbing)} @findex \a' @r{(acute accent in tabbing)} @findex \a` @r{(grave accent in tabbing)} @findex \a= @r{(macron accent in tabbing)} In a @code{tabbing} environment, the commands @code{\=}, @code{\'} and @code{\`} do not produce accents as usual (@pxref{Accents}). Instead, use the commands @code{\a=}, @code{\a'} and @code{\a`}. @item \kill Sets tab stops without producing text. Works just like @code{\\} except that it throws away the current line instead of producing output for it. Any @code{\=}, @code{\+} or @code{\-} commands in that line remain in effect. @item \poptabs @findex \poptabs Restores the tab stop positions saved by the last @code{\pushtabs}. @item \pushtabs Saves all current tab stop positions. Useful for temporarily changing tab stop positions in the middle of a @code{tabbing} environment. @item \tabbingsep Distance of the text moved by @code{\'} to left of current tab stop. @end ftable This example typesets a Pascal function: @example \begin@{tabbing@} function \= fact(n : integer) : integer;\\ \> begin \= \+ \\ \> if \= n > 1 then \+ \\ fact := n * fact(n-1) \- \\ else \+ \\ fact := 1; \-\- \\ end;\\ \end@{tabbing@} @end example @noindent The output looks like this. @example function fact(n : integer) : integer; begin if n > 1 then fact := n * fact(n-1); else fact := 1; end; @end example @PkgIndex{algorithm2e} @PkgIndex{listings} @PkgIndex{minted} @PkgIndex{fancyvrb} @noindent This example is just for illustration of the environment. To actually typeset computer code in typewriter like this, a verbatim environment (@pxref{verbatim}) would normally be best. For pretty-printed code, there are quite a few packages, including @package{algorithm2e}, @package{fancyvrb}, @package{listings}, and @package{minted}. @node table @section @code{table} @EnvIndex{table} @cindex tables, creating @cindex creating tables Synopsis: @example \begin@{table@}[@var{placement}] @var{table body} \caption[@var{loftitle}]@{@var{title}@} % optional \label@{@var{label@}} % also optional \end@{table@} @end example A class of floats (@pxref{Floats}). They cannot be split across pages and so they are not typeset in sequence with the normal text but instead are floated to a convenient place, such as the top of a following page. This example @code{table} environment contains a @code{tabular} @example \begin@{table@} \centering\small \begin@{tabular@}@{ll@} \multicolumn@{1@}@{c@}@{\textit@{Author@}@} &\multicolumn@{1@}@{c@}@{\textit@{Piece@}@} \\ \hline Bach &Cello Suite Number 1 \\ Beethoven &Cello Sonata Number 3 \\ Brahms &Cello Sonata Number 1 \end@{tabular@} \caption@{Top cello pieces@} \label@{tab:cello@} \end@{table@} @end example @noindent but you can put many different kinds of content in a @code{table}: the @var{table body} may contain text, @LaTeX{} commands, graphics, etc. It is typeset in a @code{parbox} of width @code{\textwidth}. For the possible values of @var{placement} and their effect on the float placement algorithm, see @ref{Floats}. The label is optional; it is used for cross references (@pxref{Cross references}). @findex \caption The @code{\caption} command is also optional. It specifies caption text @var{title} for the table (@pxref{\caption}). By default it is numbered. If its optional @var{lottitle} is present then that text is used in the list of tables instead of @var{title} (@pxref{Table of contents etc.}). In this example the table and caption will float to the bottom of a page, unless it is pushed to a float page at the end. @example \begin@{table@}[b] \centering \begin@{tabular@}@{r|p@{2in@}@} \hline One &The loneliest number \\ Two &Can be as sad as one. It's the loneliest number since the number one. \end@{tabular@} \caption@{Cardinal virtues@} \label@{tab:CardinalVirtues@} \end@{table@} @end example @node tabular @section @code{tabular} @EnvIndex{tabular} @cindex lines in tables @cindex lining text up in tables Synopsis: @example \begin@{tabular@}[@var{pos}]@{@var{cols}@} @var{column 1 entry} &@var{column 2 entry} ... &@var{column n entry} \\ ... \end@{tabular@} @end example @noindent or @example \begin@{tabular*@}@{@var{width}@}[@var{pos}]@{@var{cols}@} @var{column 1 entry} &@var{column 2 entry} ... &@var{column n entry} \\ ... \end@{tabular*@} @end example Produce a table, a box consisting of a sequence of horizontal rows. Each row consists of items that are aligned vertically in columns. This illustrates many of the features. @example \begin@{tabular@}@{l|l@} \textit@{Player name@} &\textit@{Career home runs@} \\ \hline Hank Aaron &755 \\ Babe Ruth &714 \end@{tabular@} @end example @noindent The output will have two left-aligned columns with a vertical bar between them. This is specified in @code{tabular}'s argument @code{@{l|l@}}. @findex & @r{(for table cells)} Put the entries into different columns by separating them with an ampersand, @code{&}. The end of each row is marked with a double backslash, @code{\\}. Put a horizontal rule below a row, after a double backslash, with @code{\hline}. @findex \\ @r{(for @code{tabular})} After the last row the @code{\\} is optional, unless an @code{\hline} command follows to put a rule below the table. The required and optional arguments to @code{tabular} consist of: @table @var @item pos Optional. Specifies the table's vertical position. The default is to align the table so its vertical center matches the baseline of the surrounding text. There are two other possible alignments: @code{t} aligns the table so its top row matches the baseline of the surrounding text, and @code{b} aligns on the bottom row. This only has an effect if there is other text. In the common case of a @code{tabular} alone in a @code{center} environment this option makes no difference. @item cols Required. Specifies the formatting of columns. It consists of a sequence of the following specifiers, corresponding to the types of column and intercolumn material. @table @code @item l A column of left-aligned items. @item r A column of right-aligned items. @item c A column of centered items. @item | A vertical line the full height and depth of the environment. @item @@@{@var{text or space}@} Insert @var{text or space} at this location in every row. The @var{text or space} material is typeset in LR mode. This text is fragile (@pxref{\protect}). If between two column specifiers there is no @@-expression then @LaTeX{}'s @code{book}, @code{article}, and @code{report} classes will put on either side of each column a space of width @code{\tabcolsep}, which by default is 6@dmn{pt}. That is, by default adjacent columns are separated by 12@dmn{pt} (so @code{\tabcolsep} is misleadingly named since it is only half of the separation between tabular columns). In addition, a space of @code{\tabcolsep} also comes before the first column and after the final column, unless you put a @code{@@@{...@}} there. If you override the default and use an @@-expression then @LaTeX{} does not insert @code{\tabcolsep} so you must insert any desired space yourself, as in @code{@@@{\hspace@{1em@}@}}. An empty expression @code{@@@{@}} will eliminate the space. In particular, sometimes you want to eliminate the space before the first column or after the last one, as in the example below where the tabular lines need to lie on the left margin. @example \begin@{flushleft@} \begin@{tabular@}@{@@@{@}l@} ... \end@{tabular@} \end@{flushleft@} @end example The next example shows text, a decimal point between the columns, arranged so the numbers in the table are aligned on it. @example \begin@{tabular@}@{r@@@{$.$@}l@} $3$ &$14$ \\ $9$ &$80665$ \end@{tabular@} @end example @anchor{\extracolsep} @findex \extracolsep An @code{\extracolsep@{@var{wd}@}} command in an @@-expression causes an extra space of width @var{wd} to appear to the left of all subsequent columns, until countermanded by another @code{\extracolsep}. Unlike ordinary intercolumn space, this extra space is not suppressed by an @@-expression. An @code{\extracolsep} command can be used only in an @@-expression in the @code{cols} argument. Below, @LaTeX{} inserts the right amount of intercolumn space to make the entire table 4 inches wide. @example \begin@{tabular*@}@{4in@}@{l@@@{\extracolsep@{\fill@}@}l@} Seven times down, eight times up \ldots &such is life! \end@{tabular*@} @end example To insert commands that are automatically executed before a given column, load the @code{array} package and use the @code{>@{...@}} specifier. @c xx should fully explain array, tabularx, and all other base packages... @item p@{@var{wd}@} Each item in the column is typeset in a parbox of width @var{wd}, as if it were the argument of a @code{\parbox[t]@{wd@}@{...@}} command. A line break double backslash @code{\\} may not appear in the item, except inside an environment like @code{minipage}, @code{array}, or @code{tabular}, or inside an explicit @code{\parbox}, or in the scope of a @code{\centering}, @code{\raggedright}, or @code{\raggedleft} declaration (when used in a @code{p}-column element these declarations must appear inside braces, as with @code{@{\centering .. \\ ..@}}). Otherwise @LaTeX{} will misinterpret the double backslash as ending the tabular row. Instead, to get a line break in there use @code{\newline} (@pxref{\newline}). @item *@{@var{num}@}@{@var{cols}@} Equivalent to @var{num} copies of @var{cols}, where @var{num} is a positive integer and @var{cols} is a list of specifiers. Thus the specifier @code{\begin@{tabular@}@{|*@{3@}@{l|r@}|@}} is equivalent to the specifier @code{\begin@{tabular@}@{|l|rl|rl|r|@}}. Note that @var{cols} may contain another @code{*}-expression. @end table @item width Required for @code{tabular*}, not allowed for @code{tabular}. Specifies the width of the @code{tabular*} environment. The space between columns should be rubber, as with @code{@@@{\extracolsep@{\fill@}@}}, to allow the table to stretch or shrink to make the specified width, or else you are likely to get the @code{Underfull \hbox (badness 10000) in alignment ...} warning. @end table Parameters that control formatting: @c xx defaults, own node (xref from array)? @ftable @code @item \arrayrulewidth @anchor{tabular arrayrulewidth} A length that is the thickness of the rule created by @code{|}, @code{\hline}, and @code{\vline} in the @code{tabular} and @code{array} environments. The default is @samp{.4pt}. Change it as in @code{\setlength@{\arrayrulewidth@}@{0.8pt@}}. @item \arraystretch @anchor{tabular arraystrech} A factor by which the spacing between rows in the @code{tabular} and @code{array} environments is multiplied. The default is @samp{1}, for no scaling. Change it as @code{\renewcommand@{\arraystretch@}@{1.2@}}. @item \doublerulesep @anchor{tabular doublerulesep} A length that is the distance between the vertical rules produced by the @code{||} specifier. The default is @samp{2pt}. @item \tabcolsep @anchor{tabular tabcolsep} A length that is half of the space between columns. The default is @samp{6pt}. Change it with @code{\setlength}. @end ftable The following commands can be used inside the body of a @code{tabular} environment, the first two inside an entry and the second two between lines: @menu * \multicolumn:: Make an item spanning several columns. * \vline:: Draw a vertical line. * \cline:: Draw a horizontal line spanning some columns. * \hline:: Draw a horizontal line spanning all columns. @end menu @node \multicolumn @subsection @code{\multicolumn} @findex \multicolumn Synopsis: @example \multicolumn@{@var{numcols}@}@{@var{cols}@}@{@var{text}@} @end example Make an @code{array} or @code{tabular} entry that spans several columns. The first argument @var{numcols} gives the number of columns to span. The second argument @var{cols} specifies the formatting of the entry, with @code{c} for centered, @code{l} for flush left, or @code{r} for flush right. The third argument @var{text} gives the contents of that entry. In this example, in the first row, the second and third columns are spanned by the single heading @samp{Name}. @example \begin@{tabular@}@{lccl@} \textit@{ID@} &\multicolumn@{2@}@{c@}@{\textit@{Name@}@} &\textit@{Age@} \\ \hline 978-0-393-03701-2 &O'Brian &Patrick &55 \\ ... \end@{tabular@} @end example What counts as a column is:@tie{}the column format specifier for the @code{array} or @code{tabular} environment is broken into parts, where each part (except the first) begins with @code{l}, @code{c}, @code{r}, or@tie{}@code{p}. So from @code{\begin@{tabular@}@{|r|ccp@{1.5in@}|@}} the parts are @code{|r|}, @code{c}, @code{c}, and@tie{}@code{p@{1.5in@}|}. The @var{cols} argument overrides the @code{array} or @code{tabular} environment's intercolumn area default adjoining this multicolumn entry. To affect that area, this argument can contain vertical bars @code{|} indicating the placement of vertical rules, and @code{@@@{...@}} expressions. Thus if @var{cols} is @samp{|c|} then this multicolumn entry will be centered and a vertical rule will come in the intercolumn area before it and after it. This table details the exact behavior. @example \begin@{tabular@}@{|cc|c|c|@} \multicolumn@{1@}@{r@}@{w@} % entry one &\multicolumn@{1@}@{|r|@}@{x@} % entry two &\multicolumn@{1@}@{|r@}@{y@} % entry three &z % entry four \end@{tabular@} @end example @noindent Before the first entry the output will not have a vertical rule because the @code{\multicolumn} has the @var{cols} specifier @samp{r} with no initial vertical bar. Between entry one and entry two there will be a vertical rule; although the first @var{cols} does not have an ending vertical bar, the second @var{cols} does have a starting one. Between entry two and entry three there is a single vertical rule; despite that the @var{cols} in both of the surrounding @code{multicolumn}'s call for a vertical rule, you only get one rule. Between entry three and entry four there is no vertical rule; the default calls for one but the @var{cols} in the entry three @code{\multicolumn} leaves it out, and that takes precedence. Finally, following entry four there is a vertical rule because of the default. The number of spanned columns @var{numcols} can be 1. Besides giving the ability to change the horizontal alignment, this also is useful to override for one row the @code{tabular} definition's default intercolumn area specification, including the placement of vertical rules. In the example below, in the @code{tabular} definition the first column is specified to default to left justified but in the first row the entry is centered with @code{\multicolumn@{1@}@{c@}@{\textsc@{Period@}@}}. Also in the first row, the second and third columns are spanned by a single entry with @code{\multicolumn@{2@}@{c@}@{\textsc@{Span@}@}}, overriding the specification to center those two columns on the page range en-dash. @example \begin@{tabular@}@{l|r@@@{--@}l@} \multicolumn@{1@}@{c@}@{\textsc@{Period@}@} &\multicolumn@{2@}@{c@}@{\textsc@{Span@}@} \\ \hline Baroque &1600 &1760 \\ Classical &1730 &1820 \\ Romantic &1780 &1910 \\ Impressionistic &1875 &1925 \end@{tabular@} @end example @noindent Although the @code{tabular} specification by default puts a vertical rule between the first and second columns, no such vertical rule appears in the first row here. That's because there is no vertical bar in the @var{cols} part of the first row's first @code{\multicolumn} command. @node \vline @subsection @code{\vline} @findex \vline Draw a vertical line in a @code{tabular} or @code{array} environment extending the full height and depth of an entry's row. Can also be used in an @@-expression, although its synonym vertical bar@tie{}@code{|} is more common. This command is rarely used in the body of a table; typically a table's vertical lines are specified in @code{tabular}'s @var{cols} argument and overridden as needed with @code{\multicolumn} (@pxref{tabular}). The example below illustrates some pitfalls. In the first row's second entry the @code{\hfill} moves the @code{\vline} to the left edge of the cell. But that is different than putting it halfway between the two columns, so between the first and second columns there are two vertical rules, with the one from the @code{@{c|cc@}} specifier coming before the one produced by the @code{\vline\hfill}. In contrast, the first row's third entry shows the usual way to put a vertical bar between two columns. In the second row, the @code{ghi} is the widest entry in its column so in the @code{\vline\hfill} the @code{\hfill} has no effect and the vertical line in that entry appears immediately next to the @code{g}, with no whitespace. @example \begin@{tabular@}@{c|cc@} x &\vline\hfill y &\multicolumn@{1@}@{|r@}@{z@} \\ % row 1 abc &def &\vline\hfill ghi % row 2 \end@{tabular@} @end example @node \cline @subsection @code{\cline} @findex \cline Synopsis: @example \cline@{@var{i}-@var{j}@} @end example In an @code{array} or @code{tabular} environment, draw a horizontal rule beginning in column@tie{}@var{i} and ending in column@tie{}@var{j}. The dash, @code{-}, must appear in the mandatory argument. To span a single column use the number twice, as with @code{\cline@{2-2@}}. This example puts two horizontal lines between the first and second rows, one line in the first column only, and the other spanning the third and fourth columns. The two lines are side-by-side, at the same height. @example \begin@{tabular@}@{llrr@} a &b &c &d \\ \cline@{1-1@} \cline@{3-4@} e &f &g &h \end@{tabular@} @end example @node \hline @subsection @code{\hline} @findex \hline Draw a horizontal line the width of the enclosing @code{tabular} or @code{array} environment. It's most commonly used to draw a line at the top, bottom, and between the rows of a table. In this example the top of the table has two horizontal rules, one above the other, that span both columns. The bottom of the table has a single rule spanning both columns. Because of the @code{\hline}, the @code{tabular} second row's line ending double backslash@tie{}@code{\\} is required. @example \begin@{tabular@}@{ll@} \hline\hline Baseball &Red Sox \\ Basketball &Celtics \\ \hline \end@{tabular@} @end example @node thebibliography @section @code{thebibliography} @EnvIndex{thebibliography} @cindex bibliography, creating (manually) Synopsis: @example \begin@{thebibliography@}@{@var{widest-label}@} \bibitem[@var{label}]@{@var{cite_key@}} ... \end@{thebibliography@} @end example Produce a bibliography or reference list. There are two ways to produce bibliographic lists. This environment is suitable when you have only a few references and can maintain the list by hand. @xref{Using BibTeX}, for a more sophisticated approach. This shows the environment with two entries. @example This work is based on \cite@{latexdps@}. Together they are \cite@{latexdps, texbook@}. ... \begin@{thebibliography@}@{9@} \bibitem@{latexdps@} Leslie Lamport. \textit@{\LaTeX@{@}: a document preparation system@}. Addison-Wesley, Reading, Massachusetts, 1993. \bibitem@{texbook@} Donald Ervin Knuth. \textit@{The \TeX book@}. Addison-Wesley, Reading, Massachusetts, 1983. \end@{thebibliography@} @end example @noindent This styles the first reference as @samp{[1] Leslie ...}, and so that @code{... based on \cite@{latexdps@}} produces the matching @samp{... based on [1]}. The second @code{\cite} produces @samp{[1, 2]}. You must compile the document twice to resolve these references. The mandatory argument @var{widest-label} is text that, when typeset, is as wide as the widest item label produced by the @code{\bibitem} commands. The tradition is to use @code{9} for bibliographies with less than 10 references, @code{99} for ones with less than 100, etc. @findex \bibname @findex \refname The bibliographic list is headed by a title such as @samp{Bibliography}. To change it there are two cases. In the @file{book} and @file{report} classes, where the top level sectioning is @code{\chapter} and the default title is @samp{Bibliography}, that title is in the macro @code{\bibname}. For @file{article}, where the class's top level sectioning is @code{\section} and the default is @samp{References}, the title is in macro @code{\refname}. Change it by redefining the command, as with @code{\renewcommand@{\refname@}@{Cited references@}}, after @code{\begin@{document@}}. @PkgIndex{babel} Language support packages such as @package{babel} will automatically redefine @code{\refname} or @code{\bibname} to fit the selected language. @xref{list}, for the list layout control parameters. @menu * \bibitem:: Specify a bibliography item. * \cite:: Refer to a bibliography item. * \nocite:: Include an item in the bibliography. * Using BibTeX:: Automatic generation of bibliographies. @end menu @node \bibitem @subsection @code{\bibitem} @findex \bibitem Synopsis: @example \bibitem@{@var{cite_key}@} @end example @noindent or @example \bibitem[@var{label}]@{@var{cite_key}@} @end example Generate an entry labeled by default by a number generated using the @code{enumi} counter. The @dfn{citation key} @cindex citation key @var{cite_key} can be any string of letters, numbers, and punctuation symbols (but not comma). @xref{thebibliography}, for an example. When provided, the optional @var{label} becomes the entry label and the @code{enumi} counter is not incremented. With this @example \begin@{thebibliography@} \bibitem[Lamport 1993]@{latexdps@} Leslie Lamport. \textit@{\LaTeX@{@}: a document preparation system@}. Addison-Wesley, Reading, Massachusetts, 1993. \bibitem@{texbook@} Donald Ervin Knuth. \textit@{The \TeX book@}. Addison-Wesley, Reading, Massachusetts, 1983. \end@{thebibliography@} @end example @noindent the first entry will be styled as @samp{[Lamport 1993] Leslie ...} (The amount of horizontal space that @LaTeX{} leaves for the label depends on the @var{widest-label} argument of the @code{thebibliography} environment; see @ref{thebibliography}.) Similarly, @code{... based on \cite@{latexdps@}} will produce @samp{... based on [Lamport 1994]}. If you mix @code{\bibitem} entries having a @var{label} with those that do not then @LaTeX{} will number the unlabelled ones sequentially. In the example above the @code{texbook} entry will appear as @samp{[1] Donald ...}, despite that it is the second entry. If you use the same @var{cite_key} twice then you get @samp{LaTeX Warning: There were multiply-defined labels}. Under the hood, @LaTeX{} remembers the @var{cite_key} and @var{label} information because @code{\bibitem} writes it to the auxiliary file @file{@var{jobname}.aux} (@pxref{Jobname}). For instance, the above example causes the two @code{\bibcite@{latexdps@}@{Lamport, 1993@}} and @code{\bibcite@{texbook@}@{1@}} to appear in that file. The @file{.aux} file is read by the @code{\begin@{document@}} command and then the information is available for @code{\cite} commands. This explains why you need to run @LaTeX{} twice to resolve references: once to write it out and once to read it in. Because of this two-pass algorithm, when you add a @code{\bibitem} or change its @var{cite_key} you may get @samp{LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right}. Fix it by recompiling. @node \cite @subsection @code{\cite} @findex \cite Synopsis: @example \cite@{@var{keys}@} @end example @noindent or @example \cite[@var{subcite}]@{@var{keys}@} @end example Generate as output a citation to the references associated with @var{keys}. The mandatory @var{keys} is a citation key, or a comma-separated list of citation keys (@pxref{\bibitem}). This @example The ultimate source is \cite@{texbook@}. ... \begin@{thebibliography@} \bibitem@{texbook@} Donald Ervin Knuth. \textit@{The \TeX book@}. Addison-Wesley, Reading, Massachusetts, 1983. \end@{thebibliography@} @end example @noindent produces output like @samp{... source is [1]}. You can change the appearance of the citation and of the reference by using bibliography styles if you generate automatically the @code{thebibliography} environment. More information in @ref{Using BibTeX}. The optional argument @var{subcite} is appended to the citation. For example, @code{See 14.3 in \cite[p.~314]@{texbook@}} might produce @samp{See 14.3 in [1, p.@tie{}314]}. In addition to what appears in the output, @code{\cite} writes information to the auxiliary file @file{@var{jobname}.aux} (@pxref{Jobname}). For instance, @code{\cite@{latexdps@}} writes @samp{\citation@{latexdps@}} to that file. This information is used by Bib@TeX{} to include in your reference list only those works that you have actually cited; see @ref{\nocite} also. If @var{keys} is not in your bibliography information then you get @samp{LaTeX Warning: There were undefined references}, and in the output the citation shows as a boldface question mark between square brackets. There are two possible causes. If you have mistyped something, as in @code{\cite@{texbok@}} then you need to correct the spelling. On the other hand, if you have just added or modified the bibliographic information and so changed the @file{.aux} file (@pxref{\bibitem}) then the fix may be to run @LaTeX{} again. @node \nocite @subsection @code{\nocite} @findex \nocite Synopsis: @example @code{\nocite@{@var{keys}@}} @end example Produces no output but writes @var{keys} to the auxiliary file @file{@var{jobname}.aux} (@pxref{Jobname}). The mandatory argument @var{keys} is a comma-separated list of one or more citation keys (@pxref{\bibitem}). This information is used by Bib@TeX{} to include these works in your reference list even though you have not explicitly cited them (@pxref{\cite}). @node Using BibTeX @subsection Using Bib@TeX{} @cindex using Bib@TeX{} @cindex bib@TeX{}, using @cindex bibliography, creating (automatically) @findex \bibliographystyle @findex \bibliography As described in @code{thebibliography} (@pxref{thebibliography}), a sophisticated approach to managing bibliographies is provided by the Bib@TeX{} program. This is only an introduction; see the full documentation on CTAN (@pxref{CTAN}). With Bib@TeX{}, you don't use the @code{thebibliography} environment directly (@pxref{thebibliography}). Instead, include these lines: @example \bibliographystyle@{@var{bibstyle}@} \bibliography@{@var{bibfile1}, @var{bibfile2}, ...@} @end example @noindent The @var{bibstyle} refers to a file @file{@var{bibstyle}.bst}, which defines how your citations will look. The standard @var{bibstyle}'s distributed with Bib@TeX{} are: @table @code @item alpha Labels are formed from name of author and year of publication. The bibliographic items are sorted alphabetically. @item plain Labels are integers. Sort the bibliographic items alphabetically. @item unsrt Like @code{plain}, but entries are in order of citation. @item abbrv Like @code{plain}, but more compact labels. @end table @noindent Many, many other Bib@TeX{} style files exist, tailored to the demands of various publications. See the CTAN topic @url{https://ctan.org/topic/bibtex-sty}. The @code{\bibliography} command is what actually produces the bibliography. Its argument is a comma-separated list, referring to files named @file{@var{bibfile1}.bib}, @file{@var{bibfile2}.bib}, @dots{} These contain your database in Bib@TeX{} format. This shows a typical couple of entries in that format. @example @@book@{texbook, title = @{The @{@{\TeX@}@}book@}, author = @{D.E. Knuth@}, isbn = @{0201134489@}, series = @{Computers \& typesetting@}, year = @{1983@}, publisher = @{Addison-Wesley@} @} @@book@{sexbook, author = @{W.H. Masters and V.E. Johnson@}, title = @{Human Sexual Response@}, year = @{1966@}, publisher = @{Bantam Books@} @} @end example Only the bibliographic entries referred to via @code{\cite} and @code{\nocite} will be listed in the document's bibliography. Thus you can keep all your sources together in one file, or a small number of files, and rely on Bib@TeX{} to include in this document only those that you used. @cindex @samp{*}, to @code{\nocite} all keys @findex \nocite @r{@{*@}, for all keys} With Bib@TeX{}, the @var{keys} argument to @code{\nocite} can also be the single character @samp{*}. This means to implicitly cite all entries from all given bibliographies. @menu * Bib@TeX{} error messages:: @end menu @node Bib@TeX{} error messages @subsubsection Bib@TeX{} error messages @cindex Bib@TeX{} error messages @cindex error messages, from Bib@TeX{} @findex .aux @r{file and Bib@TeX{} commands} If you forget to use @code{\bibliography} or @code{\bibliographystyle} in your document (or, less likely, any @code{\cite} or @code{\nocite} command), Bib@TeX{} will issue an error message. Because Bib@TeX{} can be used with any program, not just @LaTeX{}, the error messages refer to the internal commands read by Bib@TeX{} (from the @file{.aux} file), rather than the user-level commands described above. Here is a table showing internal commands mentioned in the Bib@TeX{} errors, and the corresponding user-level commands. @ftable @code @item \bibdata @findex \bibliography @r{and internal @code{\bibdata}} @code{\bibliography} @item \bibstyle @findex \bibliographystyle @r{and internal @code{\bibstyle}} @code{\bibliographystyle} @item \citation @findex \cite @r{and internal @code{\citation}} @findex \nocite @r{and internal @code{\citation}} @code{\cite}, @code{\nocite} @end ftable For example, if your document has no @code{\bibliographystyle} command, Bib@TeX{} complains as follows: @example I found no \bibstyle command---while reading file @var{document}.aux @end example @node theorem @section @code{theorem} @EnvIndex{theorem} @cindex theorems, typesetting Synopsis: @example \begin@{theorem@} @var{theorem body} \end@{theorem@} @end example Produces @samp{Theorem @var{n}} in boldface followed by @var{theorem body} in italics. The numbering possibilities for @var{n} are described under @code{\newtheorem} (@pxref{\newtheorem}). @example \newtheorem@{lem@}@{Lemma@} % in preamble \newtheorem@{thm@}@{Theorem@} ... \begin@{lem@} % in document body text of lemma \end@{lem@} The next result follows immediately. \begin@{thm@}[Gauss] % put `Gauss' in parens after theorem head text of theorem \end@{thm@} @end example @PkgIndex{amsmath} @PkgIndex{amsthm} Most new documents use the packages @package{amsthm} and @package{amsmath} from the American Mathematical Society. Among other things these packages include a large number of options for theorem environments, such as styling options. @node titlepage @section @code{titlepage} @EnvIndex{titlepage} @cindex making a title page @cindex title pages, creating Synopsis: @example \begin@{titlepage@} ... text and spacing ... \end@{titlepage@} @end example Create a title page, a page with no printed page number or heading and with succeeding pages numbered starting with page one. In this example all formatting, including vertical spacing, is left to the author. @example \begin@{titlepage@} \vspace*@{\stretch@{1@}@} \begin@{center@} @{\huge\bfseries Thesis \\[1ex] title@} \\[6.5ex] @{\large\bfseries Author name@} \\ \vspace@{4ex@} Thesis submitted to \\[5pt] \textit@{University name@} \\[2cm] in partial fulfilment for the award of the degree of \\[2cm] \textsc@{\Large Doctor of Philosophy@} \\[2ex] \textsc@{\large Mathematics@} \\[12ex] \vfill Department of Mathematics \\ Address \\ \vfill \today \end@{center@} \vspace@{\stretch@{2@}@} \end@{titlepage@} @end example To instead produce a standard title page without a @code{titlepage} environment, use @code{\maketitle} (@pxref{\maketitle}). @node verbatim @section @code{verbatim} @EnvIndex{verbatim} @cindex verbatim text @cindex simulating typed text @cindex typed text, simulating @cindex code, typesetting @cindex computer programs, typesetting Synopsis: @example \begin@{verbatim@} @var{literal-text} \end@{verbatim@} @end example A paragraph-making environment in which @LaTeX{} produces as output exactly what you type as input. For instance inside @var{literal-text} the backslash@tie{}@code{\} character does not start commands, it produces a printed @samp{\}, and carriage returns and blanks are taken literally. The output appears in a monospaced typewriter-like font (@code{\tt}). @example \begin@{verbatim@} Symbol swearing: %&$#?@!. \end@{verbatim@} @end example The only restriction on @code{literal-text} is that it cannot include the string @code{\end@{verbatim@}}. @PkgIndex{cprotect} You cannot use the verbatim environment in the argument to macros, for instance in the argument to a @code{\section}. This is not the same as commands being fragile (@pxref{\protect}), instead it just cannot work, as the @code{verbatim} environment changes the catcode regime before processing its contents, and restore it immediately afterward, nevertheless with a macro argument the content of the argument has already be converted to a token list along the catcode regime in effect when the macro was called. However, the @package{cprotect} package can help with this. @PkgIndex{listings} @PkgIndex{minted} One common use of verbatim input is to typeset computer code. There are packages that are an improvement the @code{verbatim} environment. For instance, one improvement is to allow the verbatim inclusion of external files, or parts of those files. Such packages include @package{listings}, and @package{minted}. @PkgIndex{fancyvrb} @PkgIndex{verbatimbox} A package that provides many more options for verbatim environments is @package{fancyvrb}. Another is @package{verbatimbox}. For a list of all the relevant packages, see CTAN (@pxref{CTAN}). @menu * \verb:: The macro form of the @code{verbatim} environment. @end menu @node \verb @subsection @code{\verb} @findex \verb @cindex verbatim text, inline Synopsis: @example \verb @var{char} @var{literal-text} @var{char} \verb* @var{char} @var{literal-text} @var{char} @end example Typeset @var{literal-text} as it is input, including special characters and spaces, using the typewriter (@code{\tt}) font. This example shows two different invocations of @code{\verb}. @example This is \verb!literally! the biggest pumpkin ever. And this is the best squash, \verb+literally!+ @end example @noindent The first @code{\verb} has its @var{literal-text} surrounded with exclamation point, @code{!}. The second instead uses plus, @code{+}, because the exclamation point is part of @code{literal-text}. The single-character delimiter @var{char} surrounds @var{literal-text}---it must be the same character before and after. No spaces come between @code{\verb} or @code{\verb*} and @var{char}, or between @var{char} and @var{literal-text}, or between @var{literal-text} and the second occurrence of @var{char} (the synopsis shows a space only to distinguish one component from the other). The delimiter must not appear in @var{literal-text}. The @var{literal-text} cannot include a line break. @cindex visible space The @code{*}-form differs only in that spaces are printed with a visible space character. @tex (Namely, {\tt\char`\ }.) @end tex The output from this will include a visible space on both side of word @samp{with}: @example The command's first argument is \verb*!filename with extension! and ... @end example @PkgIndex{url} For typesetting Internet addresses, urls, the package @package{url} is a better option than the @code{\verb} command, since it allows line breaks. @PkgIndex{listings} @PkgIndex{minted} For computer code there are many packages with advantages over @code{\verb}. One is @package{listings}, another is @package{minted}. @PkgIndex{cprotect} You cannot use @code{\verb} in the argument to a macro, for instance in the argument to a @code{\section}. It is not a question of @code{\verb} being fragile (@pxref{\protect}), instead it just cannot work, as the @code{\verb} command changes the catcode regime before reading its argument, and restore it immediately afterward, nevertheless with a macro argument the content of the argument has already be converted to a token list along the catcode regime in effect when the macro was called. However, the @package{cprotect} package can help with this. @node verse @section @code{verse} @EnvIndex{verse} @cindex poetry, an environment for Synopsis: @example \begin@{verse@} @var{line1} \\ @var{line2} \\ ... \end@{verse@} @end example An environment for poetry. Here are two lines from Shakespeare's Romeo and Juliet. @example Then plainly know my heart's dear love is set \\ On the fair daughter of rich Capulet. @end example @findex \\ @r{(for @code{verse})} Separate the lines of each stanza with @code{\\}, and use one or more blank lines to separate the stanzas. @example \begin@{verse@} \makebox[\linewidth][c]@{\textit@{Shut Not Your Doors@} ---Walt Whitman@} \\[1\baselineskip] Shut not your doors to me proud libraries, \\ For that which was lacking on all your well-fill'd shelves, \\ \qquad yet needed most, I bring, \\ Forth from the war emerging, a book I have made, \\ The words of my book nothing, the drift of it every thing, \\ A book separate, not link'd with the rest nor felt by the intellect, \\ But you ye untold latencies will thrill to every page. \end@{verse@} @end example @noindent The output has margins indented on the left and the right, paragraphs are not indented, and the text is not right-justified. @node Line breaking @chapter Line breaking @cindex line breaking @cindex breaking lines The first thing @LaTeX{} does when processing ordinary text is to translate your input file into a sequence of glyphs and spaces. To produce a printed document, this sequence must be broken into lines (and these lines must be broken into pages). @LaTeX{} usually does the line (and page) breaking in the text body for you but in some environments you manually force line breaks. A common workflow is to get a final version of the document content before taking a final pass through and considering line breaks (and page breaks). This differs from word processing, where you are formatting text as you input it. Putting these off until the end prevents a lot of fiddling with breaks that will change anyway. @c Alernative text proposed here: https://tug.org/pipermail/latexrefman/2021q3/000803.html @c this text is that of the French version. @ignore A common workflow with LaTeX is to get a final version of the document content before taking a final pass through and considering line breaks (and page breaks). Most people do not consider LaTeX as a word processor, because it does not show the output instantly. However differing the output encourages the user to put off until the end formatting adjustments, and thus it prevents a lot of fiddling with breaks that will change anyway. @noindent Differing the output has other advantages: it enables to make no compromise about the typesetting, which ensures that what you see it exactly what you get, and it also helps authors concentrate their mind on either writing or reading rather than distract it by doing both a the same time. @end ignore @menu * \\:: Start a new line. * \obeycr & \restorecr:: Make each input line start a new output line. * \newline:: Break the line * \- (hyphenation):: Insert explicit hyphenation. * \discretionary:: Explicit control of the hyphen character. * \fussy & \sloppy:: Be more or less particular with line breaking. * \hyphenation:: Tell @LaTeX{} how to hyphenate a word. * \linebreak & \nolinebreak:: Forcing & avoiding line breaks. @end menu @node \\ @section @code{\\} @findex \\ @r{(force line break)} @cindex new line, starting @cindex line break, forcing Synopsis, one of: @example \\ \\[@var{morespace}] @end example @noindent or one of: @example \\* \\*[@var{morespace}] @end example End the current line. The optional argument @var{morespace} specifies extra vertical space to be inserted before the next line. This is a rubber length (@pxref{Lengths}) and can be negative. The text before the line break is set at its normal length, that is, it is not stretched to fill out the line width. This command is fragile (@pxref{\protect}). @example \title@{My story: \\[0.25in] a tale of woe@} @end example @noindent The starred form, @code{\\*}, tells @LaTeX{} not to start a new page between the two lines, by issuing a @code{\nobreak}. Explicit line breaks in the main text body are unusual in @LaTeX{}. In particular, don't start new paragraphs with @code{\\}. Instead leave a blank line between the two paragraphs. And don't put in a sequence of @code{\\}'s to make vertical space. Instead use @code{\vspace@{@var{length}@}}, or @code{\leavevmode\vspace@{@var{length}@}}, or @code{\vspace*@{@var{length}@}} if you want the space to not be thrown out at the top of a new page (@pxref{\vspace}). The @code{\\} command is mostly used outside of the main flow of text such as in a @code{tabular} or @code{array} environment or in an equation environment. The @code{\\} command is a synonym for @code{\newline} (@pxref{\newline}) under ordinary circumstances (an example of an exception is the @code{p@{...@}} column in a @code{tabular} environment; @pxref{tabular}). @c credit: David Carlisle https://tex.stackexchange.com/a/82666 The @code{\\} command is a macro, and its definition changes by context so that its definition in normal text, a @code{center} environment, a @code{flushleft} environment, and a @code{tabular} are all different. In normal text when it forces a linebreak it is essentially a shorthand for @code{\newline}. It does not end horizontal mode or end the paragraph, it just inserts some glue and penalties so that when the paragraph does end a linebreak will occur at that point, with the short line padded with white space. You get @samp{LaTeX Error: There's no line here to end} if you use @code{\\} to ask for a new line, rather than to end the current line. An example is if you have @code{\begin@{document@}\\} or, more likely, something like this. @example \begin@{center@} \begin@{minipage@}@{0.5\textwidth@} \\ In that vertical space put your mark. \end@{minipage@} \end@{center@} @end example @noindent Fix it by replacing the double backslash with something like @code{\vspace@{\baselineskip@}}. @node \obeycr & \restorecr @section @code{\obeycr} & @code{\restorecr} @anchor{\obeycr} @anchor{\restorecr} @findex \obeycr @findex \restorecr @cindex new line, output as input The @code{\obeycr} command makes a return in the input file (@samp{^^M}, internally) the same as @code{\\}, followed by @code{\relax}. So each new line in the input will also be a new line in the output. The @code{\restorecr} command restores normal line-breaking behavior. This is not the way to show verbatim text or computer code. Use @code{verbatim} (@pxref{verbatim}) instead. With @LaTeX{}'s usual defaults, this @example aaa bbb \obeycr ccc ddd eee \restorecr fff ggg hhh iii @end example @noindent produces output like this. @example aaa bbb ccc ddd eee fff ggg hhh iii @end example @noindent The indents are paragraph indents. @node \newline @section @code{\newline} @findex \newline @cindex new line, starting (paragraph mode) In ordinary text, this ends a line in a way that does not right-justify it, so the text before the end of line is not stretched. That is, in paragraph mode (@pxref{Modes}), the @code{\newline} command is equivalent to double-backslash (@pxref{\\}). This command is fragile (@pxref{\protect}). However, the two commands are different inside a @code{tabular} or @code{array} environment. In a column with a specifier producing a paragraph box such as typically @code{p@{...@}}, @code{\newline} will insert a line end inside of the column; that is, it does not break the entire tabular row. To break the entire row use @code{\\} or its equivalent @code{\tabularnewline}. This will print @samp{Name:} and @samp{Address:} as two lines in a single cell of the table. @example \begin@{tabular@}@{p@{1in@}@@@{\hspace@{2in@}@}p@{1in@}@} Name: \newline Address: &Date: \\ \hline \end@{tabular@} @end example @noindent The @samp{Date:} will be baseline-aligned with @samp{Name:}. @node \- (hyphenation) @section @code{\-} (discretionary hyphen) @findex \- @r{(hyphenation)} @cindex hyphenation, forcing Tell @LaTeX{} that it may hyphenate the word at that point. When you insert @code{\-} commands in a word, the word will only be hyphenated at those points and not at any of the other hyphenation points that @LaTeX{} might otherwise have chosen. This command is robust (@pxref{\protect}). @LaTeX{} is good at hyphenating and usually finds most of the correct hyphenation points, while almost never using an incorrect one. The @code{\-} command is for exceptional cases. For example, @LaTeX{} does not ordinarily hyphenate words containing a hyphen. Below, the long and hyphenated word means @LaTeX{} has to put in unacceptably large spaces to set the narrow column. @example \begin@{tabular@}@{rp@{1.75in@}@} Isaac Asimov &The strain of anti-intellectualism % an\-ti-in\-tel\-lec\-tu\-al\-ism has been a constant thread winding its way through our political and cultural life, nurtured by the false notion that democracy means that `my ignorance is just as good as your knowledge'. \end@{tabular@} @end example @noindent Commenting out the third line and uncommenting the fourth makes a much better fit. The @code{\-} command only allows @LaTeX{} to break there, it does not require that it break there. You can force a split with something like @code{Hef-\linebreak feron}. Of course, if you later change the text then this forced break may look out of place, so this approach requires care. @node \discretionary @section @code{\discretionary} (generalized hyphenation point) @cindex hyphenation, discretionary @cindex discretionary hyphenation Synopsis: @example \discretionary@{@var{pre-break}@}@{@var{post-break}@}@{@var{no-break}@} @end example Handle word changes around hyphens. This command is not often used in @LaTeX{} documents. If a line break occurs at the point where @code{\discretionary} appears then @TeX{} puts @var{pre-break} at the end of the current line and puts @var{post-break} at the start of the next line. If there is no line break here then @TeX{} puts @var{no-break}. In @samp{difficult} the three letters @code{ffi} form a ligature. But @TeX{} can nonetheless break between the two @samp{f}'s with this. @example di\discretionary@{f-@}@{fi@}@{ffi@}cult @end example Note that users do not have to do this. It is typically handled automatically by @TeX{}'s hyphenation algorithm. @c xxx TODO, complete this node, see LaTeX-fr (copied & pasted below, @c with accented letter escaped) @ignore @c Les arguments de @code{\discretionary} ne peuvent contenir que des @c caract@`eres, des bo@^{@dotless{i}}tes ou des cr@'enages. @c @c La commande @code{\discretionary} permet de contr@^oler @c finement la c@'esure dans les cas o@`u ne suffisent ni le contr@^ole standard @c de la c@'esure fait l'algorithme de c@'esure de @TeX{} et les r@`egles de @c c@'esures donn@'ees par les paquetages de gestion linguistiques, ni les @c moyens de contr@^ole explicites offerts par les commandes @c @code{\hyphenation} (@pxref{\hyphenation}) et @code{\-} (@pxref{\- @c (hyphenation),\- (c@'esure @`a gr@'e)}). @c @c L'usage typique de @code{\discretionary} est par exemple de contr@^oler la @c c@'esure au sein d'une formule math@'ematique en mode ligne (voir aussi @c @ref{Math miscellany,Miscellan@'ees math@'ematique (entr@'ee \*)}). Ci-dessous @c un exemple de contr@^ole de la c@'esure au sein d'une adresse r@'eticulaire, @c o@`u l'on autorise la c@'esure sur les obliques mais en utilisant une @c contr'oblique violette en lieu de trait d'union@tie{}: @c @c @example @c \documentclass@{article@} @c \usepackage[T1]@{fontenc@} @c \usepackage[utf8]@{inputenc@} @c \usepackage@{xcolor@} @c \usepackage@{hyperref@} @c \usepackage@{french@} @c \newcommand*\DiscrSlash@{\discretionary@{\mbox@{\textcolor @c @{purple@}@{\textbackslash@}@}@}@{/@}@{/@}@} @c \begin@{document@} @c Allez donc @`a \href@{http://une/tr\%c3\%A8s/tr\%c3\%A8s/longue% @c /mais/vraiment/tr\%c3\%A8s/longue/adresse/r\%C3\%A9ticulaire% @c /index.html@}@{http://une\DiscrSlash tr@`es\DiscrSlash tr@`es\DiscrSlash @c longue\DiscrSlash mais\DiscrSlash vraiment\DiscrSlash @c tr@`es\DiscrSlash longue\DiscrSlash adresse\DiscrSlash @c r@'eticulaire\DiscrSlash index.html@} @c \end@{document@} @c @end example @end ignore @node \fussy & \sloppy @section @code{\fussy} & @code{\sloppy} @anchor{\fussy} @anchor{\sloppy} @findex \fussy @findex \sloppy @cindex line breaks, changing Declarations to make @TeX{} more picky or less picky about line breaking. Declaring @code{\fussy} usually avoids too much space between words, at the cost of an occasional overfull box. Conversely, @code{\sloppy} avoids overfull boxes while suffering loose interword spacing. The default is @code{\fussy}. Line breaking in a paragraph is controlled by whichever declaration is current at the end of the paragraph, i.e., at the blank line or @code{\par} or displayed equation ending that paragraph. So to affect the line breaks, include that paragraph-ending material in the scope of the command. @menu * sloppypar:: Environment version of \sloppy command. @end menu @node sloppypar @subsection @code{sloppypar} @EnvIndex{sloppypar} @cindex sloppypar environment Synopsis: @example \begin@{sloppypar@} ... paragraphs ... \end@{sloppypar@} @end example Typeset the paragraphs with @code{\sloppy} in effect (@pxref{\fussy & \sloppy}). Use this to locally adjust line breaking, to avoid @samp{Overfull box} or @samp{Underfull box} errors. The example is simple. @example \begin@{sloppypar@} Her plan for the morning thus settled, she sat quietly down to her book after breakfast, resolving to remain in the same place and the same employment till the clock struck one; and from habitude very little incommoded by the remarks and ejaculations of Mrs.\ Allen, whose vacancy of mind and incapacity for thinking were such, that as she never talked a great deal, so she could never be entirely silent; and, therefore, while she sat at her work, if she lost her needle or broke her thread, if she heard a carriage in the street, or saw a speck upon her gown, she must observe it aloud, whether there were anyone at leisure to answer her or not. \end@{sloppypar@} @end example @node \hyphenation @section @code{\hyphenation} @findex \hyphenation @cindex hyphenation, defining Synopsis: @example \hyphenation@{@var{word1} ...@} @end example Declares allowed hyphenation points within the words in the list. The words in that list are separated by spaces. Show permitted points for hyphenation with a dash character, @code{-}. Here is an example: @example \hyphenation@{hat-er il-lit-e-ra-ti tru-th-i-ness@} @end example Use lowercase letters. @TeX{} will only hyphenate if the word matches exactly, no inflections are tried. Multiple @code{\hyphenation} commands accumulate. @c xx Re-align on LaTeX-fr which also mentions fontenc, and that @c babel/polyglossia already load hyphenation patterns, and you have to @c declare only non existing words. @node \linebreak & \nolinebreak @section @code{\linebreak} & @code{\nolinebreak} @anchor{\linebreak} @anchor{\nolinebreak} @findex \linebreak @findex \nolinebreak @cindex line breaks, forcing @cindex line breaks, preventing Synopses, one of: @example \linebreak \linebreak[@var{zero-to-four}] @end example @noindent or one of these. @example \nolinebreak \nolinebreak[@var{zero-to-four}] @end example Encourage or discourage a line break. The optional @var{zero-to-four} is an integer lying between 0 and 4 that allows you to soften the instruction. The default is 4, so that without the optional argument these commands entirely force or prevent the break. But for instance, @code{\nolinebreak[1]} is a suggestion that another place may be better. The higher the number, the more insistent the request. Both commands are fragile (@pxref{\protect}). Here we tell @LaTeX{} that a good place to put a linebreak is after the standard legal text. @example \boilerplatelegal@{@} \linebreak[2] We especially encourage applications from members of traditionally underrepresented groups. @end example When you issue @code{\linebreak}, the spaces in the line are stretched out so that the break point reaches the right margin. @xref{\\} and@tie{}@ref{\newline}, to have the spaces not stretched out. @node Page breaking @chapter Page breaking @cindex page breaking @cindex breaking pages Ordinarily @LaTeX{} automatically takes care of breaking output into pages with its usual aplomb. But if you are writing commands, or tweaking the final version of a document, then you may need to understand how to influence its actions. @c credit: H Vogt https://tex.stackexchange.com/a/115563 @cindex badness @LaTeX{}'s algorithm for splitting a document into pages is more complex than just waiting until there is enough material to fill a page and outputting the result. Instead, @LaTeX{} typesets more material than would fit on the page and then chooses a break that is optimal in some way (it has the smallest @dfn{badness}). An example of the advantage of this approach is that if the page has some vertical space that can be stretched or shrunk, such as with rubber lengths between paragraphs, then @LaTeX{} can use that to avoid widow lines (where a new page starts with the last line of a paragraph; @LaTeX{} can squeeze the extra line onto the first page) and orphans (where the first line of paragraph is at the end of a page; @LaTeX{} can stretch the material of the first page so the extra line falls on the second page). Another example is where @LaTeX{} uses available vertical shrinkage to fit on a page not just the header for a new section but also the first two lines of that section. But @LaTeX{} does not optimize over the entire document's set of page breaks. So it can happen that the first page break is great but the second one is lousy; to break the current page @LaTeX{} doesn't look as far ahead as the next page break. So occasionally you may want to influence page breaks while preparing a final version of a document. @xref{Layout}, for more material that is relevant to page breaking. @menu * \clearpage & \cleardoublepage:: Start a new page; eject floats. * \newpage:: Start a new page. * \enlargethispage:: Enlarge the current page a bit. * \pagebreak & \nopagebreak:: Forcing & avoiding page breaks. @end menu @node \clearpage & \cleardoublepage @section @code{\clearpage} & @code{\cleardoublepage} @anchor{\clearpage} @findex \clearpage @cindex flushing floats and starting a page @cindex starting a new page and clearing floats @anchor{\cleardoublepage} @findex \cleardoublepage @cindex starting on a right-hand page Synopsis: @example \clearpage @end example @noindent or @example \cleardoublepage @end example End the current page and output all of the pending floating figures and tables (@pxref{Floats}). If there are too many floats to fit on the page then @LaTeX{} will put in extra pages containing only floats. In two-sided printing, @code{\cleardoublepage} also makes the next page of content a right-hand page, an odd-numbered page, if necessary inserting a blank page. The @code{\clearpage} command is robust while @code{\cleardoublepage} is fragile (@pxref{\protect}). @LaTeX{}'s page breaks are optimized so ordinarily you only use this command in a document body to polish the final version, or inside commands. @c credit: https://www.tex.ac.uk/FAQ-reallyblank.html The @code{\cleardoublepage} command will put in a blank page, but it will have the running headers and footers. To get a really blank page, use this command. @example \let\origdoublepage\cleardoublepage \newcommand@{\clearemptydoublepage@}@{% \clearpage @{\pagestyle@{empty@}\origdoublepage@}% @} @end example @noindent If you want @LaTeX{}'s standard @code{\chapter} command to do this then add the line @code{\let\cleardoublepage\clearemptydoublepage}. (Of course this affects all uses of @code{\cleardoublepage}, not just the one in @code{\chapter}.) The command @code{\newpage} (@pxref{\newpage}) also ends the current page, but without clearing pending floats. And, if @LaTeX{} is in two-column mode then @code{\newpage} ends the current column while @code{\clearpage} and @code{\cleardoublepage} end the current page. @node \newpage @section @code{\newpage} @findex \newpage @cindex new page, starting @cindex starting a new page Synopsis: @example \newpage @end example End the current page. This command is robust (@pxref{\protect}). @LaTeX{}'s page breaks are optimized so ordinarily you only use this command in a document body to polish the final version, or inside commands. While the commands @code{\clearpage} and @code{\cleardoublepage} also end the current page, in addition they clear pending floats (@pxref{\clearpage & \cleardoublepage}). And, if @LaTeX{} is in two-column mode then @code{\clearpage} and @code{\cleardoublepage} end the current page, possibly leaving an empty column, while @code{\newpage} only ends the current column. In contrast with @code{\pagebreak} (@pxref{\pagebreak & \nopagebreak}), the @code{\newpage} command will cause the new page to start right where requested. This @example Four score and seven years ago our fathers brought forth on this continent, \newpage \noindent a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal. @end example @noindent makes a new page start after @samp{continent}, and the cut-off line is not right justified. In addition, @code{\newpage} does not vertically stretch out the page, as @code{\pagebreak} does. @node \enlargethispage @section @code{\enlargethispage} @findex \enlargethispage @cindex enlarge current page Synopsis, one of: @example \enlargethispage@{@var{size}@} \enlargethispage*@{@var{size}@} @end example Enlarge the @code{\textheight} for the current page. The required argument @var{size} must be a rigid length (@pxref{Lengths}). It may be positive or negative. This command is fragile (@pxref{\protect}). A common strategy is to wait until you have the final text of a document, and then pass through it tweaking line and page breaks. This command allows you some page size leeway. This will allow one extra line on the current page. @example \enlargethispage@{\baselineskip@} @end example The starred form @code{\enlargesthispage*} tries to squeeze the material together on the page as much as possible, for the common use case of getting one more line on the page. This is often used together with an explicit @code{\pagebreak}. @node \pagebreak & \nopagebreak @section @code{\pagebreak} & @code{\nopagebreak} @anchor{\pagebreak} @anchor{\nopagebreak} @findex \pagebreak @findex \nopagebreak @cindex page break, forcing @cindex page break, preventing Synopses: @example \pagebreak \pagebreak[@var{zero-to-four}] @end example @noindent or @example \nopagebreak \nopagebreak[@var{zero-to-four}] @end example Encourage or discourage a page break. The optional @var{zero-to-four} is an integer that allows you to soften the request. The default is 4, so that without the optional argument these commands entirely force or prevent the break. But for instance @code{\nopagebreak[1]} suggests to @LaTeX{} that another spot might be preferable. The higher the number, the more insistent the request. Both commands are fragile (@pxref{\protect}). @LaTeX{}'s page endings are optimized so ordinarily you only use these commands in a document body to polish the final version, or inside commands. If you use these inside a paragraph, they apply to the point following the line in which they appear. So this @example Four score and seven years ago our fathers brought forth on this continent, \pagebreak a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal. @end example @noindent does not give a page break at @samp{continent}, but instead at @samp{nation}, since that is where @LaTeX{} breaks that line. In addition, with @code{\pagebreak} the vertical space on the page is stretched out where possible so that it extends to the normal bottom margin. This can look strange, and if @code{\flushbottom} is in effect this can cause you to get @samp{Underfull \vbox (badness 10000) has occurred while \output is active}. @xref{\newpage}, for a command that does not have these effects. @findex \samepage @findex samepage @r{environment} (There is an obsolete declaration @code{\samepage}, which tries to only allow a break between two paragraphs. There is a related environment @code{samepage}, also obsolete. Neither of these work reliably. For more on keeping material on the same page, see the FAQ entry @url{https://texfaq.org/FAQ-nopagebrk}.) @node Footnotes @chapter Footnotes @cindex footnotes, creating Place a footnote at the bottom of the current page, as here. @example No@"{e}l Coward quipped that having to read a footnote is like having to go downstairs to answer the door, while in the midst of making love.\footnote@{% I wouldn't know, I don't read footnotes.@} @end example You can put multiple footnotes on a page. If the footnote text becomes too long then it will flow to the next page. You can also produce footnotes by combining the @code{\footnotemark} and the @code{\footnotetext} commands, which is useful in special circumstances. To make bibliographic references come out as footnotes you need to include a bibliographic style with that behavior (@pxref{Using BibTeX}). @menu * \footnote:: Insert a footnote. * \footnotemark:: Insert footnote mark only. * \footnotetext:: Insert footnote text only. * Footnotes in section headings:: Chapter or section titles. * Footnotes in a table:: Table footnotes. * Footnotes of footnotes:: Multiple classes of footnotes. @end menu @node \footnote @section @code{\footnote} @findex \footnote Synopsis, one of: @example \footnote@{@var{text}@} \footnote[@var{number}]@{@var{text}@} @end example Place a footnote @var{text} at the bottom of the current page. @example There are over a thousand footnotes in Gibbon's \textit@{Decline and Fall of the Roman Empire@}.\footnote@{% After reading an early version with endnotes David Hume complained, ``One is also plagued with his Notes, according to the present Method of printing the Book'' and suggested that they ``only to be printed at the Margin or the Bottom of the Page.''@} @end example The optional argument @var{number} allows you to specify the number of the footnote. If you use this then @LaTeX{} does not increment the @code{footnote} counter. @cindex footnotes, symbols instead of numbers @findex \fnsymbol@r{, and footnotes} @findex \@@fnsymbol By default, @LaTeX{} uses arabic numbers as footnote markers. Change this with something like @code{\renewcommand@{\thefootnote@}@{\fnsymbol@{footnote@}@}}, which uses a sequence of symbols (@pxref{\alph \Alph \arabic \roman \Roman \fnsymbol}). To make this change global put that in the preamble. If you make the change local then you may want to reset the counter with @code{\setcounter@{footnote@}@{0@}}. @LaTeX{} determines the spacing of footnotes with two parameters. @cindex footnote parameters @cindex parameters, for footnotes @ftable @code @item \footnoterule @anchor{footnote footnoterule} Produces the rule separating the main text on a page from the page's footnotes. Default dimensions in the standard document classes (except @code{slides}, where it does not appear) is: vertical thickness of @code{0.4pt}, and horizontal size of @code{0.4\columnwidth} long. Change the rule with something like this. @c Credit egreg: https://tex.stackexchange.com/a/21917 @example \renewcommand@{\footnoterule@}@{% Kerns avoid vertical space \kern -3pt % This -3 is negative \hrule width \textwidth height 1pt % of the sum of this 1 \kern 2pt@} % and this 2 @end example @item \footnotesep @anchor{footnote footnotesep} @cindex strut The height of the strut placed at the beginning of the footnote (@pxref{\strut}). By default, this is set to the normal strut for @code{\footnotesize} fonts (@pxref{Font sizes}), therefore there is no extra space between footnotes. This is @samp{6.65pt} for @samp{10pt}, @samp{7.7pt} for @samp{11pt}, and @samp{8.4pt} for @samp{12pt}. Change it as with @code{\setlength@{\footnotesep@}@{11pt@}}. @end ftable The @code{\footnote} command is fragile (@pxref{\protect}). @LaTeX{}'s default puts many restrictions on where you can use a @code{\footnote}; for instance, you cannot use it in an argument to a sectioning command such as @code{\chapter} (it can only be used in outer paragraph mode; @pxref{Modes}). There are some workarounds; see following sections. @cindex footnotes, in a minipage @cindex mpfootnote counter In a @code{minipage} environment the @code{\footnote} command uses the @code{mpfootnote} counter instead of the @code{footnote} counter, so they are numbered independently. They are shown at the bottom of the environment, not at the bottom of the page. And by default they are shown alphabetically. @xref{minipage} and @ref{Footnotes in a table}. @node \footnotemark @section @code{\footnotemark} @findex \footnotemark Synopsis, one of: @example \footnotemark \footnotemark[@var{number}] @end example Put the current footnote mark in the text. To specify associated text for the footnote see@tie{}@ref{\footnotetext}. The optional argument @var{number} causes the command to use that number to determine the footnote mark. This command can be used in inner paragraph mode (@pxref{Modes}). If you use @code{\footnotemark} without the optional argument then it increments the @code{footnote} counter, but if you use the optional @var{number} then it does not. The next example produces several consecutive footnote markers referring to the same footnote. @example The first theorem\footnote@{Due to Gauss.@} and the second theorem\footnotemark[\value@{footnote@}] and the third theorem.\footnotemark[\value@{footnote@}] @end example If there are intervening footnotes then you must remember the value of the number of the common mark. This example gives the same institutional affiliation to both the first and third authors (@code{\thanks} is a version of @code{\footnote}), by-hand giving the number of the footnote. @example \title@{A Treatise on the Binomial Theorem@} \author@{J Moriarty\thanks@{University of Leeds@} \and A C Doyle\thanks@{Durham University@} \and S Holmes\footnotemark[1]@} \begin@{document@} \maketitle @end example This uses a counter to remember the footnote number. The third sentence is followed by the same footnote marker as the first. @example \newcounter@{footnoteValueSaver@} All babies are illogical.\footnote@{% Lewis Carroll.@}\setcounter@{footnoteValueSaver@}@{\value@{footnote@}@} Nobody is despised who can manage a crocodile.\footnote@{% Captain Hook.@} Illogical persons are despised.\footnotemark[\value@{footnoteValueSaver@}] Therefore, anyone who can manage a crocodile is not a baby. @end example @PkgIndex{cleveref} @PkgIndex{hyperref} This example accomplishes the same by using the package @package{cleveref}. @c from SE user Jake http://tex.stackexchange.com/a/10116/339 @example \usepackage@{cleveref@}[2012/02/15] % in preamble \crefformat@{footnote@}@{#2\footnotemark[#1]#3@} ... The theorem is from Evers.\footnote@{\label@{fn:TE@}Tinker, Evers, 1994.@} The corollary is from Chance.\footnote@{Evers, Chance, 1990.@} But the key lemma is from Tinker.\cref@{fn:TE@} @end example @PkgIndex{hyperref} It will work with the package @package{hyperref}. @node \footnotetext @section @code{\footnotetext} @findex \footnotetext Synopsis, one of: @example \footnotetext@{@var{text}@} \footnotetext[@var{number}]@{@var{text}@} @end example Place @var{text} at the bottom of the page as a footnote. It pairs with @code{\footnotemark} (@pxref{\footnotemark}) and can come anywhere after that command, but must appear in outer paragraph mode (@pxref{Modes}). The optional argument @var{number} changes the number of the footnote mark. @xref{\footnotemark} and@tie{}@ref{Footnotes in a table}, for usage examples. @node Footnotes in section headings @section Footnotes in section headings @cindex footnote, in section headings @cindex table of contents, avoiding footnotes Putting a footnote in a section heading, as in: @example \section@{Full sets\protect\footnote@{This material due to ...@}@} @end example @noindent causes the footnote to appear at the bottom of the page where the section starts, as usual, but also at the bottom of the table of contents, where it is not likely to be desired. The simplest way to have it not appear on the table of contents is to use the optional argument to @code{\section} @example \section[Please]@{Please\footnote@{% Don't footnote in chapter and section headers!@}@} @end example @noindent No @code{\protect} is needed in front of @code{\footnote} here because what gets moved to the table of contents is the optional argument. @node Footnotes in a table @section Footnotes in a table @cindex footnote, in a table Inside a @code{tabular} or @code{array} environment the @code{\footnote} command does not work; there is a footnote mark in the table cell but the footnote text does not appear. The solution is to use a @code{minipage} environment as here (@pxref{minipage}). @example \begin@{center@} \begin@{minipage@}@{\textwidth@} \centering \begin@{tabular@}@{l|l@} \textsc@{Ship@} &\textsc@{Book@} \\ \hline \textit@{HMS Sophie@} &Master and Commander \\ \textit@{HMS Polychrest@} &Post Captain \\ \textit@{HMS Lively@} &Post Captain \\ \textit@{HMS Surprise@} &A number of books\footnote@{% Starting with \textit@{HMS Surprise@}.@} \end@{tabular@} \end@{minipage@} \end@{center@} @end example Inside a @code{minipage}, footnote marks are lowercase letters. Change that with something like @code{\renewcommand@{\thempfootnote@}@{\arabic@{mpfootnote@}@}} (@pxref{\alph \Alph \arabic \roman \Roman \fnsymbol}). The footnotes in the prior example appear at the bottom of the @code{minipage}. To have them appear at the bottom of the main page, as part of the regular footnote sequence, use the @code{\footnotemark} and @code{\footnotetext} pair and make a new counter. @example \newcounter@{mpFootnoteValueSaver@} \begin@{center@} \begin@{minipage@}@{\textwidth@} \setcounter@{mpFootnoteValueSaver@}@{\value@{footnote@}@} \centering \begin@{tabular@}@{l|l@} \textsc@{Woman@} &\textsc@{Relationship@} \\ \hline Mona &Attached\footnotemark \\ Diana Villiers &Eventual wife \\ Christine Hatherleigh Wood &Fiance\footnotemark \end@{tabular@} \end@{minipage@}% percent sign keeps footnote text close to minipage \stepcounter@{mpFootnoteValueSaver@}% \footnotetext[\value@{mpFootnoteValueSaver@}]@{% Little is known other than her death.@}% \stepcounter@{mpFootnoteValueSaver@}% \footnotetext[\value@{mpFootnoteValueSaver@}]@{% Relationship is unresolved in XXI.@} \end@{center@} @end example @PkgIndex{tablefootnote} For a floating @code{table} environment (@pxref{table}), use the @package{tablefootnote} package. @example \usepackage@{tablefootnote@} % in preamble ... \begin@{table@} \centering \begin@{tabular@}@{l|l@} \textsc@{Date@} &\textsc@{Campaign@} \\ \hline 1862 &Fort Donelson \\ 1863 &Vicksburg \\ 1865 &Army of Northern Virginia\tablefootnote@{% Ending the war.@} \end@{tabular@} \caption@{Forces captured by US Grant@} \end@{table@} @end example @noindent The footnote appears at the page bottom and is numbered in sequence with other footnotes. @node Footnotes of footnotes @section Footnotes of footnotes @cindex footnote, of a footnote @PkgIndex{bigfoot} Particularly in the humanities, authors can have multiple classes of footnotes, including having footnotes of footnotes. The package @package{bigfoot} extends @LaTeX{}'s default footnote mechanism in many ways, including allow these two, as in this example. @example \usepackage@{bigfoot@} % in preamble \DeclareNewFootnote@{Default@} \DeclareNewFootnote@{from@}[alph] % create class \footnotefrom@{@} ... The third theorem is a partial converse of the second.\footnotefrom@{% Noted in Wilson.\footnote@{Second edition only.@}@} @end example @node Definitions @chapter Definitions @cindex definitions @LaTeX{} has support for making new commands of many different kinds. @menu * \newcommand & \renewcommand:: (Re)define a new command. * \providecommand:: Define a new command, if name not used. * \makeatletter & \makeatother:: Change the status of the at-sign character. * \@@ifstar:: Define your own commands with *-variants. * \newcounter:: Define a new counter. * \newlength:: Define a new length. * \newsavebox:: Define a new box. * \newenvironment & \renewenvironment:: Define a new environment. * \newtheorem:: Define a new theorem-like environment. * \newfont:: Define a new font name. * \protect:: Using tricky commands. * \ignorespaces & \ignorespacesafterend:: Discard extra spaces. * xspace package:: Space after a macro, conditionally. @end menu @node \newcommand & \renewcommand @section @code{\newcommand} & @code{\renewcommand} @anchor{\newcommand} @anchor{\renewcommand} @findex \newcommand @findex \renewcommand @cindex commands, defining new ones @cindex commands, redefining @cindex defining a new command @cindex redefining a command @cindex new commands, defining Synopses, one of (three regular forms, three starred forms): @example \newcommand@{\@var{cmd}@}@{@var{defn}@} \newcommand@{\@var{cmd}@}[@var{nargs}]@{@var{defn}@} \newcommand@{\@var{cmd}@}[@var{nargs}][@var{optargdefault}]@{@var{defn}@} \newcommand*@{\@var{cmd}@}@{@var{defn}@} \newcommand*@{\@var{cmd}@}[@var{nargs}]@{@var{defn}@} \newcommand*@{\@var{cmd}@}[@var{nargs}][@var{optargdefault}]@{@var{defn}@} @end example @noindent or all the same possibilities with @code{\renewcommand} instead of @code{\newcommand}: @example \renewcommand@{\@var{cmd}@}@{@var{defn}@} \renewcommand@{\@var{cmd}@}[@var{nargs}]@{@var{defn}@} \renewcommand@{\@var{cmd}@}[@var{nargs}][@var{optargdefault}]@{@var{defn}@} \renewcommand*@{\@var{cmd}@}@{@var{defn}@} \renewcommand*@{\@var{cmd}@}[@var{nargs}]@{@var{defn}@} \renewcommand*@{\@var{cmd}@}[@var{nargs}][@var{optargdefault}]@{@var{defn}@} @end example Define or redefine a command (see also @code{\DeclareRobustCommand} in @ref{Class and package commands}). @cindex starred form, defining new commands @cindex *-form, defining new commands @findex \long The starred form of these two forbids the arguments from containing multiple paragraphs of text (in plain @TeX{} terms: the commands are not @code{\long}). With the default form, arguments can be multiple paragraphs. These are the parameters (examples follow): @table @var @item cmd Required; @code{\@var{cmd}} is the command name. It must begin with a backslash, @code{\}, and must not begin with the four character string @code{\end}. For @code{\newcommand}, it must not be already defined. For @code{\renewcommand}, this name must already be defined. @item nargs Optional; an integer from 0 to 9, specifying the number of arguments that the command takes, including any optional argument. Omitting this argument is the same as specifying 0, meaning that the command has no arguments. If you redefine a command, the new version can have a different number of arguments than the old version. @item optargdefault @cindex optional arguments, defining and using @cindex arguments, optional, defining and using Optional; if this argument is present then the first argument of @code{\@var{cmd}} is optional, with default value @var{optargdefault} (which may be the empty string). If @var{optargdefault} is not present then @code{\@var{cmd}} does not take an optional argument. That is, if @code{\@var{cmd}} is called with a following argument in square brackets, as in @code{\@var{cmd}[@var{optval}]@{...@}...}, then within @var{defn} the parameter@tie{}@code{#1} is set to @var{optval}. On the other hand, if @code{\@var{cmd}} is called without following square brackets then within @var{defn} the parameter @code{#1} is set to @var{optargdefault}. In either case, the required arguments start with @code{#2}. Omitting @code{[@var{optargdefault}]} from the definition is entirely different from giving the square brackets with empty contents, as in @code{[]}. The former says the command being defined takes no optional argument, so @code{#1} is the first required argument (if @math{@var{nargs} @geq{} 1}); the latter sets the optional argument @code{#1} to the empty string as the default, if no optional argument was given in the call. Similarly, omitting @code{[@var{optval}]} from a call is also entirely different from giving the square brackets with empty contents. The former sets @code{#1} to the value of @var{optval} (assuming the command was defined to take an optional argument); the latter sets @code{#1} to the empty string, just as with any other value. If a command is not defined to take an optional argument, but is called with an optional argument, the results are unpredictable: there may be a @LaTeX{} error, there may be incorrect typeset output, or both. @item defn @cindex parameters, substituting Required; the text to be substituted for every occurrence of @code{\@var{cmd}}. The parameters @code{#1}, @code{#2}, @dots{}, @code{#@var{nargs}} are replaced by the values supplied when the command is called (or by @var{optargdefault} in the case of an optional argument not specified in the call, as just explained). @end table @cindex blanks, after control sequences @TeX{} ignores blanks in the source following a control word (@pxref{Control sequences}), as in @samp{\cmd }. If you want a space there, one solution is to type @code{@{@}} after the command (@samp{\cmd@{@} }), and another solution is to use an explicit control space (@samp{\cmd\ }). A simple example of defining a new command: @code{\newcommand@{\RS@}@{Robin Smith@}} results in @code{\RS} being replaced by the longer text. Redefining an existing command is similar: @code{\renewcommand@{\qedsymbol@}@{@{\small QED@}@}}. If you use @code{\newcommand} and the command name has already been used then you get something like @samp{LaTeX Error: Command \fred already defined. Or name \end... illegal, see p.192 of the manual}. Similarly, If you use @code{\renewcommand} and the command name has not been defined then you get something like @samp{LaTeX Error: \hank undefined}. Here the first definition creates a command with no arguments, and the second, a command with one required argument: @example \newcommand@{\student@}@{Ms~O'Leary@} \newcommand@{\defref@}[1]@{Definition~\ref@{#1@}@} @end example @noindent Use the first as in @code{I highly recommend \student@{@} to you}. The second has a variable argument, so that @code{\defref@{def:basis@}} expands to @code{Definition~\ref@{def:basis@}}, which ultimately expands to something like @samp{Definition~3.14}. Similarly, but with two required arguments: @code{\newcommand@{\nbym@}[2]@{$#1 \times #2$@}} is invoked as @code{\nbym@{2@}@{k@}}. This example has an optional argument. @example \newcommand@{\salutation@}[1][Sir or Madam]@{Dear #1:@} @end example @noindent Then @code{\salutation} gives @samp{Dear Sir or Madam:} while @code{\salutation[John]} gives @samp{Dear John:}. And @code{\salutation[]} gives @samp{Dear :}. This example has an optional argument and two required arguments. @example \newcommand@{\lawyers@}[3][company]@{#2, #3, and~#1@} I employ \lawyers[Howe]@{Dewey@}@{Cheatem@}. @end example @noindent The output is @samp{I employ Dewey, Cheatem, and Howe.}. The optional argument, @code{Howe}, is associated with @code{#1}, while @code{Dewey} and @code{Cheatem} are associated with @code{#2} and@tie{}@code{#3}. Because of the optional argument, @code{\lawyers@{Dewey@}@{Cheatem@}} will give the output @samp{I employ Dewey, Cheatem, and company.}. The braces around @var{defn} do not define a group, that is, they do not delimit the scope of the result of expanding @var{defn}. For example, with @code{\newcommand@{\shipname@}[1]@{\it #1@}}, in this sentence, @example The \shipname@{Monitor@} met the \shipname@{Merrimac@}. @end example @noindent the words @samp{met the}, and the period, would incorrectly be in italics. The solution is to put another pair of braces inside the definition: @code{\newcommand@{\shipname@}[1]@{@{\it #1@}@}}. @menu * Control sequences:: Control sequence, control word and control symbol. @end menu @node Control sequences @subsection Control sequence, control word and control symbol @cindex control sequences When reading input @TeX{} converts the stream of read characters into a sequence of @dfn{tokens}. When @TeX{} sees a backslash @code{\}, it will handle the following characters in a special way in order to make a @dfn{control sequence} token. The control sequences fall into two categories: @itemize @item @cindex control word, defined @dfn{control word}, when the control sequence is gathered from a @code{\} followed by at least one ASCII letter (@code{A-Z} and @code{a-z}), followed by at least one non-letter. @item @cindex control symbol, defined @dfn{control symbol}, when the control sequence is gathered from a @code{\} followed by one non-letter character. @end itemize The sequence of characters so found after the @code{\} is also called the @dfn{control sequence name}. Blanks after a control word are ignored and do not produce any whitespace in the output (@pxref{\newcommand & \renewcommand} and @ref{\(SPACE)}). Just as the @code{\relax} command does nothing, the following input will simply print @samp{Hello!} @inlinefmt{tex,We use visible spaces @samp{@visiblespace{}} instead of blanks}@inlinefmt{info, (if you use the Emacs info viewer@comma{} turn on the @code{whitespace-mode} minor mode to see the trailing spaces)}: @example Hel\relax@visiblespace{}@visiblespace{}@visiblespace{} @visiblespace{}@visiblespace{}@visiblespace{}lo! @end example @noindent This is because blanks after @code{\relax}, including the newline, are ignored, and blanks at the beginning of a line are also ignored (@pxref{Leading blanks}). @node \providecommand @section @code{\providecommand} @findex \providecommand @cindex commands, defining new ones @cindex defining a new command @cindex new commands, defining Synopses, one of: @example \providecommand@{\@var{cmd}@}@{@var{defn}@} \providecommand@{\@var{cmd}@}[@var{nargs}]@{@var{defn}@} \providecommand@{\@var{cmd}@}[@var{nargs}][@var{optargdefault}]@{@var{defn}@} \providecommand*@{\@var{cmd}@}@{@var{defn}@} \providecommand*@{\@var{cmd}@}[@var{nargs}]@{@var{defn}@} \providecommand*@{\@var{cmd}@}[@var{nargs}][@var{optargdefault}]@{@var{defn}@} @end example Defines a command, as long as no command of this name already exists. If no command of this name already exists then this has the same effect as @code{\newcommand}. If a command of this name already exists then this definition does nothing. This is particularly useful in a file that may be loaded more than once, such as a style file. @xref{\newcommand & \renewcommand}, for the description of the arguments. This example @example \providecommand@{\myaffiliation@}@{Saint Michael's College@} \providecommand@{\myaffiliation@}@{Lyc\'ee Henri IV@} From \myaffiliation. @end example @noindent outputs @samp{From Saint Michael's College.}. Unlike @code{\newcommand}, the repeated use of @code{\providecommand} to (try to) define @code{\myaffiliation} does not give an error. @node \makeatletter & \makeatother @section @code{\makeatletter} & @code{\makeatother} @anchor{\makeatletter} @anchor{\makeatother} @findex \makeatother @findex \makeatother Synopsis: @example \makeatletter ... definition of commands with @@ in their name .. \makeatother @end example Use this pair when you redefine @LaTeX{} commands that are named with an at-sign character@tie{}@samp{@code{@@}}. The @code{\makeatletter} declaration makes the at-sign character have the category code of a letter, code@tie{}11. The @code{\makeatother} declaration sets the category code of the at-sign to code@tie{}12, its default value. As @TeX{} reads characters, it assigns each one a category code, or @cindex catcode @cindex character category code @cindex category code, character @dfn{catcode}. For instance, it assigns the backslash character@tie{}@samp{@code{\}} the catcode@tie{}0. Command names consist of a category@tie{}0 character, ordinarily backslash, followed by letters, category@tie{}11 characters (except that a command name can also consist of a category@tie{}0 character followed by a single non-letter symbol). @LaTeX{}'s source code has the convention that some commands use @code{@@} in their name. These commands are mainly intended for package or class writers. The convention prevents authors who are just using a package or class from accidentally replacing such a command with one of their own, because by default the at-sign has catcode@tie{}12. Use the pair @code{\makeatletter} and @code{\makeatother} inside a @file{.tex} file, typically in the preamble, when you are defining or redefining commands named with @code{@@}, by having them surround your definition. Don't use these inside @file{.sty} or @file{.cls} files since the @code{\usepackage} and @code{\documentclass} commands already arrange that the at-sign has the character code of a letter, catcode@tie{}11. @PkgIndex{macros2e} For a comprehensive list of macros with an at-sign in their names see @url{https://ctan.org/pkg/macros2e}. In this example the class file has a command @code{\thesis@@universityname} that the user wants to change. These three lines should go in the preamble, before the @code{\begin@{document@}}. @example \makeatletter \renewcommand@{\thesis@@universityname@}@{Saint Michael's College@} \makeatother @end example @node \@@ifstar @section @code{\@@ifstar} @findex \@@ifstar @cindex commands, star-variants @cindex star-variants, commands Synopsis: @example \newcommand@{\mycmd@}@{\@@ifstar@{\mycmd@@star@}@{\mycmd@@nostar@}@} \newcommand@{\mycmd@@nostar@}[@var{nostar-num-args}]@{@var{nostar-body}@} \newcommand@{\mycmd@@star@}[@var{star-num-args}]@{@var{star-body}@} @end example Many standard @LaTeX{} environments or commands have a variant with the same name but ending with a star character@tie{}@code{*}, an asterisk. Examples are the @code{table} and @code{table*} environments and the @code{\section} and @code{\section*} commands. When defining environments, following this pattern is straightforward because @code{\newenvironment} and @code{\renewenvironment} allow the environment name to contain a star. So you just have to write @code{\newenvironment@{@var{myenv}@}} or @code{\newenvironment@{@var{myenv}*@}} and continue the definition as usual. For commands the situation is more complex as the star not being a letter cannot be part of the command name. As in the synopsis above, there will be a user-called command, given above as @code{\mycmd}, which peeks ahead to see if it is followed by a star. For instance, @LaTeX{} does not really have a @code{\section*} command; instead, the @code{\section} command peeks ahead. This command does not accept arguments but instead expands to one of two commands that do accept arguments. In the synopsis these two are @code{\mycmd@@nostar} and @code{\mycmd@@star}. They could take the same number of arguments or a different number, or no arguments at all. As always, in a @LaTeX{} document a command using an at-sign@tie{}@code{@@} in its name must be enclosed inside a @code{\makeatletter ... \makeatother} block (@pxref{\makeatletter & \makeatother}). This example of @code{\@@ifstar} defines the command @code{\ciel} and a variant @code{\ciel*}. Both have one required argument. A call to @code{\ciel@{blue@}} will return "not starry blue sky" while @code{\ciel*@{night@}} will return "starry night sky". @example \makeatletter \newcommand*@{\ciel@@unstarred@}[1]@{not starry #1 sky@} \newcommand*@{\ciel@@starred@}[1]@{starry #1 sky@} \newcommand*@{\ciel@}@{\@@ifstar@{\ciel@@starred@}@{\ciel@@unstarred@}@} \makeatother @end example In the next example, the starred variant takes a different number of arguments than the unstarred one. With this definition, Agent 007's @code{``My name is \agentsecret*@{Bond@}, \agentsecret@{James@}@{Bond@}.''} is equivalent to entering the commands @code{``My name is \textsc@{Bond@}, \textit@{James@} textsc@{Bond@}.''} @example \newcommand*@{\agentsecret@@unstarred@}[2]@{\textit@{#1@} \textsc@{#2@}@} \newcommand*@{\agentsecret@@starred@}[1]@{\textsc@{#1@}@} \newcommand*@{\agentsecret@}@{% \@@ifstar@{\agentsecret@@starred@}@{\agentsecret@@unstarred@}@} @end example After a command name, a star is handled similarly to an optional argument. (This differs from environment names in which the star is part of the name itself and as such could be in any position.) Thus, it is technically possible to put any number of spaces between the command and the star. Thus @code{\agentsecret*@{Bond@}} and @code{\agentsecret@w{ *}@{Bond@}} are equivalent. However, the standard practice is not to insert any such spaces. @PkgIndex{suffix} @PkgIndex{xparse} There are two alternative ways to accomplish the work of @code{\@@ifstar}. (1)@tie{}The @package{suffix} package allows the construct @code{\newcommand\mycommand@{@var{unstarred-variant}@}} followed by @code{\WithSuffix\newcommand\mycommand*@{@var{starred-variant}@}}. (2)@tie{}@LaTeX{} provides the @package{xparse} package, which allows this code: @example \NewDocumentCommand\foo@{s@}@{\IfBooleanTF#1 @{@var{starred-variant}@}% @{@var{unstarred-variant}@}% @} @end example @node \newcounter @section @code{\newcounter}: Allocating a counter @findex \newcounter @cindex counters, defining new Synopsis, one of: @example \newcounter@{@var{countername}@} \newcounter@{@var{countername}@}[@var{supercounter}] @end example Globally defines a new counter named @var{countername} and initialize it to zero (@pxref{Counters}). The name @var{countername} must consist of letters only. It does not begin with a backslash. This name must not already be in use by another counter. When you use the optional argument @code{[@var{supercounter}]} then the counter @var{countername} will be reset to zero whenever @var{supercounter} is incremented. For example, ordinarily @code{subsection} is numbered within @code{section} so that any time you increment @var{section}, either with @code{\stepcounter} (@pxref{\stepcounter}) or @code{\refstepcounter} (@pxref{\refstepcounter}), then @LaTeX{} will reset @var{subsection} to zero. This example @example \newcounter@{asuper@} \setcounter@{asuper@}@{1@} \newcounter@{asub@}[asuper] \setcounter@{asub@}@{3@} % Note `asuper' The value of asuper is \arabic@{asuper@} and of asub is \arabic@{asub@}. \stepcounter@{asuper@} Now asuper is \arabic@{asuper@} while asub is \arabic@{asub@}. @end example produces @samp{The value of asuper is 1 and that of asub is 3} and @samp{Now asuper is 2 while asub is 0}. If the counter already exists, for instance by entering @code{asuper} twice, then you get something like @samp{LaTeX Error: Command \c@@asuper already defined. Or name \end... illegal, see p.192 of the manual.}. If you use the optional argument then the super counter must already exist. Entering @code{\newcounter@{jh@}[lh]} when @code{lh} is not a defined counter will get you @samp{LaTeX Error: No counter 'lh' defined.} @node \newlength @section @code{\newlength} @findex \newlength @cindex lengths, allocating new @cindex rubber lengths, defining new @cindex skip register, plain @TeX{} @cindex glue register, plain @TeX{} Synopsis: @example \newlength@{\@var{len}@} @end example Allocate a new length register (@pxref{Lengths}). The required argument @code{\@var{len}} has to be a control sequence (@pxref{Control sequences}), and as such must begin with a backslash, @code{\} under normal circumstances. The new register holds rubber lengths such as @code{72.27pt} or @code{1in plus.2in minus.1in} (a @LaTeX{} length register is what plain @TeX{} calls a @code{skip} register). The initial value is zero. The control sequence @code{\@var{len}} must not be already defined. An example: @example \newlength@{\graphichgt@} @end example If you forget the backslash then you get @samp{Missing control sequence inserted}. If the control sequence already exists then you get something like @samp{LaTeX Error: Command \graphichgt already defined. Or name \end... illegal, see p.192 of the manual}. @node \newsavebox @section @code{\newsavebox} @findex \newsavebox @cindex box, allocating new Synopsis: @example \newsavebox@{\@var{cmd}@} @end example Define \@var{cmd}, the string consisting of a backslash followed by @var{cmd}, to refer to a new bin for storing material. These bins hold material that has been typeset, to use multiple times or to measure or manipulate (@pxref{Boxes}). The bin name \@var{cmd} is required, must start with a backslash, \, and must not already be a defined command. This command is fragile (@pxref{\protect}). This allocates a bin and then puts typeset material into it. @example \newsavebox@{\logobox@} \savebox@{\logobox@}@{LoGo@} Our logo is \usebox@{\logobox@}. @end example @noindent The output is @samp{Our logo is LoGo}. If there is an already defined bin then you get something like @samp{LaTeX Error: Command \logobox already defined. Or name \end... illegal, see p.192 of the manual}. The allocation of a box is global. @node \newenvironment & \renewenvironment @section @code{\newenvironment} & @code{\renewenvironment} @anchor{\newenvironment} @anchor{\renewenvironment} @findex \newenvironment @findex \renewenvironment @cindex environments, defining @cindex defining new environments @cindex redefining environments Synopses, one of: @example \newenvironment@{@var{env}@}@{@var{begdef}@}@{@var{enddef}@} \newenvironment@{@var{env}@}[@var{nargs}]@{@var{begdef}@}@{@var{enddef}@} \newenvironment@{@var{env}@}[@var{nargs}][@var{optargdefault}]@{@var{begdef}@}@{@var{enddef}@} \newenvironment*@{@var{env}@}@{@var{begdef}@}@{@var{enddef}@} \newenvironment*@{@var{env}@}[@var{nargs}]@{@var{begdef}@}@{@var{enddef}@} \newenvironment*@{@var{env}@}[@var{nargs}][@var{optargdefault}]@{@var{begdef}@}@{@var{enddef}@} @end example @noindent or one of these. @example \renewenvironment@{@var{env}@}@{@var{begdef}@}@{@var{enddef}@} \renewenvironment@{@var{env}@}[@var{nargs}]@{@var{begdef}@}@{@var{enddef}@} \renewenvironment@{@var{env}@}[@var{nargs}][@var{optargdefault}]@{@var{begdef}@}@{@var{enddef}@} \renewenvironment*@{@var{env}@}@{@var{begdef}@}@{@var{enddef}@} \renewenvironment*@{@var{env}@}[@var{nargs}]@{@var{begdef}@}@{@var{enddef}@} \renewenvironment*@{@var{env}@}[@var{nargs}][@var{optargdefault}]@{@var{begdef}@}@{@var{enddef}@} @end example Define or redefine the environment @var{env}, that is, create the construct @code{\begin@{@var{env}@} ... @var{body} ... \end@{@var{env}@}}. @cindex @code{*}-form of environment commands The starred form of these commands requires that the arguments not contain multiple paragraphs of text. However, the body of these environments can contain multiple paragraphs. @table @var @item env Required; the environment name. It consists only of letters or the @code{*} character, and thus does not begin with backslash, @code{\}. It must not begin with the string @code{end}. For @code{\newenvironment}, the name @var{env} must not be the name of an already existing environment, and also the command @code{\@var{env}} must be undefined. For @code{\renewenvironment}, @var{env} must be the name of an existing environment. @item nargs Optional; an integer from 0 to 9 denoting the number of arguments of that the environment takes. When you use the environment these arguments appear after the @code{\begin}, as in @code{\begin@{@var{env}@}@{@var{arg1}@} ... @{@var{argn}@}}. Omitting this is equivalent to setting it to 0; the environment will have no arguments. When redefining an environment, the new version can have a different number of arguments than the old version. @item optargdefault Optional; if this is present then the first argument of the defined environment is optional, with default value @var{optargdefault} (which may be the empty string). If this is not in the definition then the environment does not take an optional argument. That is, when @var{optargdefault} is present in the definition of the environment then you can start the environment with square brackets, as in @code{\begin@{@var{env}@}[@var{optval}]@{...@} ... \end@{@var{env}@}}. In this case, within @var{begdefn} the parameter @code{#1} is set to the value of @var{optval}. If you call @code{\begin@{@var{env}@}} without square brackets, then within @var{begdefn} the parameter @code{#1} is set to the value of the default @var{optargdefault}. In either case, any required arguments start with @code{#2}. Omitting @code{[@var{myval}]} in the call is different than having the square brackets with no contents, as in @code{[]}. The former results in @code{#1} expanding to @var{optargdefault}; the latter results in @code{#1} expanding to the empty string. @item begdef Required; the text expanded at every occurrence of @code{\begin@{@var{env}@}}. Within @var{begdef}, the parameters @code{#1}, @code{#2}, ... @code{#@var{nargs}}, are replaced by the values that you supply when you call the environment; see the examples below. @item enddef Required; the text expanded at every occurrence of @code{\end@{@var{env}@}}. This may not contain any parameters, that is, you cannot use @code{#1}, @code{#2}, etc., here (but see the final example below). @end table All environments, that is to say the @var{begdef} code, the environment body, and the @var{enddef} code, are processed within a group. Thus, in the first example below, the effect of the @code{\small} is limited to the quote and does not extend to material following the environment. If you try to define an environment and the name has already been used then you get something like @samp{LaTeX Error: Command \fred already defined. Or name \end... illegal, see p.192 of the manual}. If you try to redefine an environment and the name has not yet been used then you get something like @samp{LaTeX Error: Environment hank undefined.}. This example gives an environment like @LaTeX{}'s @code{quotation} except that it will be set in smaller type. @example \newenvironment@{smallquote@}@{% \small\begin@{quotation@} @}@{% \end@{quotation@} @} @end example This has an argument, which is set in boldface at the start of a paragraph. @example \newenvironment@{point@}[1]@{% \noindent\textbf@{#1@} @}@{% @} @end example This one shows the use of a optional argument; it gives a quotation environment that cites the author. @example \newenvironment@{citequote@}[1][Shakespeare]@{% \begin@{quotation@} \noindent\textit@{#1@}: @}@{% \end@{quotation@} @} @end example @noindent The author's name is optional, and defaults to @samp{Shakespeare}. In the document, use the environment like this. @example \begin@{citequote@}[Lincoln] ... \end@{citequote@} @end example The final example shows how to save the value of an argument to use in @var{enddef}, in this case in a box (@pxref{\sbox & \savebox}). @example \newsavebox@{\quoteauthor@} \newenvironment@{citequote@}[1][Shakespeare]@{% \sbox\quoteauthor@{#1@}% \begin@{quotation@} @}@{% \hspace@{1em plus 1fill@}---\usebox@{\quoteauthor@} \end@{quotation@} @} @end example @node \newtheorem @section @code{\newtheorem} @findex \newtheorem @cindex theorems, defining @cindex defining new theorems @cindex theorem-like environment @cindex environment, theorem-like Synopses: @example \newtheorem@{@var{name}@}@{@var{title}@} \newtheorem@{@var{name}@}@{@var{title}@}[@var{numbered_within}] \newtheorem@{@var{name}@}[@var{numbered_like}]@{@var{title}@} @end example Define a new theorem-like environment. You can specify one of @var{numbered_within} and @var{numbered_like}, or neither, but not both. The first form, @code{\newtheorem@{@var{name}@}@{@var{title}@}}, creates an environment that will be labelled with @var{title}; see the first example below. The second form, @code{\newtheorem@{@var{name}@}@{@var{title}@}[@var{numbered_within}]}, creates an environment whose counter is subordinate to the existing counter @var{numbered_within}, so this counter will be reset when @var{numbered_within} is reset. See the second example below. The third form @code{\newtheorem@{@var{name}@}[@var{numbered_like}]@{@var{title}@}}, with optional argument between the two required arguments, creates an environment whose counter will share the previously defined counter @var{numbered_like}. See the third example. This command creates a counter named @var{name}. In addition, unless the optional argument @var{numbered_like} is used, inside of the theorem-like environment the current @code{\ref} value will be that of @code{\the@var{numbered_within}} (@pxref{\ref}). This declaration is global. It is fragile (@pxref{\protect}). Arguments: @table @var @item name The name of the environment. It is a string of letters. It must not begin with a backslash, @code{\}. It must not be the name of an existing environment, and the command name @code{\@var{name}} must not already be defined. @item title The text to be printed at the beginning of the environment, before the number. For example, @samp{Theorem}. @item numbered_within Optional; the name of an already defined counter, usually a sectional unit such as @code{chapter} or @code{section}. When the @var{numbered_within} counter is reset then the @var{name} environment's counter will also be reset. If this optional argument is not used then the command @code{\the@var{name}} is set to @code{\arabic@{@var{name}@}}. @item numbered_like Optional; the name of an already defined theorem-like environment. The new environment will be numbered in sequence with @var{numbered_like}. @end table Without any optional arguments the environments are numbered sequentially. The example below has a declaration in the preamble that results in @samp{Definition@tie{}1} and @samp{Definition@tie{}2} in the output. @example \newtheorem@{defn@}@{Definition@} \begin@{document@} \section@{...@} \begin@{defn@} First def \end@{defn@} \section@{...@} \begin@{defn@} Second def \end@{defn@} @end example This example has the same document body as the prior one. But here @code{\newtheorem}'s optional argument @var{numbered_within} is given as @code{section}, so the output is like @samp{Definition@tie{}1.1} and @samp{Definition@tie{}2.1}. @example \newtheorem@{defn@}@{Definition@}[section] \begin@{document@} \section@{...@} \begin@{defn@} First def \end@{defn@} \section@{...@} \begin@{defn@} Second def \end@{defn@} @end example In the next example there are two declarations in the preamble, the second of which calls for the new @code{thm} environment to use the same counter as @code{defn}. It gives @samp{Definition@tie{}1.1}, followed by @samp{Theorem@tie{}2.1} and @samp{Definition@tie{}2.2}. @example \newtheorem@{defn@}@{Definition@}[section] \newtheorem@{thm@}[defn]@{Theorem@} \begin@{document@} \section@{...@} \begin@{defn@} First def \end@{defn@} \section@{...@} \begin@{thm@} First thm \end@{thm@} \begin@{defn@} Second def \end@{defn@} @end example @node \newfont @section @code{\newfont} @findex \newfont @cindex fonts, new commands for @cindex defining new fonts @c @findex .fd @r{file} This command is obsolete. This description is here only to help with old documents. New documents should define fonts in families through the New Font Selection Scheme which allows you to, for example, associate a boldface with a roman (@pxref{Fonts}). @c This is done either by using @c @file{.fd} files or through the use of an engine that can access system @c fonts such as Xe@LaTeX{} (@pxref{@TeX{} engines}). Synopsis: @example \newfont@{\@var{cmd}@}@{@var{font description}@} @end example Define a command @code{\@var{cmd}} that will change the current font. The control sequence must not already be defined. It must begin with a backslash, @code{\}. @cindex at clause, in font definitions @cindex design size, in font definitions The @var{font description} consists of a @var{fontname} and an optional @dfn{at clause}. @LaTeX{} will look on your system for a file named @file{@var{fontname}.tfm}. The at clause can have the form either @code{at @var{dimen}} or @code{scaled @var{factor}}, where a @var{factor} of @samp{1000} means no scaling. For @LaTeX{}'s purposes, all this does is scale all the character and other font dimensions relative to the font's design size, which is a value defined in the @file{.tfm} file. This defines two equivalent fonts and typesets a few characters in each. @example \newfont@{\testfontat@}@{cmb10 at 11pt@} \newfont@{\testfontscaled@}@{cmb10 scaled 1100@} \testfontat abc \testfontscaled abc @end example @node \protect @section @code{\protect} @findex \protect @cindex fragile commands @cindex robust commands All @LaTeX{} commands are either @dfn{fragile} or @dfn{robust}. A fragile command can break when it is used in the argument to certain other commands. Commands that contain data that @LaTeX{} writes to an auxiliary file and re-reads later are fragile. This includes material that goes into a table of contents, list of figures, list of tables, etc. Fragile commands also include line breaks, any command that has an optional argument, and many more. To prevent such commands from breaking, one solution is to preceded them with the command @code{\protect}. For example, when @LaTeX{} runs the @code{\section@{@var{section name}@}} command it writes the @var{section name} text to the @file{.aux} auxiliary file, moving it there for use elsewhere in the document such as in the table of contents. Any argument that is internally expanded by @LaTeX{} without typesetting it directly is referred to as a @cindex moving arguments @dfn{moving argument}. A command is fragile if it can expand during this process into invalid @TeX{} code. Some examples of moving arguments are those that appear in the @code{\caption@{...@}} command (@pxref{figure}), in the @code{\thanks@{...@}} command (@pxref{\maketitle}), and in @@-expressions in the @code{tabular} and @code{array} environments (@pxref{tabular}). If you get strange errors from commands used in moving arguments, try preceding it with @code{\protect}. Every fragile commands must be protected with their own @code{\protect}. Although usually a @code{\protect} command doesn't hurt, length commands are robust and should not be preceded by a @code{\protect} command. Nor can a @code{\protect} command be used in the argument to @code{\addtocounter} or @code{\setcounter} command. In this example the @code{\caption} command gives a mysterious error about an extra curly brace. Fix the problem by preceding each @code{\raisebox} command with @code{\protect}. @example \begin@{figure@} ... \caption@{Company headquarters of A\raisebox@{1pt@}@{B@}\raisebox@{-1pt@}@{C@}@} \end@{figure@} @end example In the next example the @code{\tableofcontents} command gives an error because the @code{\(..\)} in the section title expands to illegal @TeX{} in the @file{.toc} file. You can solve this by changing @code{\(..\)} to @code{\protect\(..\protect\)}. @example \begin@{document@} \tableofcontents ... \section@{Einstein's \( e=mc^2 \)@} ... @end example @node \ignorespaces & \ignorespacesafterend @section @code{\ignorespaces & \ignorespacesafterend} @anchor{\ignorespaces} @anchor{\ignorespacesafterend} @findex \ignorespaces @findex \ignorespacesafterend @cindex spaces, ignore around commands @cindex commands, ignore spaces Synopsis: @example \ignorespaces @end example @noindent or @example \ignorespacesafterend @end example Both commands cause @LaTeX{} to ignore blanks (that is, characters of catcode@tie{}10 such as space or tabulation) after the end of the command up to the first box or non-blank character. The first is a primitive command of @TeX{}, and the second is @LaTeX{}-specific. The @code{\ignorespaces} is often used when defining commands via @code{\newcommand}, or @code{\newenvironment}, or @code{\def}. The example below illustrates. It allows a user to show the points values for quiz questions in the margin but it is inconvenient because, as shown in the @code{enumerate} list, users must not put any space between the command and the question text. @example \newcommand@{\points@}[1]@{\makebox[0pt]@{\makebox[10em][l]@{#1~pts@}@} \begin@{enumerate@} \item\points@{10@}no extra space output here \item\points@{15@} extra space between the number and the `extra' \end@{enumerate@} @end example @noindent The solution is to change to this. @example \newcommand@{\points@}[1]@{% \makebox[0pt]@{\makebox[10em][l]@{#1~pts@}@}\ignorespaces@} @end example A second example shows blanks being removed from the front of text. The commands below allow a user to uniformly attach a title to names. But, as given, if a title accidentally starts with a space then @code{\fullname} will reproduce that. @example \newcommand@{\honorific@}[1]@{\def\honorific@{#1@}@} % remember title \newcommand@{\fullname@}[1]@{\honorific~#1@} % put title before name \begin@{tabular@}@{|l|@} \honorific@{Mr/Ms@} \fullname@{Jones@} \\ % no extra space here \honorific@{ Mr/Ms@} \fullname@{Jones@} % extra space before title \end@{tabular@} @end example @noindent To fix this, change to @code{\newcommand@{\fullname@}[1]@{\ignorespaces\honorific~#1@}}. The @code{\ignorespaces} is also often used in a @code{\newenvironment} at the end of the @var{begin} clause, as in @code{\begin@{newenvironment@}@{@var{env name}@}@{... \ignorespaces@}@{...@}}. To strip blanks off the end of an environment use @code{\ignorespacesafterend}. An example is that this will show a much larger vertical space between the first and second environments than between the second and third. @example \newenvironment@{eq@}@{\begin@{equation@}@}@{\end@{equation@}@} \begin@{eq@} e=mc^2 \end@{eq@} \begin@{equation@} F=ma \end@{equation@} \begin@{equation@} E=IR \end@{equation@} @end example Putting a comment character@tie{}@code{%} immediately after the @code{\end@{eq@}} will make the vertical space disappear, but that is inconvenient. The solution is to change to @code{\newenvironment@{eq@}@{\begin@{equation@}@}@{\end@{equation@}\ignorespacesafterend@}}. @node xspace package @section xspace package @findex \xspace @PkgIndex{xspace} @cindex spaces, ignore around commands @cindex commands, ignore spaces Synopsis: @example \usepackage@{xspace@} ... \newcommand@{...@}@{...\xspace@} @end example The @code{\xspace} macro, when used at the end of a command definition, adds a space unless the command is followed by certain punctuation characters. After a command control sequence that is a control word (@pxref{Control sequences}, as opposed to control symbols such as @code{\$}), @TeX{} gobbles blank characters. Thus, in the first sentence below, the output has @samp{Vermont} placed snugly against the period, without any intervening space. @example \newcommand@{\VT@}@{Vermont@} Our college is in \VT . The \VT@{@} summers are nice. @end example But because of the gobbling, the second sentence needs the empty curly braces or else there would be no space separating @samp{Vermont} from @samp{summers}. (Many authors instead use a backslash-space @code{\ } for this. @xref{\(SPACE)}.) The @package{xspace} package provides @code{\xspace}. It is for writing commands which are designed to be used mainly in text. It must be placed at the very end of the definition of these commands. It inserts a space after that command unless what immediately follows is in a list of exceptions. In this example, the empty braces are not needed. @example \newcommand@{\VT@}@{Vermont\xspace@} Our college is in \VT . \VT summers are nice. @end example The default exception list contains the characters @code{,.'/?;:!~-)}, the open curly brace and the backslash-space command discussed above, and the commands @code{\footnote} or @code{\footnotemark}. Add to that list as with @code{\xspaceaddexceptions@{\myfni \myfnii@}} which adds @code{\myfni} and@tie{}@code{\myfnii} to the list, and remove from that list as with @code{\xspaceremoveexception@{!@}}. @c David Carlisle https://tex.stackexchange.com/a/86620/339 A comment: many experts prefer not to use @code{\xspace}. Putting it in a definition means that the command will usually get the spacing right. But it isn't easy to predict when to enter empty braces because @code{\xspace} will get it wrong, such as when it is followed by another command, and so @code{\xspace} can make editing material harder and more error-prone than instead always inserting the empty braces. @node Counters @chapter Counters @cindex counters, a list of @cindex variables, a list of Everything @LaTeX{} numbers for you has a counter associated with it. The name of the counter is often the same as the name of the environment or command associated with the number, except that the counter's name has no backslash@tie{}@code{\}. Thus, associated with the @code{\chapter} command is the @code{chapter} counter that keeps track of the chapter number. Below is a list of the counters used in @LaTeX{}'s standard document classes to control numbering. @findex part counter @findex chapter counter @findex section counter @findex subsection counter @findex subsubsection counter @findex paragraph counter @findex subparagraph counter @findex page counter @findex equation counter @findex figure counter @findex table counter @findex footnote counter @findex mpfootnote counter @findex enumi counter @findex enumii counter @findex enumiii counter @findex enumiv counter @example part paragraph figure enumi chapter subparagraph table enumii section page footnote enumiii subsection equation mpfootnote enumiv subsubsection @end example The @code{mpfootnote} counter is used by the @code{\footnote} command inside of a minipage (@pxref{minipage}). The counters @code{enumi} through @code{enumiv} are used in the @code{enumerate} environment, for up to four levels of nesting (@pxref{enumerate}). Counters can have any integer value but they are typically positive. New counters are created with @code{\newcounter}. @xref{\newcounter}. @menu * \alph \Alph \arabic \roman \Roman \fnsymbol:: Print value of a counter. * \usecounter:: Use a specified counter in a list environment. * \value:: Use the value of a counter in an expression. * \setcounter:: Set the value of a counter. * \addtocounter:: Add a quantity to a counter. * \refstepcounter:: Add to a counter. * \stepcounter:: Add to a counter, resetting subsidiary counters. * \day & \month & \year:: Numeric date values. @end menu @node \alph \Alph \arabic \roman \Roman \fnsymbol @section @code{\alph \Alph \arabic \roman \Roman \fnsymbol}: Printing counters @cindex counters, printing Print the value of a counter, in a specified style. For instance, if the counter @var{counter} has the value 1 then a @code{\alph@{@var{counter}@}} in your source will result in a lowercase letter@tie{}a appearing in the output. All of these commands take a single counter as an argument, for instance, @code{\alph@{enumi@}}. Note that the counter name does not start with a backslash. @ftable @code @item \alph@{@var{counter}@} Print the value of @var{counter} in lowercase letters: `a', `b', @enddots{} If the counter's value is less than 1 or more than 26 then you get @samp{LaTeX Error: Counter too large.} @item \Alph@{@var{counter}@} Print in uppercase letters: `A', `B', @enddots{} If the counter's value is less than 1 or more than 26 then you get @samp{LaTeX Error: Counter too large.} @item \arabic@{@var{counter}@} Print in Arabic numbers such as @samp{5} or @samp{-2}. @item \roman@{@var{counter}@} Print in lowercase roman numerals: `i', `ii', @enddots{} If the counter's value is less than 1 then you get no warning or error but @LaTeX{} does not print anything in the output. @item \Roman@{@var{counter}@} Print in uppercase roman numerals: `I', `II', @enddots{} If the counter's value is less than 1 then you get no warning or error but @LaTeX{} does not print anything in the output. @item \fnsymbol@{@var{counter}@} Prints the value of @var{counter} using a sequence of nine symbols that are traditionally used for labeling footnotes. The value of @var{counter} should be between@tie{}1 and@tie{}9, inclusive. If the counter's value is less than 0 or more than 9 then you get @samp{LaTeX Error: Counter too large}, while if it is 0 then you get no error or warning but @LaTeX{} does not output anything. Here are the symbols: @multitable @columnfractions .11 .30 .30 .29 @headitem Number@tab Name@tab Command@tab Symbol @item 1@tab asterisk@tab@code{\ast}@tab@iftexthenelse{@math{\ast},*} @item 2@tab dagger@tab@code{\dagger}@tab@BES{2020,\dagger} @item 3@tab ddagger@tab@code{\ddagger}@tab@BES{2021,\ddagger} @item 4@tab section-sign@tab@code{\S}@tab@BES{00A7,\S} @item 5@tab paragraph-sign@tab@code{\P}@tab@BES{00B6,\P} @item 6@tab double-vert@tab@code{\parallel}@tab@BES{2016,\parallel} @item 7@tab double-asterisk@tab@code{\ast\ast}@tab@iftexthenelse{@math{\ast\ast},**} @item 8@tab double-dagger@tab@code{\dagger\dagger}@tab@BES{2020,\dagger}@BES{2020,\dagger} @item 9@tab double-ddagger@tab@code{\ddagger\ddagger}@tab@BES{2021,\ddagger}@BES{2021,\ddagger} @end multitable @end ftable @node \usecounter @section @code{\usecounter} @findex \usecounter @cindex list items, specifying counter @cindex numbered items, specifying counter Synopsis: @example \usecounter@{@var{counter}@} @end example Used in the second argument of the @code{list} environment (@pxref{list}), this declares that list items will be numbered by @var{counter}. It initializes @var{counter} to zero, and arranges that when @code{\item} is called without its optional argument then @var{counter} is incremented by @code{\refstepcounter}, making its value be the current @code{ref} value (@pxref{\ref}). This command is fragile (@pxref{\protect}). Put in the document preamble, this example makes a new list environment enumerated with @var{testcounter}: @example \newcounter@{testcounter@} \newenvironment@{test@}@{% \begin@{list@}@{@}@{% \usecounter@{testcounter@} @} @}@{% \end@{list@} @} @end example @node \value @section @code{\value} @findex \value @cindex counters, getting value of Synopsis: @example \value@{@var{counter}@} @end example Expands to the value of the counter @var{counter}. (Note that the name of a counter does not begin with a backslash.) This example outputs @samp{Test counter is@tie{}6. Other counter is@tie{}5.}. @example \newcounter@{test@} \setcounter@{test@}@{5@} \newcounter@{other@} \setcounter@{other@}@{\value@{test@}@} \addtocounter@{test@}@{1@} Test counter is \arabic@{test@}. Other counter is \arabic@{other@}. @end example The @code{\value} command is not used for typesetting the value of the counter. For that, see @ref{\alph \Alph \arabic \roman \Roman \fnsymbol}. It is often used in @code{\setcounter} or @code{\addtocounter} but @code{\value} can be used anywhere that @LaTeX{} expects a number, such as in @code{\hspace@{\value@{foo@}\parindent@}}. It must not be preceded by @code{\protect} (@pxref{\protect}). This example inserts @code{\hspace@{4\parindent@}}. @example \setcounter@{myctr@}@{3@} \addtocounter@{myctr@}@{1@} \hspace@{\value@{myctr@}\parindent@} @end example @node \setcounter @section @code{\setcounter} @findex \setcounter @cindex counters, setting @cindex setting counters Synopsis: @example \setcounter@{@var{counter}@}@{@var{value}@} @end example Globally set the counter @var{counter} to have the value of the @var{value} argument, which must be an integer. Thus, you can set a counter's value as @code{\setcounter@{section@}@{5@}}. Note that the counter name does not start with a backslash. In this example if the counter @code{theorem} has value 12 then the second line will print @samp{XII}. @example \setcounter@{exercise@}@{\value@{theorem@}@} Here it is in Roman: \Roman@{exercise@}. @end example @node \addtocounter @section @code{\addtocounter} @findex \addtocounter Synopsis: @example \addtocounter@{@var{counter}@}@{@var{value}@} @end example Globally increment @var{counter} by the amount specified by the @var{value} argument, which may be negative. In this example the section value appears as @samp{VII}. @example \setcounter@{section@}@{5@} \addtocounter@{section@}@{2@} Here it is in Roman: \Roman@{section@}. @end example @node \refstepcounter @section @code{\refstepcounter} @findex \refstepcounter Synopsis: @example \refstepcounter@{@var{counter}@} @end example Globally increments the value of @var{counter} by one, as does @code{\stepcounter} (@pxref{\stepcounter}). The difference is that this command resets the value of any counter numbered within it. (For the definition of ``counters numbered within'', @pxref{\newcounter}.) In addition, this command also defines the current @code{\ref} value to be the result of @code{\thecounter}. While the counter value is set globally, the @code{\ref} value is set locally, i.e., inside the current group. @node \stepcounter @section @code{\stepcounter} @findex \stepcounter Synopsis: @example \stepcounter@{@var{counter}@} @end example Globally adds one to @var{counter} and resets all counters numbered within it. (For the definition of ``counters numbered within'', @pxref{\newcounter}.) This command differs from @code{\refstepcounter} in that this one does not influence references; that is, it does not define the current @code{\ref} value to be the result of @code{\thecounter} (@pxref{\refstepcounter}). @node \day & \month & \year @section @code{\day} & @code{\month} & @code{\year} @anchor{\day} @anchor{\month} @anchor{\year} @findex \day @findex \month @findex \year @LaTeX{} defines the counter @code{\day} for the day of the month (nominally with value between 1 and 31), @code{\month} for the month of the year (nominally with value between 1 and 12), and @code{\year} for the year. When @TeX{} starts up, they are set from the current values on the system. The related command @code{\today} produces a string representing the current day (@pxref{\today}). They counters are not updated as the job progresses so in principle they could be incorrect by the end. In addition, @TeX{} does no sanity check: @example \day=-2 \month=13 \year=-4 \today @end example @noindent gives no error or warning and results in the output @samp{-2, -4} (the bogus month value produces no output). @xref{Command line input}, to force the date to a given value from the command line. @node Lengths @chapter Lengths @cindex lengths, defining and using A @dfn{length} is a measure of distance. Many @LaTeX{} commands take a length as an argument. @cindex rigid lengths @cindex rubber lengths @cindex dimen @r{plain @TeX{}} @cindex skip @r{plain @TeX{}} @cindex glue @r{plain @TeX{}} Lengths come in two types. A @dfn{rigid length} such as @code{10pt} does not contain a @code{plus} or @code{minus} component. (Plain @TeX{} calls this a @dfn{dimen}.) A @dfn{rubber length} (what plain @TeX{} calls a @dfn{skip} or @dfn{glue}) such as with @code{1cm plus0.05cm minus0.01cm} can contain either or both of those components. In that rubber length, the @code{1cm} is the @dfn{natural length} while the other two, the @code{plus} and @code{minus} components, allow @TeX{} to stretch or shrink the length to optimize placement. The illustrations below use these two commands. @example % make a black bar 10pt tall and #1 wide \newcommand@{\blackbar@}[1]@{\rule@{#1@}@{10pt@}@} % Make a box around #2 that is #1 wide (excluding the border) \newcommand@{\showhbox@}[2]@{% \fboxsep=0pt\fbox@{\hbox to #1@{#2@}@}@} @end example @noindent This example uses those commands to show a black bar 100@tie{}points long between @samp{XXX} and @samp{YYY}. This length is rigid. @example XXX\showhbox@{100pt@}@{\blackbar@{100pt@}@}YYY @end example As for rubber lengths, shrinking is simpler one: with @code{1cm minus 0.05cm}, the natural length is 1@dmn{cm} but @TeX{} can shrink it down as far as 0.95@dmn{cm}. Beyond that, @TeX{} refuses to shrink any more. Thus, below the first one works fine, producing a space of 98@tie{}points between the two bars. @example XXX\showhbox@{300pt@}@{% \blackbar@{101pt@}\hspace@{100pt minus 2pt@}\blackbar@{101pt@}@}YYY XXX\showhbox@{300pt@}@{% \blackbar@{105pt@}\hspace@{100pt minus 1pt@}\blackbar@{105pt@}@}YYY @end example @noindent But the second one gets a warning like @samp{Overfull \hbox (1.0pt too wide) detected at line 17}. In the output the first @samp{Y} is overwritten by the end of the black bar, because the box's material is wider than the 300@dmn{pt} allocated, as @TeX{} has refused to shrink the total to less than 309@tie{}points. Stretching is like shrinking except that if @TeX{} is asked to stretch beyond the given amount, it will do it. Here the first line is fine, producing a space of 110@tie{}points between the bars. @example XXX\showhbox@{300pt@}@{% \blackbar@{95pt@}\hspace@{100pt plus 10pt@}\blackbar@{95pt@}@}YYY XXX\showhbox@{300pt@}@{% \blackbar@{95pt@}\hspace@{100pt plus 1pt@}\blackbar@{95pt@}@}YYY @end example @noindent In the second line @TeX{} needs a stretch of 10@tie{}points and only 1@tie{}point was specified. @TeX{} stretches the space to the required length but it gives you a warning like @samp{Underfull \hbox (badness 10000) detected at line 22}. (We won't discuss badness.) You can put both stretch and shrink in the same length, as in @code{1ex plus 0.05ex minus 0.02ex}. If @TeX{} is setting two or more rubber lengths then it allocates the stretch or shrink in proportion. @example XXX\showhbox@{300pt@}@{% \blackbar@{100pt@}% left \hspace@{0pt plus 50pt@}\blackbar@{80pt@}\hspace@{0pt plus 10pt@}% middle \blackbar@{100pt@}@}YYY % right @end example @noindent The left and right bars take up 100@tie{}points, so the middle needs another 100. The middle bar is 80@tie{}points so the two @code{\hspace}'s must stretch 20@tie{}points. Because the two are @code{plus 50pt} and @code{plus 10pt}, @TeX{} gets 5/6 of the stretch from the first space and 1/6 from the second. The @code{plus} or @code{minus} component of a rubber length can contain a @dfn{fill} component, as in @code{1in plus2fill}. This gives the length infinite stretchability or shrinkability so that @TeX{} could set it to any distance. Here the two figures will be equal-spaced across the page. @example \begin@{minipage@}@{\linewidth@} \hspace@{0pt plus 1fill@}\includegraphics@{godel.png@}% \hspace@{0pt plus 1fill@}\includegraphics@{einstein.png@}% \hspace@{0pt plus 1fill@} \end@{minipage@} @end example @TeX{} has three levels of infinity for glue components: @code{fil}, @code{fill}, and @code{filll}. The later ones are more infinite than the earlier ones. Ordinarily document authors only use the middle one (@pxref{\hfill} and @pxref{\vfill}). Multiplying a rubber length by a number turns it into a rigid length, so that after @code{\setlength@{\ylength@}@{1in plus 0.2in@}} and @code{\setlength@{\zlength@}@{3\ylength@}} then the value of @code{\zlength} is @code{3in}. @menu * Units of length:: The units that @LaTeX{} knows. * \setlength:: Set the value of a length. * \addtolength:: Add a quantity to a length. * \settodepth:: Set a length to the depth of something. * \settoheight:: Set a length to the height of something. * \settowidth:: Set a length to the width of something. * \stretch:: Add infinite stretchability. * Expressions:: Compute with lengths and integers. @end menu @node Units of length @section Units of length @cindex units, of length @TeX{} and @LaTeX{} know about these units both inside and outside of math mode. @ftable @code @item pt @cindex point @anchor{units of length pt} Point, 1/72.27 inch. The (approximate) conversion to metric units is 1@dmn{point} = .35146@dmn{mm} = .035146@dmn{cm}. @item pc @cindex pica @anchor{units of length pc} Pica, 12 pt @item in @cindex inch @anchor{units of length in} Inch, 72.27 pt @item bp @cindex big point @cindex PostScript point @anchor{units of length bp} Big point, 1/72 inch. This length is the definition of a point in PostScript and many desktop publishing systems. @item mm @cindex millimeter @anchor{units of length mm} Millimeter, 2.845@dmn{pt} @item cm @cindex centimeter @anchor{units of length cm} Centimeter, 10@dmn{mm} @item dd @cindex didot point @anchor{units of length dd} Didot point, 1.07 pt @item cc @cindex cicero @anchor{units of length cc} Cicero, 12 dd @item sp @cindex scaled point @anchor{units of length sp} Scaled point, 1/65536 pt @end ftable Three other units are defined according to the current font, rather than being an absolute dimension. @ftable @code @item ex @cindex x-height @cindex ex @anchor{Lengths/ex} @anchor{units of length ex} The x-height of the current font @dfn{ex}, traditionally the height of the lowercase letter x, is often used for vertical lengths. @item em @cindex m-width @cindex em @anchor{Lengths/em} @anchor{units of length em} Similarly @dfn{em}, traditionally the width of the capital letter M, is often used for horizontal lengths. This is also often the size of the current font, e.g., a nominal 10@dmn{pt} font will have 1@dmn{em} = 10@dmn{pt}. @LaTeX{} has several commands to produce horizontal spaces based on the em (@pxref{\enspace & \quad & \qquad}). @item mu @cindex mu, math unit @anchor{units of length mu} Finally, in math mode, many definitions are expressed in terms of the math unit @dfn{mu}, defined by 1@dmn{em} = 18@dmn{mu}, where the em is taken from the current math symbols family. @xref{Spacing in math mode}. @end ftable Using these units can help make a definition work better across font changes. For example, a definition of the vertical space between list items given as @code{\setlength@{\itemsep@}@{1ex plus 0.05ex minus 0.01ex@}} is more likely to still be reasonable if the font is changed than a definition given in points. @node \setlength @section @code{\setlength} @findex \setlength @cindex lengths, setting Synopsis: @example \setlength@{\@var{len}@}@{@var{amount}@} @end example Set the length \@var{len} to @var{amount}. The length name @code{\@var{len}} has to be a control sequence (@pxref{Control sequences}), and as such must begin with a backslash, @code{\} under normal circumstances. The @var{amount} can be a rubber length (@pxref{Lengths}). It can be positive, negative or zero, and can be in any units that @LaTeX{} understands (@pxref{Units of length}). Below, with @LaTeX{}'s defaults the first paragraph will be indented while the second will not. @example I told the doctor I broke my leg in two places. \setlength@{\parindent@}@{0em@} He said stop going to those places. @end example If you did not declare \@var{len} with @code{\newlength}, for example if you mistype it as in @code{\newlength@{\specparindent@}\setlength@{\sepcparindent@}@{...@}}, then you get an error like @samp{Undefined control sequence. \sepcindent}. If you omit the backslash at the start of the length name then you get an error like @samp{Missing number, treated as zero.}. @node \addtolength @section @code{\addtolength} @findex \addtolength @cindex lengths, adding to Synopsis: @example \addtolength@{\@var{len}@}@{@var{amount}@} @end example Increment the length \@var{len} by @var{amount}. The length name @code{\@var{len}} has to be a control sequence (@pxref{Control sequences}), and as such must begin with a backslash, @code{\} under normal circumstances. The @var{amount} is a rubber length (@pxref{Lengths}). It can be positive, negative or zero, and can be in any units that @LaTeX{} understands (@pxref{Units of length}). Below, if @code{\parskip} starts with the value @code{0pt plus 1pt} @example Doctor: how is the boy who swallowed the silver dollar? \addtolength@{\parskip@}@{1pt@} Nurse: no change. @end example @noindent then it has the value @code{1pt plus 1pt} for the second paragraph. If you did not declare \@var{len} with @code{\newlength}, for example if you mistype it as in @code{\newlength@{\specparindent@}\addtolength@{\sepcparindent@}@{...@}}, then you get an error like @samp{Undefined control sequence. \sepcindent}. If the @var{amount} uses some length that has not been declared, for instance if for example you mistype the above as @code{\addtolength@{\specparindent@}@{0.6\praindent@}}, then you get something like @samp{Undefined control sequence. \praindent}. If you leave off the backslash at the start of \@var{len}, as in @code{\addtolength@{parindent@}@{1pt@}}, then you get something like @samp{You can't use `the letter p' after \advance}. @node \settodepth @section @code{\settodepth} @findex \settodepth Synopsis: @example \settodepth@{\@var{len}@}@{@var{text}@} @end example Set the length \@var{len} to the depth of box that @LaTeX{} gets on typesetting the @var{text} argument. The length name @code{\@var{len}} has to be a control sequence (@pxref{Control sequences}), and as such must begin with a backslash, @code{\} under normal circumstances. This will print how low the character descenders go. @example \newlength@{\alphabetdepth@} \settodepth@{\alphabetdepth@}@{abcdefghijklmnopqrstuvwxyz@} \the\alphabetdepth @end example If you did not declare \@var{len} with @code{\newlength}, if for example you mistype the above as @code{\settodepth@{\aplhabetdepth@}@{abc...@}}, then you get something like @samp{Undefined control sequence. \aplhabetdepth}. If you leave the backslash out of \@var{len}, as in @code{\settodepth@{alphabetdepth@}@{...@}} then you get something like @samp{Missing number, treated as zero. \setbox}. @node \settoheight @section @code{\settoheight} @findex \settoheight Synopsis: @example \settoheight@{\@var{len}@}@{text@} @end example Sets the length \@var{len} to the height of box that @LaTeX{} gets on typesetting the @code{text} argument. The length name @code{\@var{len}} has to be a control sequence (@pxref{Control sequences}), and as such must begin with a backslash, @code{\} under normal circumstances. This will print how high the characters go. @example \newlength@{\alphabetheight@} \settoheight@{\alphabetheight@}@{abcdefghijklmnopqrstuvwxyz@} \the\alphabetheight @end example If no such length \@var{len} has been declared with @code{\newlength}, if for example you mistype as @code{\settoheight@{\aplhabetheight@}@{abc...@}}, then you get something like @samp{Undefined control sequence. \alphabetheight}. If you leave the backslash out of \@var{len}, as in @code{\settoheight@{alphabetheight@}@{...@}} then you get something like @samp{Missing number, treated as zero. \setbox}. @node \settowidth @section @code{\settowidth} @findex \settowidth Synopsis: @example \settowidth@{\@var{len}@}@{@var{text}@} @end example Set the length \@var{len} to the width of the box that @LaTeX{} gets on typesetting the @var{text} argument. The length name @code{\@var{len}} has to be a control sequence (@pxref{Control sequences}), and as such must begin with a backslash, @code{\} under normal circumstances. This prints the width of the lowercase ASCII alphabet. @example \newlength@{\alphabetwidth@} \settowidth@{\alphabetwidth@}@{abcdefghijklmnopqrstuvwxyz@} \the\alphabetwidth @end example If no such length \@var{len} has been declared with @code{\newlength}, if for example you mistype the above as @code{\settowidth@{\aplhabetwidth@}@{abc...@}}, then you get something like @samp{Undefined control sequence. \aplhabetwidth}. If you leave the backslash out of \@var{len}, as in @code{\settoheight@{alphabetwidth@}@{...@}} then you get something like @samp{Missing number, treated as zero. \setbox}. @node \stretch @section @code{\stretch} @findex \stretch Synopsis: @example \stretch@{@var{number}@} @end example Produces a rubber length with zero natural length and @var{number} times @code{\fill} units of stretchability (@pxref{Lengths}). The @var{number} can be positive or negative. This command is robust (@pxref{\protect}). It works for both vertical and horizontal spacing. In this horizontal example, @LaTeX{} produces three tick marks, and the distance between the first and second is half again as long as the distance between the second and third. @example \rule@{0.4pt@}@{1ex@}\hspace@{\stretch@{1.5@}@}% \rule@{0.4pt@}@{1ex@}\hspace@{\stretch@{1@}@}% \rule@{0.4pt@}@{1ex@} @end example In this vertical example, the @samp{We dedicate @dots{}} will have three times as much space under it as above it. @example \newenvironment@{dedication@}@{% in document preamble \clearpage\thispagestyle@{empty@}% \vspace*@{\stretch@{1@}@} % stretchable space at top \it @}@{% \vspace@{\stretch@{3@}@} % space at bot is 3x as at top \clearpage @} ... \begin@{dedication@} % in document body We dedicate this book to our wives. \end@{dedication@} @end example @node Expressions @section Expressions @findex expressions @c Much from Joseph Wright's https://tex.stackexchange.com/a/245663/339 Synopsis, one of: @example \numexpr @var{expression} \dimexpr @var{expression} \glueexpr @var{expression} \muglue @var{expression} @end example Any place where you may write an integer, or a @TeX{} dimen, or @TeX{} glue, or muglue, you can instead write an expression to compute that type of quantity. An example is that @code{\the\dimexpr\linewidth-4pt\relax} will produce as output the length that is four points less than width of a line (the only purpose of @code{\the} is to show the result in the document). Analogously, @code{\romannumeral\numexpr6+3\relax} will produce @samp{ix}, and @code{\the\glueexpr 5pt plus 1pt * 2 \relax} will produce @samp{10.0pt plus 2.0pt}. A convenience here over doing calculations by allocating registers and then using @code{\advance}, etc., is that the evaluation of expressions does not involve assignments and can therefore be performed in places where assignments are not allowed. The next example computes the width of the @code{\parbox}. @example \newlength@{\offset@}\setlength@{\offset@}@{2em@} \begin@{center@} \parbox@{\dimexpr\linewidth-\offset*3@}@{With malice toward none with charity for all with firmness in the right as God gives us to see the right let us strive on to finish the work we are in to bind up the nation's wounds, to care for him who shall have borne the battle and for his widow and his orphan \textasciitilde\ to do all which may achieve and cherish a just and lasting peace among ourselves and with all nations. ---Abraham Lincoln, Second Inaugural Address, from the memorial@} \end@{center@} @end example The @var{expression} consists of one or more terms of the same type (integer, dimension, etc.) that are added or subtracted. A term that is a type of number, dimension, etc., consists of a factor of that type, optionally multiplied or divided by factors. A factor of a type is either a quantity of that type or a parenthesized subexpression. The expression produces a result of the given type, so that @code{\numexpr} produces an integer, @code{\dimexpr} produces a dimension, etc. In the quotation example above, changing to @code{\dimexpr\linewidth-3*\offset} gives the error @code{Illegal unit of measure (pt inserted)}. This is because for @code{\dimexpr} and @code{\glueexpr}, the input consists of a dimension or glue value followed by an optional multiplication factor, and not the other way around. Thus @code{\the\dimexpr 1pt*10\relax} is valid and produces @samp{10.0pt}, but @code{\the\dimexpr 10*1pt\relax} gives the @code{Illegal unit} error. The expressions absorb tokens and carry out appropriate mathematics up to a @code{\relax} (which will be absorbed), or up to the first non-valid token. Thus, @code{\the\numexpr2+3px} will print @samp{5px}, because @LaTeX{} reads the @code{\numexpr2+3}, which is made up of numbers, and then finds the letter @code{p}, which cannot be part of a number. It therefore terminates the expression and produces the @samp{5}, followed by the regular text @samp{px}. This termination behavior is useful in comparisons. In @code{\ifnum\numexpr\parindent*2 < 10pt Yes\else No\fi}, the less than sign terminates the expression and the result is @samp{No} (in a standard @LaTeX{} article). Expressions may use the operators @code{+}, @code{-}, @code{*} and @code{/} along with parentheses for subexpressions, @code{(...)}. In glue expressions the @code{plus} and @code{minus} parts do not need parentheses to be affected by a factor. So @code{\the\glueexpr 5pt plus 1pt * 2 \relax} results in @samp{10pt plus 2pt}. @TeX{} will coerce other numerical types in the same way as it does when doing register assignment. Thus @code{\the\numexpr\dimexpr 1pt\relax\relax} will result in @samp{65536}, which is @code{1pt} converted to scaled points (@pxref{units of length sp,@code{sp}}, @TeX{}'s internal unit) and then coerced into an integer. With a @code{\glueexpr} here, the stretch and shrink would be dropped. Going the other way, a @code{\numexpr} inside a @code{\dimexpr} or @code{\glueexpr} will need appropriate units, as in @code{\the\dimexpr\numexpr 1 + 2\relax pt\relax}, which produces @samp{3.0pt}. The details of the arithmetic: each factor is checked to be in the allowed range, numbers must be less than @math{2^{31}} in absolute value, and dimensions or glue components must be less than @math{2^{14}} points, or @code{mu}, or @code{fil}, etc. The arithmetic operations are performed individually, except for a scaling operation (a multiplication immediately followed by a division) which is done as one combined operation with a 64-bit product as intermediate value. The result of each operation is again checked to be in the allowed range. Finally, division and scaling take place with rounding (unlike @TeX{}'s @code{\divide}, which truncates). Thus @code{\the\dimexpr 5pt*(3/2)\relax} puts @samp{10.0pt} in the document, because it rounds @code{3/2} to @code{2}, while @code{\the\dimexpr 5pt*(4/3)\relax} produces @samp{5.0pt}. @node Making paragraphs @chapter Making paragraphs @cindex making paragraphs @cindex paragraphs To start a paragraph, just type some text. To end the current paragraph, put an empty line. This is three paragraphs, the separation of which is made by two empty lines. @example It is a truth universally acknowledged, that a single man in possession of a good fortune, must be in want of a wife. However little known the feelings or views of such a man may be on his first entering a neighbourhood, this truth is so well fixed in the minds of the surrounding families, that he is considered the rightful property of some one or other of their daughters. ``My dear Mr. Bennet,'' said his lady to him one day, ``have you heard that Netherfield Park is let at last?'' @end example A paragraph separator can be made of a sequence of at least one blank line, at least one of which is not terminated by a comment. A blank line is a line that is empty or made only of blank characters such as space or tab. Comments in source code are started with a @code{%} and span up to the end of line. In the following example the two columns are identical: @example \documentclass[twocolumn]@{article@} \begin@{document@} First paragraph. Second paragraph. \newpage First paragraph. % separator lines may contain blank characters. Second paragraph. \end@{document@} @end example Once @LaTeX{} has gathered all of a paragraph's contents it divides that content into lines in a way that is optimized over the entire paragraph (@pxref{Line breaking}). There are places where a new paragraph is not permitted. Don't put a blank line in math mode (@pxref{Modes}); here the blank line before the @code{\end@{equation@}} @example \begin@{equation@} 2^@{|S|@} > |S| \end@{equation@} @end example @noindent will get you the error @samp{Missing $ inserted}. Similarly, the blank line in this @code{\section} argument @example \section@{aaa bbb@} @end example @noindent gets @samp{Runaway argument? @{aaa ! Paragraph ended before \@@sect was complete}. @menu * \par:: End the current paragraph. * \indent & \noindent:: Go into horizontal mode, possibly with an indent. * \parindent & \parskip:: Space added before paragraphs. * Marginal notes:: Put remarks in the margin. @end menu @node \par @section @code{\par} @findex \par @cindex paragraph, ending Synopsis (note that while reading the input @TeX{} converts any sequence of one or more blank lines to a @code{\par}, @ref{Making paragraphs}): @example \par @end example End the current paragraph. The usual way to separate paragraphs is with a blank line but the @code{\par} command is entirely equivalent. This command is robust (@pxref{\protect}). This example uses @code{\par} rather than a blank line simply for readability. @example \newcommand@{\syllabusLegalese@}@{% \whatCheatingIs\par\whatHappensWhenICatchYou@} @end example In LR mode the @code{\par} command does nothing and is ignored. In paragraph mode, the @code{\par} command terminates paragraph mode, switching @LaTeX{} to vertical mode (@pxref{Modes}). You cannot use the @code{\par} command in a math mode. You also cannot use it in the argument of many commands, such as the sectioning commands, e.g.@: @code{\section} (@pxref{Making paragraphs} and @ref{\newcommand & \renewcommand}). The @code{\par} command is not the same as the @code{\paragraph} command. The latter is, like @code{\section} or @code{\subsection}, a sectioning command used by the @LaTeX{} document standard classes (@pxref{\subsubsection & \paragraph & \subparagraph}). The @code{\par} command is not the same as @code{\newline} or the line break double backslash, @code{\\}. The difference is that @code{\par} ends the paragraph, not just the line, and also triggers the addition of the between-paragraph vertical space @code{\parskip} (@pxref{\parindent & \parskip}). The output from this example @example xyz \setlength@{\parindent@}@{3in@} \setlength@{\parskip@}@{5in@} \noindent test\indent test1\par test2 @end example @noindent is: after @samp{xyz} there is a vertical skip of 5@tie{}inches and then @samp{test} appears, aligned with the left margin. On the same line, there is an empty horizontal space of 3@tie{}inches and then @samp{test1} appears. Finally. there is a vertical space of 5@tie{}inches, followed by a fresh paragraph with a paragraph indent of 3@tie{}inches, and then @LaTeX{} puts the text @samp{test2}. @node \indent & \noindent @section @code{\indent} & @code{\noindent} @anchor{\indent} @anchor{\noindent} @findex \indent @findex \noindent @cindex indent, forcing Synopsis: @example \indent @end example @noindent or @example \noindent @end example Go into horizontal mode (@pxref{Modes}). The @code{\indent} command first outputs an empty box whose width is @code{\parindent}. These commands are robust (@pxref{\protect}). Ordinarily you create a new paragraph by putting in a blank line. @xref{\par}, for the difference between this command and @code{\par}. To start a paragraph without an indent, or to continue an interrupted paragraph, use @code{\noindent}. In the middle of a paragraph the @code{\noindent} command has no effect, because @LaTeX{} is already in horizontal mode there. The @code{\indent} command's only effect is to output a space. This example starts a fresh paragraph. @example ... end of the prior paragraph. \noindent This paragraph is not indented. @end example @noindent and this continues an interrupted paragraph. @example The data \begin@{center@} \begin@{tabular@}@{rl@} ... \end@{tabular@} \end@{center@} \noindent shows this clearly. @end example @findex \parindent To omit indentation in the entire document put @code{\setlength@{\parindent@}@{0pt@}} in the preamble. If you do that, you may want to also set the length of spaces between paragraphs, @code{\parskip} (@pxref{\parindent & \parskip}). @PkgIndex{indentfirst} Default @LaTeX{} styles have the first paragraph after a section that is not indented, as is traditional typesetting in English. To change that, look on CTAN for the package @package{indentfirst}. @node \parindent & \parskip @section @code{\parindent} & @code{\parskip} @anchor{\parindent} @anchor{\parskip} @findex \parindent @findex \parskip @cindex paragraph indentation @cindex horizontal paragraph indentation @cindex vertical space before paragraphs Synopsis: @example \setlength@{\parindent@}@{@var{horizontal len}@} \setlength@{\parskip@}@{@var{vertical len}@} @end example Both are rubber lengths (@pxref{Lengths}). They affect the indentation of ordinary paragraphs, not paragraphs inside minipages (@pxref{minipage}), and the vertical space between paragraphs, respectively. For example, if this is put in the preamble: @example \setlength@{\parindent@}@{0em@} \setlength@{\parskip@}@{1ex@} @end example @noindent The document will have paragraphs that are not indented, but instead are vertically separated by about the height of a lowercase @samp{x}. In @LaTeX{} standard class documents, the default value for @code{\parindent} in one-column documents is @code{15pt} when the default text size is @code{10pt}, @code{17pt} for @code{11pt}, and @code{1.5em} for @code{12pt}. In two-column documents it is @code{1em}. (These values are set before @LaTeX{} calls @code{\normalfont} so @code{em} is derived from the default font, Computer Modern. If you use a different font then to set @code{\parindent} to 1@dmn{em} matching that font, put @code{\AtBeginDocument@{\setlength@{\parindent@}@{1em@}@}} in the preamble.) The default value for @code{\parskip} in @LaTeX{}'s standard document classes is @code{0pt plus1pt}. @node Marginal notes @section Marginal notes @cindex marginal notes @cindex notes in the margin @cindex remarks in the margin @findex \marginpar Synopsis, one of: @example \marginpar@{@var{right}@} \marginpar[@var{left}]@{@var{right}@} @end example Create a note in the margin. The first line of the note will have the same baseline as the line in the text where the @code{\marginpar} occurs. The margin that @LaTeX{} uses for the note depends on the current layout (@pxref{Document class options}) and also on @code{\reversemarginpar} (see below). If you are using one-sided layout (document option @code{oneside}) then it goes in the right margin. If you are using two-sided layout (document option @code{twoside}) then it goes in the outside margin. If you are in two-column layout (document option @code{twocolumn}) then it goes in the nearest margin. @findex \reversemarginpar @findex \normalmarginpar If you declare @code{\reversemarginpar} then @LaTeX{} will place subsequent marginal notes in the opposite margin to that given in the prior paragraph. Revert that to the default position with @code{\normalmarginpar}. When you specify the optional argument @var{left} then it is used for a note in the left margin, while the mandatory argument @var{right} is used for a note in the right margin. Normally, a note's first word will not be hyphenated. You can enable hyphenation there by beginning @var{left} or @var{right} with @code{\hspace@{0pt@}}. These parameters affect the formatting of the note: @ftable @code @item \marginparpush @anchor{marginal notes marginparpush} Minimum vertical space between notes; default @samp{7pt} for @samp{12pt} documents, @samp{5pt} else. See also@tie{}@ref{page layout parameters marginparpush}. @item \marginparsep @anchor{marginal notes marginparsep} Horizontal space between the main text and the note; default @samp{11pt} for @samp{10pt} documents, @samp{10pt} else. @item \marginparwidth @anchor{marginal notes marginparwidth} Width of the note itself; default for a one-sided @samp{10pt} document is @samp{90pt}, @samp{83pt} for @samp{11pt}, and @samp{68pt} for @samp{12pt}; @samp{17pt} more in each case for a two-sided document. In two column mode, the default is @samp{48pt}. @end ftable The standard @LaTeX{} routine for marginal notes does not prevent notes from falling off the bottom of the page. @c @TeX{} FAQ entry on this topic (xx when there): @c @url{http://www.tex.ac.uk/cgi-bin/texfaq2html?label=marginparside}. @c (+marginfix) @node Math formulas @chapter Math formulas @cindex math formulas @cindex formulas, math @cindex math mode, entering @EnvIndex{math} @EnvIndex{displaymath} @EnvIndex{equation} Produce mathematical text by putting @LaTeX{} into math mode or display math mode (@pxref{Modes}). This example shows both. @example The wave equation for \( u \) is \begin@{displaymath@} \frac@{\partial^2u@}@{\partial t^2@} = c^2\nabla^2u \end@{displaymath@} where \( \nabla^2 \) is the spatial Laplacian and \( c \) is constant. @end example @noindent Math mode is for inline mathematics. In the above example it is invoked by the starting @code{\(} and finished by the matching ending @code{\)}. Display math mode is for displayed equations and here is invoked by the @code{displaymath} environment. Note that any mathematical text whatever, including mathematical text consisting of just one character, is handled in math mode. When in math mode or display math mode, @LaTeX{} handles many aspects of your input text differently than in other text modes. For example, @example contrast x+y with \( x+y \) @end example @noindent in math mode the letters are in italics and the spacing around the plus sign is different. There are three ways to make inline formulas, to put @LaTeX{} in math mode. @example \( @var{mathematical material} \) $ @var{mathematical material} $ \begin@{math@} @var{mathematical material} \end@{math@} @end example @noindent The first form is preferred and the second is quite common, but the third form is rarely used. You can sometimes use one and sometimes another, as in @code{\(x\) and $y$}. You can use these in paragraph mode or in LR mode (@pxref{Modes}). To make displayed formulas, put @LaTeX{} into display math mode with either: @example \begin@{displaymath@} @var{mathematical material} \end@{displaymath@} @end example @noindent or @example \begin@{equation@} @var{mathematical material} \end@{equation@} @end example @noindent (@pxref{displaymath}, @pxref{equation}). The only difference is that with the @code{equation} environment, @LaTeX{} puts a formula number alongside the formula. The construct @code{\[ @var{math} \]} is equivalent to @code{\begin@{displaymath@} @var{math} \end@{displaymath@}}. These environments can only be used in paragraph mode (@pxref{Modes}). @PkgIndex{amsmath} @PkgIndex{amsfonts} @PkgIndex{mathtools} The American Mathematical Society has made freely available a set of packages that greatly expand your options for writing mathematics, @package{amsmath} and @package{amssymb} (also be aware of the @package{mathtools} package that is an extension to, and loads, @package{amsmath}). New documents that will have mathematical text should use these packages. Descriptions of these packages is outside the scope of this document; see their documentation on CTAN. @menu * Subscripts & superscripts:: Also known as exponents or indices. * Math symbols:: Various mathematical squiggles. * Math functions:: Math function names like sin and exp. * Math accents:: Accents in math. * Over- and Underlining:: Things over or under formulas. * Spacing in math mode:: Thick, medium, thin, and negative spaces. * Math styles:: Determine the size of things. * Math miscellany:: Stuff that doesn't fit anywhere else. @end menu @node Subscripts & superscripts @section Subscripts & superscripts @anchor{superscript} @anchor{subscript} @cindex superscript @cindex subscript @findex ^ @r{superscript} @findex _ @r{subscript} @cindex exponent Synopsis (in math mode or display math mode), one of: @example @var{base}^@var{exp} @var{base}^@{@var{exp}@} @end example @noindent or, one of: @example @var{base}_@var{exp} @var{base}_@{@var{exp}@} @end example Make @var{exp} appear as a superscript of @var{base} (with the caret character,@tie{}@code{^}) or a subscript (with underscore,@tie{}@code{_}). In this example the @code{0}'s and @code{1}'s are subscripts while the @code{2}'s are superscripts. @example \( (x_0+x_1)^2 \leq (x_0)^2+(x_1)^2 \) @end example To have the subscript or superscript contain more than one character, surround the expression with curly braces, as in @code{e^@{-2x@}}. This example's fourth line shows curly braces used to group an expression for the exponent. @example \begin@{displaymath@} (3^3)^3=27^3=19\,683 \qquad 3^@{(3^3)@}=3^@{27@}=7\,625\,597\,484\,987 \end@{displaymath@} @end example @LaTeX{} knows how to handle a superscript on a superscript, or a subscript on a subscript, or supers on subs, or subs on supers. So, expressions such as @code{e^@{x^2@}} and @code{x_@{i_0@}} give correct output. Note the use in those expressions of curly braces to give the @var{base} a determined @var{exp}. If you enter @code{\(3^3^3\)}, this interpreted as @code{\(3^@{3@}^@{3@}\)} and then you get @TeX{} error @samp{Double superscript}. @LaTeX{} does the right thing when something has both a subscript and a superscript. In this example the integral has both. They come out in the correct place without any author intervention. @example \begin@{displaymath@} \int_@{x=a@}^b f'(x)\,dx = f(b)-f(a) \end@{displaymath@} @end example @noindent Note the curly braces around @code{x=a} to make the entire expression a subscript. To put a superscript or subscript before a symbol, use a construct like @code{@{@}_t K^2}. The empty curly braces @code{@{@}} give the subscript something to attach to and keeps it from accidentally attaching to a prior symbols. Using the subscript or superscript character outside of math mode or display math mode, as in @code{the expression x^2}, will get you the @TeX{} error @samp{Missing $ inserted}. @PkgIndex{mhchem} A common reason to want subscripts outside of a mathematics mode is to typeset chemical formulas. There are packages for that, such as @package{mhchem}; see CTAN. @node Math symbols @section Math symbols @cindex math symbols @cindex symbols, math @cindex greek letters @PkgIndex{comprehensive} @LaTeX{} provides almost any mathematical or technical symbol that anyone uses. For example, if you include @code{$\pi$} in your source, you will get the pi symbol @BES{03C0,\pi}. See the ``Comprehensive @LaTeX{} Symbol List'' package at @url{https://ctan.org/pkg/comprehensive}. Here is a list of commonly-used symbols. It is by no means exhaustive. Each symbol is described with a short phrase, and its symbol class, which determines the spacing around it, is given in parenthesis. Unless said otherwise, the commands for these symbols can be used only in math mode. To redefine a command so that it can be used whatever the current mode, see @ref{\ensuremath}. @c xx Add Negation: for negations of relevant symbols @c Useful: http://www.w3.org/TR/WD-math-970515/section6.html @ftable @code @item \| @BES{2225,\|} Parallel (relation). Synonym:@tie{}@code{\parallel}. @item \aleph @BES{2135,\aleph} Aleph, transfinite cardinal (ordinary). @item \alpha @BES{03B1,\alpha} Lowercase Greek letter alpha (ordinary). @item \amalg @BES{2A3F,\amalg} Disjoint union (binary) @item \angle @BES{2220,\angle} Geometric angle (ordinary). Similar: less-than sign@tie{}@code{<} and angle bracket@tie{}@code{\langle}. @item \approx @BES{2248,\approx} Almost equal to (relation). @item \ast @BES{2217,\ast} Asterisk operator, convolution, six-pointed (binary). Synonym:@tie{}@code{*}, which is often a superscript or subscript, as in the Kleene star. Similar:@tie{}@code{\star}, which is five-pointed, and is sometimes used as a general binary operation, and sometimes reserved for cross-correlation. @item \asymp @BES{224D,\asymp} Asymptotically equivalent (relation). @item \backslash \ Backslash (ordinary). Similar: set minus@tie{}@code{\setminus}, and @code{\textbackslash} for backslash outside of math mode. @item \beta @BES{03B2,\beta} Lowercase Greek letter beta (ordinary). @item \bigcap @BES{22C2,\bigcap} Variable-sized, or n-ary, intersection (operator). Similar: binary intersection@tie{}@code{\cap}. @item \bigcirc @BES{26AA,\bigcirc} Circle, larger (binary). Similar: function composition@tie{}@code{\circ}. @c bb Best unicode symbol for this? @item \bigcup @BES{22C3,\bigcup} Variable-sized, or n-ary, union (operator). Similar: binary union@tie{}@code{\cup}. @item \bigodot @BES{2A00,\bigodot} Variable-sized, or n-ary, circled dot operator (operator). @item \bigoplus @BES{2A01,\bigoplus} Variable-sized, or n-ary, circled plus operator (operator). @item \bigotimes @BES{2A02,\bigotimes} Variable-sized, or n-ary, circled times operator (operator). @item \bigtriangledown @BES{25BD,\bigtriangledown} Variable-sized, or n-ary, open triangle pointing down (binary). Synonym: @var{\varbigtriangledown}. @item \bigtriangleup @BES{25B3,\bigtriangleup} Variable-sized, or n-ary, open triangle pointing up (binary). Synonym: @var{\varbigtriangleup}. @item \bigsqcup @BES{2A06,\bigsqcup} Variable-sized, or n-ary, square union (operator). @item \biguplus @BES{2A04,\biguplus} Variable-sized, or n-ary, union operator with a plus (operator). (Note that the name has only one p.) @item \bigvee @BES{22C1,\bigvee} Variable-sized, or n-ary, logical-or (operator). @item \bigwedge @BES{22C0,\bigwedge} Variable-sized, or n-ary, logical-and (operator). @item \bot @BES{22A5}, Up tack, bottom, least element of a partially ordered set, or a contradiction (ordinary). See also@tie{}@code{\top}. @item \bowtie @BES{22C8,\bowtie} Natural join of two relations (relation). @item \Box @BES{25A1,\Box} Modal operator for necessity; square open box (ordinary). @value{NeedsAMSSymb} @c bb Best Unicode equivalent? @item \bullet @cindex bullet symbol @BES{2022,\bullet} Bullet (binary). Similar: multiplication dot@tie{}@code{\cdot}. @item \cap @BES{2229,\cap} Intersection of two sets (binary). Similar: variable-sized operator@tie{}@code{\bigcap}. @item \cdot @BES{22C5,\cdot} Multiplication (binary). Similar: Bullet dot@tie{}@code{\bullet}. @item \chi @BES{03C7,\chi} Lowercase Greek chi (ordinary). @item \circ @BES{2218,\circ} Function composition, ring operator (binary). Similar: variable-sized operator@tie{}@code{\bigcirc}. @item \clubsuit @BES{2663,\clubsuit} Club card suit (ordinary). @item \complement @BES{2201}, Set complement, used as a superscript as in @code{$S^\complement$} (ordinary). @value{NeedsAMSSymb} Also used: @code{$S^@{\mathsf@{c@}@}$} or@tie{}@code{$\bar@{S@}$}. @item \cong @BES{2245,\cong} Congruent (relation). @item \coprod @BES{2210,\coprod} Coproduct (operator). @item \cup @BES{222A,\cup} Union of two sets (binary). Similar: variable-sized operator@tie{}@code{\bigcup}. @item \dagger @BES{2020,\dagger} Dagger relation (binary). @item \dashv @BES{22A3,\dashv} Dash with vertical, reversed turnstile (relation). Similar: turnstile@tie{}@code{\vdash}. @item \ddagger @BES{2021,\ddagger} Double dagger relation (binary). @item \Delta @BES{0394,\Delta} Greek uppercase delta, used for increment (ordinary). @item \delta @BES{03B4,\delta} Greek lowercase delta (ordinary). @item \Diamond @BES{25C7,\Diamond} Large diamond operator (ordinary). @value{NeedsAMSSymb} @item \diamond @BES{22C4,\diamond} Diamond operator (binary). Similar: large diamond@tie{}@code{\Diamond}, circle bullet@tie{}@code{\bullet}. @item \diamondsuit @BES{2662,\diamondsuit} Diamond card suit (ordinary). @item \div @BES{00F7,\div} Division sign (binary). @item \doteq @BES{2250,\doteq} Approaches the limit (relation). Similar: geometrically equal to@tie{}@code{\Doteq}. @item \downarrow @BES{2193,\downarrow} Down arrow, converges (relation). Similar: @code{\Downarrow} double line down arrow. @item \Downarrow @BES{21D3,\Downarrow} Double line down arrow (relation). Similar: @code{\downarrow} single line down arrow. @item \ell @BES{2113,\ell} Lowercase cursive letter l (ordinary). @item \emptyset @BES{2205,\emptyset} Empty set symbol (ordinary). The variant form is @code{\varnothing}. @c bb Why Unicode has \revemptyset but no \emptyset? @item \epsilon @BES{03F5,\epsilon} Lowercase lunate epsilon (ordinary). Similar to Greek text letter. More widely used in mathematics is the script small letter epsilon @code{\varepsilon}@tie{}@BES{03B5,\varepsilon}. Related: the set membership relation @code{\in}@tie{}@BES{2208,\in}. @c src: David Carlisle http://tex.stackexchange.com/a/98018/339 and @c Unicode referenced there asserts varepsilon is much more widely used. @item \equiv @BES{2261,\equiv} Equivalence (relation). @item \eta @BES{03B7,\eta} Lowercase Greek letter (ordinary). @item \exists @BES{2203,\exists} Existential quantifier (ordinary). @item \flat @BES{266D,\flat} Musical flat (ordinary). @item \forall @BES{2200,\forall} Universal quantifier (ordinary). @item \frown @BES{2322,\frown} Downward curving arc (ordinary). @item \Gamma @BES{0393,\Gamma} uppercase Greek letter (ordinary). @item \gamma @BES{03B3,\gamma} Lowercase Greek letter (ordinary). @item \ge @BES{2265,\ge} Greater than or equal to (relation). This is a synonym for@tie{}@code{\geq}. @item \geq @BES{2265,\geq} Greater than or equal to (relation). This is a synonym for@tie{}@code{\ge}. @item \gets @BES{2190,\gets} Is assigned the value (relation). Synonym:@tie{}@code{\leftarrow}. @item \gg @BES{226B,\gg} Much greater than (relation). Similar: much less than@tie{}@code{\ll}. @item \hbar @BES{210F,\hbar} Planck constant over two pi (ordinary). @item \heartsuit @BES{2661,\heartsuit} Heart card suit (ordinary). @item \hookleftarrow @BES{21A9,\hookleftarrow} Hooked left arrow (relation). @item \hookrightarrow @BES{21AA,\hookrightarrow} Hooked right arrow (relation). @item \iff @BES{27F7,\iff} If and only if (relation). It is @code{\Longleftrightarrow} with a @code{\thickmuskip} on either side. @item \Im @BES{2111,\Im} Imaginary part (ordinary). See: real part@tie{}@code{\Re}. @item \imath @cindex dotless i, math Dotless i; used when you are putting an accent on an i (@pxref{Math accents}). @item \in @BES{2208,\in} Set element (relation). See also: lowercase lunate epsilon@tie{}@code{\epsilon}@BES{03F5,\epsilon} and small letter script epsilon@tie{}@code{\varepsilon}. @item \infty @BES{221E,\infty} Infinity (ordinary). @item \int @BES{222B,\int} Integral (operator). @item \iota @BES{03B9,\iota} Lowercase Greek letter (ordinary). @item \Join @BES{2A1D,\Join} Condensed bowtie symbol (relation). Not available in Plain @TeX{}. @item \jmath @cindex dotless j, math Dotless j; used when you are putting an accent on a j (@pxref{Math accents}). @item \kappa @BES{03BA,\kappa} Lowercase Greek letter (ordinary). @item \Lambda @BES{039B,\Lambda} uppercase Greek letter (ordinary). @item \lambda @BES{03BB,\lambda} Lowercase Greek letter (ordinary). @item \land @BES{2227,\land} Logical and (binary). Synonym:@tie{}@code{\wedge}. See also logical@tie{}or@tie{}@code{\lor}. @item \langle @BES{27E8,\langle} Left angle, or sequence, bracket (opening). Similar: less-than@tie{}@code{<}. Matches@tie{}@code{\rangle}. @item \lbrace @BES{007B,\lbrace} Left curly brace (opening). Synonym:@tie{}@code{\@{}. Matches@tie{}@code{\rbrace}. @item \lbrack @BES{005B,\lbrack} Left square bracket (opening). Synonym:@tie{}@code{[}. Matches@tie{}@code{\rbrack}. @item \lceil @BES{2308,\lceil} Left ceiling bracket, like a square bracket but with the bottom shaved off (opening). Matches@tie{}@code{\rceil}. @item \le @BES{2264,\le} Less than or equal to (relation). This is a synonym for@tie{}@code{\leq}. @item \leadsto @BES{21DD,\leadsto} Squiggly right arrow (relation). To get this symbol outside of math mode you can put @code{\newcommand*@{\Leadsto@}@{\ensuremath@{\leadsto@}@}} in the preamble and then use @code{\Leadsto} instead. @c bb Best Unicode equivalent? @item \Leftarrow @BES{21D0,\Leftarrow} Is implied by, double-line left arrow (relation). Similar: single-line left arrow@tie{}@code{\leftarrow}. @item \leftarrow @BES{2190,\leftarrow} Single-line left arrow (relation). Synonym:@tie{}@code{\gets}. Similar: double-line left arrow@tie{}@code{\Leftarrow}. @item \leftharpoondown @BES{21BD,\leftharpoondown} Single-line left harpoon, barb under bar (relation). @item \leftharpoonup @BES{21BC,\leftharpoonup} Single-line left harpoon, barb over bar (relation). @item \Leftrightarrow @BES{21D4,\Leftrightarrow} Bi-implication; double-line double-headed arrow (relation). Similar: single-line double headed arrow@tie{}@code{\leftrightarrow}. @item \leftrightarrow @BES{2194,\leftrightarrow} Single-line double-headed arrow (relation). Similar: double-line double headed arrow@tie{}@code{\Leftrightarrow}. @item \leq @BES{2264,\leq} Less than or equal to (relation). This is a synonym for@tie{}@code{\le}. @item \lfloor @BES{230A,\lfloor} Left floor bracket (opening). Matches:@tie{}@code{\floor}. @item \lhd @BES{25C1,\lhd} Arrowhead, that is, triangle, pointing left (binary). For the normal subgroup symbol you should load @package{amssymb} and use@tie{}@code{\vartriangleleft} (which is a relation and so gives better spacing). @item \ll @BES{226A,\ll} Much less than (relation). Similar: much greater than@tie{}@code{\gg}. @item \lnot @BES{00AC,\lnot} Logical negation (ordinary). Synonym:@tie{}@code{\neg}. @item \longleftarrow @BES{27F5,\longleftarrow} Long single-line left arrow (relation). Similar: long double-line left arrow@tie{}@code{\Longleftarrow}. @item \longleftrightarrow @BES{27F7,\longleftrightarrow} Long single-line double-headed arrow (relation). Similar: long double-line double-headed arrow@tie{}@code{\Longleftrightarrow}. @item \longmapsto @BES{27FC,\longmapsto} Long single-line left arrow starting with vertical bar (relation). Similar: shorter version@tie{}@code{\mapsto}. @item \longrightarrow @BES{27F6,\longrightarrow} Long single-line right arrow (relation). Similar: long double-line right arrow@tie{}@code{\Longrightarrow}. @item \lor @BES{2228,\lor} Logical or (binary). Synonym:@tie{}@code{\vee}. See also logical@tie{}and@tie{}@code{\land}. @item \mapsto @BES{21A6,\mapsto} Single-line left arrow starting with vertical bar (relation). Similar: longer version@tie{}@code{\longmapsto}. @item \mho @BES{2127,\mho} Conductance, half-circle rotated capital omega (ordinary). @item \mid @BES{2223,\mid} Single-line vertical bar (relation). A typical use of @code{\mid} is for a set @code{\@{\, x \mid x\geq 5 \,\@}}. Similar: @code{\vert} and@tie{}@code{|} produce the same single-line vertical bar symbol but without any spacing (they fall in class ordinary) and you should not use them as relations but instead only as ordinals, i.e., footnote symbols. For absolute value, see the entry for@tie{}@code{\vert} and for norm see the entry for@tie{}@code{\Vert}. @item \models @BES{22A8,\models} Entails, or satisfies; double turnstile, short double dash (relation). Similar: long double dash@tie{}@code{\vDash}. @item \mp @BES{2213,\mp} Minus or plus (relation). @item \mu @BES{03BC,\mu} Lowercase Greek letter (ordinary). @item \nabla @BES{2207,\nabla} Hamilton's del, or differential, operator (ordinary). @item \natural @BES{266E,\natural} Musical natural notation (ordinary). @item \ne @BES{2260,\ne} Not equal (relation). Synonym:@tie{}@code{\neq}. @item \nearrow @BES{2197,\nearrow} North-east arrow (relation). @item \neg @BES{00AC,\neg} Logical negation (ordinary). Synonym:@tie{}@code{\lnot}. Sometimes instead used for negation:@tie{}@code{\sim}. @item \neq @BES{2260,\neq} Not equal (relation). Synonym:@tie{}@code{\ne}. @item \ni @BES{220B,\ni} Reflected membership epsilon; has the member (relation). Synonym:@tie{}@code{\owns}. Similar: is a member of@tie{}@code{\in}. @item \not @c the "@ "s put in spaces so the not slash doesn't hit the next char. @BES{0020,\not}@ @ @ @ Long solidus, or slash, used to overstrike a following operator (relation). Many negated operators are available that don't require @code{\not}, particularly with the @package{amssymb} package. For example, @code{\notin} is typographically preferable to @code{\not\in}. @item \notin @BES{2209,\notin} Not an element of (relation). Similar: not subset of@tie{}@code{\nsubseteq}. @item \nu @BES{03BD,\nu} Lowercase Greek letter (ordinary). @item \nwarrow @BES{2196,\nwarrow} North-west arrow (relation). @item \odot @BES{2299,\odot} Dot inside a circle (binary). Similar: variable-sized operator@tie{}@code{\bigodot}. @item \oint @BES{222E,\oint} Contour integral, integral with circle in the middle (operator). @item \Omega @BES{03A9,\Omega} uppercase Greek letter (ordinary). @item \omega @BES{03C9,\omega} Lowercase Greek letter (ordinary). @item \ominus @BES{2296,\ominus} Minus sign, or dash, inside a circle (binary). @item \oplus @BES{2295,\oplus} Plus sign inside a circle (binary). Similar: variable-sized operator@tie{}@code{\bigoplus}. @item \oslash @BES{2298,\oslash} Solidus, or slash, inside a circle (binary). @item \otimes @BES{2297,\otimes} Times sign, or cross, inside a circle (binary). Similar: variable-sized operator@tie{}@code{\bigotimes}. @item \owns @BES{220B,\owns} Reflected membership epsilon; has the member (relation). Synonym:@tie{}@code{\ni}. Similar: is a member of@tie{}@code{\in}. @item \parallel @BES{2225,\parallel} Parallel (relation). Synonym:@tie{}@code{\|}. @item \partial @BES{2202,\partial} Partial differential (ordinary). @item \perp @BES{27C2,\perp} Perpendicular (relation). Similar:@tie{}@code{\bot} uses the same glyph but the spacing is different because it is in the class ordinary. @item \Phi @BES{03A6,\Phi} Uppercase Greek letter (ordinary). @item \phi @BES{03D5,\phi} Lowercase Greek letter (ordinary). The variant form is @code{\varphi}@tie{}@BES{03C6,\varphi}. @item \Pi @BES{03A0,\Pi} uppercase Greek letter (ordinary). @item \pi @BES{03C0,\pi} Lowercase Greek letter (ordinary). The variant form is @code{\varpi}@tie{}@BES{03D6,\varpi}. @item \pm @BES{00B1,\pm} Plus or minus (binary). @item \prec @BES{227A,\prec} Precedes (relation). Similar: less than@tie{}@code{<}. @item \preceq @BES{2AAF,\preceq} Precedes or equals (relation). Similar: less than or equals@tie{}@code{\leq}. @item \prime @BES{2032,\prime} Prime, or minute in a time expression (ordinary). Typically used as a superscript: @code{$f^\prime$}; @code{$f^\prime$} and @code{$f'$} produce the same result. An advantage of the second is that @code{$f'''$} produces the desired symbol, that is, the same result as @code{$f^@{\prime\prime\prime@}$}, but uses rather less typing. You can only use @code{\prime} in math mode. Using the right single quote@tie{}@code{'} in text mode produces a different character (apostrophe). @item \prod @BES{220F,\prod} Product (operator). @item \propto @BES{221D,\propto} Is proportional to (relation) @item \Psi @BES{03A8,\Psi} uppercase Greek letter (ordinary). @item \psi @BES{03C8,\psi} Lowercase Greek letter (ordinary). @item \rangle @BES{27E9,\rangle} Right angle, or sequence, bracket (closing). Similar: greater than@tie{}@code{>}. Matches:@code{\langle}. @item \rbrace @BES{007D,\rbrace} Right curly brace (closing). Synonym:@tie{}@code{\@}}. Matches@tie{}@code{\lbrace}. @item \rbrack @BES{005D,\rbrack} Right square bracket (closing). Synonym:@tie{}@code{]}. Matches@tie{}@code{\lbrack}. @item \rceil @BES{2309,\rceil} Right ceiling bracket (closing). Matches@tie{}@code{\lceil}. @item \Re @BES{211C,\Re} Real part, real numbers, cursive capital R (ordinary). Related: double-line, or blackboard bold, R@tie{}@code{\mathbb@{R@}}; to access this, load the @package{amsfonts} package. @item \restriction @BES{21BE}, Restriction of a function (relation). Synonym: @code{\upharpoonright}. @value{NeedsAMSSymb} @item \revemptyset @BES{29B0}, Reversed empty set symbol (ordinary). Related: @code{\varnothing}. @value{NeedsSTIX} @item \rfloor @BES{230B,\rfloor} Right floor bracket, a right square bracket with the top cut off (closing). Matches@tie{}@code{\lfloor}. @item \rhd @BES{25C1,\rhd} Arrowhead, that is, triangle, pointing right (binary). For the normal subgroup symbol you should instead load @package{amssymb} and use@tie{}@code{\vartriangleright} (which is a relation and so gives better spacing). @item \rho @BES{03C1,\rho} Lowercase Greek letter (ordinary). The variant form is @code{\varrho}@tie{}@BES{03F1,\varrho}. @item \Rightarrow @BES{21D2,\Rightarrow} Implies, right-pointing double line arrow (relation). Similar: right single-line arrow@tie{}@code{\rightarrow}. @item \rightarrow @BES{2192,\rightarrow} Right-pointing single line arrow (relation). Synonym:@tie{}@code{\to}. Similar: right double line arrow@tie{}@code{\Rightarrow}. @item \rightharpoondown @BES{21C1,\rightharpoondown} Right-pointing harpoon with barb below the line (relation). @item \rightharpoonup @BES{21C0,\rightharpoonup} Right-pointing harpoon with barb above the line (relation). @item \rightleftharpoons @BES{21CC,\rightleftharpoons} Right harpoon up above left harpoon down (relation). @item \searrow @BES{2198,\searrow} Arrow pointing southeast (relation). @item \setminus @BES{29F5,\setminus} Set difference, reverse solidus or reverse slash, like \ (binary). Similar: backslash@tie{}@code{\backslash} and also @code{\textbackslash} outside of math mode. @item \sharp @BES{266F,\sharp} Musical sharp (ordinary). @item \Sigma @BES{03A3,\Sigma} uppercase Greek letter (ordinary). @item \sigma @BES{03C3,\sigma} Lowercase Greek letter (ordinary). The variant form is @code{\varsigma}@tie{}@BES{03C2,\varsigma}. @item \sim @BES{223C,\sim} Similar, in a relation (relation). @item \simeq @BES{2243,\simeq} Similar or equal to, in a relation (relation). @item \smallint @BES{222B,\smallint} Integral sign that does not change to a larger size in a display (operator). @item \smile @BES{2323,\smile} Upward curving arc, smile (ordinary). @item \spadesuit @BES{2660,\spadesuit} Spade card suit (ordinary). @item \sqcap @BES{2293,\sqcap} Square intersection symbol (binary). Similar: intersection@tie{}@code{cap}. @item \sqcup @BES{2294,\sqcup} Square union symbol (binary). Similar: union@tie{}@code{cup}. Related: variable-sized operator@tie{}@code{\bigsqcup}. @item \sqsubset @BES{228F}, Square subset symbol (relation). Similar: subset@tie{}@code{\subset}. @value{NeedsAMSSymb} @item \sqsubseteq @BES{2291,\sqsubseteq} Square subset or equal symbol (binary). Similar: subset or equal to@tie{}@code{\subseteq}. @item \sqsupset @BES{2290}, Square superset symbol (relation). Similar: superset@tie{}@code{\supset}. @value{NeedsAMSSymb} @item \sqsupseteq @BES{2292,\sqsupseteq} Square superset or equal symbol (binary). Similar: superset or equal@tie{}@code{\supseteq}. @item \star @BES{22C6,\star} Five-pointed star, sometimes used as a general binary operation but sometimes reserved for cross-correlation (binary). Similar: the synonyms asterisk@tie{}@code{*} and @code{\ast}, which are six-pointed, and more often appear as a superscript or subscript, as with the Kleene star. @item \subset @BES{2282,\subset} Subset (occasionally, is implied by) (relation). @item \subseteq @BES{2286,\subseteq} Subset or equal to (relation). @item \succ @BES{227B,\succ} Comes after, succeeds (relation). Similar: is less than@tie{}@code{>}. @item \succeq @BES{2AB0,\succeq} Succeeds or is equal to (relation). Similar: less than or equal to@tie{}@code{\leq}. @item \sum @BES{2211,\sum} Summation (operator). Similar: Greek capital sigma@tie{}@code{\Sigma}. @item \supset @BES{2283,\supset} Superset (relation). @item \supseteq @BES{2287,\supseteq} Superset or equal to (relation). @item \surd @BES{221A,\surd} Radical symbol (ordinary). The @LaTeX{} command @code{\sqrt@{...@}} typesets the square root of the argument, with a bar that extends to cover the argument. @item \swarrow @BES{2199,\swarrow} Southwest-pointing arrow (relation). @item \tau @BES{03C4,\tau} Lowercase Greek letter (ordinary). @item \theta @BES{03B8,\theta} Lowercase Greek letter (ordinary). The variant form is @code{\vartheta}@tie{}@BES{03D1,\vartheta}. @item \times @BES{00D7,\times} Primary school multiplication sign (binary). See also@tie{}@code{\cdot}. @item \to @BES{2192,\to} Right-pointing single line arrow (relation). Synonym:@tie{}@code{\rightarrow}. @item \top @BES{22A4,\top} Top, greatest element of a partially ordered set (ordinary). See also@tie{}@code{\bot}. @item \triangle @BES{25B3,\triangle} Triangle (ordinary). @item \triangleleft @BES{25C1,\triangleleft} Not-filled triangle pointing left (binary). Similar:@tie{}@code{\lhd}. For the normal subgroup symbol you should load @package{amssymb} and use@tie{}@code{\vartriangleleft} (which is a relation and so gives better spacing). @item \triangleright @BES{25B7,\triangleright} Not-filled triangle pointing right (binary). For the normal subgroup symbol you should instead load @package{amssymb} and use@tie{}@code{\vartriangleright} (which is a relation and so gives better spacing). @item \unlhd @BES{22B4,\unlhd} Left-pointing not-filled underlined arrowhead, that is, triangle, with a line under (binary). For the normal subgroup symbol load @package{amssymb} and use@tie{}@code{\vartrianglelefteq} (which is a relation and so gives better spacing). @item \unrhd @BES{22B5,\unrhd} Right-pointing not-filled underlined arrowhead, that is, triangle, with a line under (binary). For the normal subgroup symbol load @package{amssymb} and use@tie{}@code{\vartrianglerighteq} (which is a relation and so gives better spacing). @item \Uparrow @BES{21D1,\Uparrow} Double-line upward-pointing arrow (relation). Similar: single-line up-pointing arrow@tie{}@code{\uparrow}. @item \uparrow @BES{2191,\uparrow} Single-line upward-pointing arrow, diverges (relation). Similar: double-line up-pointing arrow@tie{}@code{\Uparrow}. @item \Updownarrow @BES{21D5,\Updownarrow} Double-line upward-and-downward-pointing arrow (relation). Similar: single-line upward-and-downward-pointing arrow@tie{}@code{\updownarrow}. @item \updownarrow @BES{2195,\updownarrow} Single-line upward-and-downward-pointing arrow (relation). Similar: double-line upward-and-downward-pointing arrow@tie{}@code{\Updownarrow}. @item \upharpoonright @BES{21BE}, Up harpoon, with barb on right side (relation). Synonym:@tie{}@code{@backslashchar{}restriction}. @value{NeedsAMSSymb} @item \uplus @BES{228E,\uplus} Multiset union, a union symbol with a plus symbol in the middle (binary). Similar: union@tie{}@code{\cup}. Related: variable-sized operator@tie{}@code{\biguplus}. @item \Upsilon @BES{03A5,\Upsilon} uppercase Greek letter (ordinary). @item \upsilon @BES{03C5,\upsilon} Lowercase Greek letter (ordinary). @item \varepsilon @BES{03B5,\varepsilon} Small letter script epsilon (ordinary). This is more widely used in mathematics than the non-variant lunate epsilon form @code{\epsilon}@tie{}@BES{03F5,\epsilon}. Related: set membership@tie{}@code{\in}. @item \vanothing @BES{2205}, Empty set symbol. Similar: @code{\emptyset}. Related: @code{\revemptyset}. @value{NeedsAMSSymb} @item \varphi @BES{03C6,\varphi} Variant on the lowercase Greek letter (ordinary). The non-variant form is @code{\phi}@tie{}@BES{03D5,\phi}. @item \varpi @BES{03D6,\varpi} Variant on the lowercase Greek letter (ordinary). The non-variant form is @code{\pi}@tie{}@BES{03C0,\pi}. @item \varrho @BES{03F1,\varrho} Variant on the lowercase Greek letter (ordinary). The non-variant form is @code{\rho}@tie{}@BES{03C1,\rho}. @item \varsigma @BES{03C2,\varsigma} Variant on the lowercase Greek letter (ordinary). The non-variant form is @code{\sigma}@tie{}@BES{03C3,\sigma}. @item \vartheta @BES{03D1,\vartheta} Variant on the lowercase Greek letter (ordinary). The non-variant form is @code{\theta}@tie{}@BES{03B8,\theta}. @item \vdash @BES{22A2,\vdash} Provable; turnstile, vertical and a dash (relation). Similar: turnstile rotated a half-circle@tie{}@code{\dashv}. @item \vee @BES{2228,\vee} Logical or; a downwards v shape (binary). Related: logical and@tie{}@code{\wedge}. Similar: variable-sized operator@tie{}@code{\bigvee}. @item \Vert @BES{2016,\Vert} Vertical double bar (ordinary). @xref{Delimiters}, for how to use the @package{mathtools} package to create flexibly-sized norm symbols. @item \vert @BES{007C,\vert} Single line vertical bar (ordinary). For ``such that'', as in the definition of a set, use@tie{}@code{\mid} because it is a relation. @xref{Delimiters}, for how to use the @package{mathtools} package to create flexibly-sized absolute-value symbols. @item \wedge @BES{2227,\wedge} Logical and (binary). Synonym:@tie{}@code{\land}. See also logical or @code{\vee}. Similar: variable-sized operator@tie{}@code{\bigwedge}. @item \wp @BES{2118,\wp} Weierstrass p (ordinary). @item \wr @BES{2240,\wr} Wreath product (binary). @item \Xi @BES{039E,\Xi} uppercase Greek letter (ordinary). @item \xi @BES{03BE,\xi} Lowercase Greek letter (ordinary). @item \zeta @BES{03B6,\zeta} Lowercase Greek letter (ordinary). @end ftable The following symbols are most often used in plain text but @LaTeX{} provides versions to use in mathematical text. @ftable @code @item \mathdollar Dollar sign in math mode: $. @item \mathparagraph Paragraph sign (pilcrow) in math mode, @BES{00B6,\P}. @item \mathsection Section sign in math mode: @BES{00A7,\S}. @item \mathsterling Sterling sign in math mode: @pounds{}. @item \mathunderscore Underscore in math mode: _. @end ftable @menu * Arrows:: List of arrows. * \boldmath & \unboldmath:: Symbols in boldface. * Blackboard bold:: Doublestruck characters. * Calligraphic:: Cursive characters. * Delimiters:: Parentheses, braces, etc. * Dots:: Ellipses, etc. * Greek letters:: List of Greek letters. @end menu @node Arrows @subsection Arrows @cindex arrows @cindex symbols, arrows @findex math, arrows @PkgIndex{amsfonts} @PkgIndex{latexsym} These are the arrows that come with standard @LaTeX{}. The @package{latexsym} and @package{amsfonts} packages contain many more. @multitable @columnfractions .10 .40 .50 @headitem Symbol@tab Command@tab @item @BES{021D3,\Downarrow} @tab @code{\Downarrow} @tab @item @BES{02193,\downarrow} @tab @code{\downarrow} @tab @item @BES{021A9,\hookleftarrow} @tab @code{\hookleftarrow} @tab @item @BES{021AA,\hookrightarrow} @tab @code{\hookrightarrow} @tab @item @BES{2190,\leftarrow} @tab @code{\leftarrow} @tab @item @BES{021D0,\Leftarrow} @tab @code{\Leftarrow} @tab @item @BES{021D4,\Leftrightarrow} @tab @code{\Leftrightarrow} @tab @item @BES{02194,\leftrightarrow} @tab @code{\leftrightarrow} @tab @item @BES{027F5,\longleftarrow} @tab @code{\longleftarrow} @tab @item @BES{027F8,\Longleftarrow} @tab @code{\Longleftarrow} @tab @item @BES{027F7,\longleftrightarrow} @tab @code{\longleftrightarrow} @tab @item @BES{027FA,\Longleftrightarrow} @tab @code{\Longleftrightarrow} @tab @item @BES{027FC,\longmapsto} @tab @code{\longmapsto} @tab @item @BES{027F9,\Longrightarrow} @tab @code{\Longrightarrow} @tab @item @BES{027F6,\longrightarrow} @tab @code{\longrightarrow} @tab @item @BES{021A6,\mapsto} @tab @code{\mapsto} @tab @item @BES{02197,\nearrow} @tab @code{\nearrow} @tab @item @BES{02196,\nwarrow} @tab @code{\nwarrow} @tab @item @BES{021D2,\Rightarrow} @tab @code{\Rightarrow} @tab @item @BES{02192,\rightarrow} @tab @code{\rightarrow}, or @code{\to} @tab @item @BES{02198,\searrow} @tab @code{\searrow} @tab @item @BES{02199,\swarrow} @tab @code{\swarrow} @tab @item @BES{02191,\uparrow} @tab @code{\uparrow} @tab @item @BES{021D1,\Uparrow} @tab @code{\Uparrow} @tab @item @BES{02195,\updownarrow} @tab @code{\updownarrow} @tab @item @BES{021D5,\Updownarrow} @tab @code{\Updownarrow} @tab @end multitable An example of the difference between @code{\to} and @code{\mapsto} is: @code{\( f\colon D\to C \) given by \( n\mapsto n^2 \)}. @PkgIndex{amscd} @PkgIndex{tikz-cd} For commutative diagrams there are a number of packages, including @package{tikz-cd} and @package{amscd}. @node \boldmath & \unboldmath @subsection @code{\boldmath} & @code{\unboldmath} @anchor{\boldmath} @anchor{\unboldmath} @findex \boldmath @findex \unboldmath @cindex boldface mathematics @cindex mathematics, boldface Synopsis (used in paragraph mode or LR mode): @example \boldmath \( @var{math} \) @end example @noindent or @example \unboldmath \( @var{math} \) @end example @findex \boldmath @findex \unboldmath Declarations to change the letters and symbols in @var{math} to be in a bold font, or to countermand that and bring back the regular (non-bold) default, respectively. They must be used when @emph{not} in math mode or display math mode (@pxref{Modes}). Both commands are fragile (@pxref{\protect}). In this example each @code{\boldmath} command takes place inside an @code{\mbox}, @example we have $\mbox@{\boldmath \( v \)@} = 5\cdot\mbox@{\boldmath \( u \)$@}$ @end example @noindent which means @code{\boldmath} is only called in a text mode, here LR mode, and explains why we must switch @LaTeX{} into math mode to set @code{v} and @code{u}. If you use either command inside math mode, as with @code{Trouble: \( \boldmath x \)}, then you get something like @samp{LaTeX Font Warning: Command \boldmath invalid in math mode} and @samp{LaTeX Font Warning: Command \mathversion invalid in math mode}. @menu * bm:: The @package{bm} package for individual bold symbols. * OpenType bold math:: @code{FakeBold} or @code{\symbf}. @end menu @node bm @subsubsection @package{bm}: Individual bold math symbols @PkgIndex{bm} @cindex symbols, boldface @c https://github.com/latex3/latex2e/issues/974 Specifying @code{\boldmath} is the best method for typesetting a whole math expression in bold. But to typeset individual symbols within an expression in bold, the @package{bm} package provided by the @LaTeX{} Project team is better. Its usage is outside the scope of this document (see its documentation at @url{https://ctan.org/pkg/bm} or in your installation) but the spacing in the output of this small example will show that it is an improvement over @code{\boldmath} within an expression: @example \usepackage@{bm@} % in preamble ... we have $\bm@{v@} = 5\cdot\bm@{u@}$ @end example @node OpenType bold math @subsubsection OpenType bold math @PkgIndex{fontspec} Unfortunately, when using the Unicode engines (Xe@LaTeX{}, Lua@LaTeX{}), neither @code{\boldmath} nor @package{bm} usually work well, because the OpenType math fonts normally used with those engines rarely come with a bold companion, and both @code{\boldmath} and @package{bm} require this. (The implementation of @package{bm} relies on @code{\boldmath}, so the requirements are the same.) If you do have a bold math font, though, then @code{\boldmath} and @package{bm} work fine. If no such font is available, one alternative is to construct fake bold fonts with the @package{fontspec} package's @code{FakeBold=1} parameter (see its documentation, @url{https://ctan.org/pkg/fontspec}). This may be acceptable for drafting or informal distribution, but the results are far from a true bold font. @PkgIndex{unicode-math} @findex \symbf @findex \symbfit Another alternative to handling bold for OpenType math fonts is to use the @code{\symbf} (bold), @code{\symbfit} (bold italic), and related commands from the @package{unicode-math} package. These do not change the current font, but rather change the (Unicode) ``alphabet'' used, which in practice is more widely supported than a separate bold font. Many variations are possible, and so there are subtleties to getting the desired output. As usual, see the package documentation (@url{https://ctan.org/pkg/unicode-math}). @node Blackboard bold @subsection Blackboard bold @cindex blackboard bold @cindex doublestruck Synopsis: @example \usepackage@{amssymb@} % in preamble ... \mathbb@{@var{uppercase-letter}@} @end example Provide blackboard bold symbols, sometimes also known as doublestruck letters, used to denote number sets such as the natural numbers, the integers, etc. Here @example \( \forall n \in \mathbb@{N@}, n^2 \geq 0 \) @end example @noindent the @code{\mathbb@{N@}} gives blackboard bold symbol @BES{2115,\mathbbN}, representing the natural numbers. If the argument contains something other than an uppercase letter, you do not get an error but you do get strange results, including unexpected characters. There are packages that give access to symbols other than just the capital letters; look on CTAN. @node Calligraphic @subsection Calligraphic @cindex calligraphic fonts @cindex script fonts @cindex fonts, script Synopsis: @example \mathcal@{@var{uppercase-letters}@} @end example Use a script-like font. In this example the graph identifier is output in a cursive font. @example Let the graph be \( \mathcal@{G@} \). @end example If you use something other than an uppercase letter then you do not get an error but you also do not get math calligraphic output. For instance, @code{\mathcal@{g@}} outputs a close curly brace symbol. @node Delimiters @subsection Delimiters @cindex delimiters @cindex parentheses @cindex braces @cindex curly braces @cindex brackets Delimiters are parentheses, braces, or other characters used to mark the start and end of subformulas. This formula has three sets of parentheses delimiting the three subformulas. @example (z-z_0)^2 = (x-x_0)^2 + (y-y_0)^2 @end example @noindent The delimiters do not need to match, so you can enter @code{\( [0,1) \)}. Here are the common delimiters: @multitable @columnfractions .11 .20 .40 .29 @headitem Delimiter@tab Command@tab Name @item ( @tab @code{(} @tab Left parenthesis @item ) @tab @code{)} @tab Right parenthesis @item \@} @tab @code{@{} or @code{\lbrace} @tab Left brace @item \@{ @tab @code{@}} or @code{\rbrace} @tab Right brace @item [ @tab @code{[} or @code{\lbrack} @tab Left bracket @item ] @tab @code{]} or @code{\rbrack} @tab Right bracket @item @BES{230A,\lfloor} @tab @code{\lfloor} @tab Left floor bracket @item @BES{230B,\rfloor} @tab @code{\rfloor} @tab Right floor bracket @item @BES{2308,\lceil} @tab @code{\lceil} @tab Left ceiling bracket @item @BES{2309,\rceil} @tab @code{\rceil} @tab Right ceiling bracket @item @BES{27E8,\langle} @tab @code{\langle} @tab Left angle bracket @item @BES{27E9,\rangle} @tab @code{\rangle} @tab Right angle bracket @item / @tab @code{/} @tab Slash, or forward slash @item \ @tab @code{\backslash} @tab Reverse slash, or backslash @item | @tab @code{|} or @code{\vert} @tab Vertical bar @item @BES{2016,\|} @tab @code{\|} or @code{\Vert} @tab Double vertical bar @end multitable @PkgIndex{mathtools} The @package{mathtools} package allows you to create commands for paired delimiters. For instance, if you put @code{\DeclarePairedDelimiter\abs@{\lvert@}@{\rvert@}} in your preamble then you get two commands for single-line vertical bars (they only work in math mode). The starred form, such as @code{\abs*@{\frac@{22@}@{7@}@}}, has the height of the vertical bars match the height of the argument. The unstarred form, such as @code{\abs@{\frac@{22@}@{7@}@}}, has the bars fixed at a default height. This form accepts an optional argument, as in @code{\abs[@var{size command}]@{\frac@{22@}@{7@}@}}, where the height of the bars is given in @var{size command}, such as @code{\Bigg}. Using instead @code{\lVert} and @code{\rVert} as the symbols will give you a norm symbol with the same behavior. @menu * \left & \right:: Automatically sized delimiters. * \bigl & \bigr etc.:: Manually sized delimiters. @end menu @node \left & \right @subsubsection @code{\left} & @code{\right} @anchor{\left} @anchor{\right} @findex \left @findex \right @cindex delimiters, paired @cindex paired delimiters @cindex matching parentheses @cindex matching brackets @cindex null delimiter @c Credit: SE userPhilipp https://tex.stackexchange.com/a/12793 Synopsis: @example \left @var{delimiter1} ... \right @var{delimiter2} @end example Make matching parentheses, braces, or other delimiters. @LaTeX{} makes the delimiters tall enough to just cover the size of the formula that they enclose. This makes a unit vector surrounded by parentheses tall enough to cover the entries. @example \begin@{equation@} \left(\begin@{array@}@{c@} 1 \\ 0 \\ \end@{array@}\right) \end@{equation@} @end example @xref{Delimiters}, for a list of the common delimiters. Every @code{\left} must have a matching @code{\right}. In the above example, leaving out the @code{\left(} gets the error message @samp{Extra \right}. Leaving out the @code{\right)} gets @samp{You can't use `\eqno' in math mode}. @PkgIndex{amsmath} @PkgIndex{mathtools} However, @var{delimiter1} and @var{delimiter2} need not match. A common case is that you want an unmatched brace, as below. Use a period, @samp{.}, as a @dfn{null delimiter}. @example \begin@{equation@} f(n)=\left\@{\begin@{array@}@{ll@} 1 &\mbox@{--if \(n=0\)@} \\ f(n-1)+3n^2 &\mbox@{--else@} \end@{array@}\right. \end@{equation@} @end example @noindent Note that to get a curly brace as a delimiter you must prefix it with a backslash, @code{\@{} (@pxref{Reserved characters}). (The packages @package{amsmath} and @package{mathtools} allow you to get the above construct through in a @code{cases} environment.) The @code{\left ... \right} pair make a group. One consequence is that the formula enclosed in the @code{\left ... \right} pair cannot have line breaks in the output. This includes both manual line breaks and @LaTeX{}-generated automatic ones. In this example, @LaTeX{} breaks the equation to make the formula fit the margins. @example Lorem ipsum dolor sit amet \( (a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+r+s+t+u+v+w+x+y+z) \) @end example @noindent But with @code{\left} and @code{\right} @example Lorem ipsum dolor sit amet \( \left(a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+r+s+t+u+v+w+x+y+z\right) \) @end example @noindent @LaTeX{} won't break the line, causing the formula to extend into the margin. Because @code{\left ... \right} make a group, all the usual grouping rules hold. Here, the value of @code{\testlength} set inside the equation will be forgotten, and the output is @samp{1.2pt}. @example \newlength@{\testlength@} \setlength@{\testlength@}@{1.2pt@} \begin@{equation@} \left( a+b=c \setlength@{\testlength@}@{3.4pt@} \right) \the\testlength \end@{equation@} @end example The @code{\left ... \right} pair affect the horizontal spacing of the enclosed formula, in two ways. The first is that in @code{\( \sin(x) = \sin\left(x\right) \)} the one after the equals sign has more space around the @code{x}. That's because @code{\left( ... \right)} inserts an inner node while @code{( ... )} inserts an opening node. The second way that the pair affect the horizontal spacing is that because they form a group, the enclosed subformula will be typeset at its natural width, with no stretching or shrinking to make the line fit better. @TeX{} scales the delimiters according to the height and depth of the enclosed formula. Here @LaTeX{} grows the brackets to extend the full height of the integral. @example \begin@{equation@} \left[ \int_@{x=r_0@}^@{\infty@} -G\frac@{Mm@}@{r^2@}\, dr \right] \end@{equation@} @end example Manual sizing is often better. For instance, although below the rule has no depth, @TeX{} will create delimiters that extend far below the rule. @example \begin@{equation@} \left( \rule@{1pt@}@{1cm@} \right) \end@{equation@} @end example @noindent @TeX{} can choose delimiters that are too small, as in @code{\( \left| |x|+|y| \right| \)}. It can also choose delimiters that are too large, as here. @example \begin@{equation@} \left( \sum_@{0\leq i1/2@}+ \underbrace@{1/5+1/6+1/7+1/8@}_@{>1/2@}+\cdots \end@{displaymath@} @end example The superscript appears on top of the expression, and so can look unconnected to the underbrace. @item \overbrace@{@var{math}@} Put a brace over @var{math}, as with @code{\overbrace@{x+x+\cdots+x@}^@{\mbox@{\(k\) times@}@}}. See also @code{\underbrace}. @end ftable @PkgIndex{mathtools} The package @package{mathtools} adds an over- and underbrace, as well as some improvements on the braces. See the documentation on CTAN. @node Spacing in math mode @section Spacing in math mode @cindex spacing within math mode @cindex math mode, spacing When typesetting mathematics, @LaTeX{} puts in spacing according to the normal rules for mathematics texts. If you enter @code{y=m x} then @LaTeX{} ignores the space and in the output the m is next to the x, as @math{y=mx}. But @LaTeX{}'s rules occasionally need tweaking. For example, in an integral the tradition is to put a small extra space between the @code{f(x)} and the @code{dx}, here done with the @code{\,} command: @example \int_0^1 f(x)\,dx @end example @LaTeX{} provides the commands that follow for use in math mode. Many of these spacing definitions are expressed in terms of the math unit @dfn{mu}. It is defined as 1/18@dmn{em}, where the em is taken from the current math symbols family (@pxref{Units of length}). Thus, a @code{\thickspace} is something like 5/18 times the width of a@tie{}@samp{M}. @table @code @item \; @findex \; @findex \thickspace @anchor{spacing in math mode thickspace} @PkgIndex{amsmath} Synonym: @code{\thickspace}. Normally @code{5.0mu plus 5.0mu}. With the @package{amsmath} package, or as of the 2020-10-01 @LaTeX{} release, can be used in text mode as well as math mode; otherwise, in math mode only. @item \negthickspace @findex \negthickspace Normally @code{-5.0mu plus 2.0mu minus 4.0mu}. With the @package{amsmath} package, or as of the 2020-10-01 @LaTeX{} release, can be used in text mode as well as math mode; otherwise, in math mode only. @item \: @itemx \> @findex \: @findex \> @findex \medspace @anchor{spacing in math mode medspace} Synonym: @code{\medspace}. Normally @code{4.0mu plus 2.0mu minus 4.0mu}. With the @package{amsmath} package, or as of the 2020-10-01 @LaTeX{} release, can be used in text mode as well as math mode; before that, in math mode only. @item \negmedspace @findex \negmedspace Normally @code{-4.0mu plus 2.0mu minus 4.0mu}. With the @package{amsmath} package, or as of the 2020-10-01 @LaTeX{} release, can be used in text mode as well as math mode; before that, in math mode only. @item \, @findex \, @findex \thinspace @cindex thin space @anchor{Spacing in math mode/\thinspace} @anchor{spacing in math mode thinspace} Synonym: @code{\thinspace}. Normally @code{3mu}, which is 1/6@dmn{em}. Can be used in both math mode and text mode (@pxref{\thinspace & \negthinspace}). This space is widely used, for instance between the function and the infinitesimal in an integral @code{\int f(x)\,dx} and, if an author does this, before punctuation in a displayed equation. @example The antiderivative is \begin@{equation@} 3x^@{-1/2@}+3^@{1/2@}\,. \end@{equation@} @end example @item \! @findex \! @findex \negthinspace @cindex thin space, negative @anchor{spacing in math mode negthinspace} Synonym: @code{\negthinspace}. A negative thin space. Normally @code{-3mu}. With the @package{amsmath} package, or as of the 2020-10-01 @LaTeX{} release, can be used in text mode as well as math mode; otherwise, the @code{\!} command is math mode only but the @code{\negthinspace} command has always also worked in text mode (@pxref{\thinspace & \negthinspace}). @item \quad @cindex quad @findex \quad @anchor{spacing in math mode quad} This is 18@dmn{mu}, that is, 1@dmn{em}. This is often used for space surrounding equations or expressions, for instance for the space between two equations inside a @code{displaymath} environment. It is available in both text and math mode. @item \qquad @findex \qquad @anchor{spacing in math mode qquad} A length of 2 quads, that is, 36@dmn{mu} = 2@dmn{em}. It is available in both text and math mode. @end table @menu * \smash:: Eliminate height or depth of a subformula. * \phantom & \vphantom & \hphantom:: Make empty box same size as argument. * \mathstrut:: Add some vertical space to a formula. @end menu @node \smash @subsection @code{\smash} @cindex vertical spacing, math mode @cindex math mode, vertical space Synopsis: @example \smash@{@var{subformula}@} @end example Typeset @var{subformula} as if its height and depth were zero. In this example the exponential is so tall that without the @code{\smash} command @LaTeX{} would separate its line from the line above it, and the uneven line spacing might be unsightly. @example To compute the tetration $\smash@{2^@{2^@{2^2@}@}@}$, evaluate from the top down, as $2^@{2^4@}=2^@{16@}=65536$. @end example (Because of the @code{\smash} the printed expression could run into the line above so you may want to wait until the final version of the document to make such adjustments.) This pictures the effect of @code{\smash} by using @code{\fbox} to surround the box that @LaTeX{} will put on the line. The @code{\blackbar} command makes a bar extending from 10@tie{}points below the baseline to 20@tie{}points above. @example \newcommand@{\blackbar@}@{\rule[-10pt]@{5pt@}@{30pt@}@} \fbox@{\blackbar@} \fbox@{\smash@{\blackbar@}@} @end example The first box that @LaTeX{} places is 20@tie{}points high and 10@tie{}points deep. But the second box is treated by @LaTeX{} as having zero height and zero depth, despite that the ink printed on the page still extends well above and below the line. The @code{\smash} command appears often in mathematics to adjust the size of an element that surrounds a subformula. Here the first radical extends below the baseline while the second lies just on the baseline. @example \begin@{equation@} \sqrt@{\sum_@{0\leq k< n@} f(k)@} \sqrt@{\vphantom@{\sum@}\smash@{\sum_@{0\leq k< n@}@} f(k)@} \end@{equation@} @end example Note the use of @code{\vphantom} to give the @code{\sqrt} command an argument with the height of the @code{\sum} (@pxref{\phantom & \vphantom & \hphantom}). While most often used in mathematics, the @code{\smash} command can appear in other contexts. However, it doesn't change into horizontal mode. So if it starts a paragraph then you should first put a @code{\leavevmode}, as in the bottom line below. @example xxx xxx xxx \smash@{yyy@} % no paragraph indent \leavevmode\smash@{zzz@} % usual paragraph indent @end example @PkgIndex{mathtools} The package @package{mathtools} has operators that provide even finer control over smashing a subformula box. @node \phantom & \vphantom & \hphantom @subsection @code{\phantom} & @code{\vphantom} & @code{\hphantom} @anchor{\phantom} @anchor{\vphantom} @anchor{\hphantom} @findex \phantom @findex \vphantom @findex \hphantom @cindex spacing, math mode @cindex horizontal spacing @cindex vertical spacing @cindex math mode, spacing @cindex invisible character @cindex character, invisible Synopsis: @example \phantom@{@var{subformula}@} @end example or @example \vphantom@{@var{subformula}@} @end example or @example \hphantom@{@var{subformula}@} @end example The @code{\phantom} command creates a box with the same height, depth, and width as @var{subformula}, but empty. That is, this command causes @LaTeX{} to typeset the space but not fill it with the material. Here @LaTeX{} will put a blank line that is the correct width for the answer, but will not show that answer. @example \begin@{displaymath@} \int x^2\,dx=\mbox@{\underline@{$\phantom@{(1/3)x^3+C@}$@}@} \end@{displaymath@} @end example The @code{\vphantom} variant produces an invisible box with the same vertical size as @var{subformula}, the same height and depth, but having zero width. And @code{\hphantom} makes a box with the same width as @var{subformula} but with zero height and depth. In this example, the tower of exponents in the second summand expression is so tall that @TeX{} places this expression further down than its default. Without adjustment, the two summand expressions would be at different levels. The @code{\vphantom} in the first expression tells @TeX{} to leave as much vertical room as it does for the tower, so the two expressions come out at the same level. @example \begin@{displaymath@} \sum_@{j\in\@{0,\ldots\, 10\@}\vphantom@{3^@{3^@{3^j@}@}@}@} \sum_@{i\in\@{0,\ldots\, 3^@{3^@{3^j@}@}\@}@} i\cdot j \end@{displaymath@} @end example These commands are often used in conjunction with @code{\smash}. @xref{\smash}, which includes another example of @code{\vphantom}. @PkgIndex{mathtools} The three phantom commands appear often but note that @LaTeX{} provides a suite of other commands to work with box sizes that may be more convenient, including @code{\makebox} (@pxref{\mbox & \makebox}) as well as @code{\settodepth} (@pxref{\settodepth}), @code{\settoheight} (@pxref{\settoheight}), and @code{\settowidth} (@pxref{\settowidth}). In addition, the @package{mathtools} package has many commands that offer fine-grained control over spacing. @PkgIndex{amsmath} All three commands produce an ordinary box, without any special mathematics status. So to do something like attaching a superscript you should give it such a status, for example with the @code{\operatorname} command from the package @package{amsmath}. While most often used in mathematics, these three can appear in other contexts. However, they don't cause @LaTeX{} to change into horizontal mode. So if one of these starts a paragraph then you should prefix it with @code{\leavevmode}. @node \mathstrut @subsection @code{\mathstrut} @findex @code{\mathstrut} @cindex spacing, math mode @cindex vertical spacing @cindex math mode, spacing @cindex invisible character @cindex character, invisible @cindex strut, math Synopsis: @example \mathstrut @end example The analogue of @code{\strut} for mathematics. @xref{\strut}. The input @code{$\sqrt@{x@} + \sqrt@{x^i@}$} gives output where the second radical is taller than the first. To add extra vertical space without any horizontal space, so that the two have the same height, use @code{$\sqrt@{x\mathstrut@} + \sqrt@{x^i\mathstrut@}$}. The @code{\mathstrut} command adds the vertical height of an open parenthesis, @code{(}, but no horizontal space. It is defined as @code{\vphantom@{(@}}, so see @ref{\phantom & \vphantom & \hphantom} for more. An advantage over @code{\strut} is that @code{\mathstrut} adds no depth, which is often the right thing for formulas. Using the height of an open parenthesis is just a convention; for complete control over the amount of space, use @code{\rule} with a width of zero. @xref{\rule}. @node Math styles @section Math styles @cindex math styles @TeX{}'s rules for typesetting a formula depend on the context. For example, inside a displayed equation, the input @code{\sum_@{0\leq i \noreg}. @node lrbox @section @code{lrbox} @findex lrbox Synopsis: @example \begin@{lrbox@}@{@var{box-cmd}@} @var{text} \end@{lrbox@} @end example This is the environment form of the @code{\sbox} and @code{\savebox} commands, and is equivalent to them. @xref{\sbox & \savebox}, for the full description. The @var{text} inside the environment is saved in the box register referred to by variable @code{@var{box-cmd}}. The variable name @var{box-cmd} must begin with a backslash, @code{\}. You must allocate this box register in advance with @code{\newsavebox} (@pxref{\newsavebox}). In this example the environment is convenient for entering the @code{tabular}. @example \newsavebox@{\jhreg@} \begin@{lrbox@}@{\jhreg@} \begin@{tabular@}@{c@} \includegraphics[height=1in]@{jh.png@} \\ Jim Hef@{@}feron \end@{tabular@} \end@{lrbox@} ... \usebox@{\jhreg@} @end example @node \usebox @section @code{\usebox} @findex \usebox @cindex box, use saved box Synopsis: @example \usebox@{@var{box-cmd}@} @end example Produce the box most recently saved in the box register @var{box-cmd} by the commands @code{\sbox} or @code{\savebox}, or the @code{lrbox} environment. For more information and examples, @pxref{\sbox & \savebox}. (Note that the variable name @var{box-cmd} starts with a backslash, @code{\}.) This command is robust (@pxref{\protect}). @node Color @chapter Color @cindex color You can add color to text, rules, etc. You can also have color in a box or on an entire page and write text on top of it. Color support comes as an additional package. So put @code{\usepackage@{color@}} in your document preamble to use the commands described here. Many other packages also supplement @LaTeX{}'s color abilities. Particularly worth mentioning is @file{xcolor}, which is widely used and significantly extends the capabilities described here, including adding @samp{HTML} and @samp{Hsb} color models. @menu * Color package options:: Options when you load the standard package. * Color models:: How colors are represented. * Commands for color:: The available commands. @end menu @node Color package options @section @code{color} package options @cindex color package options @cindex options, color package Synopsis (must be in the document preamble): @example \usepackage[@var{comma-separated option list}]@{color@} @end example When you load the @file{color} package there are two kinds of available options. The first specifies the @dfn{printer driver}. @LaTeX{} doesn't contain information about different output systems but instead depends on information stored in a file. Normally you should not specify the driver option in the document, and instead rely on your system's default. One advantage of this is that it makes the document portable across systems. For completeness we include a list of the drivers. The currently relevant ones are: @file{dvipdfmx}, @file{dvips}, @file{dvisvgm}, @file{luatex}, @file{pdftex}, @file{xetex}. The two @file{xdvi} and @file{oztex} are essentially aliases for @file{dvips} (and @file{xdvi} is monochrome). Ones that should not be used for new systems are: @file{dvipdf}, @file{dvipdfm}, @file{dviwin}, @file{dvipsone}, @file{emtex}, @file{pctexps}, @file{pctexwin}, @file{pctexhp}, @file{pctex32}, @file{truetex}, @file{tcidvi}, @file{vtex} (and @file{dviwindo} is an alias for @file{dvipsone}). The second kind of options, beyond the drivers, are below. @table @code @item monochrome Disable the color commands, so that they do not generate errors but do not generate color either. @item dvipsnames Make available a list of 68 color names that are often used, particularly in legacy documents. These color names were originally provided by the @file{dvips} driver, giving the option name. @item nodvipsnames Do not load that list of color names, saving @LaTeX{} a tiny amount of memory space. @end table @node Color models @section Color models @cindex color models A @dfn{color model} is a way of representing colors. @LaTeX{}'s capabilities depend on the printer driver. However, the @file{pdftex}, @file{xetex}, and @file{luatex} printer drivers are today by far the most commonly used. The models below work for those drivers. All but one of these is also supported by essentially all other printer drivers used today. Note that color combination can be additive or subtractive. Additive mixes colors of light, so that for instance combining full intensities of red, green, and blue produces white. Subtractive mixes pigments, such as with inks, so that combining full intensity of cyan, magenta, and yellow makes black. @table @code @anchor{color models cmyk} @item cmyk A comma-separated list with four real numbers between 0 and 1, inclusive. The first number is the intensity of cyan, the second is magenta, and the others are yellow and black. A number value of 0 means minimal intensity, while a 1 is for full intensity. This model is often used in color printing. It is a subtractive model. @anchor{color models gray} @item gray A single real number between 0 and 1, inclusive. The colors are shades of grey. The number 0 produces black while 1 gives white. @anchor{color models rgb} @item rgb A comma-separated list with three real numbers between 0 and 1, inclusive. The first number is the intensity of the red component, the second is green, and the third the blue. A number value of 0 means that none of that component is added in, while a 1 means full intensity. This is an additive model. @anchor{color models RGB} @item RGB (@file{pdftex}, @file{xetex}, @file{luatex} drivers) A comma-separated list with three integers between 0 and 255, inclusive. This model is a convenience for using @code{rgb} since outside of @LaTeX{} colors are often described in a red-green-blue model using numbers in this range. The values entered here are converted to the @code{rgb} model by dividing by 255. @anchor{color models named} @item named Colors are accessed by name, such as @samp{PrussianBlue}. The list of names depends on the driver, but all support the names @samp{black}, @samp{blue}, @samp{cyan}, @samp{green}, @samp{magenta}, @samp{red}, @samp{white}, and @samp{yellow} (See the @code{dvipsnames} option in @ref{Color package options}). @end table @node Commands for color @section Commands for color @cindex color package commands These are the commands available with the @file{color} package. @menu * Define colors:: Give a color a name. * Colored text:: Text or rules in color. * Colored boxes:: A box of color, to write over. * Colored pages:: A whole page colored. @end menu @node Define colors @subsection Define colors @cindex color @cindex define color @cindex color, define Synopsis: @example \definecolor@{@var{name}@}@{@var{model}@}@{@var{specification}@} @end example Give the name @var{name} to the color. For example, after this @example \definecolor@{silver@}@{rgb@}@{0.75,0.75,0.74@} @end example @noindent you can use that color name with @code{Hi ho, \textcolor@{silver@}@{Silver@}!}. This example gives the color a more abstract name, so it could change and not be misleading. @example \definecolor@{logocolor@}@{RGB@}@{145,92,131@} % RGB needs pdflatex \newcommand@{\logo@}@{\textcolor@{logocolor@}@{Bob's Big Bagels@}@} @end example Often a document's colors are defined in the preamble, or in the class or style, rather than in the document body. @node Colored text @subsection Colored text @cindex color @cindex colored text Synopses: @example \textcolor@{@var{name}@}@{...@} \textcolor[@var{color model}]@{@var{color specification}@}@{...@} @end example @noindent or @example \color@{@var{name}@} \color[@var{color model}]@{@var{color specification}@} @end example The affected text gets the color. This line @example \textcolor@{magenta@}@{My name is Ozymandias, King of Kings;@} Look on my works, ye Mighty, and despair! @end example @noindent causes the first half to be in magenta while the rest is in black. You can use a color declared with @code{\definecolor} in exactly the same way that we just used the builtin color @samp{magenta}. @example \definecolor@{MidlifeCrisisRed@}@{rgb@}@{1.0,0.11,0.0@} I'm thinking about getting a \textcolor@{MidlifeCrisisRed@}@{sports car@}. @end example The two @code{\textcolor} and @code{\color} differ in that the first is a command form, enclosing the text to be colored as an argument. Often this form is more convenient, or at least more explicit. The second form is a declaration, as in @code{The moon is made of @{\color@{green@} green@} cheese}, so it is in effect until the end of the current group or environment. This is sometimes useful when writing macros or as below where it colors everything inside the @code{center} environment, including the vertical and horizontal lines. @example \begin@{center@} \color@{blue@} \begin@{tabular@}@{l|r@} UL &UR \\ \hline LL &LR \end@{tabular@} \end@{center@} @end example You can use color in equations. A document might have this definition in the preamble @example \definecolor@{highlightcolor@}@{RGB@}@{225,15,0@} @end example @noindent and then contain this equation. @example \begin@{equation@} \int_a^b \textcolor@{highlightcolor@}@{f'(x)@}\,dx=f(b)-f(a) \end@{equation@} @end example Typically the colors used in a document are declared in a class or style but sometimes you want a one-off. Those are the second forms in the synopses. @example Colors of \textcolor[rgb]@{0.33,0.14,0.47@}@{Purple@} and @{\color[rgb]@{0.72,0.60,0.37@}Gold@} for the team. @end example The format of @var{color specification} depends on the color model (@pxref{Color models}). For instance, while @code{rgb} takes three numbers, @code{gray} takes only one. @example The selection was \textcolor[gray]@{0.5@}@{grayed out@}. @end example Colors inside colors do not combine. Thus @example \textcolor@{green@}@{kind of \textcolor@{blue@}@{blue@}@} @end example @noindent has a final word that is blue, not a combination of blue and green. @c xx address coloring a line of a table? @node Colored boxes @subsection Colored boxes @cindex color @cindex colored boxes @cindex box, colored Synopses: @example \colorbox@{@var{name}@}@{...@} \colorbox[@var{model name}]@{@var{box background color}@}@{...@} @end example @noindent or @example \fcolorbox@{@var{frame color}@}@{@var{box background color}@}@{...@} \fcolorbox[@var{model name}]@{@var{frame color}@}@{@var{box background color}@}@{...@} @end example Make a box with the stated background color. The @code{\fcolorbox} command puts a frame around the box. For instance this @example Name:~\colorbox@{cyan@}@{\makebox[5cm][l]@{\strut@}@} @end example @noindent makes a cyan-colored box that is five centimeters long and gets its depth and height from the @code{\strut} (so the depth is @code{-.3\baselineskip} and the height is @code{\baselineskip}). This puts white text on a blue background. @example \colorbox@{blue@}@{\textcolor@{white@}@{Welcome to the machine.@}@} @end example The @code{\fcolorbox} commands use the same parameters as @code{\fbox} (@pxref{\fbox & \framebox}), @code{\fboxrule} and @code{\fboxsep}, to set the thickness of the rule and the boundary between the box interior and the surrounding rule. @LaTeX{}'s defaults are @code{0.4pt} and @code{3pt}, respectively. This example changes the thickness of the border to 0.8 points. Note that it is surrounded by curly braces so that the change ends at the end of the second line. @example @{\setlength@{\fboxrule@}@{0.8pt@} \fcolorbox@{black@}@{red@}@{Under no circumstances turn this knob.@}@} @end example @node Colored pages @subsection Colored pages @cindex color @cindex colored page @cindex page, colored @cindex background, colored Synopses: @example \pagecolor@{@var{name}@} \pagecolor[@var{color model}]@{@var{color specification}@} \nopagecolor @end example The first two set the background of the page, and all subsequent pages, to the color. For an explanation of the specification in the second form @pxref{Colored text}. The third returns the background to normal, which is a transparent background. (If that is not supported use @code{\pagecolor@{white@}}, although that will make a white background rather than the default transparent background.) @example ... \pagecolor@{cyan@} ... \nopagecolor @end example @node Graphics @chapter Graphics @cindex graphics @cindex graphics package You can use graphics such as PNG or PDF files in your @LaTeX{} document. You need an additional package, which comes standard with @LaTeX{}. This example is the short how-to. @example \include@{graphicx@} % goes in the preamble ... \includegraphics[width=0.5\linewidth]@{plot.pdf@} @end example To use the commands described here your document preamble must contain either @code{\usepackage@{graphicx@}} or @code{\usepackage@{graphics@}}. Most of the time, @package{graphicx} is the better choice. Graphics come in two main types, raster and vector. @LaTeX{} can use both. In raster graphics the file contains an entry for each location in an array, describing what color it is. An example is a photograph in JPG format. In vector graphics, the file contains a list of instructions such as @samp{draw a circle with this radius and that center}. An example is a line drawing produced by the Asymptote program, in PDF format. Generally vector graphics are more useful because you can rescale their size without pixelation or other problems, and because they often have a smaller size. There are systems particularly well-suited to make graphics for a @LaTeX{} document. For example, these allow you to use the same fonts as in your document. @LaTeX{} comes with a @code{picture} environment (@pxref{picture}) that has simple capabilities. Besides that, there are other ways to include the graphic-making commands in the document. Two such systems are the PSTricks and TikZ packages. There are also systems external to @LaTeX{}, that generate a graphic that you include using the commands of this chapter. Two that use a programming language are Asymptote and MetaPost. One that uses a graphical interface is Xfig. Full description of these systems is outside the scope of this document; see their documentation on CTAN. @menu * Graphics package options:: Options when you load the package. * Graphics package configuration:: Where to look for files, which file types. * Commands for graphics:: The available commands. @end menu @node Graphics package options @section @code{graphics} package options @cindex graphics package options @cindex options, graphics package Synopsis (must be in the document preamble): @example \usepackage[@var{comma-separated option list}]@{graphics@} @end example @noindent or @example \usepackage[@var{comma-separated option list}]@{graphicx@} @end example The @code{graphicx} package has a format for optional arguments to the @code{\includegraphics} command that is convenient (it is the key-value format), so it is the better choice for new documents. When you load the @package{graphics} or @package{graphicx} package with @code{\usepackage} there are two kinds of available options. The first is that @LaTeX{} does not contain information about different output systems but instead depends on information stored in a @dfn{printer driver} file. Normally you should not specify the driver option in the document, and instead rely on your system's default. One advantage of this is that it makes the document portable across systems. For completeness here is a list of the drivers. The currently relevant ones are: @file{dvipdfmx}, @file{dvips}, @file{dvisvgm}, @file{luatex}, @file{pdftex}, @file{xetex}. The two @file{xdvi} and @file{oztex} are essentially aliases for @file{dvips} (and @file{xdvi} is monochrome). Ones that should not be used for new systems are: @file{dvipdf}, @file{dvipdfm}, @file{dviwin}, @file{dvipsone}, @file{emtex}, @file{pctexps}, @file{pctexwin}, @file{pctexhp}, @file{pctex32}, @file{truetex}, @file{tcidvi}, @file{vtex} (and @file{dviwindo} is an alias for @file{dvipsone}). These are stored in files with a @file{.def} extension, such as @file{pdftex.def}. The second kind of options are below. @table @code @item demo Instead of an image file, @LaTeX{} puts in a 150@tie{}pt by 100@tie{}pt rectangle (unless another size is specified in the @code{\includegraphics} command). @item draft For each graphic file, it is not shown but instead its file name is printed in a box of the correct size. In order to determine the size, the file must be present. @item final (Default) Override any previous @code{draft} option, so that the document shows the contents of the graphic files. @item hiderotate Do not show rotated text. (This allows for the possibility that a previewer does not have the capability to rotate text.) @c what does it show? @item hidescale Do not show scaled text. (This allows for the possibility that a previewer does not have the capability to scale.) @c what does it show? @item hiresbb In a PS or EPS file the graphic size may be specified in two ways. The @code{%%BoundingBox} lines describe the graphic size using integer multiples of a PostScript point, that is, integer multiples of 1/72 inch. A later addition to the PostScript language allows decimal multiples, such as 1.23, in @code{%%HiResBoundingBox} lines. This option has @LaTeX{} to read the size from the latter. @end table @node Graphics package configuration @section @code{graphics} package configuration @cindex graphics @cindex graphics package @cindex configuration, graphics package These commands configure the way @LaTeX{} searches the file system for the graphic. The behavior of file system search code is necessarily platform dependent. In this document we cover GNU/Linux, Macintosh, and Windows, as those systems are typically configured. For other situations consult the documentation in @file{grfguide.pdf}, or the @LaTeX{} source, or your @TeX{} distribution's documentation. @menu * \graphicspath:: Directories to search. * \DeclareGraphicsExtensions:: File types, such as JPG or EPS. * \DeclareGraphicsRule:: How to handle file types. @end menu @node \graphicspath @subsection @code{\graphicspath} @findex \graphicspath Synopsis: @example \graphicspath@{@var{list of directories inside curly braces}@} @end example Declare a list of directories to search for graphics files. This allows you to later say something like @code{\includegraphics@{lion.png@}} instead of having to give its path. @LaTeX{} always looks for graphic files first in the current directory (and the output directory, if specified; @pxref{output directory}). The declaration below tells the system to then look in the subdirectory @file{pix}, and then @file{../pix}. @example \usepackage@{graphicx@} % or graphics; put in preamble ... \graphicspath@{ @{pix/@} @{../pix/@} @} @end example The @code{\graphicspath} declaration is optional. If you don't include it then @LaTeX{}'s default is to search all of the places that it usually looks for a file (it uses @LaTeX{}'s @code{\input@@path}). In particular, in this case one of the places it looks is the current directory. Enclose each directory name in curly braces; for example, above it says @samp{@code{@{pix@}}}. Do this even if there is only one directory. Each directory name must end in a forward slash, @file{/}. This is true even on Windows, where good practice is to use forward slashes for all the directory separators since it makes the document portable to other platforms. If you have spaces in your directory name then use double quotes, as with @code{@{"my docs/"@}}. Getting one of these rules wrong will cause @LaTeX{} to report @code{Error: File `@var{filename}' not found}. Basically, the algorithm is that with this example, after looking in the current directory, @example \graphicspath@{ @{pix/@} @{../pix/@} @} ... \usepackage@{lion.png@} @end example @noindent for each of the listed directories, @LaTeX{} concatenates it with the filename and searches for the result, checking for @file{pix/lion.png} and then @file{../pix/lion.png}. This algorithm means that the @code{\graphicspath} command does not recursively search subdirectories: if you issue @code{\graphicspath@{@{a/@}@}} and the graphic is in @file{a/b/lion.png} then @LaTeX{} will not find it. It also means that you can use absolute paths such as @code{\graphicspath@{@{/home/jim/logos/@}@}} or @code{\graphicspath@{@{C:/Users/Albert/Pictures/@}@}}. However, using these means that the document is not portable. (You could preserve portability by adjusting your @TeX{} system settings configuration file parameter @code{TEXINPUTS}; see the documentation of your system.) You can use @code{\graphicspath} anywhere in the document. You can use it more than once. Show its value with @code{\makeatletter\typeout@{\Ginput@@path@}\makeatother}. The directories are taken with respect to the base file. That is, suppose that you are working on a document based on @file{book/book.tex} and it contains @code{\include@{chapters/chap1@}}. If in @file{chap1.tex} you put @code{\graphicspath@{@{plots/@}@}} then @LaTeX{} will not search for graphics in @file{book/chapters/plots}, but instead in @file{book/plots}. @node \DeclareGraphicsExtensions @subsection @code{\DeclareGraphicsExtensions} @findex \DeclareGraphicsExtensions Synopses: @example \DeclareGraphicsExtensions@{@var{comma-separated list of file extensions}@} @end example Declare the filename extensions to try. This allows you to specify the order in which to choose graphic formats when you include graphic files by giving the filename without the extension, as in @code{\includegraphics@{functionplot@}}. In this example, @LaTeX{} will find files in the PNG format before PDF files. @example \DeclareGraphicsExtensions@{.png,PNG,.pdf,.PDF@} ... \includegraphics@{lion@} % will find @file{lion.png} before @file{lion.pdf} @end example @noindent Because the filename @file{lion} does not have a period, @LaTeX{} uses the extension list. For each directory in the graphics path (@pxref{\graphicspath}), @LaTeX{} will try the extensions in the order given. If it does not find such a file after trying all the directories and extensions then it reports @samp{! LaTeX Error: File `@file{lion}' not found}. Note that you must include the periods at the start of the extensions. Because GNU/Linux and Macintosh filenames are case sensitive, the list of file extensions is case sensitive on those platforms. The Windows platform is not case sensitive. You are not required to include @code{\DeclareGraphicsExtensions} in your document; the printer driver has a sensible default. For example, the most recent @file{pdftex.def} has this extension list. @example .pdf,.png,.jpg,.mps,.jpeg,.jbig2,.jb2,.PDF,.PNG,.JPG,.JPEG,.JBIG2,.JB2 @end example @PkgIndex{grfext} To change the order, use the @package{grfext} package. You can use this command anywhere in the document. You can use it more than once. Show its value with @code{\makeatletter\typeout@{\Gin@@extensions@}\makeatother}. @node \DeclareGraphicsRule @subsection @code{\DeclareGraphicsRule} @findex \DeclareGraphicsRule Synopsis: @example \DeclareGraphicsRule@{@var{extension}@}@{@var{type}@}@{@var{size-file extension}@}@{@var{command}@} @end example Declare how to handle graphic files whose names end in @var{extension}. This example declares that all files with names of the form @file{filename-without-dot.mps} will be treated as output from MetaPost, meaning that the printer driver will use its MetaPost-handling code to input the file. @example \DeclareGraphicsRule@{.mps@}@{mps@}@{.mps@}@{@} @end example This @example \DeclareGraphicsRule@{*@}@{mps@}@{*@}@{@} @end example @noindent tells @LaTeX{} that it should handle as MetaPost output any file with an extension not covered by another rule, so it covers @file{filename.1}, @file{filename.2}, etc. This describes the four arguments. @table @var @item extension The file extension to which this rule applies. The extension is anything after and including the first dot in the filename. Use the Kleene star, @code{*}, to denote the default behavior for all undeclared extensions. @item type The type of file involved. This type is a string that must be defined in the printer driver. For instance, files with extensions @file{.ps}, @file{.eps}, or @file{.ps.gz} may all be classed as type @code{eps}. All files of the same type will be input with the same internal command by the printer driver. For example, the file types that @file{pdftex} recognizes are: @code{jpg}, @code{jbig2}, @code{mps}, @code{pdf}, @code{png}, @code{tif}. @item size-file extension The extension of the file to be read to determine the size of the graphic, if there is such a file. It may be the same as @var{extension} but it may be different. As an example, consider a PostScript graphic. To make it smaller, it might be compressed into a @file{.ps.gz} file. Compressed files are not easily read by @LaTeX{} so you can put the bounding box information in a separate file. If @var{size-file extension} is empty then you must specify size information in the arguments of @code{\includegraphics}. If the driver file has a procedure for reading size files for @code{type} then that will be used, otherwise it will use the procedure for reading @file{.eps} files. (Thus you may specify the size of bitmap files in a file with a PostScript style @code{%%BoundingBox} line if no other format is available.) @item command A command that will be applied to the file. This is often left empty. This command must start with a single backward quote. Thus, @code{\DeclareGraphicsRule@{.eps.gz@}@{eps@}@{.eps.bb@}@{`gunzip -c #1@}} specifies that any file with the extension @file{.eps.gz} should be treated as an @code{eps} file, with the BoundingBox information stored in the file with extension @file{.eps.bb}, and that the command @code{gunzip -c} will run on your platform to decompresses the file. Such a command is specific to your platform. In addition, your @TeX{} system must allow you to run external commands; as a security measure modern systems restrict running commands unless you explicitly allow it. See the documentation for your @TeX{} distribution. @end table @node Commands for graphics @section Commands for graphics @cindex graphics package commands @cindex commands, graphics package These are the commands available with the @package{graphics} and @package{graphicx} packages. @menu * \includegraphics:: Using a graphic in your document. * \rotatebox:: Rotating boxes, including graphics. * \scalebox:: Scaling boxes, including graphics. * \resizebox:: Scaling boxes, including graphics, to a set size. @end menu @node \includegraphics @subsection @code{\includegraphics} @cindex graphics @cindex graphics package @cindex including graphics @cindex importing graphics @cindex EPS files @cindex JPEG files @cindex JPG files @cindex PDF graphic files @cindex PNG files @findex \includegraphics Synopses for @package{graphics} package: @example \includegraphics@{@var{filename}@} \includegraphics[@var{urx},@var{ury}]@{@var{filename}@} \includegraphics[@var{llx},@var{lly}][@var{urx},@var{ury}]@{@var{filename}@} \includegraphics*@{@var{filename}@} \includegraphics*[@var{urx},@var{ury}]@{@var{filename}@} \includegraphics*[@var{llx},@var{lly}][@var{urx},@var{ury}]@{@var{filename}@} @end example Synopses for @package{graphicx} package: @example \includegraphics@{@var{filename}@} \includegraphics[@var{key-value list}]@{@var{filename}@} \includegraphics*@{@var{filename}@} \includegraphics*[@var{key-value list}]@{@var{filename}@} @end example Include a graphics file. The starred form @code{\includegraphics*} will clip the graphic to the size specified, while for the unstarred form any part of the graphic that is outside the box of the specified size will over-print the surrounding area. This @example \usepackage@{graphicx@} % in preamble ... \begin@{center@} \includegraphics@{plot.pdf@} \end@{center@} @end example @noindent will incorporate into the document the graphic in @file{plot.pdf}, centered and at its nominal size. You can also give a path to the file, as with @code{\includegraphics@{graphics/plot.pdf@}}. To specify a list of locations to search for the file, @pxref{\graphicspath}. If your filename includes spaces then put it in double quotes. An example is @code{\includegraphics@{"sister picture.jpg"@}}. The @code{\includegraphics@{@var{filename}@}} command decides on the type of graphic by splitting @var{filename} on the first dot. You can instead use @var{filename} with no dot, as in @code{\includegraphics@{turing@}}, and then @LaTeX{} tries a sequence of extensions such as @code{.png} and @code{.pdf} until it finds a file with that extension (@pxref{\DeclareGraphicsExtensions}). If your file name contains dots before the extension then you can hide them with curly braces, as in @code{\includegraphics@{@{plot.2018.03.12.a@}.pdf@}}. Or, if you use the @package{graphicx} package then you can use the options @code{type} and @code{ext}; see below. This and other filename issues are also handled with the package @file{grffile}. This example puts a graphic in a @code{figure} environment so @LaTeX{} can move it to the next page if fitting it on the current page is awkward (@pxref{figure}). @example \begin@{figure@} \centering \includegraphics[width=3cm]@{lungxray.jpg@} \caption@{The evidence is overwhelming: don't smoke.@} \label@{fig:xray@} \end@{figure@} @end example This places a graphic that will not float, so it is sure to appear at this point in the document even if makes @LaTeX{} stretch the text or resort to blank areas on the page. It will be centered and will have a caption. @example \usepackage@{caption@} % in preamble ... \begin@{center@} \includegraphics@{pix/nix.png@} \captionof@{figure@}@{The spirit of the night@} \label@{pix:nix@} % optional \end@{center@} @end example This example puts a box with a graphic side by side with one having text, with the two vertically centered. @example \newcommand*@{\vcenteredhbox@}[1]@{\begin@{tabular@}@{@@@{@}c@@@{@}@}#1\end@{tabular@}@} ... \begin@{center@} \vcenteredhbox@{\includegraphics[width=0.4\textwidth]@{plot@}@} \hspace@{1em@} \vcenteredhbox@{\begin@{minipage@}@{0.4\textwidth@} \begin@{displaymath@} f(x)=x\cdot \sin (1/x) \end@{displaymath@} \end@{minipage@}@} \end@{center@} @end example If you use the @package{graphics} package then the only options involve the size of the graphic (but see @ref{\rotatebox} and @ref{\scalebox}). When one optional argument is present then it is @code{[@var{urx},@var{ury}]} and it gives the coordinates of the top right corner of the image, as a pair of @TeX{} dimensions (@pxref{Units of length}). If the units are omitted they default to @code{bp}. In this case, the lower left corner of the image is assumed to be at (0,0). If two optional arguments are present then the leading one is @code{[@var{llx},@var{lly}]}, specifying the coordinates of the image's lower left. Thus, @code{\includegraphics[1in,0.618in]@{...@}} calls for the graphic to be placed so it is 1@tie{}inch wide and 0.618@tie{}inches tall and so its origin is at (0,0). The @package{graphicx} package gives you many more options. Specify them in a key-value form, as here. @example \begin@{center@} \includegraphics[width=1in,angle=90]@{lion@} \hspace@{2em@} \includegraphics[angle=90,width=1in]@{lion@} \end@{center@} @end example @noindent The options are read left-to-right. So the first graphic above is made one inch wide and then rotated, while the second is rotated and then made one inch wide. Thus, unless the graphic is perfectly square, the two will end with different widths and heights. There are many options. The primary ones are listed first. @cindex bounding box @cindex box, bounding Note that a graphic is placed by @LaTeX{} into a box, which is traditionally referred to as its @dfn{bounding box} (distinct from the PostScript BoundingBox described below). The graphic's printed area may go beyond this box, or sit inside this box, but when @LaTeX{} makes up a page it puts together boxes and this is the box allocated for the graphic. @table @code @anchor{includegraphics width} @item width The graphic will be shown so its bounding box is this width. An example is @code{\includegraphics[width=1in]@{plot@}}. You can use the standard @TeX{} dimensions (@pxref{Units of length}) and also convenient is @code{\linewidth}, or in a two-column document, @code{\columnwidth} (@pxref{Page layout parameters}). An example is that by using the @file{calc} package you can make the graphic be 1@tie{}cm narrower than the width of the text with @code{\includegraphics[width=\linewidth-1.0cm]@{hefferon.jpg@}}. @item height @anchor{includegraphics height} The graphic will be shown so its bounding box is this height. You can use the standard @TeX{} dimensions (@pxref{Units of length}), and also convenient are @code{\pageheight} and @code{\textheight} (@pxref{Page layout parameters}). For instance, the command @code{\includegraphics[height=0.25\textheight]@{godel@}} will make the graphic a quarter of the height of the text area. @item totalheight @anchor{includegraphics totalheight} The graphic will be shown so its bounding box has this height plus depth. This differs from the height if the graphic was rotated. For instance, if it has been rotated by -90 then it will have zero height but a large depth. @item keepaspectratio @anchor{includegraphics keepaspectratio} If set to @code{true}, or just specified as here @example @code{\includegraphics[...,keepaspectratio,...]@{...@}} @end example @noindent and you give as options both @code{width} and @code{height} (or @code{totalheight}), then @LaTeX{} will make the graphic is as large as possible without distortion. That is, @LaTeX{} will ensure that neither is the graphic wider than @code{width} nor taller than @code{height} (or @code{totalheight}). @item scale Factor by which to scale the graphic. To make a graphic twice its nominal size, enter @code{\includegraphics[scale=2.0]@{...@}}. This number may be any value; a number between 0 and@tie{}1 will shrink the graphic and a negative number will reflect it. @item angle Rotate the graphic. The angle is taken in degrees and counterclockwise. The graphic is rotated about its @code{origin}; see that option. For a complete description of how rotated material is typeset, @pxref{\rotatebox}. @item origin The point of the graphic about which the rotation happens. Possible values are any string containing one or two of: @code{l} for left, @code{r} for right, @code{b} for bottom, @code{c} for center, @code{t} for top, and @code{B} for baseline. Thus, entering the command @code{\includegraphics[angle=180,origin=c]@{moon@}} will turn the picture upside down about that picture's center, while the command @code{\includegraphics[angle=180,origin=lB]@{LeBateau@}} will turn its picture upside down about its left baseline. (The character @code{c} gives the horizontal center in @code{bc} or @code{tc}, but gives the vertical center in @code{lc} or @code{rc}.) The default is @code{lB}. To rotate about an arbitrary point, @pxref{\rotatebox}. @end table These are lesser-used options. @table @code @anchor{includegraphics viewport} @item viewport Pick out a subregion of the graphic to show. Takes four arguments, separated by spaces and given in @TeX{} dimensions, as with @code{\includegraphics[.., viewport=0in 0in 1in 0.618in]@{...@}}. When the unit is omitted, the dimensions default to big points,@tie{}@code{bp}. They are taken relative to the origin specified by the bounding box. See also the @code{trim} option. @anchor{includegraphics trim} @item trim Gives parts of the graphic to not show. Takes four arguments, separated by spaces, that are given in @TeX{} dimensions, as with @code{\includegraphics[.., trim= 0in 0.1in 0.2in 0.3in, ...]@{...@}}. These give the amounts of the graphic not to show, that is, @LaTeX{} will crop the picture by 0@tie{}inches on the left, 0.1@tie{}inches on the bottom, 0.2@tie{}inches on the right, and 0.3@tie{}inches on the top. See also the @code{viewport} option. @anchor{includegraphics clip} @item clip If set to @code{true}, or just specified as here @example \includegraphics[...,clip,...]@{...@} @end example @noindent then the graphic is cropped to the bounding box. This is the same as using the starred form of the command, @code{\includegraphics*[...]@{...@}}. @anchor{includegraphics page} @item page Give the page number of a multi-page PDF file. The default is @code{page=1}. @anchor{includegraphics pagebox} @item pagebox Specifies which bounding box to use for PDF files from among @code{mediabox}, @code{cropbox}, @code{bleedbox}, @code{trimbox}, or @code{artbox}. PDF files do not have the BoundingBox that PostScript files have, but may specify up to four predefined rectangles. The MediaBox gives the boundaries of the physical medium. The CropBox is the region to which the contents of the page are to be clipped when displayed. The BleedBox is the region to which the contents of the page should be clipped in production. The TrimBox is the intended dimensions of the finished page. The ArtBox is the extent of the page's meaningful content. The driver will set the image size based on CropBox if present, otherwise it will not use one of the others, with a driver-defined order of preference. MediaBox is always present. @anchor{includegraphics interpolate} @item interpolate Enable or disable interpolation of raster images by the viewer. Can be set with @code{interpolate=true} or just specified as here. @example \includegraphics[...,interpolate,...]@{...@} @end example @anchor{includegraphics quiet} @item quiet Do not write information to the log. You can set it with @code{quiet=true} or just specified it with @code{\includegraphics[...,quiet,...]@{...@}}, @anchor{includegraphics draft} @item draft If you set it with @code{draft=true} or just specify it with @example \includegraphics[...,draft,...]@{...@} @end example @noindent then the graphic will not appear in the document, possibly saving color printer ink. Instead, @LaTeX{} will put an empty box of the correct size with the filename printed in it. @end table These options address the bounding box for Encapsulated PostScript graphic files, which have a size specified with a line @code{%%BoundingBox} that appears in the file. It has four values, giving the lower @math{x} coordinate, lower @math{y} coordinate, upper @math{x} coordinate, and upper @math{y} coordinate. The units are PostScript points, equivalent to @TeX{}'s big points, 1/72@tie{}inch. For example, if an @file{.eps} file has the line @code{%%BoundingBox 10 20 40 80} then its natural size is 30/72@tie{}inch wide by 60/72@tie{}inch tall. @table @code @anchor{includegraphics bb} @item bb Specify the bounding box of the displayed region. The argument is four dimensions separated by spaces, as with @code{\includegraphics[.., bb= 0in 0in 1in 0.618in]@{...@}}. Usually @code{\includegraphics} reads the BoundingBox numbers from the EPS file automatically, so this option is only useful if the bounding box is missing from that file or if you want to change it. @anchor{includegraphics bbllx} @anchor{includegraphics bblly} @anchor{includegraphics bburx} @anchor{includegraphics bbury} @item bbllx, bblly, bburx, bbury Set the bounding box. These four are obsolete, but are retained for compatibility with old packages. @anchor{includegraphics natwidth} @anchor{includegraphics natheight} @item natwidth, natheight An alternative for @code{bb}. Setting @example \includegraphics[...,natwidth=1in,natheight=0.618in,...]@{...@} @end example @noindent is the same as setting @code{bb=0 0 1in 0.618in}. @anchor{includegraphics hiresbb} @item hiresbb If set to @code{true}, or just specified as with @example \includegraphics[...,hiresbb,...]@{...@} @end example @noindent then @LaTeX{} will look for @code{%%HiResBoundingBox} lines instead of @code{%%BoundingBox} lines. (The @code{BoundingBox} lines use only natural numbers while the @code{HiResBoundingBox} lines use decimals; both use units equivalent to @TeX{}'s big points, 1/72@tie{}inch.) To override a prior setting of @code{true}, you can set it to @code{false}. @end table These following options allow a user to override @LaTeX{}'s method of choosing the graphic type based on the filename extension. An example is that @code{\includegraphics[type=png,ext=.xxx,read=.xxx]@{lion@}} will read the file @file{lion.xxx} as though it were @file{lion.png}. For more on these, @pxref{\DeclareGraphicsRule}. @table @code @anchor{includegraphics type} @item type Specify the graphics type. @anchor{includegraphics ext} @item ext Specify the graphics extension. Only use this in conjunction with the option @code{type}. @anchor{includegraphics read} @item read Specify the file extension of the read file. Only use this in conjunction with the option @code{type}. @anchor{includegraphics command} @item command Specify a command to be applied to this file. Only use this in conjunction with the option @code{type}. @xref{Command line options}, for a discussion of enabling the @code{\write18} functionality to run external commands. @end table @node \rotatebox @subsection @code{\rotatebox} @cindex rotation @cindex rotating graphics @cindex rotating text @findex \rotatebox Synopsis if you use the @package{graphics} package: @example \rotatebox@{@var{angle}@}@{@var{material}@} @end example Synopses if you use the @package{graphicx} package: @example \rotatebox@{@var{angle}@}@{@var{material}@} \rotatebox[@var{key-value list}]@{@var{angle}@}@{@var{material}@} @end example Put @var{material} in a box and rotate it @var{angle} degrees counterclockwise. This example rotates the table column heads forty-five degrees. @example \begin@{tabular@}@{ll@} \rotatebox@{45@}@{Character@} &\rotatebox@{45@}@{NATO phonetic@} \\ A &AL-FAH \\ B &BRAH-VOH \end@{tabular@} @end example The @var{material} can be anything that goes in a box, including a graphic. @example \rotatebox[origin=c]@{45@}@{\includegraphics[width=1in]@{lion@}@} @end example To place the rotated material, the first step is that @LaTeX{} sets @var{material} in a box, with a reference point on the left baseline. The second step is the rotation, by default about the reference point. The third step is that @LaTeX{} computes a box to bound the rotated material. Fourth, @LaTeX{} moves this box horizontally so that the left edge of this new bounding box coincides with the left edge of the box from the first step (they need not coincide vertically). This new bounding box, in its new position, is what @LaTeX{} uses as the box when typesetting this material. If you use the @package{graphics} package then the rotation is about the reference point of the box. If you use the @package{graphicx} package then these are the options that can go in the @var{key-value list}, but note that you can get the same effect without needing this package, except for the @code{x} and @code{y} options (@pxref{\includegraphics}). @table @code @item origin The point of the @var{material}'s box about which the rotation happens. Possible value is any string containing one or two of: @code{l} for left, @code{r} for right, @code{b} for bottom, @code{c} for center, @code{t} for top, and @code{B} for baseline. Thus, the first line here @example \rotatebox[origin=c]@{180@}@{moon@} \rotatebox[origin=lB]@{180@}@{LeBateau@} @end example @noindent will turn the picture upside down from the center while the second will turn its picture upside down about its left baseline. (The character @code{c} gives the horizontal center in @code{bc} or @code{tc} but gives the vertical center in @code{lc} or @code{rc}, and gives both in @code{c}.) The default is @code{lB}. @item x, y Specify an arbitrary point of rotation with @code{\rotatebox[x=@var{@TeX{} dimension},y=@var{@TeX{} dimension}]@{...@}} (@pxref{Units of length}). These give the offset from the box's reference point. @item units This key allows you to change the default of degrees counterclockwise. Setting @code{units=-360} changes the direction to degrees clockwise and setting @code{units=6.283185} changes to radians counterclockwise. @end table @node \scalebox @subsection @code{\scalebox} @cindex graphics, scaling @cindex graphics, resizing @cindex scaling @cindex resizing @cindex text, scaling @cindex text, resizing @findex \scalebox @findex \reflectbox Synopses: @example \scalebox@{@var{horizontal factor}@}@{@var{material}@} \scalebox@{@var{horizontal factor}@}[@var{vertical factor}]@{@var{material}@} \reflectbox@{@var{material}@} @end example Scale the @var{material}. This example halves the size, both horizontally and vertically, of the first text and doubles the size of the second. @example \scalebox@{0.5@}@{DRINK ME@} and \scalebox@{2.0@}@{Eat Me@} @end example If you do not specify the optional @var{vertical factor} then it defaults to the same value as the @var{horizontal factor}. You can use this command to resize a graphic, as here. @example \scalebox@{0.5@}@{\includegraphics@{lion@}@} @end example @noindent If you use the @package{graphicx} package then you can accomplish the same thing with optional arguments to @code{\includegraphics} (@pxref{\includegraphics}). The @code{\reflectbox} command abbreviates @code{\scalebox@{-1@}[1]@{@var{material}@}}. Thus, @code{Able was I\reflectbox@{Able was I@}} will show the phrase @samp{Able was I} immediately followed by its mirror reflection against a vertical axis. @node \resizebox @subsection @code{\resizebox} @cindex graphics, scaling @cindex graphics, resizing @cindex scaling @cindex resizing @cindex text, scaling @cindex text, resizing @findex \resizebox Synopses: @example \resizebox@{@var{horizontal length}@}@{@var{vertical length}@}@{@var{material}@} \resizebox*@{@var{horizontal length}@}@{@var{vertical length}@}@{@var{material}@} @end example Given a size, such as @code{3cm}, transform @var{material} to make it that size. If either @var{horizontal length} or @var{vertical length} is an exclamation point@tie{}@code{!} then the other argument is used to determine a scale factor for both directions. This example makes the graphic be a half inch wide and scales it vertically by the same factor to keep it from being distorted. @example \resizebox@{0.5in@}@{!@}@{\includegraphics@{lion@}@} @end example The unstarred form @code{\resizebox} takes @var{vertical length} to be the box's height while the starred form @code{\resizebox*} takes it to be height+depth. For instance, make the text have a height+depth of a quarter-inch with @code{\resizebox*@{!@}@{0.25in@}@{\parbox@{3.5in@}@{This box has both height and depth.@}@}}. You can use @code{\depth}, @code{\height}, @code{\totalheight}, and @code{\width} to refer to the original size of the box. Thus, make the text two inches wide but keep the original height with @code{\resizebox@{2in@}@{\height@}@{Two inches@}}. @node Special insertions @chapter Special insertions @cindex special insertions @cindex insertions of special characters @LaTeX{} provides commands for inserting characters that have a special meaning do not correspond to simple characters you can type. @menu * Reserved characters:: Inserting @samp{# $ % & @{ @} _ ~ ^ \} * Upper and lower case:: Make text upper or lower case. * Symbols by font position:: Inserting font symbols by number. * Text symbols:: Inserting other non-letter symbols in text. * Accents:: Inserting accents. * Additional Latin letters:: Inserting other non-English characters. * inputenc package:: Set the input file text encoding. * \rule:: Inserting lines and rectangles. * \today:: Inserting today's date. @end menu @node Reserved characters @section Reserved characters @cindex reserved characters @cindex characters, reserved @cindex special characters @cindex characters, special @LaTeX{} sets aside the following characters for special purposes. For example, the percent sign@tie{}@code{%} is for comments. They are called @dfn{reserved characters} or @dfn{special characters}. They are all discussed elsewhere in this manual. @example # $ % & @{ @} _ ~ ^ \ @end example @findex \# @findex \$ @findex \% @findex \& @findex \_ @findex \@{ @findex \@} If you want a reserved character to be printed as itself, in the text body font, for all but the final three characters in that list simply put a backslash@tie{}@code{\} in front of the character. Thus, typing @code{\$1.23} will produce@tie{}@code{$1.23} in your output. @findex \~ @findex \^ @findex \textbackslash As to the last three characters, to get a tilde in the text body font use @code{\~@{@}} (omitting the curly braces would result in the next character receiving a tilde accent). Similarly, to get a text body font circumflex use @code{\^@{@}}. To get a backslash in the font of the text body, enter @code{\textbackslash@{@}}. To produce the reserved characters in a typewriter font use @code{\verb!!} as below (the double backslash@tie{}@code{\\} in the example is only there to split the lines in the output). @example \begin@{center@} \# \$ \% \& \@{ \@} \_ \~@{@} \^@{@} \textbackslash \\ \verb!# $ % & @{ @} _ ~ ^ \! \end@{center@} @end example @node Upper and lower case @section Upper and lower case @cindex uppercase @cindex lowercase @cindex characters, case of @cindex changing case of characters Synopsis: @example \uppercase@{@var{text}@} \lowercase@{@var{text}@} \MakeUppercase@{@var{text}@} \MakeLowercase@{@var{text}@} @end example Change the case of characters. The @TeX{} primitive commands @code{\uppercase} and @code{\lowercase} are set up by default to work only with the 26 letters a--z and A--Z. The @LaTeX{} commands @code{\MakeUppercase} and @code{\MakeLowercase} commands also change characters accessed by commands such as @code{\ae} or @code{\aa}. The commands @code{\MakeUppercase} and @code{\MakeLowercase} are robust but they have moving arguments (@pxref{\protect}). These commands do not change the case of letters used in the name of a command within @var{text}. But they do change the case of every other Latin letter inside the argument @var{text}. Thus, @code{\MakeUppercase@{Let $y=f(x)$}@} produces @samp{LET Y=F(X)}. Another example is that the name of an environment will be changed, so that @code{\MakeUppercase@{\begin@{tabular@} ... \end@{tabular@}@}} will produce an error because the first half is changed to @code{\begin@{TABULAR@}}. @LaTeX{} uses the same fixed table for changing case throughout a document, The table used is designed for the font encoding T1; this works well with the standard @TeX{} fonts for all Latin alphabets but will cause problems when using other alphabets. To change the case of text that results from a macro inside @var{text} you need to do expansion. Here the @code{\Schoolname} produces @samp{COLLEGE OF MATHEMATICS}. @example \newcommand@{\schoolname@}@{College of Mathematics@} \newcommand@{\Schoolname@}@{\expandafter\MakeUppercase @w{ }\expandafter@{\schoolname@}@} @end example @PkgIndex{textcase} The @package{textcase} package brings some of the missing feature of the standard @LaTeX{} commands @code{\MakeUppercase} and @code{\MakeLowerCase}. @PkgIndex{mfirstuc} To uppercase only the first letter of words, you can use the package @package{mfirstuc}. @PkgIndex{expl3} @cindex Wright, Joseph Handling all the casing rules specified by Unicode, e.g., for non-Latin scripts, is a much bigger job than anything envisioned in the original @TeX{} and @LaTeX{}. It has been implemented in the @package{expl3} package as of 2020. The article ``Case changing: From @TeX{} primitives to the Unicode algorithm'', (Joseph Wright, @cite{TUGboat}@tie{}41:1, @url{https://tug.org/TUGboat/tb41-1/tb127wright-case.pdf}), gives a good overview of the topic, past and present. @node Symbols by font position @section Symbols by font position @findex \symbol @cindex accessing any character of a font @cindex font symbols, by number You can access any character of the current font using its number with the @code{\symbol} command. For example, the visible space character used in the @code{\verb*} command has the code decimal 32 in the standard Computer Modern typewriter font, so it can be typed as @code{\symbol@{32@}}. You can also specify numbers in octal (base 8) by using a @code{'} prefix, or hexadecimal (base 16) with a @code{"} prefix, so the visible space at 32 decimal could also be written as @code{\symbol@{'40@}} or @code{\symbol@{"20@}}. @node Text symbols @section Text symbols @cindex text symbols @cindex symbols, text @PkgIndex{textcomp} @cindex TS1 encoding @LaTeX{} provides commands to generate a number of non-letter symbols in running text. Some of these, especially the more obscure ones, are not available in OT1. As of the @LaTeX{} February 2020 release, all symbols are available by default; before that, it was necessary to use the @code{textcomp} package for some (technically, those in the @code{TS1} font encoding). @ftable @code @item \copyright @itemx \textcopyright @cindex copyright symbol @copyright{} The copyright symbol. @item \dag @cindex dagger, in text @BES{2020,@math{\dag}} The dagger symbol (in text). @item \ddag @cindex double dagger, in text @BES{2021,@math{\ddag}} The double dagger symbol (in text). @item \LaTeX @cindex @LaTeX{} logo @cindex logo, @LaTeX{} The @LaTeX{} logo. @item \LaTeXe @cindex @LaTeX{}2e logo @cindex logo, @LaTeX{}2e The @LaTeX{}2e logo. @item \guillemotleft @r{(@guillemotleft{})} @itemx \guillemotright @r{(@guillemotright{})} @itemx \guilsinglleft @r{(@guilsinglleft{})} @itemx \guilsinglright @r{(@guilsinglright{})} @cindex double guillemets @cindex single guillemets @cindex left angle quotation marks @cindex right angle quotation marks @cindex double angle quotation marks @cindex single angle quotation marks @cindex French quotation marks @cindex quotation marks, French @guillemotleft{}, @guillemotright{}, @guilsinglleft{}, @guilsinglright{} Double and single angle quotation marks, commonly used in French. @item \ldots @itemx \textellipsis @itemx \dots @cindex ellipsis @dots{} An ellipsis (three dots at the baseline): @code{\ldots} and @code{\dots} also work in math mode (@pxref{Dots}). See that math mode ellipsis description for additional general information. @item \lq @cindex left quote @cindex opening quote ` Left (opening) quote. @item \P @itemx \textparagraph @cindex paragraph symbol @cindex pilcrow @BES{00B6,\P} Paragraph sign (pilcrow). @item \pounds @itemx \textsterling @cindex pounds symbol @cindex sterling symbol @pounds{} English pounds sterling. @item \quotedblbase @r{(@quotedblbase{})} @itemx \quotesinglbase @r{(@quotesinglbase{})} @cindex double low-9 quotation mark @cindex single low-9 quotation mark @cindex low-9 quotation marks, single and double @quotedblbase{} and @quotesinglbase{} Double and single quotation marks on the baseline. @item \rq @cindex right quote @cindex closing quote ' Right (closing) quote. @item \S @itemx \textsection @cindex section symbol @BES{00A7,\S} Section sign. @item \TeX @cindex @TeX{} logo @cindex logo, @TeX{} The @TeX{} logo. @item \textasciicircum @cindex circumflex, ASCII, in text @cindex ASCII circumflex, in text ^ ASCII circumflex. @item \textasciitilde @cindex tilde, ASCII, in text @cindex ASCII tilde, in text ~ ASCII tilde. @item \textasteriskcentered @cindex asterisk, centered, in text @cindex centered asterisk, in text * Centered asterisk. @item \textbackslash @cindex backslash, in text \ Backslash. However, @code{\texttt@{\textbackslash@}} produces a roman (not typewriter) backslash by default; for a typewriter backslash, it is necessary to use the T1 (or other non-default) font encoding, as in: @example \usepackage[T1]@{fontenc@} @end example @c https://github.com/latex3/latex2e/issues/824 @item \textbar @cindex vertical bar, in text @cindex bar, vertical, in text | Vertical bar. @item \textbardbl @cindex vertical bar, double, in text @cindex bar, double vertical, in text @cindex double vertical bar, in text @BES{23F8,||} Double vertical bar. @item \textbigcircle @cindex big circle symbols, in text @cindex circle symbol, big, in text @BES{25EF}, Big circle symbol. @item \textbraceleft @cindex left brace, in text @cindex brace, left, in text @{ Left brace. See remarks at @code{\textbackslash} above about making @code{\texttt@{\textbraceleft@}} produce a typewriter brace. @item \textbraceright @cindex right brace, in text @cindex brace, right, in text @} Right brace. See remarks at @code{\textbackslash} above about making @code{\texttt@{\textbraceright@}} produce a typewriter brace. @item \textbullet @cindex bullet, in text @bullet{} Bullet. @item \textcircled@{@var{letter}@} @cindex circled letter, in text @BES{24B6}, Circle around @var{letter}. @item \textcompwordmark @itemx \textcapitalcompwordmark @itemx \textascendercompwordmark @cindex composite word mark, in text @cindex cap height @cindex ascender height Used to separate letters that would normally ligature. For example, @code{f\textcompwordmark i} produces @samp{fi} without a ligature. This is most useful in non-English languages. The @code{\textcapitalcompwordmark} form has the cap height of the font while the @code{\textascendercompwordmark} form has the ascender height. @item \textdagger @cindex dagger, in text @BES{2020,@math{\dag}} Dagger. @item \textdaggerdbl @cindex dagger, double, in text @cindex double dagger, in text @BES{2021,@math{\ddag}} Double dagger. @item \textdollar @r{(or @code{\$})} @cindex dollar sign @cindex currency, dollar $ Dollar sign. @item \textemdash @r{(or @code{---})} @cindex em-dash @raggedright --- Em-dash. Used for punctuation, usually similar to commas or parentheses, as in `@code{The playoffs---if you're lucky enough to make the playoffs---are more like a sprint.}' Conventions for spacing around em-dashes vary widely. @end raggedright @item \textendash @r{(or @code{--})} @cindex e-dash -- En-dash. Used for ranges, as in `@code{see pages 12--14}'. @item \texteuro @cindex euro symbol @cindex currency, euro @PkgIndex{eurosym} The Euro currency symbol: @euro{}. @PkgIndex{eurosym} For an alternative glyph design, try the @package{eurosym} package; also, most fonts nowadays come with their own Euro symbol (Unicode U+20AC). @item \textexclamdown @r{(or @code{!`})} @cindex exclamation point, upside-down @exclamdown{} Upside down exclamation point. @item \textfiguredash @cindex figure dash character Dash used between numerals, Unicode U+2012. Defined in the June 2021 release of @LaTeX{}. When used in pdf@TeX{}, approximated by an en-dash; with a Unicode engine, either typesets the glyph if available in the current font, or writes the usual ``Missing character'' warning to the log file. @item \textgreater @cindex greater than symbol, in text > Greater than symbol. @item \texthorizontalbar @cindex horizontal bar character Horizontal bar character, Unicode U+2015. Defined in the June 2021 release of @LaTeX{}. Behavior as with @code{\textfiguredash} above; the pdf@TeX{} approximation is an em-dash. @item \textless @cindex less than symbol, in text < Less than symbol. @item \textleftarrow @cindex arrow, left, in text @cindex left arrow, in text @BES{2190}, Left arrow. @item \textnonbreakinghyphen @cindex non-breaking hyphen character @cindex hyphen character, non-breaking Non-breaking hyphen character, Unicode U+2011. Defined in the June 2021 release of @LaTeX{}. Behavior as with @code{\textfiguredash} above; the pdf@TeX{} approximation is a regular ASCII hyphen (with breaks disallowed after). @item \textordfeminine @itemx \textordmasculine @cindex feminine ordinal symbol @cindex masculine ordinal symbol @cindex ordinals, feminine and masculine @cindex Spanish ordinals, feminine and masculine @ordf{}, @ordm{} Feminine and masculine ordinal symbols. @item \textperiodcentered @cindex period, centered, in text @cindex centered period, in text @BES{00B7,\cdot} Centered period. @item \textquestiondown @r{(or @code{?`})} @cindex question mark, upside-down @questiondown{} Upside down question mark. @item \textquotedblleft @r{(or @code{``})} @cindex left quote, double @cindex double left quote `` Double left quote. @item \textquotedblright @r{(or @code{''})} @cindex right quote, double @cindex double right quote '' Double right quote. @item \textquoteleft @r{(or @code{`})} @cindex left quote, single @cindex single left quote ` Single left quote. @item \textquoteright @r{(or @code{'})} @cindex right quote, single @cindex single right quote ' Single right quote. @item \textquotesingle @cindex quote, single straight @cindex straight single quote @cindex single quote, straight @BES{0027}, Straight single quote. (From TS1 encoding.) @item \textquotestraightbase @itemx \textquotestraightdblbase @cindex quote, straight base @cindex straight quote, base @cindex double quote, straight base @cindex straight double quote, base @c Unicode doesn't have these https://en.wikipedia.org/wiki/Quotation_mark Single and double straight quotes on the baseline. @item \textregistered @cindex registered symbol @registeredsymbol{} Registered symbol. @item \textrightarrow @cindex arrow, right, in text @cindex right arrow, in text @BES{2192}, Right arrow. @item \textthreequartersemdash @cindex three-quarters em-dash @cindex em-dash, three-quarters @BES{FE58}, ``Three-quarters'' em-dash, between en-dash and em-dash. @item \texttrademark @cindex trademark symbol @BES{2122,^{\hbox{TM}}} Trademark symbol. @c ?? Diff from \textthreequartersemdash? In Unicode? @item \texttwelveudash @cindex two-thirds em-dash @cindex em-dash, two-thirds @BES{FE58}, ``Two-thirds'' em-dash, between en-dash and em-dash. @item \textunderscore @cindex underscore, in text _ Underscore. @item \textvisiblespace @cindex visible space symbol, in text @BES{2423}, Visible space symbol. @end ftable @node Accents @section Accents @cindex accents @cindex characters, accented @cindex letters, accented @PkgIndex{babel} @PkgIndex{polyglossia} @cindex multilingual support @LaTeX{} has wide support for many of the world's scripts and languages, provided through the core @package{babel} package, which supports pdf@LaTeX{}, Xe@LaTeX{} and Lua@LaTeX{}. The @package{polyglossia} package provides similar support with the latter two engines. This section does not cover that support. It only lists the core @LaTeX{} commands for creating accented characters. The @code{\capital...} commands shown here produce alternative forms for use with capital letters. These are not available with OT1. Below, to make them easier to find, the accents are all illustrated with lowercase @samp{o}. @findex \i @r{(dotless i)} @cindex dotless i Note that @code{\i} produces a dotless i, @c @dotless{i}, @findex \j @r{(dotless j)} @cindex dotless j and @code{\j} produces a dotless j. @c @dotless{j}. These are often used in place of their dotted counterparts when they are accented. @table @code @item \" @itemx \capitaldieresis @findex \" @r{(umlaut accent)} @findex \capitaldieresis @cindex umlaut accent @cindex dieresis accent @"{o} Umlaut (dieresis). @item \' @itemx \capitalacute @findex \' @r{(acute accent)} @findex \capitalacute @cindex acute accent @'{o} Acute accent. @item \. @findex \. @r{(dot-over accent)} @cindex dot accent @cindex dot-over accent @dotaccent{o} Dot accent. @item \= @itemx \capitalmacron @findex \= @r{(macron accent)} @findex \capitalmacron @cindex macron accent @cindex overbar accent @cindex bar-over accent @={o} Macron (overbar) accent. @item \^ @itemx \capitalcircumflex @findex \^ @r{(circumflex accent)} @findex \capitalcircumflex @cindex circumflex accent @cindex hat accent @^{o} Circumflex (hat) accent. @item \` @itemx \capitalgrave @findex \` @r{(grave accent)} @findex \capitalgrave @cindex grave accent @`{o} Grave accent. @item \~ @itemx \capitaltilde @findex \~ @r{(tilde accent)} @findex \capitaltilde @cindex tilde accent @~{n} Tilde accent. @item \b @findex \b @r{(bar-under accent)} @cindex bar-under accent @ubaraccent{o} Bar accent underneath. @findex \underbar @cindex underbar Related to this, @code{\underbar@{@var{text}@}} produces a bar under @var{text}. The argument is always processed in LR mode (@pxref{Modes}). The bar is always a fixed position under the baseline, thus crossing through descenders. See also @code{\underline} in @ref{Over- and Underlining}. @item \c @itemx \capitalcedilla @findex \c @r{(cedilla accent)} @findex \capitalcedilla @cindex cedilla accent @,{c} Cedilla accent underneath. @item \d @itemx \capitaldotaccent @findex \d @r{(dot-under accent)} @findex \capitaldotaccent @cindex dot-under accent @udotaccent{o} Dot accent underneath. @item \H @itemx \capitalhungarumlaut @findex \H @r{(Hungarian umlaut accent)} @findex \capitalhungarumlaut @cindex hungarian umlaut accent @H{o} Long Hungarian umlaut accent. @item \k @itemx \capitalogonek @findex \k @r{(ogonek)} @findex \capitalogonek @cindex ogonek @ogonek{o} Ogonek. Not available in the OT1 encoding. @item \r @itemx \capitalring @findex \r @r{(ring accent)} @findex \capitalring @cindex ring accent @ringaccent{o} Ring accent. @item \t @itemx \capitaltie @itemx \newtie @itemx \capitalnewtie @findex \t @r{(tie-after accent)} @findex \capitaltie @findex \newtie @findex \capitalnewtie @cindex tie-after accent @iftex @tieaccent{oo} @end iftex Tie-after accent (used for transliterating from Cyrillic, such as in the ALA-LC romanization). It expects that the argument has two characters. The @code{\newtie} form is centered in its box. @item \u @itemx \capitalbreve @findex \u @r{(breve accent)} @findex \capitalbreve @cindex breve accent @u{o} Breve accent. @item \v @itemx \capitalcaron @findex \v @r{(breve accent)} @findex \capitalcaron @cindex hacek accent @cindex check accent @cindex caron accent @v{o} H@'a@v{c}ek (check, caron) accent. @end table @menu * \accent:: Low level command to produce an accented character. @end menu @node \accent @subsection @code{\accent} @findex \accent Synopsis: @example \accent @var{number} @var{character} @end example A @TeX{} primitive command used to generate accented characters from accent marks and letters. The accent mark is selected by @var{number}, a numeric argument, followed by a space and then a @var{character} argument to construct the accented character in the current font. These are accented @samp{e} characters. @example \accent18 e \accent20 e \accent21 e \accent22 e \accent23 e @end example @noindent The first is a grave, the second a caron, the third a breve, the fourth a macron, and the fifth a ring above. The position of the accent is determined by the font designer and so the outcome of @code{\accent} use may differ between fonts. In @LaTeX{} it is desirable to have glyphs for accented characters rather than building them using @code{\accent}. Using glyphs that already contain the accented characters (as in T1 encoding) allows correct hyphenation whereas @code{\accent} disables hyphenation (specifically with OT1 font encoding where accented glyphs are absent). There can be an optional font change between @var{number} and @var{character}. Note also that this command sets the @code{\spacefactor} to 1000 (@pxref{\spacefactor}). An unavoidable characteristic of some Cyrillic letters and the majority of accented Cyrillic letters is that they must be assembled from multiple elements (accents, modifiers, etc.) while @code{\accent} provides for a single accent mark and a single letter combination. There are also cases where accents must appear between letters that \accent does not support. Still other cases exist where the letters I and J have dots above their lowercase counterparts that conflict with dotted accent marks. The use of @code{\accent} in these cases will not work as it cannot analyze upper/lower case. @node Additional Latin letters @section Additional Latin letters @anchor{Non-English characters} @cindex Latin letters, additional @cindex letters, additional Latin @cindex extended Latin @cindex special characters @cindex non-English characters @cindex characters, non-English Here are the basic @LaTeX{} commands for inserting letters beyond A--Z that extend the Latin alphabet, used primarily in languages other than English. @table @code @item \aa @itemx \AA @findex \aa @r{(@aa{})} @findex \AA @r{(@AA{})} @cindex aring @aa{} and @AA{}. @item \ae @itemx \AE @findex \ae @r{(@ae{})} @findex \AE @r{(@AE{})} @cindex ae ligature @ae{} and @AE{}. @item \dh @itemx \DH @findex \dh @r{(@dh{})} @findex \DH @r{(@DH{})} @cindex Icelandic eth @cindex eth, Icelandic letter Icelandic letter eth: @dh{} and @DH{}. Not available with @sc{OT1} encoding, you need the @file{fontenc} package to select an alternate font encoding, such as @sc{T1}. @item \dj @itemx \DJ @findex \dj @findex \DJ Crossed d and D, a.k.a.@: capital and small letter d with stroke. Not available with @sc{OT1} encoding, you need the @file{fontenc} package to select an alternate font encoding, such as @sc{T1}. @item \ij @itemx \IJ @findex \ij @r{(ij)} @findex \IJ @r{(IJ)} @cindex ij letter, Dutch ij and IJ (except somewhat closer together than appears here). @item \l @itemx \L @findex \l @r{(@l{})} @findex \L @r{(@L{})} @cindex polish l @l{} and @L{}. @item \ng @itemx \NG @findex \ng @findex \NG Lappish letter eng, also used in phonetics. @item \o @itemx \O @findex \o @r{(@o{})} @findex \O @r{(@O{})} @cindex oslash @o{} and @O{}. @item \oe @itemx \OE @findex \oe @r{(@oe{})} @findex \OE @r{(@OE{})} @cindex oe ligature @oe{} and @OE{}. @item \ss @itemx \SS @findex \ss @r{(@ss{})} @findex \SS @r{(SS)} @cindex es-zet German letter @cindex sharp S letters @ss{} and SS. @item \th @itemx \TH @findex \th @r{(@th{})} @findex \TH @r{(@TH{})} @cindex Icelandic thorn @cindex thorn, Icelandic letter Icelandic letter thorn: @th{} and @TH{}. Not available with @sc{OT1} encoding, you need the @file{fontenc} package to select an alternate font encoding, such as @sc{T1}. @end table @node inputenc package @section @code{inputenc} package @findex inputenc Synopsis: @example \usepackage[@var{encoding-name}]@{inputenc@} @end example Declare the input file's text encoding to be @var{encoding-name}. The default, if this package is not loaded, is UTF-8. Technically, specifying the encoding name is optional, but in practice it is not useful to omit it. @cindex encoding, of input files @cindex character encoding @cindex Unicode In a computer file, the characters are stored according to a scheme called the @dfn{encoding}. There are many different encodings. The simplest is ASCII, which supports 95 printable characters, not enough for most of the world's languages. For instance, to typeset the a-umlaut character @samp{@"{a}} in an ASCII-encoded @LaTeX{} source file, the sequence @code{\"a} is used. This would make source files for anything but English hard to read; even for English, often a more extensive encoding is more convenient. The modern encoding standard, in some ways a union of the others, is UTF-8, one of the representations of Unicode. This is the default for @LaTeX{} since 2018. The @code{inputenc} package is how @LaTeX{} knows what encoding is used. For instance, the following command explicitly says that the input file is UTF-8 (note the lack of a dash). @example \usepackage[utf8]@{inputenc@} @end example Caution: use @code{inputenc} only with the pdf@TeX{} engine (@pxref{@TeX{} engines}). (The Xe@TeX{} and Lua@TeX{} engines assume that the input file is UTF-8 encoded.) If you invoke @LaTeX{} with either the @command{xelatex} command or the @command{lualatex} command, and try to declare a non-UTF-8 encoding with @code{inputenc}, such as @code{latin1}, then you will get the error @code{inputenc is not designed for xetex or luatex}. An @code{inputenc} package error such as @code{Invalid UTF-8 byte "96} means that some of the material in the input file does not follow the encoding scheme. Often these errors come from copying material from a document that uses a different encoding than the input file; this one is a left single quote from a web page using @code{latin1} inside a @LaTeX{} input file that uses UTF-8. The simplest solution is to replace the non-UTF-8 character with its UTF-8 equivalent, or use a @LaTeX{} equivalent command or character. @findex \inputencoding @anchor{\inputencoding} In some documents, such as a collection of journal articles from a variety of authors, changing the encoding in mid-document may be necessary. Use the command @code{\inputencoding@{@var{encoding-name}@}}. The most common values for @var{encoding-name} are: @code{ascii}, @code{latin1}, @code{latin2}, @code{latin3}, @code{latin4}, @code{latin5}, @code{latin9}, @code{latin10}, and@tie{}@code{utf8}. @node \rule @section @code{\rule} @findex \rule Synopsis, one of: @example \rule@{@var{width}@}@{@var{thickness}@} \rule[@var{raise}]@{@var{width}@}@{@var{thickness}@} @end example Produce a @dfn{rule}, a filled-in rectangle. @cindex Halmos symbol @cindex tombstone This example produces a rectangular blob, sometimes called a Halmos symbol, or just ``qed'', often used to mark the end of a proof: @example \newcommand@{\qedsymbol@}@{\rule@{0.4em@}@{2ex@}@} @end example @PkgIndex{amsthm} @noindent The @package{amsthm} package includes this command, with a somewhat different-looking symbol. The mandatory arguments give the horizontal @var{width} and vertical @var{thickness} of the rectangle. They are rigid lengths (@pxref{Lengths}). The optional argument @var{raise} is also a rigid length, and tells @LaTeX{} how much to raise the rule above the baseline, or lower it if the length is negative. This produces a line, a rectangle that is wide but not tall. @example \noindent\rule@{\textwidth@}@{0.4pt@} @end example @noindent The line is the width of the page and 0.4@tie{}points tall. This line thickness is common in @LaTeX{}. A rule that has zero width, or zero thickness, will not show up in the output, but can cause @LaTeX{} to change the output around it. @xref{\strut}, for examples. @node \today @section @code{\today} @findex \today @cindex date, today's @cindex today's date Synopsis: @example \today @end example Produce today's date in the format @samp{@var{month} @var{dd}, @var{yyyy}}. An example of a date in that format is @samp{July 4, 1976}. @PkgIndex{babel} @PkgIndex{polyglossia} Multilingual packages such as @package{babel} or @package{polyglossia}, or classes such as @file{lettre}, will localize @code{\today}. For example, the following will output @samp{4 juillet 1976}: @example \year=1976 \month=7 \day=4 \documentclass@{minimal@} \usepackage[french]@{babel@} \begin@{document@} \today \end@{document@} @end example @noindent @code{\today} uses the counters @code{\day}, @code{\month}, and @code{\year} (@pxref{\day & \month & \year}). @PkgIndex{datetime} A number of package on CTAN work with dates. One is @package{datetime} package which can produce a wide variety of date formats, including ISO standards. The date is not updated as the @LaTeX{} process runs, so in principle the date could be incorrect by the time the program finishes. @node Splitting the input @chapter Splitting the input @cindex splitting the input file @cindex input file @LaTeX{} lets you split a large document into several smaller ones. This can simplify editing or allow multiple authors to work on the document. It can also speed processing. Regardless of how many separate files you use, there is always one @cindex root file @cindex file, root @dfn{root file}, on which @LaTeX{} compilation starts. This shows such a file with five included files. @example \documentclass@{book@} \includeonly@{ % comment out lines below to omit compiling pref, chap1, chap2, append, bib @} \begin@{document@} \frontmatter \include@{pref@} \mainmatter \include@{chap1@} \include@{chap2@} \appendix \include@{append@} \backmatter \include@{bib@} \end@{document@} @end example @noindent This will bring in material from @file{pref.tex}, @file{chap1.tex}, @file{chap2.tex}, @file{append.tex}, and @file{bib.tex}. If you compile this file, and then comment out all of the lines inside @code{\includeonly@{...@}} except for @code{chap1}, and compile again, then @LaTeX{} will only process the material in the first chapter. Thus, your output will appear more quickly and be shorter to print. However, the advantage of the @code{\includeonly} command is that @LaTeX{} will retain the page numbers and all of the cross reference information from the other parts of the document so these will appear in your output correctly. @xref{Larger book template}, for another example of @code{\includeonly}. @menu * \endinput:: Stop including material from a file. * \include & \includeonly:: Conditionally include files. * \input:: Unconditionally include a file. @end menu @node \endinput @section @code{\endinput} @findex \endinput Synopsis: @example \endinput @end example When you @code{\include@{filename@}}, inside @file{filename.tex} the material after @code{\endinput} will not be included. This command is optional; if @file{filename.tex} has no @code{\endinput} then @LaTeX{} will read all of the file. For example, suppose that a document's root file has @code{\input@{chap1@}} and this is @file{chap1.tex}. @example \chapter@{One@} This material will appear in the document. \endinput This will not appear. @end example This can be useful for putting documentation or comments at the end of a file, or for avoiding junk characters that can be added if the file is transmitted in the body of an email. It is also useful for debugging: one strategy to localize errors is to put @code{\endinput} halfway through the included file and see if the error disappears. Now, knowing which half contains the error, moving @code{\endinput} to halfway through that area further narrows down the location. This process rapidly finds the offending line. After reading @code{\endinput}, @LaTeX{} continues to read to the end of the line, so something can follow this command and be read nonetheless. This allows you, for instance, to close an @code{\if...} with a @code{\fi}. @node \include & \includeonly @section @code{\include} & @code{\includeonly} @anchor{\include} @anchor{\includeonly} @findex \include @findex \includeonly Synopsis: @example \includeonly@{ % in document preamble ... @var{filename}, ... @} ... \include@{@var{filename}@} % in document body @end example Bring material from the external file @file{@var{filename}.tex} into a @LaTeX{} document. The @code{\include} command does three things: it executes @code{\clearpage} (@pxref{\clearpage & \cleardoublepage}), then it inputs the material from @file{@var{filename}.tex} into the document, and then it does another @code{\clearpage}. This command can only appear in the document body. The @code{\includeonly} command controls which files will be read by @LaTeX{} under subsequent @code{\include} commands. Its list of filenames is comma-separated. It must appear in the preamble or even earlier, e.g., the command line; it can't appear in the document body. This example root document, @file{constitution.tex}, brings in three files, @file{preamble.tex}, @file{articles.tex}, and @file{amendments.tex}. @example \documentclass@{book@} \includeonly@{ preamble, articles, amendments @} \begin@{document@} \include@{preamble@} \include@{articles@} \include@{amendments@} \end@{document@} @end example @noindent The file @file{preamble.tex} contains no special code; you have just excerpted the chapter from @file{consitution.tex} and put it in a separate file just for editing convenience. @example \chapter@{Preamble@} We the People of the United States, in Order to form a more perfect Union, ... @end example @noindent Running @LaTeX{} on @file{constitution.tex} makes the material from the three files appear in the document but also generates the auxiliary files @file{preamble.aux}, @file{articles.aux}, and @file{amendments.aux}. These contain information such as page numbers and cross-references (@pxref{Cross references}). If you now comment out @code{\includeonly}'s lines with @code{preamble} and @code{amendments} and run @LaTeX{} again then the resulting document shows only the material from @file{articles.tex}, not the material from @file{preamble.tex} or @file{amendments.tex}. Nonetheless, all of the auxiliary information from the omitted files is still there, including the starting page number of the chapter. If the document preamble does not have @code{\includeonly} then @LaTeX{} will include all the files you call for with @code{\include} commands. The @code{\include} command makes a new page. To avoid that, see @ref{\input} (which, however, does not retain the auxiliary information). @xref{Larger book template}, for another example using @code{\include} and @code{\includeonly}. That example also uses @code{\input} for some material that will not necessarily start on a new page. File names can involve paths. @example \documentclass@{book@} \includeonly@{ chapters/chap1, @} \begin@{document@} \include@{chapters/chap1@} \end@{document@} @end example To make your document portable across distributions and platforms you should avoid spaces in the file names. The tradition is to instead use dashes or underscores. Nevertheless, for the name @samp{amo amas amat}, this works under @TeX{} Live on GNU/Linux: @findex \space @example \documentclass@{book@} \includeonly@{ "amo\space amas\space amat" @} \begin@{document@} \include@{"amo\space amas\space amat"@} \end@{document@} @end example and this works under MiK@TeX{} on Windows: @example \documentclass@{book@} \includeonly@{ @{"amo amas amat"@} @} \begin@{document@} \include@{@{"amo amas amat"@}@} \end@{document@} @end example @cindex nested @code{\include}, not allowed You cannot use @code{\include} inside a file that is being included or you get @samp{LaTeX Error: \include cannot be nested.} The @code{\include} command cannot appear in the document preamble; you will get @samp{LaTeX Error: Missing \begin@{document@}}. If a file that you @code{\include} does not exist, for instance if you @code{\include@{athiesm@}} but you meant @code{\include@{atheism@}}, then @LaTeX{} does not give you an error but will warn you @samp{No file athiesm.tex.} (It will also create @file{athiesm.aux}.) If you @code{\include} the root file in itself then you first get @samp{LaTeX Error: Can be used only in preamble.} Later runs get @samp{TeX capacity exceeded, sorry [text input levels=15]}. To fix this, you must remove the inclusion @code{\include@{@var{root}@}} but also delete the file @file{@var{root}.aux} and rerun @LaTeX{}. @node \input @section @code{\input} @findex \input Synopsis: @example \input@{@var{filename}@} @end example @LaTeX{} processes the file as if its contents were inserted in the current file. For a more sophisticated inclusion mechanism see @ref{\include & \includeonly}. If @var{filename} does not end in @samp{.tex} then @LaTeX{} first tries the filename with that extension; this is the usual case. If @var{filename} ends with @samp{.tex} then @LaTeX{} looks for the filename as it is. For example, this @example \input@{macros@} @end example @noindent will cause @LaTeX{} to first look for @file{macros.tex}. If it finds that file then it processes its contents as thought they had been copy-pasted in. If there is no file of the name @file{macros.tex} then @LaTeX{} tries the name @file{macros}, without an extension. (This may vary by distribution.) To make your document portable across distributions and platforms you should avoid spaces in the file names. The tradition is to instead use dashes or underscores. Nevertheless, for the name @samp{amo amas amat}, this works under @TeX{} Live on GNU/Linux: @findex \space @example \input@{"amo\space amas\space amat"@} @end example and this works under MiK@TeX{} on Windows: @example \input@{@{"amo amas amat"@}@} @end example @node Front/back matter @chapter Front/back matter @menu * Table of contents etc.:: Table of contents, list of figures, list of tables. * Indexes:: Generate an index. * Glossaries:: Generate a glossary. @end menu @c no comma in the node name because Texinfo doesn't support that well. @node Table of contents etc. @section Table of contents, list of figures, list of tables @cindex table of contents, creating @findex \tableofcontents @findex .toc @r{file} @findex \listoffigures @findex \listoftables @findex .lof @r{file} @findex .lot @r{file} Synopsis, one of: @example \tableofcontents \listoffigures \listoftables @end example Produce a table of contents, or list of figures, or list of tables. Put the command in the input file where you want the table or list to go. You do not type the entries; for example, typically the table of contents entries are automatically generated from the sectioning commands @code{\chapter}, etc. This example illustrates the first command, @code{\tableofcontents}. @LaTeX{} will produce a table of contents on the book's first page. @example \documentclass@{book@} % \setcounter@{tocdepth@}@{1@} \begin@{document@} \tableofcontents\newpage ... \chapter@{...@} ... \section@{...@} ... \subsection@{...@} ... \end@{document@} @end example @noindent Uncommenting the second line would cause that table to contain chapter and section listings but not subsection listings, because the @code{\section} command has level@tie{}1. @xref{Sectioning}, for level numbers of the sectioning units. For more on the @code{tocdepth} @pxref{Sectioning/tocdepth}. Another example of the use of @code{\tableofcontents} is in @ref{Larger book template}. If you want a page break after the table of contents, write a @code{\newpage} command after the @code{\tableofcontents} command, as above. To make the table of contents, @LaTeX{} stores the information in an auxiliary file named @file{@var{root-file}.toc} (@pxref{Splitting the input}). For example, this @LaTeX{} file @file{test.tex} @example \documentclass@{article@} \begin@{document@} \tableofcontents\newpage \section@{First section@} \subsection@{First subsection@} ... @end example @noindent writes these lines to @file{test.toc}. @example \contentsline @{section@}@{\numberline @{1@}First section@}@{2@} \contentsline @{subsection@}@{\numberline @{1.1@}First subsection@}@{2@} @end example @findex \contentsline @noindent Each line contains a single command, @code{\contentsline} (@pxref{\contentsline}). The first argument, the @code{section} or @code{subsection}, is the sectioning unit. The second argument has two components. The hook @code{\numberline} determines how the sectioning number, @code{1} or @code{1.1}, appears in the table of contents (@pxref{\numberline}). The remainder of the second argument of @code{\contentsline}, @samp{First section} or @samp{First subsection}, is the sectioning title text. Finally, the third argument, @samp{2}, is the page number on which this sectioning unit starts. To typeset these lines, the document class provides @code{\l@@@var{section-unit}} commands such as @code{\l@@section@{@var{text}@}@{@var{pagenumber}@}} and @code{\l@@subsection@{@var{text}@}@{@var{pagenumber}@}}. These commands often use the @code{\@@dottedtocline} command (@pxref{\@@dottedtocline}). A consequence of @LaTeX{}'s strategy of using auxiliary files is that to get the correct information in the document you must run @LaTeX{} twice, once to store the information and the second time to retrieve it. In the ordinary course of writing a document authors run @LaTeX{} a number of times, but you may notice that the first time that you compile a new document, the table of contents page will be empty except for its @samp{Contents} header. Just run @LaTeX{} again. The commands @code{\listoffigures} and @code{\listoftables} produce a list of figures and a list of tables. Their information is stored in files with extension @file{.lof} and @file{.lot}. They work the same way as @code{\tableofcontents} but the latter is more common, so we use it for most examples. You can manually add material to the table of contents, the list of figures, and the list of tables. For instance, add a line about a section to the table of contents with @code{\addcontentsline@{toc@}@{section@}@{@var{text}@}}. (@pxref{\addcontentsline}). Add arbitrary material, that is, non-line material, with @code{\addtocontents}, as with the command @code{\addtocontents@{lof@}@{\protect\vspace@{2ex@}@}}, which adds vertical space to the list of figures (@pxref{\addtocontents}). Lines in the table of contents, the list of figures, and the list of tables, have four parts. First is an indent. Next is a box into which sectioning numbers are placed, and then the third box holds the title text, such as @samp{First section}. Finally there is a box up against the right margin, inside of which @LaTeX{} puts the page number box. For the indent and the width of the number box, @pxref{\@@dottedtocline}. The right margin box has width @code{\@@tocrmarg} and the page number is flush right in that space, inside a box of width @code{\@@pnumwidth}. By default @code{\@@tocrmarg} is @code{2.55em} and @code{\@@pnumwidth} is @code{1.55em}. Change these as with @code{\renewcommand@{\@@tocrmarg@}@{3.5em@}}. @PkgIndex{tocloft} @PkgIndex{tocbibbind} CTAN has many packages for the table of contents and lists of figures and tables (@pxref{CTAN}). The package @package{tocloft} is convenient for adjusting some aspects of the default such as spacing. And, @package{tocbibbind} will automatically add the bibliography, index, etc. to the table of contents. To change the header for the table of contents page, do something like these commands before you call @code{\tableofcontents}, etc. @example \renewcommand@{\contentsname@}@{Table of Contents@} \renewcommand@{\listfigurename@}@{Plots@} \renewcommand@{\listtablename@}@{Specifications@} @end example @noindent @PkgIndex{babel} @PkgIndex{polyglossia} Internationalization packages such as @package{babel} or @package{polyglossia} will change these headers depending on the chosen base language. @menu * \@@dottedtocline:: Format entry line in table of contents, etc. * \addcontentsline:: Add an entry to table of contents, etc. * \addtocontents:: Add text directly to table of contents file, etc. * \contentsline:: Set line in table of contents, etc. * \nofiles:: Prevent writing to auxiliary files. * \numberline:: Put its number argument flush left in a box. @end menu @node \@@dottedtocline @subsection @code{\@@dottedtocline} @findex \@@dottedtocline @cindex table of contents entry, create dotted line Synopsis: @example \@@dottedtocline@{@var{section-level-num}@}@{@var{indent}@}@{@var{numwidth}@}@{@var{text}@}@{@var{pagenumber}@} @end example Used internally by @LaTeX{} to format an entry line in the table of contents, list of figures, or list of tables. Authors do not directly enter @code{\@@dottedtocline} commands. This command is typically used by @code{\l@@section}, @code{\l@@subsection}, etc., to format the content lines. For example, the @file{article.cls} file contains these definitions: @example \newcommand*\l@@section@{\@@dottedtocline@{1@}@{1.5em@}@{2.3em@}@} \newcommand*\l@@subsection@{\@@dottedtocline@{2@}@{3.8em@}@{3.2em@}@} \newcommand*\l@@subsubsection@{\@@dottedtocline@{3@}@{7.0em@}@{4.1em@}@} @end example @noindent In this example, @code{\@@dottedcline} appears to have been given only three arguments. But tracing the internal code shows that it picks up the final @var{text} and @var{pagenumber} arguments in the synopsis from a call to @code{\contentsline} (@pxref{\contentsline}). @cindex leaders, dots in table of contents Between the box for the title text of a section and the right margin box, these @code{\@@dottedtocline} commands insert @dfn{leaders}, that is, evenly-spaced dots. The dot-to-dot space is given by the command @code{\@@dotsep}. By default it is 4.5 (it is in math units, aka.@: @code{mu}, which are @code{1/18}@tie{}em. Change it using @code{\renewcommand}, as in @code{\renewcommand@{\@@dotsep@}@{3.5@}}. In the standard @file{book} class, @LaTeX{} does not use dotted leaders for the Part and Chapter table entries, and in the standard @file{article} class it does not use dotted leaders for Section entries. @node \addcontentsline @subsection @code{\addcontentsline} @findex \addcontentsline @cindex table of contents entry, manually adding Synopsis: @example \addcontentsline@{@var{ext}@}@{@var{unit}@}@{@var{text}@} @end example @findex \contentsline Add an entry to the auxiliary file with extension @var{ext}. The following will result in an @samp{Appendices} line in the table of contents. @example \addcontentsline@{toc@}@{section@}@{\protect\textbf@{Appendices@}@} @end example @noindent It will appear at the same indentation level as the sections, will be in boldface, and will be assigned the page number associated with the point where the command appears in the input file. The @code{\addcontentsline} command writes information to the file @file{@var{root-name}.@var{ext}}, where @var{root-name} is the file name of the root file (@pxref{Splitting the input}). It writes that information as the text of the command @code{\contentsline@{@var{unit}@}@{@var{text}@}@{@var{num}@}}, where @code{@var{num}} is the current value of counter @code{@var{unit}} (@pxref{\contentsline}). The most common case is the table of contents and there @var{num} is the page number of the first page of @var{unit}. This command is invoked by the sectioning commands @code{\chapter}, etc. (@pxref{Sectioning}), and also by @code{\caption} inside a float environment (@pxref{Floats}). But it is also directly used by authors. For example, an author writing a book whose style is to have an unnumbered preface may use the starred @code{\chapter*}. But that command leaves out table of contents information, which can be entered manually, as here. @example \chapter*@{Preface@} \addcontentsline@{toc@}@{chapter@}@{\protect\numberline@{@}Preface@} @end example @noindent In the @file{@var{root-name}.toc} file @LaTeX{} will put the line @code{\contentsline @{chapter@}@{\numberline @{@}Preface@}@{3@}}; note that the page number @samp{3} is automatically generated by the system, not entered manually. All of the arguments for @code{\addcontentsline} are required. @table @var @item ext Typically one of the strings @code{toc} for the table of contents, @code{lof} for the list of figures, or @code{lot} for the list of tables. The filename extension of the information file. @item unit A string that depends on the value of the @var{ext} argument, typically one of: @table @code @item toc For the table of contents, this is the name of a sectional unit: @code{part}, @code{chapter}, @code{section}, @code{subsection}, etc. @item lof For the list of figures: @code{figure}. @item lot For the list of tables: @code{table}. @end table @item text The text of the entry. You must @code{\protect} any fragile commands (@pxref{\protect}) used in it. @end table The @code{\addcontentsline} command has an interaction with @code{\include} (@pxref{\include & \includeonly}). If you use them at the same level, as with @code{\addcontentsline@{...@}@{...@}@{...@}\include@{...@}} then lines in the table of contents can come out in the wrong order. The solution is to move @code{\addcontentsline} into the file being included. If you use a @var{unit} that @LaTeX{} does not recognize, as with the typo here @example \addcontentsline@{toc@}@{setcion@}@{\protect\textbf@{Appendices@}@} @end example @noindent then you don't get an error but the formatting in the table of contents will not make sense. @node \addtocontents @subsection @code{\addtocontents} @findex \addtocontents@{@var{ext}@}@{@var{text}@} Synopsis: @example \addtocontents@{@var{ext}@}@{@var{text}@} @end example Add @var{text}, which may be text or formatting commands, directly to the auxiliary file with extension @var{ext}. This is most commonly used for the table of contents so that is the discussion here, but it also applies to the list of figures and list of tables. This will put some vertical space in the table of contents after the @samp{Contents} header. @example \tableofcontents\newpage \addtocontents@{toc@}@{\protect\vspace*@{3ex@}@} @end example @noindent This puts the word @samp{Page}, in boldface, above the column of page numbers and after the header. @example \tableofcontents \addtocontents@{toc@}@{~\hfill\textbf@{Page@}\par@} \chapter@{...@} @end example @noindent This adds a line announcing work by a new author. @example \addtocontents@{toc@}@{% \protect\vspace@{2ex@} \textbf@{Chapters by N. Other Author@}\par@} @end example The difference between @code{\addtocontents} and @code{\addcontentsline} is that the latter is strictly for lines, such as with a line giving the page number for the start of a new subset of the chapters. As the above examples show, @code{\addtocontents} is for material such as spacing. The @code{\addtocontents} command has two arguments. Both are required. @table @var @item ext Typically one of: @file{toc} for the table of contents, @file{lof} for the list of figures, or @file{lot} for the list of tables. The extension of the file holding the information. @item text The text, and possibly commands, to be written. @end table The sectioning commands such as @code{\chapter} use the @code{\addcontentsline} command to store information. This command creates lines in the @file{.toc} auxiliary file containing the @code{\contentsline} command (@pxref{\addcontentsline}). In contrast, the command @code{\addtocontents} puts material directly in that file. The @code{\addtocontents} command has an interaction with @code{\include} (@pxref{\include & \includeonly}). If you use them at the same level, as with @code{\addtocontents@{...@}@{...@}\include@{...@}} then lines in the table of contents can come out in the wrong order. The solution is to move @code{\addtocontents} into the file being included. @node \contentsline @subsection @code{\contentsline} @cindex table of contents @findex \contentsline @findex \tableofcontents @findex .toc @r{file} @findex \listoffigures @findex \listoftables @findex .lof @r{file} @findex .lot @r{file} @findex \l@@chapter @findex \l@@section @findex \l@@subsection Synopsis: @example \contentsline@{@var{unit}@}@{@var{text}@}@{@var{pagenumber}@} @end example Used internally by @LaTeX{} to typeset an entry of the table of contents, list of figures, or list of tables (@pxref{Table of contents etc.}). Authors do not directly enter @code{\contentsline} commands. Usually adding material to these lists is done automatically by the commands @code{\chapter}, @code{\section}, etc. for the table of contents, or by the @code{\caption} command inside of a @code{\figure} or @code{\table} environment (@pxref{figure} and @pxref{table}). Thus, where the root file is @file{thesis.tex}, and contains the declaration @code{\tableofcontents}, the command @code{\chapter@{Chapter One@}} produces something like this in the file @file{thesis.toc}. @example \contentsline @{chapter@}@{\numberline @{1@}Chapter One@}@{3@} @end example If the file contains the declaration @code{\listoffigures} then a figure environment involving @code{\caption@{Test@}} will produce something like this in @file{thesis.lof}. @example \contentsline @{figure@}@{\numberline @{1.1@}@{\ignorespaces Test@}@}@{6@} @end example To manually add material, use @code{\addcontentsline@{@var{filetype}@}@{@var{unit}@}@{@var{text}@}}, where @var{filetype} is @code{toc}, @code{lof}, or @code{lot} (@pxref{\addcontentsline}). @PkgIndex{tocloft} For manipulating how the @code{\contentline} material is typeset, see the @package{tocloft} package. @PkgIndex{hyperref} Note that the @package{hyperref} package changes the definition of @code{\contentsline} (and @code{\addcontentsline}) to add more arguments, to make hyperlinks. This is the source of the error @code{Argument of \contentsline has an extra @}} when one adds/remove the use of package @package{hyperref} and a compilation was already run. Fix this error by deleting the @file{.toc} or @file{.lof} or @file{.lot} file, and running @LaTeX{} again. @node \nofiles @subsection @code{\nofiles} @findex \nofiles Synopsis: @example \nofiles @end example Prevent @LaTeX{} from writing any auxiliary files. The only output will be the @file{.log} and @file{.pdf} (or @file{.dvi}) files. This command must go in the preamble. Because of the @code{\nofiles} command this example will not produce a @file{.toc} file. @example \documentclass@{book@} \nofiles \begin@{document@} \tableofcontents\newpage \chapter@{...@} ... @end example @noindent @LaTeX{} will not erase any existing auxiliary files, so if you insert the @code{\nofiles} command after you have run the file and gotten a @file{.toc} then the table of contents page will continue to show the old information. @node \numberline @subsection @code{\numberline} @findex \numberline Synopsis: @example \numberline@{@var{number}@} @end example Typeset its argument flush left in a box. This is used in a @code{\contentsline} command to typeset the section number (@pxref{\contentsline}). For example, this line in a @file{.toc} file causes the @code{1.1} to be typeset flush left. @example \contentsline @{subsection@}@{\numberline @{1.1@}Motivation@}@{2@} @end example By default, @LaTeX{} typesets the section numbers in a box of length @code{\@@tempdima}. That length is set by the commands @code{\l@@section}, @code{\l@@subsection}, etc. Put section numbers inside a natural-width box with @code{\renewcommand@{\numberline@}[1]@{#1~@}} before @code{\tableofcontents}. This command is fragile so you may need to precede it with @code{\protect} (@pxref{\protect}). An example is the use of @code{\protect} in this command, @example @code{\addcontentsline@{toc@}@{section@}@{\protect\numberline@{@}Summary@}} @end example @noindent to get the @code{\numberline} into the @code{\contentsline} command in the @file{.toc} file: @code{\contentsline @{section@}@{\numberline @{@}Summary@}@{6@}} (the page number @samp{6} is automatically added by @LaTeX{}; @pxref{\addcontentsline}). @node Indexes @section Indexes @cindex indexes @findex \makeindex @findex \index @cindex @file{.idx} file If you tell @LaTeX{} what terms you want to appear in an index then it can produce that index, alphabetized and with the page numbers automatically maintained. This illustrates the basics. @example \documentclass@{article@} \usepackage@{makeidx@} % Provide indexing commands \makeindex % \usepackage@{showidx@} % Show marginal notes of index entries ... \begin@{document@} ... Wilson's Theorem\index@{Wilson's Theorem@} says that a number $n>1$ is prime if and only if the factorial of $n-1$ is congruent to $-1$ modulo~$n$.\index@{congruence!and Wilson's Theorem@} ... \printindex \end@{document@} @end example @noindent As that shows, declare index entries with the @code{\index} command (@pxref{\index}). When you run @LaTeX{}, the @code{\index} writes its information, such as @samp{Wilson's Theorem} and the page number, to an auxiliary file whose name ends in @file{.idx}. Next, to alphabetize and do other manipulations, run an external command, typically @command{makeindex} (@pxref{makeindex}), which writes a file whose name ends in @file{.ind}. Finally, @code{\printindex} brings this manipulated information into the output (@pxref{\printindex}). Thus, if the above example is in the file @file{numth.tex} then running @samp{pdflatex numth} will save index entry and page number information to @file{numth.idx}. Then running @samp{makeindex numth} will alphabetize and save the results to @file{numth.ind}. Finally, again running @samp{pdflatex numth} will show the desired index, at the place where the @code{\printindex} command is in the source file. There are many options for the output. An example is that the exclamation point in @code{\index@{congruence!and Wilson's Theorem@}} produces a main entry of @samp{congruence} with a subentry of @samp{and Wilson's Theorem}. For more, @pxref{makeindex}. The @code{\makeindex} and @code{\printindex} commands are independent. Leaving out the @code{\makeindex} will stop @LaTeX{} from saving the index entries to the auxiliary file. Leaving out the @code{\printindex} will cause @LaTeX{} to not show the index in the document output. @PkgIndex{showidx} @PkgIndex{multind} @cindex index, multiple @cindex multiple indexes There are many packages in the area of indexing. The @package{showidx} package causes each index entries to be shown in the margin on the page where the @code{\index} appears. This can help in preparing the index. The @package{multind} package, among others, supports multiple indexes. See also the @TeX{} FAQ entry on this topic, @url{https://www.texfaq.org/FAQ-multind}, and the CTAN topic, @url{https://ctan.org/topic/index-multi}. @menu * Produce the index manually:: Alphabetize entries yourself. * \index:: Declare an index entry. * makeindex:: Alphabetize index entries automatically. * \printindex:: Put the index here. @end menu @node Produce the index manually @subsection Produce the index manually @cindex index, producing manually @findex theindex Documents that are small and static can have a manually produced index. This will make a separate page labeled @samp{Index}, in twocolumn format. @EnvIndex{theindex} @example \begin@{theindex@} \item acorn squash, 1 \subitem maple baked, 2 \indexspace \item bacon, 3 \subitem maple baked, 4 \end@{theindex@} @end example Note that the author must enter the page numbers, which is tedious and which will result in wrong numbers if the document changes. This is why in most cases automated methods such as @command{makeindex} are best. @xref{Indexes}. @findex \item @findex \subitem @findex \subsubitem @findex \indexspace However we cover the commands for completeness, and because the automated methods are based on these commands. There are three levels of entries. As the example shows, a main entry uses @code{\item}, subentries use @code{\subitem}, and the lowest level uses @code{\subsubitem}. Blank lines between entries have no effect. The example above includes @code{\indexspace} to produce vertical space in the output that some index styles use before the first entry starting with a new letter. @node \index @subsection @code{\index} @cindex index entry @findex \index Synopsis: @example \index@{@var{index-entry-string}@} @end example Declare an entry in the index. This command is fragile (@pxref{\protect}). For example, as described in @ref{Indexes}, one way to get an index from what's below is to compile the document with @code{pdflatex test}, then process the index entries with @code{makeindex test}, and then compile again with @code{pdflatex test}. @example % file test.tex ... W~Ackermann (1896--1962).\index@{Ackermann@} ... Ackermann function\index@{Ackermann!function@} ... rate of growth\index@{Ackermann!function!growth rate@} @end example @cindex index entries, subentries @noindent All three index entries will get a page number, such as @samp{Ackermann, 22}. @LaTeX{} will format the second as a subitem of the first, on the line below it and indented, and the third as a subitem of the second. Three levels deep is as far as you can nest subentries. (If you add @code{\index@{Ackermann!function!growth rate!comparison@}} then @command{makeindex} says @samp{Scanning input file test.idx....done (4 entries accepted, 1 rejected)} and the fourth level is silently missing from the index.) If you enter a second @code{\index} with the same @var{index-entry-string} then you will get a single index entry with two page numbers (unless they happen to fall on the same page). Thus, adding @code{as for Ackermann.\index@{Ackermann@}} later in the same document as above will give an index entry like @samp{Ackermann, 22, 151}. Also, you can enter the index entries in any order, so for instance @code{\index@{Ackermann!function@}} could come before @code{\index@{Ackermann@}}. @cindex index, page range Get a page range in the output, like @samp{Hilbert, 23--27}, as here. @example W~Ackermann (1896--1962).\index@{Ackermann@} ... D~Hilbert (1862--1943)\index@{Ackermann!Hilbert|(@} ... disapproved of his marriage.\index@{Ackermann!Hilbert|)@} @end example @noindent If the beginning and ending of the page range are equal then the system just gives a single page number, not a range. If you index subentries but not a main entry, as with @code{\index@{Jones!program@}} and @code{\index@{Jones!results@}}, then the output is the item @samp{Jones} with no comma or page number, followed by two subitems, like @samp{program, 50} and @samp{results, 51}. @cindex see and see also index entries @cindex index entries, `see' and `see also' @findex \seename @findex \alsoname @PkgIndex{babel} @PkgIndex{polyglossia} Generate a index entry that says @samp{see} by using a vertical bar character: @code{\index@{Ackermann!function|see@{P\'eter's function@}@}}. You can instead get @samp{see also} with @code{seealso}. (The text @samp{see} is defined by @code{\seename}, and @samp{see also} by @code{\alsoname}. You can redefine these either by using an internationalization package such as @package{babel} or @package{polyglossia}, or directly as with @code{\renewcommand@{\alsoname@}@{Also see@}}.) The @samp{see} feature is part of a more general functionality. After the vertical bar you can put the name of a one-input command, as in @code{\index@{group|textit@}} (note the missing backslash on the @code{\textit} command) and the system will apply that command to the page number, here giving something like @code{\textit@{7@}}. You can define your own one-input commands, such as @code{\newcommand@{\definedpage@}[1]@{@{\color@{blue@}#1@}@}} and then @code{\index@{Ackermann!function|definedpage@}} will give a blue page number (@pxref{Color}). Another, less practical, example is this, @c credit Ian Thompson https://tex.stackexchange.com/a/272572/121234 @example \newcommand\indexownpage[1]@{#1, \thepage@} ... Epimenides.\index@{self-reference|indexownpage@} @end example @noindent which creates an entry citing the page number of its own index listing. The two functions just described combine, as here @example \index@{Ackermann!function|(definedpage@} ... \index@{Ackermann!function|)@} @end example @noindent which outputs an index entry like @samp{function, 23--27} where the page number range is in blue. Consider an index entry such as @samp{@BES{03B1,\alpha}-ring}. Entering it as @code{$\alpha$-ring} will cause it to be alphabetized according to the dollar sign. You can instead enter it using an at-sign, as @code{\index@{alpha-ring@@$\alpha$-ring@}}. If you specify an entry with an at-sign separating two strings, @code{@var{pos}@@@var{text}}, then @var{pos} gives the alphabetical position of the entry while @var{text} produces the text of the entry. Another example is that @code{\index@{Saint Michael's College@@SMC@}} produces an index entry @samp{SMC} alphabetized into a different location than its spelling would naturally give it. To put a @code{!}, or @code{@@}, or @code{|}, or @code{"} character in an index entry, escape it by preceding it with a double quote, @code{"}. (The double quote gets deleted before alphabetization.) @PkgIndex{index} A number of packages on CTAN have additional functionality beyond that provided by @package{makeidx}. One is @package{index}, which allows for multiple indices and contains a command @code{\index*@{@var{index-entry-string}@}} that prints the @var{index-entry-string} as well as indexing it. @findex \indexentry @cindex idx file The @code{\index} command writes the indexing information to the file @file{@var{root-name}.idx} file. Specifically, it writes text of the command @code{\indexentry@{@var{index-entry-string}@}@{@var{page-num}@}}, where @var{page-num} is the value of the @code{\thepage} counter. On occasion, when the @code{\printindex} command is confused, you have to delete this file to start with a fresh slate. If you omit the closing brace of an @code{\index} command then you get a message like this. @example Runaway argument? @{Ackermann!function ! Paragraph ended before \@@wrindex was complete. @end example @node makeindex @subsection @command{makeindex} @cindex index, processing @findex makeindex, @r{program} @cindex @command{makeindex} program @cindex @file{.ind} file @cindex @file{.idx} file Synopsis, one of: @example makeindex @var{filename} makeindex -s @var{style-file} @var{filename} makeindex @var{options} @var{filename0} ... @end example Sort, and otherwise process, the index information in the auxiliary file @var{filename}. This is a command line program. It takes one or more raw index files, @file{@var{filename}.idx} files, and produces the actual index file, the @file{@var{filename}.ind} file that is input by @code{\printindex} (@pxref{\printindex}). @cindex @file{.isty} file @findex index, style file @findex makeindex, style file The first form of the command suffices for many uses. The second allows you to format the index by using an @dfn{index style file}, a @file{.isty} file. The third form is the most general; see the full documentation on CTAN. This is a simple @file{.isty} file. @example % book.isty % $ makeindex -s book.isty -p odd book.idx % creates the index as book.ind, starting on an odd page. preamble "\\pagestyle@{empty@} \\small \\begin@{theindex@} \\thispagestyle@{empty@}" postamble "\n \\end@{theindex@}" @end example The description here covers only some of the index formatting possibilities in @var{style-file}. For a full list see the documentation on CTAN. A style file consists of a list of pairs: @var{specifier} and @var{attribute}. These can appear in the file in any order. All of the @var{attribute}s are strings, except where noted. Strings are surrounded with double quotes, @code{"}, and the maximum length of a string is 144 characters. The @code{\n} is for a newline and @code{\t} is for a tab. Backslashes are escaped with another backslash, @code{\\}. If a line begins with a percent sign, @code{%}, then it is a comment. @ftable @code @anchor{makeindex preamble} @item preamble Preamble of the output index file. Defines the context in which the index is formatted. Default: @code{"\\begin@{theindex@}\n"}. @anchor{makeindex postamble} @item postamble Postamble of the output index file. Default: @code{"\n\n\\end@{theindex@}\n"}. @anchor{makeindex group skip} @item group_skip @findex \indexspace Traditionally index items are broken into groups, typically a group for entries starting with letter @samp{a}, etc. This specifier gives what is inserted when a new group begins. Default: @code{"\n\n \\indexspace\n"} (@code{\indexspace} is a command inserting a rubber length, by default @code{10pt plus5pt minus3pt}). @anchor{makeindex letheadflag} @item lethead_flag An integer. It governs what is inserted for a new group or letter. If it is 0 (which is the default) then other than @code{group_skip} nothing will be inserted before the group. If it is positive then at a new letter the @code{lethead_prefix} and @code{lethead_suffix} will be inserted, with that letter in uppercase between them. If it is negative then what will be inserted is the letter in lowercase. The default is@tie{}0. @anchor{makeindex lethead prefix} @item lethead_prefix If a new group begins with a different letter then this is the prefix inserted before the new letter header. Default: @code{""} @anchor{makeindex lethead suffix} @item lethead_suffix If a group begins with a different letter then this is the suffix inserted after the new letter header. Default: @code{""}. @anchor{makeindex item 0} @item item_0 What is put between two level@tie{}0 items. Default: @code{"\n \\item "}. @anchor{makeindex item 1} @item item_1 Put between two level@tie{}1 items. Default: @code{"\n \\subitem "}. @anchor{makeindex item 2} @item item_2 put between two level@tie{}2 items. Default: @code{"\n \\subsubitem "}. @anchor{makeindex item 01} @item item_01 What is put between a level@tie{}0 item and a level@tie{}1 item. Default: @code{"\n \\subitem "}. @anchor{makeindex item x1} @item item_x1 What is put between a level@tie{}0 item and a level@tie{}1 item in the case that the level@tie{}0 item doesn't have any page numbers (as in @code{\index@{aaa|see@{bbb@}@}}). Default: @code{"\n \\subitem "}. @anchor{makeindex item 12} @item item_12 What is put between a level@tie{}1 item and a level@tie{}2 item. Default: @code{"\n \\subsubitem "}. @anchor{makeindex item x2} @item item_x2 What is put between a level@tie{}1 item and a level@tie{}2 item, if the level@tie{}1 item doesn't have page numbers. Default: @code{"\n \\subsubitem "}. @anchor{makeindex delim 0} @item delim_0 Delimiter put between a level@tie{}0 key and its first page number. Default: a comma followed by a blank, @code{", "}. @anchor{makeindex delim 1} @item delim_1 Delimiter put between a level@tie{}1 key and its first page number. Default: a comma followed by a blank, @code{", "}. @anchor{makeindex delim 2} @item delim_2 Delimiter between a level@tie{}2 key and its first page number. Default: a comma followed by a blank, @code{", "}. @anchor{makeindex delim n} @item delim_n Delimiter between two page numbers for the same key (at any level). Default: a comma followed by a blank, @code{", "}. @anchor{makeindex delim r} @item delim_r What is put between the starting and ending page numbers of a range. Default: @code{"--"}. @anchor{makeindex line max} @item line_max An integer. Maximum length of an index entry's line in the output, beyond which the line wraps. Default: @code{72}. @anchor{makeindex indent space} @item indent_space What is inserted at the start of a wrapped line. Default: @code{"\t\t"}. @anchor{makeindex indent length} @item indent_length A number. The length of the wrapped line indentation. The default @code{indent_space} is two tabs and each tab is eight spaces so the default here is @code{16}. @anchor{makeindex page precedence} @item page_precedence A document may have pages numbered in different ways. For example, a book may have front matter pages numbered in lowercase roman while main matter pages are in arabic. This string specifies the order in which they will appear in the index. The @command{makeindex} command supports five different types of numerals: lowercase roman @code{r}, and numeric or arabic @code{n}, and lowercase alphabetic @code{a}, and uppercase roman @code{R}, and uppercase alphabetic @code{A}. Default: @code{"rnaRA"}. @end ftable @findex xindy @r{program} There are a number of other programs that do the job @command{makeindex} does. One is @command{xindy} (@uref{https://ctan.org/pkg/xindy}), which does internationalization and can process indexes for documents marked up using @LaTeX{} and a number of other languages. It is written in Lisp, highly configurable, both in markup terms and in terms of the collating order of the text, as described in its documentation. @findex xindex @r{program} A more recent indexing program supporting Unicode is @code{xindex}, written in Lua (@url{https://ctan.org/pkg/xindex}). @node \printindex @subsection @command{\printindex} @cindex index, printing @findex \printindex Synopsis: @example \printindex @end example Place the index into the output. @PkgIndex{makeidx} To get an index you must first include @code{\usepackage@{makeidx@}\makeindex} in the document preamble and compile the document, then run the system command @command{makeindex}, and then compile the document again. @xref{Indexes}, for further discussion and an example of the use of @code{\printindex}. @node Glossaries @section Glossaries @cindex glossary @cindex glossaries @cindex acronyms, list of @findex \makeglossary @findex \printglossaries Synopsis: @example \usepackage@{glossaries@} \makeglossaries ... \newglossaryentry@{@var{label}@}@{@var{settings}@} ... \gls@{@var{label}@}. ... \printglossaries @end example The @file{glossaries} package allows you to make glossaries, including multiple glossaries, as well as lists of acronyms. To get the output from this example, compile the document (for instance with @code{pdflatex filename}), then run the command line command @code{makeglossaries filename}, and then compile the document again. @example \documentclass@{...@} \usepackage@{glossaries@} \makeglossaries \newglossaryentry@{tm@}@{% name=@{Turing machine@}, description=@{A model of a machine that computes. The model is simple but can compute anything any existing device can compute. It is the standard model used in Computer Science.@}, @} \begin@{document@} Everything begins with the definition of a \gls@{tm@}. ... \printglossaries \end@{document@} @end example @noindent That gives two things. In the main text it outputs @samp{... definition of a Turing machine}. In addition, in a separate sectional unit headed @samp{Glossary} there appears a description list. In boldface it says @samp{Turing machine} and the rest of the item says in normal type @samp{A model of a machine @dots{} Computer Science}. @findex \makeglossary @findex \printglossaries @cindex @file{.glo} file The command @code{\makeglossary} opens the file that will contain the entry information, @file{@var{root-file}.glo}. Put the @code{\printglossaries} command where you want the glossaries to appear in your document. The @file{glossaries} package is very powerful. For instance, besides the commands @code{\newglossaryentry} and @code{\gls}, there are similar commands for a list of acronyms. See the package documentations on CTAN. @menu * \newglossaryentry:: Declare the content of a glossary entry. * \gls:: Give a page reference for a glossary entry. @end menu @node \newglossaryentry @subsection @code{\newglossaryentry} @cindex glossary, entries @findex \newglossaryentry Synopsis, one of: @example \newglossaryentry@{@var{label}@} @{ name=@{@var{name}@}, description=@{@var{description}@}, @var{other options}, ... @} @end example or @example \longnewglossaryentry@{@var{label}@} @{ name=@{@var{name}@}, @var{other options} ..., @} @{@var{description}@} @end example Declare a new entry for a glossary. The @var{label} must be unique for the document. The settings associated with the label are pairs: @code{@var{key}=@var{value}}. This puts the blackboard bold symbol for the real numbers @BES{211D}, in the glossary. @example \newglossaryentry@{R@} @{ name=@{\ensuremath@{\mathbb@{R@}@}@}, description=@{the real numbers@}, @} @end example Use the second command form if the @var{description} spans more than one paragraph. For a full list of @var{key}s see the package documentation on CTAN but here are a few. @ftable @code @item name (Required.) The word, phrase, or symbol that you are defining. @item description (Required.) The description that will appear in the glossary. If this has more than one paragraph then you must use the second command form given in the synopsis. @item plural The plural form of @var{name}. Refer to the plural form using @code{\glspl} or @code{\Glspl} (@pxref{\gls}). @item sort How to place this entry in the list of entries that the glossary holds. @item symbol A symbol, such as a mathematical symbol, besides the name. @end ftable @node \gls @subsection @code{\gls} @cindex glossary, entry reference @findex \gls Synopsis, one of: @example \gls@{@var{label}@} \glspl@{@var{label}@} \Gls@{@var{label}@} \Glspl@{@var{label}@} @end example Refer to a glossary entry. The entries are declared with @code{\newglossaryentry} (@pxref{\newglossaryentry}). This @example \newglossaryentry@{N@}@{% name=@{the natural numbers@}, description=@{The numbers $0$, $1$, $2$, $\ldots$\@@@}, symbol=@{\ensuremath@{\mathbb@{N@}@}@}, @} ... Consider \gls@{N@}. @end example @noindent gives the output @samp{Consider the natural numbers}. The second command form @code{\glspl@{@var{label}@}} produces the plural of @var{name} (by default it tries adding an @samp{s}). The third form capitalizes the first letter of @var{name}, as does the fourth form, which also takes the plural. @node Letters @chapter Letters @cindex letters, writing @cindex writing letters Synopsis: @example \documentclass@{letter@} \address@{@var{senders address}@} % return address \signature@{@var{sender name}@} \begin@{document@} \begin@{letter@}@{@var{recipient address}@} \opening@{@var{salutation}@} @var{letter body} \closing@{@var{closing text}@} \end@{letter@} ... \end@{document@} @end example Produce one or more letters. Each letter is in a separate @code{letter} environment, whose argument @var{recipient address} often contains multiple lines separated with a double backslash,@tie{}(@code{\\}). For example, you might have: @example \begin@{letter@}@{Ninon de l'Enclos \\ l'h\^otel Sagonne@} ... \end@{letter@} @end example The start of the @code{letter} environment resets the page number to 1, and the footnote number to 1 also. The @var{sender address} and @var{sender name} are common to all of the letters, whether there is one or more, so these are best put in the preamble. As with the recipient address, often @var{sender address} contains multiple lines separated by a double backslash@tie{}(@code{\\}). @LaTeX{} will put the @var{sender name} under the closing, after a vertical space for the traditional hand-written signature. Each @code{letter} environment body begins with a required @code{\opening} command such as @code{\opening@{Dear Madam or Sir:@}}. The @var{letter body} text is ordinary @LaTeX{} so it can contain everything from enumerated lists to displayed math, except that commands such as @code{\chapter} that make no sense in a letter are turned off. Each @code{letter} environment body typically ends with a @code{\closing} command such as @code{\closing@{Yours,@}}. @findex \\ @r{(for letters)} Additional material may come after the @code{\closing}. You can say who is receiving a copy of the letter with a command like @code{\cc@{the Boss \\ the Boss's Boss@}}. There's a similar @code{\encl} command for a list of enclosures. And, you can add a postscript with @code{\ps}. @LaTeX{}'s default is to indent the sender name and the closing above it by a length of @code{\longindentation}. By default this is @code{0.5\textwidth}. To make them flush left, put @code{\setlength@{\longindentation@}@{0em@}} in your preamble. To set a fixed date use something like @code{\renewcommand@{\today@}@{1958-Oct-12@}}. If put in your preamble then it will apply to all the letters. This example shows only one @code{letter} environment. The three lines marked as optional are typically omitted. @example \documentclass@{letter@} \address@{Sender's street \\ Sender's town@} \signature@{Sender's name \\ Sender's title@} % optional: \location@{Mailbox 13@} % optional: \telephone@{(102) 555-0101@} \begin@{document@} \begin@{letter@}@{Recipient's name \\ Recipient's address@} \opening@{Sir:@} % optional: \thispagestyle@{firstpage@} I am not interested in entering a business arrangement with you. \closing@{Your most humble, etc.,@} \end@{letter@} \end@{document@} @end example These commands are used with the @code{letter} class. @menu * \address:: Sender's return address. * \cc:: Carbon copy list. * \closing:: Saying goodbye. * \encl:: List of enclosed material. * \location:: Sender's organizational location. * \makelabels:: Make address labels. * \name:: Sender's name, for the return address. * \opening:: Saying hello. * \ps:: Adding a postscript. * \signature:: Sender's signature. * \telephone:: Sender's phone number. @end menu @node \address @section @code{\address} @findex \address Synopsis: @example \address@{@var{senders address}@} @end example Specify the return address, as it appears on the letter and on the envelope. Separate multiple lines in @var{senders address} with a double backslash,@tie{}@code{\\}. Because it can apply to multiple letters this declaration is often put in the preamble. However, it can go anywhere, including inside an individual @code{letter} environment. This command is optional: if you do not use it then the letter is formatted with some blank space on top, for copying onto pre-printed letterhead paper. If you do use the @code{\address} declaration then it is formatted as a personal letter. Here is an example. @example \address@{Stephen Maturin \\ The Grapes of the Savoy@} @end example @node \cc @section @code{\cc} @findex \cc @cindex cc list, in letters Synopsis: @example \cc@{@var{name0} \\ ... @} @end example Produce a list of names to which copies of the letter were sent. This command is optional. If it appears then typically it comes after @code{\closing}. Put the names on different lines by separating them with a double backslash, @code{\\}, as in: @example \cc@{President \\ Vice President@} @end example @node \closing @section @code{\closing} @findex \closing @cindex letters, ending @cindex closing letters Synopsis: @example \closing@{@var{text}@} @end example Produce the letter's closing. This is optional, but usual. It appears at the end of a letter, above a handwritten signature. For example: @example \closing@{Regards,@} @end example @node \encl @section @code{\encl} @findex \encl @cindex enclosure list Synopsis: @example \encl@{@var{first enclosed object} \\ ... @} @end example Produce a list of things included with the letter. This command is optional; when it is used, it typically is put after @code{\closing}. Separate multiple lines with a double backslash, @code{\\}. @example \encl@{License \\ Passport@} @end example @node \location @section @code{\location} @findex \location Synopsis: @example \location@{@var{text}@} @end example The @var{text} appears centered at the bottom of the page. It only appears if the page style is @code{firstpage}. @node \makelabels @section @code{\makelabels} @findex \makelabels Synopsis: @example \makelabels % in preamble @end example Optional, for a document that contains @code{letter} environments. If you just put @code{\makelabels} in the preamble then at the end of the document you will get a sheet with labels for all the recipients, one for each letter environment, that you can copy to a sheet of peel-off address labels. Customize the labels by redefining the commands @code{\startlabels}, @code{\mlabel}, and @code{\returnaddress} (and perhaps @code{\name}) in the preamble. The command @code{\startlabels} sets the width, height, number of columns, etc., of the page onto which the labels are printed. The command @code{\mlabel@{@var{return address}@}@{@var{recipient address}@}} produces the two labels (or one, if you choose to ignore the @var{return address}) for each letter environment. The first argument, @var{return address}, is the value returned by the macro @code{\returnaddress}. The second argument, @var{recipient address}, is the value passed in the argument to the @code{letter} environment. By default @code{\mlabel} ignores the first argument, the @var{return address}, causing the default behavior described in the prior paragraph. This illustrates customization. Its output includes a page with two columns having two labels each. @example \documentclass@{letter@} \renewcommand*@{\returnaddress@}@{Fred McGuilicuddy \\ Oshkosh, Mineola 12305@} \newcommand*\originalMlabel@{@} \let\originalMlabel\mlabel \def\mlabel#1#2@{\originalMlabel@{@}@{#1@}\originalMlabel@{@}@{#2@}@} \makelabels ... \begin@{document@} \begin@{letter@}@{A Einstein \\ 112 Mercer Street \\ Princeton, New Jersey, USA 08540@} ... \end@{letter@} \begin@{letter@}@{K G\"odel \\ 145 Linden Lane \\ Princeton, New Jersey, USA 08540@} ... \end@{letter@} \end@{document@} @end example @noindent The first column contains the return address twice. The second column contains the address for each recipient. @PkgIndex{envlab} The package @package{envlab} makes formatting the labels easier, with standard sizes already provided. The preamble lines @code{\usepackage[personalenvelope]@{envlab@}} and @code{\makelabels} are all that you need to print envelopes. @node \name @section @code{\name} @findex \name Synopsis: @example \name@{@var{name}@} @end example Optional. Sender's name, used for printing on the envelope together with the return address. @node \opening @section @code{\opening} @findex \opening @cindex letters, starting Synopsis: @example \opening@{@var{salutation}@} @end example Required. Follows the @code{\begin@{letter@}@{...@}}. The argument @var{salutation} is mandatory. For instance: @example \opening@{Dear John:@} @end example @node \ps @section @code{\ps} @findex \ps @cindex postscript, in letters Synopsis: @example \ps@{@var{text}@} @end example Add a postscript. This command is optional and usually is used after @code{\closing}. @example \ps@{P.S. After you have read this letter, burn it. Or eat it.@} @end example @node \signature @section @code{\signature} Synopsis: @example \signature@{@var{first line} \\ ... @} @end example @findex \signature The sender's name. This command is optional, although its inclusion is usual. The argument text appears at the end of the letter, after the closing. @LaTeX{} leaves some vertical space for a handwritten signature. Separate multiple lines with a double backslash,@tie{}@code{\\}. For example: @example \signature@{J Fred Muggs \\ White House@} @end example @LaTeX{}'s default for the vertical space from the @code{\closing} text down to the @code{\signature} text is @code{6\medskipamount}, which is six times @code{\medskipamount} (where @code{\medskipamount} is equal to a @code{\parskip}, which in turn is defined by default here to 0.7@dmn{em}). This command is usually in the preamble, to apply to all the letters in the document. To have it apply to one letter only, put it inside a @code{letter} environment and before the @code{\closing}. You can include a graphic in the signature as here. @example \signature@{\vspace@{-6\medskipamount@}\includegraphics@{sig.png@}\\ My name@} @end example @noindent For this you must put @code{\usepackage@{graphicx@}} in the preamble (@pxref{Graphics}). @node \telephone @section @code{\telephone} @findex \telephone Synopsis: @example \telephone@{@var{number}@} @end example The sender's telephone number. This is typically in the preamble, where it applies to all letters. This only appears if the @code{firstpage} pagestyle is selected. If so, it appears on the lower right of the page. @node Input/output @chapter Input/output @cindex input/output, to terminal @cindex terminal input/output @cindex input/output @LaTeX{} uses the ability to write to a file and later read it back in to build document components such as a table of contents or index. You can also read a file that other programs written, or write a file for others to read. You can communicate with users through the terminal. And, you can issue instructions for the operating system. @menu * \openin & \openout:: Open a file. * \read:: Read text from a file. * \typein:: Read text from the terminal. * \typeout:: Write text to the terminal. * \write:: Write text to a file or terminal. @end menu @node \openin & \openout @section @code{\openin} & @code{\openout} @anchor{\openin} @anchor{\openout} @anchor{\closein} @anchor{\closeout} @findex \openin @findex \openout @findex \closein @findex \closeout @cindex file, opening @cindex file, closing @cindex open a file Synopsis: @example \openin @var{number}=@var{filename} @end example or: @example \openout @var{number}=@var{filename} @end example Open a file for reading material, or for writing it. In most engines, the @var{number} must be between 0 and 15, as in @code{\openin3}; in Lua@LaTeX{}, @var{number} can be between 0 and 127. Here @TeX{} opens the file @file{presidents.tex} for reading. @example \newread\presidentsfile \openin\presidentsfile=presidents \typeout@{presidentsfile is \the\presidentsfile@} \read\presidentsfile to\presidentline \typeout@{\presidentline@} @end example @noindent The @code{\newread} command allocates input stream numbers from 0 to@tie{}15 (there is also a @code{\newwrite}). The @code{\presidentsfile} is more memorable but under the hood it is still a number; the first @code{\typeout} gives something like @samp{presidentsfile is 1}. In addition, @code{\newread} keeps track of the allocation so that if you use too many then you get an error like @samp{! No room for a new \read}. The second @code{\typeout} gives the first line of the file, something like @samp{1 Washington, George}. Ordinarily @TeX{} will not try to open the file until the next page shipout. To change this, use @code{\immediate\openin @var{number}=@var{filename}} or @code{\immediate\openout @var{number}=@var{filename}}. Close files with @code{\closein @var{number}} and @code{\closeout @var{number}}. How @LaTeX{} handles filenames varies among distributions, and even can vary among versions of a distribution. If the file does not have an extension then @TeX{} will add a @file{.tex}. This creates @file{presidents.tex}, writes one line to it, and closes it. @example \newwrite\presidentsfile \openout\presidentsfile=presidents \write\presidentsfile@{1 Washington, George@} \closeout\presidentsfile @end example @noindent But filenames with a period can cause trouble: if @TeX{} finds a @var{filename} of @file{presidents.dat} it could look first for @file{presidents.dat.tex} and later for @file{presidents.dat}, or it could do the opposite. Your distribution's documentation should say more, and if you find something that works for you then you are good, but to ensure complete portability the best thing is to use file names containing only the twenty six ASCII letters (not case-sensitive) and the ten digits, along with underscore and dash, and in particular with no dot or space. For @code{\openin}, if @TeX{} cannot find the file then it does not give an error. It just considers that the stream is not open (test for this with @code{\ifeof}; one recourse is the command @code{\InputIfFileExists}, @pxref{Class and package commands}). If you try to use the same number twice, @LaTeX{} won't give you an error. If you try to use a bad number then you get an error message like @samp{! Bad number (16). = l.30 \openin16=test.jh}. @node \read @section @code{\read} @findex \read @cindex file, reading @cindex read a file Synopsis: @example \read @var{number} to@var{macro} @end example Make the command @var{macro} contain the next line of input from text stream @var{number}, as in @code{\read5 to\data}. This opens the file @file{email.tex} for reading, puts the contents of the first line into the command @code{\email}, and then closes the file. @example \newread\recipientfile \openin\recipientfile=email \read\recipientfile to\email \typeout@{Email address: \email@} \closein\recipientfile @end example If @var{number} is outside the range from 0 to@tie{}15 or if no file of that number is open, or if the file has ended, then @code{\read} will take input from the terminal (or exit if interaction is not allowed, e.g., @code{\nonstopmode}; @pxref{interaction modes}). (However, the natural way in @LaTeX{} to take input from the terminal is @code{\typein} (@pxref{\typein}.) To read an entire file as additional @LaTeX{} source, use @code{\input} (@pxref{\input}) or @code{\include} (@pxref{\include & \includeonly}). @PkgIndex{datatool} @cindex mail merges A common reason to want to read from a data file is to do mail merges. CTAN has a number of packages for that; one is @package{datatool}. @node \typein @section @code{\typein} @findex \typein Synopsis, one of: @example \typein@{@var{prompt-msg}@} \typein[@var{cmd}]@{@var{prompt-msg}@} @end example Print @var{prompt-msg} on the terminal and cause @LaTeX{} to stop and wait for you to type a line of input. This line of input ends when you hit the return key. For example, this @example As long as I live I shall never forget \typein@{Enter student name:@} @end example @noindent coupled with this command line interaction @example Enter student name: \@@typein=Aphra Behn @end example @noindent gives the output @samp{... never forget Aphra Behn}. The first command version, @code{\typein@{@var{prompt-msg}@}}, causes the input you typed to be processed as if it had been included in the input file in place of the @code{\typein} command. In the second command version the optional argument @code{@var{cmd}} argument must be a command name, that is, it must begin with a backslash, \. This command name is then defined or redefined to be the input that you typed. For example, this @example \typein[\student]@{Enter student name:@} \typeout@{Recommendation for \student .@} @end example @noindent gives this output on the command line, @example Enter student name: \student=John Dee Recommendation for John Dee. @end example @noindent where the user has entered @samp{John Dee.} @node \typeout @section @code{\typeout} @findex \typeout Synopsis: @example \typeout@{@var{msg}@} @end example Print @code{msg} on the terminal and in the @code{log} file. This @example \newcommand@{\student@}@{John Dee@} \typeout@{Recommendation for \student .@} @end example @noindent outputs @samp{Recommendation for John Dee}. Like what happens here with @code{\student}, commands that are defined with @code{\newcommand} or @code{\renewcommand} (among others) are replaced by their definitions before being printed. @findex \space @LaTeX{}'s usual rules for treating multiple spaces as a single space and ignoring spaces after a command name apply to @code{msg}. Use the command @code{\space} to get a single space, independent of surrounding spaces. Use @code{^^J} to get a newline. Get a percent character with @code{\csname @@percentchar\endcsname}. This command can be useful for simple debugging, as here: @example \newlength@{\jhlength@} \setlength@{\jhlength@}@{5pt@} \typeout@{The length is \the\jhlength.@} @end example @noindent produces on the command line @samp{The length is 5.0pt}. @node \write @section @code{\write} @findex \write Synopsis: @example \write @var{number}@{@var{string}@} @end example Write @var{string} to the log file, to the terminal, or to a file opened by @code{\openout}. For instance, @code{\write6} writes to text stream number@tie{}6. If the following appears in @file{@var{basefile}.tex} then it opens @file{@var{basefile}.jh}, writes @samp{Hello World!} and a newline to it, and closes that file. @example \newwrite\myfile \immediate\openout\myfile=\jobname.jh % \jobname is root file basename ... \immediate\write\myfile@{Hello world!@} ... \immediate\closeout\myfile @end example @findex \newwrite @noindent The @code{\newwrite} allocates a stream number, giving it a symbolic name to make life easier, so that @code{stream \newwrite\myfile\the\myfile} produces something like @samp{stream 3}. Then @code{\openout} associates the stream number with the given file name. @TeX{} ultimately executed @code{\write3} which puts the string in the file. @cindex log file, writing to @cindex terminal, writing to @cindex @math{-1}, write stream number Typically @var{number} is between 0 and@tie{}15, because typically @LaTeX{} authors follow the prior example and the number is allocated by the system. If @var{number} is outside the range from 0 to 15 or if it is not associated with an open file then @LaTeX{} writes @var{string} to the log file. If @var{number} is positive then in addition @LaTeX{} writes @var{string} to the terminal. Thus, @code{test \write-1@{Hello World!@}} puts @samp{Hello World!} followed by a newline in the log file. (This is what the @code{\wlog} command does; @pxref{\wlog}). And @code{\write100@{Hello World!@}} puts the same in the log file but also puts @samp{Hello World!} followed by a newline in the terminal output. (But 16, 17, and 18 are special as @var{number}; see below.) @cindex Lua@TeX{}, 256 output streams in In Lua@TeX{}, instead of 16 output streams there are 256 (@pxref{@TeX{} engines}). @findex \@@auxout @findex \@@mainaux Use @code{\write\@@auxout@{@var{string}@}} to write to the current @file{.aux} file, which is associated with either the root file or with the current include file; and use @code{\write\@@mainaux@{@var{string}@}} to write to the main @file{.aux}. These symbolic names are defined by @LaTeX{}. @c credit: David Carlisle https://tex.stackexchange.com/a/115933/121234 By default @LaTeX{} does not write @var{string} to the file right away. This is because, for example, you may need @code{\write} to save the current page number, but when @TeX{} comes across a @code{\write} it typically does not know what the page number is, since it has not yet done the page breaking. So, you use @code{\write} in one of three contexts: @example \immediate\write\@@auxout@{@var{string}@} %1 \write\@@auxout@{@var{string}@} %2 \protected@@write\@@auxout@{@}@{@var{string}@} %3 @end example @enumerate @item @cindex immediate @code{\write} @findex \immediate\write With the first, @LaTeX{} writes @var{string} to the file immediately. Any macros in @var{string} are fully expanded (just as in @code{\edef}) so to prevent expansion you must use @code{\noexpand}, @code{toks}, etc., except that you should use @code{#} instead of @code{##}). @item @cindex delayed @code{\write} @cindex whatsit item @findex \shipout @r{and expansion} With the second, @var{string} is stored on the current list of things (as a @TeX{} ``whatsit'' item) and kept until the page is shipped out and likewise the macros are unexpanded until @code{\shipout}. At @code{\shipout}, @var{string} is fully expanded. @item @findex \protected@@write The third, @code{\protected@@write}, is like the second except that you can use @code{\protect} to avoid expansion. The extra first argument allows you to locally insert extra definitions to make more macros protected or to have some other special definition for the write. @end enumerate As a simple example of expansion with @code{\write}, @var{string} here contains a control sequence @code{\triplex} which we've defined to be the text @samp{XYZ}: @example \newwrite\jhfile \openout\jhfile=test.jh \newcommand@{\triplex@}@{XYZ@} \write\jhfile@{test \triplex test@} @end example @noindent This results in the file @file{test.jh} containing the text @samp{test XYZtest} followed by a newline. @cindex @code{\write} streams 16, 17, 18 The cases where @var{number} is 16, 17, or 18 are special. Because of @code{\write}'s behavior when @var{number} is outside the range from 0 to 15 described above, in Plain@tie{}@TeX{} @code{\write16} and @code{\write17} were sometimes used to write to the log file and the terminal; however, in @LaTeX{}, the natural way to do that is with @code{\typeout} (@pxref{\typeout}). The @code{\write18} command is even more special; modern @TeX{} systems use it for giving commands to the operating system (@pxref{\write18}). @cindex newline, in @code{\write} @cindex @code{^^J}, in @code{\write} Ordinarily @code{\write} outputs a single line. You can include a newline with @code{^^J}. Thus, this produces two lines in the log file: @example \wlog@{Parallel lines have a lot in common.^^JBut they never meet.@} @end example @PkgIndex{answers} A common case where authors need to write their own file is for answers to exercises, or another situation where you want to write out verbatim, without expanding the macros. CTAN has a number of packages for this; one is @package{answers}. @menu * \write and security:: Security. * \message:: Write text to the log file and terminal. * \wlog:: Write text to the log file. * \write18:: Run an operating system command. @end menu @node \write and security @subsection @code{\write} and security @cindex security and @code{\write} @cindex @code{\write} and security The ability to write files raises security issues. If you compiled a downloaded @LaTeX{} file and it overwrote your password file then you would be justifiably troubled. Thus, by default @TeX{} systems only allow you to open files for writing that are in the current directory or output directory, if specified (@pxref{output directory}), or in a subdirectory of those. So, this code @example \newwrite\jhfile \openout\jhfile=../test.jh @end example @noindent gives an error like: @example Not writing to ../test.jh (openout_any = p). ! I can't write on file `../test.jh' @end example @cindex parent directories, cannot write to You can get just such an error when using commands such as @code{\include@{../filename@}} because @LaTeX{} will try to open @file{../filename.aux}. The simplest solution is to put the included files in the same directory as the root file, or in subdirectories. @node \message @subsection @code{\message} @findex \message Synopsis: @example \message@{@var{string}@} @end example Write @var{string} to the log file and the terminal. Typically, @LaTeX{} authors use @code{\typeout} (@pxref{\typeout}). It allows you to use @code{\protect} on any fragile commands in @var{string} (@pxref{\protect}). But @code{\typeout} always inserts a newline at the end of @var{string} while @code{\message} does not, so the latter can be useful. With this example document body. @example before\message@{One Two@}\message@{Three@}\message@{Four^^JI@} \message@{declare a thumb war.@}After @end example @noindent under some circumstances (see below) @LaTeX{} writes the following to both the terminal and the log file. @example One Two Three Four I declare a thumb war. @end example @noindent The @code{^^J} produces a newline. Also, in the output document, between @samp{before} and @samp{After} will be a single space (from the end of line following @samp{I@}}). While @code{\message} allows you more control over formatting, a gotcha is that @LaTeX{} may mess up that formatting because it inserts line breaks depending on what it has already written. Contrast this document body, where the @samp{Two} has moved, to the one given above. @example before\message@{One@}\message@{Two Three@}\message@{Four^^JI@} \message@{declare a thumb war.@}After @end example This can happen: when @LaTeX{} is outputting the messages to the terminal, now the message with @samp{One} is shorter and it fits at the end of the output terminal line, and so @LaTeX{} breaks the line between it and the @samp{Two Three}. That line break appears also in the log file. This line break insertion can depend on, for instance, the length of the full path names of included files. So producing finely-formatted lines in a way that is portable is hard, likely requiring starting your message at the beginning of a line. @node \wlog @subsection @code{\wlog} @findex \wlog Synopsis: @example \wlog@{@var{string}@} @end example Write @var{string} to the log file. @example \wlog@{Did you hear about the mathematician who hates negatives?@} \wlog@{He'll stop at nothing to avoid them.@} @end example Ordinarily @var{string} appears in a single separate line. Use @code{^^J} to insert a newline. @example \wlog@{Helvetica and Times Roman walk into a bar.@} \wlog@{The barman says,^^JWe don't serve your type.@} @end example @node \write18 @subsection @code{\write18} @findex \write18 @cindex external commands @cindex commands, run from @LaTeX{} @cindex system commands, run from @LaTeX{} @cindex shell access @c Derived from: Joseph Wright: https://tex.stackexchange.com/a/20446/121234 Synopsis: @example \write18@{@var{shell_command}@} @end example Issue a command to the operating system shell. The operating system runs the command and @LaTeX{}'s execution is blocked until that finishes. @PkgIndex{Asymptote} This sequence (on Unix) @example \usepackage@{graphicx@} % in preamble ... \newcommand@{\fignum@}@{1@} \immediate\write18@{cd pix && asy figure\fignum@} \includegraphics@{pix/figure\fignum.pdf@} @end example @noindent will run Asymptote (the @code{asy} program) on @file{pix/figure1.asy}, so that the document can later read in the resulting graphic (@pxref{\includegraphics}). Like any @code{\write}, here @LaTeX{} expands macros in @var{shell_command} so that @code{\fignum} is replaced by @samp{1}. Another example is that you can automatically run Bib@TeX{} at the start of each @LaTeX{} run (@pxref{Using BibTeX}) by including @code{\immediate\write18@{bibtex8 \jobname@}} as the first line of the file. Note that @code{\jobname} expands to the basename of the root file unless the @code{--jobname} option is passed on the command line, in which case this is the option argument. You sometimes need to do a multi-step process to get the information that you want. This will insert into the input a list of all PDF files in the current directory (but see @package{texosquery} below): @example \immediate\write18@{ls *.pdf > tmp.dat@} \input@{tmp.dat@} @end example The standard behavior of any @code{\write} is to wait until a page is being shipped out before expanding the macros or writing to the stream (@pxref{\write}). But sometimes you want it done now. For this, use @code{\immediate\write18@{@var{shell_command}@}}. There are obvious security issues with allowing system commands inside a @LaTeX{} file. If you download a file off the net and it contains commands to delete all your files then you would be unhappy. The standard settings in modern distributions turn off full shell access. You can turn it on, if you are sure the shell commands are safe, by compiling with @code{latex --enable-write18 @var{filename}} (@pxref{Command line options}). (The @code{--shell-escape} option is a synonym, in @TeX{} Live.) @cindex restricted shell access In the place of full shell access, modern distributions by default use a restricted version that allows some commands to work, such as those that run Metafont to generate missing fonts, even if you do not use the @code{enable-write18} option. By default this list of allowed commands is short and features only commands that are under the control of the distribution maintainers (@pxref{Command line options}). @findex /bin/sh@r{, used by @code{\write18}} @findex sh@r{, used by @code{\write18}} @findex cmd.exe@r{, used by @code{\write18}} @findex SHELL@r{, environment variables} The @var{shell_command} text is always passed to @file{/bin/sh} on Unix-like operating systems, and the DOS command interpreter @file{cmd.exe} on Windows. Any different shell set by the user, and the @code{SHELL} environment variable, is ignored. @PkgIndex{texosquery} @cindex system information @cindex operating system information @cindex locale information, from system @cindex directory listings, from system If what you need is system information, such as the operating system name, locale information, or directory contents, take a look at the @package{texosquery} package, which provides a convenient and secure interface for this, unlike the above examples using the raw @code{\write18}: @url{https://ctan.org/pkg/texosquery}. @PkgIndex{shellesc} @findex \ShellEscape @findex \DelayedShellEscape @LaTeX{} provides a package @package{shellesc} on top of the primitive @code{\write18} command. Its primary purpose is to provide a command @code{\ShellEscape} which works identically on all @TeX{} engines; Lua@TeX{} intentionally did not retain @code{\write18} as a way to invoke a shell command, so some engine-specific code is needed. The @package{shellesc} package also provides a command @code{\DelayedShellEscape}, executed at @code{\output} time, for the same reason. @node Command line interface @chapter Command line interface @anchor{Command line}@c old name @cindex command line interface @cindex interface, command line @cindex CLI Synopsis (from a terminal command line): @example pdflatex @var{options} @var{argument} @end example Run @LaTeX{} on @var{argument}. In place of @command{pdflatex} you can also use (for PDF output) @command{xelatex} or @code{lualatex}, or (for DVI output) @code{latex} or @code{dvilualatex}, among others (@pxref{@TeX{} engines}). For example, this will run @LaTeX{} on the file @file{thesis.tex}, creating the output @file{thesis.pdf}. @example pdflatex thesis @end example @noindent @findex .tex, @r{default extension} Note that @file{.tex} is the default file name extension. pdf@TeX{} is an extension of the original @TeX{} program, as are Xe@TeX{} and Lua@TeX{} (@pxref{@TeX{} engines}). The first two are completely backward compatible and the latter, almost so. Perhaps the most fundamental new feature for all three is that the original @TeX{} output its own DVI format, while the newer ones can output directly to PDF. This allows them to take advantage of the extra features in PDF such as hyperlinks, support for modern image formats such as JPG and PNG, and ubiquitous viewing programs. In short, if you run @command{pdflatex} or @command{xelatex} or @command{lualatex} then you will by default get PDF and have access to all its modern features. If you run @command{latex}, or @command{dvilualatex}, then you will get DVI. The description here assumes @command{pdflatex}. @xref{Command line options}, for a selection of the most useful command line options. As to @var{argument}, the usual case is that it does not begin with a backslash, so the system takes it to be the name of a file and it compiles that file. If @var{argument} begins with a backslash then the system will interpret it as a line of @LaTeX{} input, which can be used for special effects (@pxref{Command line input}). If you gave no arguments or options then @command{pdflatex} prompts for input from the terminal. You can escape from this by entering @kbd{CTRL-D}. If @LaTeX{} finds an error in your document then by default it stops and asks you about it. @xref{Recovering from errors}, for an outline of what to do. @menu * Command line options:: Commonly used command line options. * Command line input:: Specify LaTeX code on the command line. * Jobname:: How @TeX{} sets the current job name. * Recovering from errors:: When something goes wrong. @end menu @node Command line options @section Command line options @cindex options, command line These are the command-line options relevant to ordinary document authoring. For a full list, try running @samp{latex --help} from the command line. With many implementations you can specify command line options by prefixing them with @samp{-} or @samp{--}. This is the case for both @TeX{} Live (including Mac@TeX{}) and MiK@TeX{}. We will use both conventions interchangeably. If an option takes a value, it can be specified either as a separate argument (@samp{--foo val}), or as one argument with an @samp{=} sign (@samp{--foo=val}), but there can be no spaces around the @samp{=}. We will generally use the @samp{=} syntax. @table @code @findex --version @r{command-line option} @item -version Show the current version, like @samp{pdfTeX 3.14159265-2.6-1.40.16 (TeX Live 2015/Debian)} along with a small amount of additional information, and exit. @findex --help @r{command-line option} @item -help Give a brief usage message that is useful as a prompt and exit. @anchor{interaction modes} @findex --interaction @r{command-line option} @item -interaction=@var{mode} @cindex batchmode @cindex scrollmode @cindex errorstopmode @cindex nonstopmode @TeX{} compiles a document in one of four interaction modes: @code{batchmode}, @code{nonstopmode}, @code{scrollmode}, @code{errorstopmode}. In @dfn{errorstopmode} (the default), @TeX{} stops at each error and asks for user intervention. In @dfn{batchmode} it prints nothing on the terminal, errors are scrolled as if the user hit @kbd{RETURN} at every error, and missing files cause the job to abort. In @dfn{nonstopmode}, diagnostic message appear on the terminal but as in batch mode there is no user interaction. In @dfn{scrollmode}, @TeX{} stops for missing files or keyboard input, but nothing else. For instance, starting @LaTeX{} with this command line @example pdflatex -interaction=batchmode @var{filename} @end example @noindent eliminates most terminal output. @cindex jobname @cindex filename for current job @findex --jobname @r{command-line option} @item -jobname=@var{string} Set the value of @TeX{}'s @dfn{jobname} to the string. The log file and output file will then be named @file{@var{string}.log} and @file{@var{string}.pdf}. @pxref{Jobname}. @anchor{output directory} @cindex output directory for all external files @findex --output-directory @r{command-line option} @item -output-directory=@var{directory} Write files in the directory @var{directory}. It must already exist. This applies to all external files created by @TeX{} or @LaTeX{}, such as the @file{.log} file for the run, the @file{.aux}, @file{.toc}, etc., files created by @LaTeX{}, as well as the main @file{.pdf} or @file{.dvi} output file itself. When specified, the output directory @var{directory} is also automatically checked first for any file that it is input, so that the external files can be read back in, if desired. The true current directory (in which @LaTeX{} was run) remains unchanged, and is also checked for input files. @cindex shell escape @cindex @code{\write18}, enabling @findex --enable-write18 @r{command-line option} @findex --disable-write18 @r{command-line option} @findex --shell-escape @r{command-line option} @findex --no-shell-escape @r{command-line option} @item --enable-write18 @itemx --disable-write18 @itemx --shell-escape @itemx --no-shell-escape Enable or disable @code{\write18@{@var{shell_command}@}} (@pxref{\write18}). The first two options are supported by both @TeX{} Live and MiK@TeX{}, while the second two are synonyms supported by @TeX{} Live. Enabling this functionality has major security implications, since it allows a @LaTeX{} file to run any command whatsoever. Thus, by default, unrestricted @code{\write18} is not allowed. (The default for @TeX{} Live, Mac@TeX{}, and MiK@TeX{} is to allow the execution of a limited number of @TeX{}-related programs, which they distribute.) For example, if you invoke @LaTeX{} with the option @code{no-shell-escape}, and in your document you call @code{\write18@{ls -l@}}, then you do not get an error but the log file says @samp{runsystem(ls -l)...disabled}. @findex --halt-on-error @r{command-line option} @item -halt-on-error Stop processing at the first error. @findex --file-line-error @r{command-line option} @findex --no-file-line-error @r{command-line option} @item -file-line-error @item -no-file-line-error Enable or disable @code{@var{filename}:@var{lineno}:@var{error}}-style error messages. These are only available with @TeX{} Live or Mac@TeX{}. @end table @node Command line input @section Command line input @cindex input, on command line As part of the command line invocation @example @var{latex-engine} @var{options} @var{argument} @end example @noindent you can specify arbitrary @LaTeX{} input by starting @var{argument} with a backslash. (All the engines support this.) This allows you to do some special effects. @PkgIndex{hyperref} For example, this file (which uses the @package{hyperref} package for hyperlinks) can produce two kinds of output, one to be read on physical paper and one to be read online. @example \ifdefined\paperversion % in preamble \newcommand@{\urlcolor@}@{black@} \else \newcommand@{\urlcolor@}@{blue@} \fi \usepackage[colorlinks=true,urlcolor=\urlcolor]@{hyperref@} ... \href@{https://www.ctan.org@}@{CTAN@} % in body ... @end example @noindent Compiling this document @file{book.tex} with the command line @code{pdflatex book} will give the @samp{CTAN} link in blue. But compiling it with @example pdflatex "\def\paperversion@{@}\input book.tex" @end example @noindent has the link in black. We use double quotes to prevent interpretation of the symbols by the command line shell. (This usually works on both Unix and Windows systems, but there are many peculiarities to shell quoting, so read your system documentation if need be.) In a similar way, from the single file @file{main.tex} you can compile two different versions. @c credit Paul Gaborit: https://tex.stackexchange.com/a/220101/121234 @example pdflatex -jobname=students "\def\student@{@}\input@{main@}" pdflatex -jobname=teachers "\def\teachers@{@}\input@{main@}" @end example @noindent The @code{jobname} option is there because otherwise both files would be called @file{main.pdf} and the second would overwrite the first. (@pxref{Jobname}.) In this example we use the command line to select which parts of a document to include. For a book named @file{mybook.tex} and structured like this. @example \documentclass@{book@} \begin@{document@} ... \include@{chap1@} \include@{chap2@} ... \end@{document@} @end example @noindent the command line @example pdflatex "\includeonly@{chap1@}\input@{mybook@}" @end example @noindent will give output that has the first chapter but no other chapter. @xref{Splitting the input}. @node Jobname @section Jobname @findex @code{\jobname} @cindex jobname @cindex document root name @cindex name of document root @cindex root file @cindex file, root Running @LaTeX{} creates a number of files, including the main PDF (or DVI) output but also including others. These files are named with the so-called @dfn{jobname}. The most common case is also the simplest, where for instance the command @code{pdflatex thesis} creates @code{thesis.pdf} and also @code{thesis.log} and @code{thesis.aux}. Here the job name is @code{thesis}. In general, @LaTeX{} is invoked as @code{@var{latex-engine} @var{options} @var{argument}}, where @var{latex-engine} is @command{pdflatex}, @command{lualatex}, etc.@: (@pxref{@TeX{} engines}). If @var{argument} does not start with a backslash, as is the case above with @code{thesis}, then @TeX{} considers it to be the name of the file to input as the main document. This file is referred to as the @dfn{root file} (@pxref{Splitting the input}, and@tie{}@ref{\input}). The name of that root file, without the @file{.tex} extension if any, is the jobname. If @var{argument} does start with a backslash, or if @TeX{} is in interactive mode, then it waits for the first @code{\input} command, and the jobname is the argument to @code{\input}. There are two more possibilities for the jobname. It can be directly specified with the @code{-jobname} option, as in @code{pdflatex -jobname=myname} (@pxref{Command line input} for a real example). @findex texput@r{, jobname default} @cindex fallback jobname The final possibility is @file{texput}, which is the final fallback default if no other name is available to @TeX{}. That is, if no @code{-jobname} option was specified, and the compilation stops before any input file is met, then the log file will be named @file{texput.log}. @findex \documentclass@r{, and @code{texput} jobname} @findex \RequirePackage@r{, and @code{texput} jobname} A special case of this is that in @LaTeX{} versions of (approximately) 2020 or later, the jobname is also @file{texput} if the first @code{\input} occurs as a result of being called by either @code{\documentclass} or @code{\RequirePackage}. So this will produce a file named @file{texput.pdf}: @example pdflatex "\documentclass@{minimal@}\begin@{document@}Hello!\end@{document@}" @end example However, this special case only applies to those two commands. Thus, with @c credit Herbert Voss: https://tex.stackexchange.com/a/17236/121234 @example pdflatex "\documentclass@{article@}\usepackage@{lipsum@}\input@{thesis@}" @end example @noindent the output file is @file{lipsum.pdf}, as @code{\usepackage} calls @code{\input}. @findex \jobname Within the document, the macro @code{\jobname} expands to the jobname. (When you run @LaTeX{} on a file whose name contains spaces, the string returned by @code{\jobname} contains matching start and end quotes.) In the expansion of that macro, all characters are of catcode@tie{}12 (other) except that spaces are category@tie{}10, including letters that are normally catcode@tie{}11. @findex \IfBeginWith*@r{ macro from @file{xstring}} @PkgIndex xstring Because of this catcode situation, using the jobname in a conditional can become complicated. One solution is to use the macro @code{\IfBeginWith} from the @file{xstring} package in its star variant, which is insensitive to catcode. For example, in the following text the footnote ``Including Respublica Bananensis Francorum.''@: is only present if the task name starts with @file{my-doc}. @example If a democracy is just a regime where citizens vote then all banana republics \IfBeginWith*@{\jobname@}@{my-doc@}% @{\footnote@{Including Respublica Bananensis Francorum.@}@}@{@} are democracies. @end example Manipulating the value of @code{\jobname} inside of a document does not change the name of the output file or the log file. @node Recovering from errors @section Recovering from errors If @LaTeX{} finds an error in your document then it gives you an error message and prompts you with a question mark, @code{?}. For instance, running @LaTeX{} on this file @example \newcommand@{\NP@}@{\ensuremath@{\textbf@{NP@}@}@} The \PN@{@} problem is a million dollar one. @end example @noindent causes it show this, and wait for input. @example ! Undefined control sequence. l.5 The \PN @{@} problem is a million dollar one. ? @end example @noindent The simplest thing is to enter @kbd{x} and @kbd{RETURN} and fix the typo. You could instead enter @kbd{?} and @kbd{RETURN} to see other options. @cindex @samp{*} prompt @cindex prompt, @samp{*} @findex \stop There are two other error scenarios. The first is that you forgot to include the @code{\end@{document@}} or misspelled it. In this case @LaTeX{} gives you a @samp{*} prompt. You can get back to the command line by typing @kbd{\stop} and @kbd{RETURN}; this command does its best to exit @LaTeX{} immediately, whatever state it may be in. The last scenario is that you mistyped the filename. For instance, instead of @code{pdflatex test} you might type @code{pdflatex tste}. @example ! I can't find file `tste'. <*> tste (Press Enter to retry, or Control-D to exit) Please type another input file name: @end example @noindent The simplest thing is to enter @kbd{CTRL d} (holding the Control and d keys down at the same time), and then retype the correct command line. @node Document templates @appendix Document templates @cindex document templates @cindex templates, document Although illustrative material, perhaps these document templates will be useful. Additional template resources are listed at @url{https://tug.org/interest.html#latextemplates}. @menu * beamer template:: * article template:: * book template:: * Larger book template:: @end menu @node beamer template @section @package{beamer} template @cindex @package{beamer} template and class @cindex template, @package{beamer} @PkgIndex{beamer} The @package{beamer} class creates presentation slides. It has a vast array of features, but here is a basic template: @verbatim \documentclass{beamer} \title{Beamer Class template} \author{Alex Author} \date{July 31, 2020} \begin{document} \maketitle % without [fragile], any {verbatim} code gets mysterious errors. \begin{frame}[fragile] \frametitle{First Slide} \begin{verbatim} This is \verbatim! \end{verbatim} \end{frame} \end{document} @end verbatim The Beamer package on CTAN: @url{https://ctan.org/pkg/beamer}. @node article template @section @code{article} template @cindex template (simple), @code{article} A simple template for an article. @verbatim \documentclass{article} \title{Article Class Template} \author{Alex Author} \begin{document} \maketitle \section{First section} Some text. \subsection{First section, first subsection} Additional text. \section{Second section} Some more text. \end{document} @end verbatim @node book template @section @code{book} template @cindex template, @code{book} This is a straightforward template for a book. @xref{Larger book template}, for a more elaborate one. @verbatim \documentclass{book} \title{Book Class Template} \author{Alex Author} \begin{document} \maketitle \chapter{First} Some text. \chapter{Second} Some other text. \section{A subtopic} The end. \end{document} @end verbatim @node Larger book template @section Larger @code{book} template @cindex template, @code{book} This is a somewhat elaborate template for a book. @xref{book template}, for a simpler one. This template uses @code{\frontmatter}, @code{\mainmatter}, and @code{\backmatter} to control the typography of the three main areas of a book (@pxref{\frontmatter & \mainmatter & \backmatter}). The book has a bibliography and an index. Also notable is that it uses @code{\include} and @code{\includeonly} (@pxref{Splitting the input}). While you are working on a chapter you can comment out all the other chapter entries from the argument to @code{\includeonly}. That will speed up compilation without losing any information such as cross-references. (Material that does not need to come on a new page is brought in with @code{\input} instead of @code{\include}. You don't get the cross-reference benefit with @code{\input}.) @verbatim \documentclass[titlepage]{book} \usepackage{makeidx}\makeindex \title{Book Class Template} \author{Alex Author} \includeonly{% % frontcover, preface, chap1, % appenA, } \begin{document} \frontmatter \include{frontcover} % maybe comment out while drafting: \maketitle \input{dedication} \input{copyright} \tableofcontents \include{preface} \mainmatter \include{chap1} ... \appendix \include{appenA} ... \backmatter \bibliographystyle{apalike} \addcontentsline{toc}{chapter}{Bibliography} \bibliography \addcontentsline{toc}{chapter}{Index} \printindex \include{backcover} \end{document} @end verbatim @node Index @unnumbered Index @c Keep `Command Index' working for ltx-help.el. @anchor{Command Index} @printindex cp @bye \def\DeclareTextCommand{\foo}{T1} % then |\foo| is defined to be |\T1-cmd \foo \T1\foo|, % % where |\T1\foo| is \emph{one} control sequence, not two! \newcommand \def\ProvideTextCommand % same with \providecommand \@onlypreamble\DeclareTextCommand \@onlypreamble\DeclareTextSymbol \gdef\TextSymbolUnavailable#1{% \@onlypreamble\def\DeclareTextCommandDefault#1{% \def\ProvideTextCommandDefault#1{% \def\DeclareTextAccent#1#2#3{% \def\DeclareTextCompositeCommand#1#2#3#4{% \@onlypreamble\def\DeclareTextComposite#1#2#3#4{% \def\UseTextAccent#1#2#3{% \def\UseTextSymbol#1#2{% \@onlypreamble\DeclareTextSymbolDefault@item \@onlypreamble\DeclareTextAccentDefault@item \def\UndeclareTextCommand#1#2{% @c Local Variables: @c ispell-dictionary: "english" @c coding: latin-1-unix @c End: