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}:
\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,\authorand\datestore the title block for\maketitle.\andseparates authors and\thanksadds 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.
\maketitlesets the title block where it stands.- The
abstractblock sets the abstract, under its heading. \tableofcontentslists 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.
| Option | What it does |
|---|---|
letterpaper, a4paper, a5paper, b5paper, legalpaper, executivepaper | The paper size. Letter is the default, as in LaTeX. |
landscape | Turns the paper on its side. |
10pt, 11pt, 12pt | The size of the body text, with its line spacing and margins. |
twocolumn, onecolumn | Sets 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.
articlefor papers and short documents: sections are the top level.reportadds\chapter, each starting a new page.bookadds\frontmatter,\mainmatterand\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:
\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:
| Class | What it is |
|---|---|
IEEEtran | IEEE conference and journal papers: two columns, Roman section numbers, author blocks. |
acmart | ACM papers; sigconf and sigplan in two columns. |
llncs | Springer's Lecture Notes in Computer Science, authors numbered to their institutes. |
svjour3 | Springer journal articles. |
elsarticle | Elsevier journal articles; 5p in two columns. |
revtex4-2, revtex4-1, revtex4 | APS and AIP papers; reprint in two columns, preprint in one. |
amsart | AMS articles, with addresses, subject classification and keywords. |
scrartcl, scrreprt, scrbook | KOMA-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
| Command | Level | Notes |
|---|---|---|
\part | -1 | Its own page in reports and books. |
\chapter | 0 | Reports and books only. |
\section | 1 | |
\subsection | 2 | |
\subsubsection | 3 | |
\paragraph | 4 | A run-in heading: the text follows it. |
\subparagraph | 5 | A 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
secnumdepthcounter, and listed in\tableofcontentsdown totocdepth. 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:
| Style | Heading | Body | Used for |
|---|---|---|---|
plain | Bold | Italic | Theorems, lemmas, corollaries |
definition | Bold | Upright | Definitions and examples |
remark | Italic | Upright | Remarks 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.texFiles 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.
Related packages
- Classes: every package, with its commands and an example.
- Documents and Pages: every package, with its commands and an example.
- Lists and Boxes: every package, with its commands and an example.