Documents and Classes

The shape of a document, the classes mLaTeX knows, and how a document is split across files.

The shape of a document

A document is a preamble, which says what kind of document it is and what it uses, and a body between \begin{document} and \end{document}:

report.tex
\documentclass[11pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{graphicx}

\title{Energy Estimates}
\author{Mara Ellison \and Tobias Renner}
\date{\today}

\begin{document}
\maketitle

\begin{abstract}
We revisit the energy method for the Navier--Stokes equations.
\end{abstract}

\section{Introduction}
The motion of a viscous fluid is governed by\dots

\end{document}

The preamble

Everything before \begin{document}. It sets no text; it chooses things:

  • \documentclass[options]{class} comes first and picks the class.
  • \usepackage[options]{package} loads a package. Several can share one line, as in \usepackage{amsmath,amssymb}.
  • \title, \author and \date store the title block for \maketitle. \and separates authors and \thanks adds a footnote to one.
  • Your own commands, colours, theorem kinds and settings go here too.

The body

Everything between \begin{document} and \end{document} is set on the page. Anything after \end{document} is ignored.

  • \maketitle sets the title block where it stands.
  • The abstract block sets the abstract, under its heading.
  • \tableofcontents lists the sections, with their page numbers, from the same single run.

Classes

Choosing a class

\documentclass sets the page: its paper size, type size and columns, read from the class's options.

OptionWhat it does
letterpaper, a4paper, a5paper, b5paper, legalpaper, executivepaperThe paper size. Letter is the default, as in LaTeX.
landscapeTurns the paper on its side.
10pt, 11pt, 12ptThe size of the body text, with its line spacing and margins.
twocolumn, onecolumnSets the body in two columns, or one.

Other options are read and ignored, so a class's own options never stop a document.

The standard classes

article, report and book are LaTeX's own classes.

  • article for papers and short documents: sections are the top level.
  • report adds \chapter, each starting a new page.
  • book adds \frontmatter, \mainmatter and \backmatter. The front matter is numbered in roman numerals with unnumbered chapters, the main matter in arabic numerals with numbered chapters, and the back matter keeps its chapters unnumbered.

Letters

The letter class sets letters:

letter.tex
\documentclass{letter}
\address{12 Harbour Road \\ Lisbon}
\signature{Mara Ellison}

\begin{document}
\begin{letter}{Tobias Renner \\ 4 Mill Lane \\ Porto}
\opening{Dear Tobias,}
The proofs arrived this morning.
\closing{With best wishes,}
\ps{P.S. The figures are attached.}
\encl{Two figures}
\cc{The editors}
\end{letter}
\end{document}

Slides

beamer sets slides, with frames, overlays and themes. See Slides.

Publishers' classes

Journal and conference classes are part of mLaTeX, so a template compiles without its .cls file:

ClassWhat it is
IEEEtranIEEE conference and journal papers: two columns, Roman section numbers, author blocks.
acmartACM papers; sigconf and sigplan in two columns.
llncsSpringer's Lecture Notes in Computer Science, authors numbered to their institutes.
svjour3Springer journal articles.
elsarticleElsevier journal articles; 5p in two columns.
revtex4-2, revtex4-1, revtex4APS and AIP papers; reprint in two columns, preprint in one.
amsartAMS articles, with addresses, subject classification and keywords.
scrartcl, scrreprt, scrbookKOMA-Script's classes, with their subject, subtitle and publishers fields.

What only a publisher's production system reads, such as DOIs, rights blocks and CCS concepts, is read and ignored.

Classes mLaTeX does not know

Any other class is set as article at the size and columns its options ask for, with a warning, so a journal template mLaTeX does not know still compiles.


Sections and structure

Sectioning commands

CommandLevelNotes
\part-1Its own page in reports and books.
\chapter0Reports and books only.
\section1
\subsection2
\subsubsection3
\paragraph4A run-in heading: the text follows it.
\subparagraph5A run-in heading, indented.

Each takes an optional short title for the contents and running heads, as in \section[Results]{Results of the second experiment}.

Numbering and the contents

  • Headings are numbered down to the level in the secnumdepth counter, and listed in \tableofcontents down to tocdepth. Change either with \setcounter{secnumdepth}{2}.
  • A starred form, \section*{Preface}, is unnumbered and left out of the contents. \addcontentsline{toc}{section}{Preface} puts it back in.

Appendices

\appendix switches the sections (or chapters) that follow to lettered numbering: A, B, C. The appendix package's appendices block is read too.

Designing headings

titlesec redesigns headings. \titleformat takes the heading, its format, the label, the space after the label, and code before and after the title:

\usepackage{titlesec}
\titleformat{\section}{\large\bfseries\color{blue}}{\thesection.}{1em}{}[\titlerule]

Lists

Bulleted, numbered and description lists

itemize sets bullets, enumerate numbers, and description bold labels. They nest four deep, and LaTeX's general list block is there for lists of your own.

\begin{itemize}
  \item Bullets
  \begin{enumerate}
    \item numbered inside
  \end{enumerate}
\end{itemize}
\begin{description}
  \item[Mass] in kilograms
\end{description}

enumitem

enumitem's options are read by the lists themselves, in square brackets after \begin:

\begin{enumerate}[label=(\roman*), nosep]
  \item First
  \item Second
\end{enumerate}

\setlist[itemize]{noitemsep} sets options for every list of a kind.

Compact lists and exercises

paralist's compact lists and tasks' columns of exercises work too.


Theorems and proofs

Declaring theorems

amsthm's \newtheorem{name}{Title}[counter] declares a kind of theorem, numbered within counter if one is given. \newtheorem{name}[other]{Title} shares another kind's numbers, and \newtheorem* declares an unnumbered one.

\usepackage{amsthm}
\newtheorem{theorem}{Theorem}[section]

\begin{theorem}[Fermat]
No three positive integers satisfy $a^n + b^n = c^n$ for $n > 2$.
\end{theorem}

theorem, lemma, proposition, corollary, conjecture, definition, example, remark and note are declared already when amsthm is loaded, each numbered on its own. A document that declares one itself, to share a counter or number within sections, replaces it.

Theorem styles

\theoremstyle before a \newtheorem chooses how that kind is set:

StyleHeadingBodyUsed for
plainBoldItalicTheorems, lemmas, corollaries
definitionBoldUprightDefinitions and examples
remarkItalicUprightRemarks and notes

\newtheoremstyle defines a style of your own.

Proofs

The proof block sets "Proof." and ends with a square at the right margin, as amsthm sets it. \qed sets the square anywhere:

\begin{proof}
The margin is too small.
\end{proof}

Other theorem packages

thmtools' \declaretheorem and ntheorem's styles are read as well.


Your own commands

Commands

\newcommand{\name}[arguments][default]{definition} defines a command; #1, #2 and so on stand for its arguments. With a default, the first argument is optional.

\newcommand{\vect}[1]{\boldsymbol{#1}}
\newcommand{\norm}[2][2]{\lVert #2 \rVert_{#1}}

\renewcommand redefines a command that exists, \providecommand defines one only if it does not, and \DeclareRobustCommand defines or redefines one, as in LaTeX.

Environments

\newenvironment{name}{begin}{end} defines a block. The begin and end code run inside the block's group, as in LaTeX:

\newenvironment{note}{\begin{quote}\small\textbf{Note.}}{\end{quote}}

xparse

\NewDocumentCommand and \NewDocumentEnvironment take xparse's argument specifications, such as m for a mandatory argument and O{default} for an optional one.

TeX's own definitions

\def, \edef and \let work as in TeX.


Splitting a document

\input and \include

\input{chapter} and \include{chapter} read another file in place. The file is looked for beside the file being read, then as chapter.mtex and chapter.tex.

Where files are found

A file is read only from the document's own folder and the folders given with -I:

mlatex -I chapters -I figures thesis.tex

Files carried in the document

A file the document carries itself, in a filecontents block, is kept for the run, so a later \input or \bibliography finds it. Nothing is written to disk:

\begin{filecontents}{refs.bib}
@book{knuth84, author = {Donald E. Knuth}, title = {The \TeX book},
  publisher = {Addison-Wesley}, year = 1984}
\end{filecontents}

Leaving text out

Comments

% comments out the rest of a line.

The comment package

The comment package's comment block leaves out everything up to its \end{comment}, and \excludecomment{name} makes more blocks like it.


Values from a program

\variable

When mLaTeX runs inside another program, the program can hand the document named values, read with \variable:

Dear \variable{customer}, your balance is \variable{balance}.

See Embedding.