2078 lines
94 KiB
TeX
2078 lines
94 KiB
TeX
\documentclass[twoside, 9pt]{extreport}
|
||
\usepackage{extsizes}
|
||
\usepackage[utf8]{inputenc}
|
||
\usepackage[T1]{fontenc}
|
||
\usepackage{amsmath}
|
||
\usepackage{amssymb}
|
||
\usepackage{graphicx}
|
||
\usepackage[nott]{kpfonts}
|
||
\usepackage{float}
|
||
\usepackage{longtable}
|
||
\usepackage{booktabs}
|
||
\usepackage{lipsum}
|
||
\usepackage{nicefrac}
|
||
\usepackage{quoting}
|
||
\usepackage{wrapfig}
|
||
\raggedbottom
|
||
|
||
% Easiest tables ever, plus custom table themes
|
||
\usepackage{tabularray}
|
||
\NewTblrTheme{custom1}{
|
||
\SetTblrStyle{contfoot-text}{\small}
|
||
}
|
||
|
||
|
||
|
||
% Where are our images?
|
||
\graphicspath{{./images/},{./standalone/build/}}
|
||
|
||
% Include bibliography in TOC without numbering
|
||
\usepackage[nottoc]{tocbibind}
|
||
|
||
% Let's set this as a half-letter sized sheet
|
||
\usepackage[
|
||
paperheight=8.5in,
|
||
paperwidth=5.5in,
|
||
margin=0.5in
|
||
]{geometry}
|
||
\geometry{
|
||
% paperheight=8.5in,
|
||
% paperwidth=5.5in,
|
||
% heightrounded,
|
||
% margin=0.5in
|
||
}
|
||
|
||
% Adjust the top and bottom margins
|
||
\addtolength{\topmargin}{0.4in}
|
||
\addtolength{\textheight}{-0.5in}
|
||
|
||
% Set the header style
|
||
\usepackage{fancyhdr}
|
||
\pagestyle{fancy}
|
||
\fancyhf{}
|
||
\fancyhead[LE,RO]{\thepage}
|
||
\fancyhead[RE,LO]{\textit{the little book of \LaTeX{}}}
|
||
% We won't use footers, but we'll keep this in case we change our minds.
|
||
% \cfoot{Page \thepage}
|
||
%\renewcommand{\footrulewidth}{0.5pt}
|
||
|
||
% Adjust cell spacing in tables
|
||
\usepackage{cellspace}
|
||
\cellspacetoplimit 6pt
|
||
\cellspacebottomlimit 6pt
|
||
|
||
% Make a nice border and box for the tops of our examples
|
||
\newcommand\klab[3]{\vspace{#1}\noindent{}\hrulefill~~\fbox{\texttt{~#2~}}~~\hrulefill\vspace{#3}}
|
||
|
||
% Add an \hrule with space above and below
|
||
\newcommand\krule[2]{\vspace{#1}\hrule\vspace{#2}}
|
||
|
||
% Make hrefs easier (must load package hyperref}
|
||
\newcommand\kref[2]{\href{#1}{{\texttt{#2}}}}
|
||
|
||
% Make including standalone items easier
|
||
\newcommand\kpic[2]{\bigskip%
|
||
\noindent\includegraphics[scale=#1]{#2}%
|
||
\medskip}
|
||
|
||
% Include sections and subsections in the TOC
|
||
% \setcounter{tocdepth}{1}
|
||
|
||
% We will probably want some two- or three-column sections
|
||
\usepackage{multicol}
|
||
|
||
% Stop resetting the footnote count after each chapter
|
||
\counterwithout{footnote}{chapter}
|
||
|
||
% Let's wrap some images
|
||
\usepackage{wrapfig}
|
||
|
||
% Use tab stops when we need to (especially in footnotes)
|
||
\usepackage{tabto}
|
||
% Define 18 tab stops (at 1/4" intervals)
|
||
\NumTabs{18}
|
||
|
||
% Use strikethrough
|
||
\usepackage{ulem}
|
||
|
||
% Make things neater. Thanks /u/-LeopardShark-
|
||
\usepackage{microtype}
|
||
|
||
% Use line numbers with code samples
|
||
% \begin{Verbatim}...\end{Verbatim} <-- Note the capitalization!
|
||
\usepackage{fancyvrb}
|
||
% Break lines inside this environment:
|
||
\usepackage{fvextra}
|
||
|
||
% Actual comment blocks
|
||
\usepackage{verbatim}
|
||
|
||
% Control spacing in lists
|
||
\usepackage{enumitem}
|
||
|
||
\raggedbottom
|
||
|
||
% Pictures!
|
||
\usepackage{tikz}
|
||
|
||
% Cancel units in math mode!
|
||
\usepackage{cancel}
|
||
|
||
% Better control over line-spacing
|
||
\usepackage{setspace}
|
||
|
||
% Use nice fractions
|
||
\usepackage{nicefrac}
|
||
|
||
% Keep the footnotes at the bottom of the page
|
||
\usepackage[bottom]{footmisc}
|
||
|
||
% Add custom widths to tables
|
||
\usepackage{array}
|
||
|
||
% Use chapter names in references
|
||
\usepackage{nameref}
|
||
|
||
% Change distance above chapter titles
|
||
\usepackage{titlesec}
|
||
\titleformat{\chapter}[display]
|
||
{\normalfont\LARGE\bfseries}{\chaptertitlename\ \thechapter}{10pt}{\Huge}[{\vspace{2mm}\titlerule[0.8pt]\vspace{0.5mm}\titlerule[0.3pt]}]
|
||
\titlespacing*{\chapter}{0pt}{0pt}{30pt}
|
||
|
||
% Include URLs, but hide the big red box it puts around them in the pdf.
|
||
\usepackage[hidelinks]{hyperref}
|
||
|
||
%%%% Document Information %%%%%
|
||
\author{{\small Kenneth John Odle}}
|
||
\title{
|
||
{\Huge the little book of \LaTeX{}} \\
|
||
\bigskip
|
||
{\large An Incomplete Guide \\
|
||
\vspace{5em}
|
||
1\textsuperscript{st} Edition \\
|
||
Typeset in \LaTeX{} (of course!)}
|
||
}
|
||
\date{{\small \the\year{}}}
|
||
|
||
\begin{document}
|
||
\maketitle
|
||
|
||
\section*{}
|
||
|
||
\thispagestyle{empty}
|
||
|
||
All contents \copyright\the\year{} Kenneth John Odle
|
||
|
||
\bigskip
|
||
|
||
\noindent{}FYI, this is made in \LaTeX \,using the \texttt{extreport} document class. (As opposed to the \texttt{report} document class, \texttt{extreport} lets me put everything in a 9 point font.) It then gets exported to a letterhalf (5.5 in x 8.5 in) pdf, which then gets made into a booklet using PDF Booklet (\href{https://pdfbooklet.sourceforge.io/wordpress/}{\texttt{https://pdfbooklet.sourceforge.io/wordpress/}}).
|
||
|
||
\bigskip
|
||
|
||
\noindent{}I am adding commits as I go to my personal git server. If you are interested, you can view it at
|
||
|
||
\medskip
|
||
|
||
\noindent{}\kref{https://git.kjodle.net/kjodle/little-book-of-LaTeX}{https://git.kjodle.net/kjodle/little-book-of-LaTeX}
|
||
|
||
\medskip
|
||
|
||
I may do a second volume of this, or I may simply do a second edition. If I do, you'll be able to find it there.
|
||
|
||
\tableofcontents
|
||
|
||
\listoftables
|
||
|
||
\vspace{8mm}
|
||
\begingroup
|
||
\let\clearpage\relax
|
||
\listoffigures
|
||
\endgroup
|
||
|
||
|
||
\chapter{Beginnings}
|
||
|
||
\section{About the Author}
|
||
|
||
I am neither a mathematician nor a physicist, but I've been fascinated with typography for as long as I can remember.\footnote{I majored in biology and English, so poking around in old books probably had a lot to do with it.} I finally decided to take the plunge and learn \LaTeX{}, but because I have a project-based mind, I needed a project to learn it. I ended up creating a zine about Linux,\footnote{Which you can read about at \kref{https://just13.click/thecodex/}{https://just13.click/thecodex/}} typeset entirely in \LaTeX{}. It's been a fun ongoing project, and I've learned a lot as a result. I finally decided that instead of keeping notes everywhere (mostly in the preambles of the documents I've been working on) I decided to write a little book that recorded what I've learned to use as a reference guide. If I had something like this when I started, things probably would have gone much more smoothly for me. A lot of this material has been previously published in that zine, but there is quite a bit here which is new.
|
||
|
||
\paragraph{Two Caveats} First, I am far from an expert in these matters. What follows is pretty much a listing of what I've gleaned from hours spent searching the internet and trying things out myself.
|
||
|
||
Second, some things will look differently and behave differently for you depending on variables such as the document class (see below) you are using and which other packages you have loaded. My rules for learning things like this are always:
|
||
|
||
\begin{enumerate}[noitemsep]
|
||
\item Don't compare yourself to others. Your mileage can—and will—vary, because people learn things at different rates and in different orders.
|
||
\item Practice doesn't make perfect, but it does make things less shitty.
|
||
\item A willingness to experiment is your best guide. Be sure to document your experiments.
|
||
\item You will get errors as part of the learning process. Your goal should always be to get better errors.
|
||
\end{enumerate}
|
||
|
||
Although this originated as a set of notes for my personal use, I have tried to arrange it in an order which will flatten the learning curve as much as possible. Your mileage will vary, of course, but in general I believe this order to be fairly logical. However, the table of contents and list of tables is fairly extensive, so it will helpfully serve as a good reference regardless.
|
||
|
||
When (not \textit{if}) you have problems, please consult the ``Troubleshooting'' chapter. It's not going to solve all, if any, of your problems, but it will suggest a general problem-shooting algorithm that will help you figure out where things are going wrong.
|
||
|
||
Also, if you have access to the source code so you can see how other people have done things, so much the better. (You can view the source code for this book at \href{https://git.kjodle.net/kjodle/little-book-of-LaTeX}{\texttt{https://git.kjodle.net/kjodle/little-book-of-LaTeX}}.)
|
||
|
||
\section{Other Sources of Help}\label{othersources}
|
||
|
||
These are listed roughly in the order of how often I consult them.
|
||
|
||
\begin{itemize}[noitemsep]
|
||
\item \textbf{TeX - LaTeX Stack Exchange} — \kref{https://tex.stackexchange.com/}{https://tex.stackexchange.com/}
|
||
\item \textbf{Overleaf} — Overleaf is an online \LaTeX{} editor. They have both free and paid options. They have excellent documentation at \kref{https://www.overleaf.com/learn}{https://www.overleaf.com/\\learn} and free templates at \kref{https://www.overleaf.com/latex/templates}{https://www.overleaf.com/latex/templates}
|
||
\item The \textbf{\LaTeX{} Community} has a helpful forum at \kref{https://latex.org/forum/}{https://latex.org/forum/}
|
||
\item \textbf{texblog — because \LaTeX{} matters} has a number of useful articles but hasn't been updated in a while. You can read it at \kref{https://texblog.org/}{https://texblog.org/}
|
||
\item \textbf{CTAN — Comprehensive \TeX{} Archive Network} — \kref{https://ctan.org/}{https://ctan.org/} has lots of good information. This is where I go to find information about packages.
|
||
\item \textbf{LaTeX Wikibook} — \kref{https://en.wikibooks.org/wiki/LaTeX}{https://en.wikibooks.org/wiki/LaTeX}
|
||
\item \textbf{Dickimaw Books — \LaTeX{} Resources} — A website by a retired math professor with some useful information.\\ \kref{https://www.dickimaw-books.com/latexresources.html}{https://www.dickimaw-books.com/latexresources.html}
|
||
\item \textbf{\TeX{} FAQ} — \kref{https://texfaq.org/}{https://texfaq.org/}
|
||
\item \textbf{texdoc online documentation} — The \TeX{} and \LaTeX{} documentation lookup system. \kref{https://texdoc.org/index.html}{https://texdoc.org/index.html}
|
||
\item \textbf{The Prac\TeX{} Journal} — The online journal of the Tex Users Group. No new issues since 2012. This journal does not contain as much useful information, but it does contain \textit{interesting} information.\\ \kref{https://tug.org/pracjourn/2012-1/toc.html}{https://tug.org/pracjourn/2012-1/toc.html}
|
||
\item \textbf{\textsc{TUGboat}} — The communications of the \TeX{} Users Group. Again, there is less useful information to a \LaTeX{} novice, but lots of \textit{interesting} information. \kref{https://www.tug.org/TUGboat/}{https://www.tug.org/TUGboat/}
|
||
\end{itemize}
|
||
|
||
|
||
\chapter{\LaTeX{} Basics}
|
||
|
||
\section{Files vs. Documents}
|
||
|
||
In this book, I use the word \textit{file} to refer to the \texttt{.tex} file you are entering text and code into, whereas I use the word \textit{document} to refer to the output you get from processing that file, which is usually a \texttt{.pdf} file/document.
|
||
|
||
\section{Files}
|
||
|
||
\LaTeX{} uses plain text files with a file extension of \texttt{.tex}. That's it! They contain plain text only and no binary codes or hidden formatting extensions. You can use any text editor, although a GUI is available for most operating systems.
|
||
|
||
\section{File Structure}
|
||
|
||
Every \LaTeX{} file has two parts:
|
||
|
||
\begin{enumerate}[noitemsep]
|
||
\item A \textbf{preamble} in which you declare the class and add any packages you may need, as well as set other variables such as the title and author.
|
||
\item A \textbf{document} environment which contains the actual text of the document.
|
||
\end{enumerate}
|
||
|
||
If you are familiar with \texttt{html}, these correspond roughly to the \texttt{<head>} and \texttt{<body>} elements.
|
||
|
||
\subsection{The Preamble}
|
||
|
||
Within the preamble, you can declare the document's \textit{class}, which is a description of the type of document you are creating. The most common classes are summarized in section \ref{sec:document-classes}. A typical class declaration looks like:
|
||
|
||
\begin{Verbatim}
|
||
\documentclass[twoside]{report}
|
||
\end{Verbatim}
|
||
|
||
The class is described between curly brackets, but you can also include several \textit{options} in square brackets. The above document class is a two-sided report. ``Two-sided'' means that it may have different margins, headers, and footers on right and left handed pages. Other options, such as paper size and font size, are available.
|
||
|
||
\subsection{The \texttt{document} Environment}
|
||
|
||
Anything not in the preamble goes in the \texttt{document} environment, which looks like this:
|
||
|
||
\begin{Verbatim}[commandchars=\+\(\)]
|
||
\begin{document}
|
||
+textit(…your stuff…)
|
||
\end{document}
|
||
\end{Verbatim}
|
||
|
||
\subsection{Document Structure}
|
||
|
||
Each \LaTeX{} document can be divided into a hierarchical structure consisting of the following sections:
|
||
|
||
\begin{verbatim}
|
||
Part
|
||
Chapter
|
||
Section
|
||
Subsection
|
||
Subsubsection
|
||
Paragraph
|
||
Subparagraph
|
||
\end{verbatim}
|
||
|
||
\noindent{} To add one, use:
|
||
|
||
\kpic{1}{book[]}
|
||
|
||
Notice that we have the option \texttt{[Books]} which describes how this chapter will appear in the table of contents. To prevent a section from being numbered or appearing in the table of contents, replace this entire option with an asterisk:
|
||
|
||
\kpic{1}{book*}
|
||
|
||
For best results, stick to the hierarchical structure shown above, as this is also how each section will be numbered. See the table of contents of this booklet as an example.
|
||
|
||
\section{Document Classes}\label{sec:document-classes}
|
||
|
||
The different types of document classes help you build a specific type of document. Here is a brief description of the most common classes:
|
||
|
||
\bigskip
|
||
|
||
% Provide some additional spacing in this table; may move this to preamble later
|
||
\setlength{\tabcolsep}{14pt}
|
||
\renewcommand{\arraystretch}{1.4}
|
||
|
||
\begin{longtblr}
|
||
[
|
||
caption = {Document Classes in \LaTeX{} },
|
||
label = {tbl:docclasses}
|
||
]{
|
||
% width = {10cm},
|
||
colspec = { X[1,l] X[4,l] },
|
||
hlines = {0.75pt,solid},
|
||
vlines = {0.75pt,solid},
|
||
rows = {5mm, m, rowsep=1.5pt}
|
||
}
|
||
\textbf{Class} & \textbf{Usage} \\
|
||
\textbf{article} & Articles for scientific or mathematical journals, short reports, and any kind of short document which does not require separate chapters or parts. \\
|
||
\textbf{report} & A long article form that contains chapters. It is often used for small books and theses. \\
|
||
\textbf{book} & Used to typeset actual books. It can contain chapters and parts, left and right pages, frontmatter, etc. \\
|
||
\textbf{beamer} & Slide decks (It has supplanted the \texttt{slides} class.) \\
|
||
\textbf{letter} & For writing letters \\
|
||
\textbf{exam} & For producing exams and quizzes \\
|
||
\textbf{proc} & For writing meeting proceedings \\
|
||
\end{longtblr}
|
||
|
||
|
||
\section{Paragraphs and White Space}
|
||
|
||
To start a new paragraph, simply skip a line. \LaTeX{} compresses white space, so if you are importing text from a text document, any lines that are adjacent to each other will be in the same paragraph. Additionally, multiple spaces will appear as a single space. For example, this code:
|
||
|
||
\begin{Verbatim}[frame=lines, numbers=left, label=\fbox{White Space Example}, breaklines=true, framesep=3mm]
|
||
This is the first paragraph.
|
||
This text, although it is on a separate line, is also part of the first paragraph.
|
||
|
||
We have skipped a line, so this starts a new paragraph.
|
||
This line is also in the second paragraph.
|
||
|
||
Readers will not see
|
||
all of these
|
||
spaces.
|
||
\end{Verbatim}
|
||
|
||
\noindent{} renders like this:
|
||
|
||
\klab{6pt}{White Space Example}{6pt}
|
||
%\vspace{2mm}
|
||
|
||
This is the first paragraph.
|
||
This text, although it is on a separate line, is also part of the first paragraph.
|
||
|
||
We have skipped a line, so this starts a new paragraph.
|
||
This line is also in the second paragraph.
|
||
|
||
Readers will not see
|
||
all of these
|
||
spaces.
|
||
|
||
\krule{2mm}{0mm}
|
||
|
||
\section{Comments}
|
||
|
||
Comments are created by adding a \texttt{\%} to the line. Anything beyond the percent sign will be ignored when your document is compiled.
|
||
|
||
To create multi-line comments, surround those lines with \verb|\iffalse| and \verb|\fi|:
|
||
|
||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{Multi-line Comment Block}]
|
||
\iffalse
|
||
These lines will not appear in your published text.
|
||
That is because they are surrounded by \iffalse and \fi.
|
||
If you didn't use that construction, you would need to put a \% in front of each line.
|
||
\fi
|
||
\end{Verbatim}
|
||
|
||
If the use of \verb|\iffalse| and \verb|\fi| is not intuitive to you, you can also load the \texttt{verbatim} package and use \verb|\begin{comment}| and \verb|\end{comment}| to surround multi-line comments.
|
||
|
||
\section{Environments}
|
||
|
||
\noindent{} This is where \LaTeX{} shows its power, as environments are used to to take care of typesetting tasks. Every environment begins with \verb+\begin{<environ+ \verb+ment>}+ and ends with \verb+\end{<environment>}+. In fact, we've already seen one environment: the \texttt{document} environment, which encompasses our entire document.
|
||
|
||
\texttt{enumerate} and \texttt{itemize} are used for creating lists. See the chapter ``\nameref{listenv}'' on page \pageref{listenv} for more information.
|
||
|
||
Many packages introduce additional environments. For other useful environments that do not require additional packages (but which can easily be expanded upon by other packages), please see the chapter ``\nameref{specenv}'' on page \pageref{specenv} for more information.
|
||
|
||
\chapter{Formatting Words}
|
||
|
||
\section{Font Variations}
|
||
|
||
\LaTeX{} has various ways of formatting type:
|
||
|
||
\begin{longtblr}
|
||
[
|
||
caption = {Font Variations in \LaTeX{} },
|
||
label = {tbl:fontvar}
|
||
]{
|
||
width = {114.3mm},
|
||
colspec = { X[1,l] X[2,l] X[1,l] },
|
||
hlines = {0.75pt,solid},
|
||
vline{1,4} = {0.75pt,solid},
|
||
rows = {5mm, m, rowsep=1.5pt},
|
||
row{1} = {font=\bfseries},
|
||
}
|
||
Effect & Code & Example \\
|
||
Bold & \Verb+\textbf{Bold}+ & \textbf{Bold} \\
|
||
Italic & \Verb+\textit{Italic}+ & \textit{Italic} \\
|
||
Slanted & \Verb+\textsl{Slanted}+ & \textsl{Slanted} \\
|
||
Emphasis & \Verb+\emph{Emphasis}+ & \emph{Emphasis} \\
|
||
Typewriter & \Verb+\texttt{Typewriter}+ & \texttt{Typewriter} \\
|
||
Small Caps & \Verb+\textsc{Small Caps}+ & \textsc{Small Caps} \\
|
||
Sans Serif & \Verb+\textsf{Sans Serif}+ & \textsf{Sans Serif} \\
|
||
\end{longtblr}
|
||
|
||
|
||
It is possible to combine these. For example, to write \textit{\textsc{Italic text in Small Caps}}, you would use:
|
||
|
||
\bigskip
|
||
|
||
\noindent{}\verb+\textit{\textsc{Italic text in Small Caps}}+
|
||
|
||
You could also use them in reverse order (small caps first then then italic text). It makes no difference in the final output.
|
||
|
||
\paragraph{Deprecated Code} — Note that in \LaTeX2e{} code such as \verb+{\it some text}+ and \verb+{\bf some text}+ are deprecated.
|
||
%\footnote{(See ~\cite{website:stexc002} and ~\cite{website:stexc003}.)}
|
||
\footnote{See \kref{https://tex.stackexchange.com/questions/41681/correct-way-to-bold-italicize-text}{https://tex.stackexchange.com/questions/41681/correct-way-to-bold-italicize-text} and \kref{https://tex.stackexchange.com/questions/516/does-it-matter-if-i-use-textit-or-it-bfseries-or-bf-etc}{https://tex.stackexchange.com/questions/516/does-it-matter-if-i-use-textit-or-it-bfs\\eries-or-bf-etc} for more information.}
|
||
|
||
\section{Size Variations}
|
||
|
||
\subsection{Global}
|
||
|
||
To set the overall size of text in your document, pass it to your \texttt{documentclass} command as an option. For most classes (\texttt{article}, \texttt{book}, \texttt{report}, \texttt{letter}, and \texttt{proc}), the default font size is 10 pt, but 11pt and 12 pt are also available.
|
||
|
||
The default for the \texttt{memoir} class is 10pt, and the other available options are 9pt, 11pt, 12pt, 14pt, 17pt, 20pt, 25pt, 30pt, 36pt, 48pt, and 60pt.
|
||
|
||
The default for the the \texttt{beamer} class is 11pt, and the other available options are 8pt, 9pt, 10pt, 11pt, 12pt, 14pt, 17pt, and 20pt.
|
||
|
||
You can also add the \texttt{extsizes} package, which gives you these additional document classes: \texttt{extarticle}, \texttt{extreport}, \texttt{extletter}, and \texttt{extproc}. If you use one of those document classes, you get access to other global sizes: 8pt, 9pt, 10pt, 11pt, 12pt, 14pt, 17pt, and 20pt.
|
||
|
||
\bigskip
|
||
|
||
\noindent{}This book contains this line in the preamble:
|
||
|
||
\begin{verbatim}
|
||
\documentclass[twoside, 9pt]{extreport}
|
||
\end{verbatim}
|
||
|
||
\subsection{Local}
|
||
|
||
You can also change the size of a portion of text locally. These are the defaults that are built into \LaTeX{}:
|
||
|
||
\begin{longtblr}
|
||
[
|
||
caption = {Local Size Commands},
|
||
label = {tb:localsizecommands}
|
||
]{
|
||
width = {10cm},
|
||
colspec = { X[1,c] X[1,c] },
|
||
hlines = {0.75pt,solid},
|
||
vlines = {0.75pt,solid},
|
||
rows = {5mm, m, rowsep=1.5pt},
|
||
row{1} = {font=\bfseries},
|
||
}
|
||
Markup & Renders as \\
|
||
\Verb+{{\tiny example}}+ & {\tiny example} \\
|
||
\Verb+{{\scriptsize example}}+ & {\scriptsize example} \\
|
||
\Verb+{{\footnotesize example}}+ & {\footnotesize example} \\
|
||
\Verb+{{\small example}}+ & {\small example} \\
|
||
\Verb+{{\normalsize example}}+ & {\normalsize example} \\
|
||
\Verb+{{\large example}}+ & {\large example} \\
|
||
\Verb+{{\Large example}}+ & {\Large example} \\
|
||
\Verb+{{\LARGE example}}+ & {\LARGE example} \\
|
||
\Verb+{{\huge example}}+ & {\huge example} \\
|
||
\Verb+{{\Huge example}}+ & {\Huge example} \\
|
||
\end{longtblr}
|
||
|
||
Note that all of these sizes are relative to the base size you set up in your preamble when declaring your document class.
|
||
|
||
\section{Displaying Code}
|
||
|
||
For more information, see the section ``\nameref{codeexp}'' on page \pageref{codeexp}.
|
||
|
||
|
||
\chapter{Formatting Paragraphs}
|
||
|
||
\section{Alignment}
|
||
|
||
By default, \LaTeX{} fully justifies text. That is, there are equal margins for each line on both the left and the right sides.
|
||
|
||
\subsection{Centered Text}
|
||
|
||
To center text, surround it with a \texttt{center} environment:
|
||
|
||
\begin{Verbatim}
|
||
\begin{center}
|
||
This text is centered.
|
||
\end{center}
|
||
\end{Verbatim}
|
||
|
||
\noindent{}produces this text:
|
||
|
||
\begin{center}
|
||
This text is centered.
|
||
\end{center}
|
||
|
||
\subsection{Left-Aligned Text}
|
||
|
||
To produce left-aligned text with a ragged right edge, use the \texttt{flushleft} environment:
|
||
|
||
\begin{Verbatim}[]
|
||
\begin{flushleft}
|
||
This text will be left-aligned with a ragged right edge.
|
||
\end{flushleft}
|
||
\end{Verbatim}
|
||
|
||
\begin{flushleft}
|
||
You don’t know about me without you have read a book by the name of \textit{The Adventures of Tom Sawyer}; but that ain’t no matter. That book was made by Mr. Mark Twain, and he told the truth, mainly. There was things which he stretched, but mainly he told the truth. That is nothing. I never seen anybody but lied one time or another, without it was Aunt Polly, or the widow, or maybe Mary. Aunt Polly—Tom’s Aunt Polly, she is—and Mary, and the Widow Douglas is all told about in that book, which is mostly a true book, with some stretchers, as I said before.\end{flushleft}
|
||
|
||
\subsection{Right-Aligned Text}
|
||
|
||
To produce right-aligned text with a ragged left edge, use the \texttt{flushright} environment:
|
||
|
||
\begin{Verbatim}[]
|
||
\begin{flushright}
|
||
This text will be left-aligned with a ragged right edge.
|
||
\end{flushright}
|
||
\end{Verbatim}
|
||
|
||
\begin{flushright}
|
||
You don’t know about me without you have read a book by the name of \textit{The Adventures of Tom Sawyer}; but that ain’t no matter. That book was made by Mr. Mark Twain, and he told the truth, mainly. There was things which he stretched, but mainly he told the truth. That is nothing. I never seen anybody but lied one time or another, without it was Aunt Polly, or the widow, or maybe Mary. Aunt Polly—Tom’s Aunt Polly, she is—and Mary, and the Widow Douglas is all told about in that book, which is mostly a true book, with some stretchers, as I said before.
|
||
\end{flushright}
|
||
|
||
\section{Vertical Space}
|
||
|
||
\subsection{\texttt{vspace}}
|
||
|
||
The \texttt{vspace} command will allow you to insert a vertical space in any unit understood by \LaTeX{}.
|
||
|
||
\begin{Verbatim}[]
|
||
This line has a five millimeter high space below it.\vspace{5mm}
|
||
|
||
This is the next line
|
||
\end{Verbatim}
|
||
|
||
\noindent{}gives us this:
|
||
|
||
\medskip
|
||
|
||
\noindent{}This line has a five millimeter high space below it.\vspace{5mm}
|
||
|
||
\noindent{}This is the next line
|
||
|
||
\subsection{Other Vertical Spacing Commands}
|
||
|
||
There are other ways to insert a vertical small space, using a single command.
|
||
|
||
\begin{longtblr}
|
||
[
|
||
caption = {Vertical Spacing Commands},
|
||
label = {tb:vertspacom},
|
||
theme = {custom1},
|
||
]{
|
||
width = {\textwidth},
|
||
colspec = { X[1,l] X[3,l] },
|
||
hlines = {0.75pt,solid},
|
||
vline{1,3} = {0.75pt,solid},
|
||
rows = {5mm, m, rowsep=1.5pt},
|
||
rowhead = 1
|
||
}
|
||
\Verb+\vfill+ & Inserts a vertical space that will stretch to fill the space available. This can be used to push content to the bottom of the page. \\
|
||
\Verb+\smallskip+ & Adds an approximately 3pt skip. \\
|
||
\Verb+\medskip+ & Adds an approximately 6pt skip. \\
|
||
\Verb+\bigskip+ & Adds an approximately 12pt skip.
|
||
\end{longtblr}
|
||
|
||
\section{Horizontal Space}
|
||
|
||
\subsection{\texttt{hspace}}
|
||
|
||
The \texttt{hspace} command will allow you to insert a horizontal space in any unit understood by \LaTeX{}.
|
||
|
||
\begin{Verbatim}[]
|
||
This line has a\hspace{2cm}two centimeter wide space in the middle.
|
||
\end{Verbatim}
|
||
|
||
\noindent{}gives us this:
|
||
|
||
\medskip
|
||
|
||
\noindent{}This line has a \hspace{2cm}two centimeter wide space in the middle.
|
||
|
||
\subsection{Single Horizontal Spaces}
|
||
|
||
Spacing commands can be found in math mode, but most of the ones in the table below can be used in text mode if you load the \texttt{amsmath} package. Some of the commands below will \textit{only} work in math mode as shown in the ``code'' column.\footnote{For more information, see \kref{https://tex.stackexchange.com/questions/74353/what-commands-are-there-for-horizontal-spacing}{https://tex.stackexchange.com/questions/74353/what-commands-ar\\e-there-for-horizontal-spacing}.}
|
||
|
||
\begin{longtblr}
|
||
[
|
||
caption = {Horizontal Spacing Characters},
|
||
label = {tb:horspacchar},
|
||
theme = {custom1},
|
||
]{
|
||
width = {\textwidth},
|
||
colspec = { X[2.5,l] X[1,c] X[1,c] },
|
||
hlines = {0.5pt,solid},
|
||
vline{1,4} = {0.5pt,solid},
|
||
rows = {5mm, m, rowsep=1.5pt},
|
||
column{1} = {font=\small\selectfont},
|
||
row{1} = {font=\bfseries},
|
||
rowhead = 1
|
||
}
|
||
Description & Code & Example \\
|
||
No separation & & OO \\
|
||
Thick space (0.2777em) & \Verb+\;+ & O\;O \\
|
||
Medium space (0.2222em) & \Verb+\:+ & O\:O \\
|
||
Medium space (0.2222em) & \Verb+\>+ & O\>O \\
|
||
Thin space (0.16667em) & \Verb+\,+ & O\,O \\
|
||
Negative thin space (-0.16667em) & \Verb+\!+ & O\!O \\
|
||
Enspace (0.5em) & \Verb+$\enspace$+ & O$\enspace$O \\
|
||
Quad (1em) & \Verb+$\quad$+ & O$\quad$O \\
|
||
Qquad (2em) & \Verb+$\qquad$+ & O$\qquad$O \\
|
||
Nonbreaking space & \Verb+$<char>~<char>$+ & $O~O$ \\
|
||
\end{longtblr}
|
||
|
||
\section{Phantoms}
|
||
|
||
Sometimes you need to insert a blank space that is the width of a particular character or stretch of space. To do this, you will need to use the \texttt{phantom} command.
|
||
|
||
\begin{itemize}[noitemsep]
|
||
\item \verb+\phantom+~ inserts an empty box with the same dimensions (horizontal as well as vertical) as the argument.
|
||
\item \verb+\hphantom+~ inserts an empty box that has zero height, zero depth, but the width of its argument.
|
||
\item \verb+\vphantom+~ inserts an empty box that has the height and depth of the argument, but zero width.
|
||
\end{itemize}
|
||
|
||
\textit{height} is the length above the baseline and \textit{depth} is the length below the baseline. A character such as ``w'' will have a height but zero depth, and ``y'' has height as well as depth.
|
||
|
||
\section{Breaks}
|
||
|
||
\subsection{Line Breaks}
|
||
|
||
\LaTeX{} has a number of ways to break lines.
|
||
|
||
\begin{longtblr}
|
||
[
|
||
caption = {Breaking Commands},
|
||
label = {tb:breaks},
|
||
theme = {custom1}
|
||
]{
|
||
width = {\textwidth},
|
||
colspec = { X[1,l] X[4.5,l] },
|
||
hlines = {0.5pt,solid},
|
||
vline{1,3} = {0.5pt,solid},
|
||
rows = {5mm, m, rowsep=1.5pt},
|
||
row{1} = {font=\bfseries},
|
||
rowhead = 1
|
||
}
|
||
Code & Description \\
|
||
\Verb+\newline+ & Breaks the line and allows a page break after. \\
|
||
\texttt{\textbackslash\textbackslash} & Breaks the line and allows a page break after. \\
|
||
\texttt{\textbackslash\textbackslash*} & Breaks the line and prohibits a page break after. \\
|
||
\Verb+\break+ & {Breaks the line without filling it. \\ (Can results in an awkward appearance.) } \\
|
||
\Verb+\hfill\break+ & {Breaks the line and fills it. This avoids the awkward appearance we get from the command above. \\ (Produces the same results as \Verb+\newline+ and \texttt{\textbackslash\textbackslash}.) } \\
|
||
\Verb+linebreak[<num>]+ & Allows you to set a priority for the break by inserting a number from 0 to 4. \LaTeX{} will easily ignore a 0, whereas it will definitely break on a 4.
|
||
\end{longtblr}
|
||
|
||
\subsection{Page Breaks}
|
||
|
||
\LaTeX{} has two commands for inserting a page break.
|
||
|
||
\begin{itemize}[noitemsep]
|
||
\item \Verb+\newpage+ will insert a page break, with the remaining text on the old page left at the top, the way the text appears on the last page of a chapter.
|
||
\item \Verb+\pagebreak+ will insert a page break, but \LaTeX{} will insert space between the paragraphs on the old page, so that they occupy the entire length of the page.
|
||
\end{itemize}
|
||
|
||
\texttt{pagebreak} can also accept an optional numerical argument the same way \texttt{linebreak} does, and with the same effect.
|
||
|
||
\section{Line Spacing}
|
||
\LaTeX{} was designed to write documents; as such, its ability to fine-tune certain document parameters, such as line-spacing, is fairly limited out of the box. You can fine-tune this with the \texttt{setspace} package. Add that to your preamble, and you can adjust the line spacing of your document by adding either \texttt{singlespacing}, \texttt{onehalfspacing}, or the \texttt{doublespacing} command to your preamble.
|
||
|
||
That gives you the versatility that you had with a typewriter. To set more precise line spacing, you can use the \texttt{setstretch} command in your preamble:
|
||
|
||
\begin{verbatim}
|
||
\setstretch{1.1}
|
||
\end{verbatim}
|
||
|
||
\noindent which sets a line spacing equivalent to 1.1 lines. If you want to change the line spacing for just a portion of your document, use the \texttt{spacing} environment:
|
||
|
||
\begin{verbatim}
|
||
\begin{spacing}{2.5}
|
||
Your widely spaced text goes here.
|
||
\end{spacing}
|
||
\end{verbatim}
|
||
|
||
\section{Indents}
|
||
|
||
\LaTeX{} will automatically indent every paragraph that doesn't come immediately after a section heading. If you do not want to indent a paragraph, use the \texttt{noindent} command:
|
||
|
||
\begin{Verbatim}[]
|
||
\noindent{}This paragraph will not be indented.
|
||
\end{Verbatim}
|
||
|
||
\noindent{}This paragraph will not be indented.
|
||
|
||
The amount that each paragraph will be indented is controlled by a variable called \texttt{parindent}, who default value depends on the document calss. You can print that value by adding this to your document:
|
||
|
||
\noindent{}\begin{Verbatim}[]
|
||
\the\parindent
|
||
\end{Verbatim}
|
||
|
||
For this document, using the \texttt{extreport} class, the value is \the\parindent. If you want to change that amount, add this to your preamble:
|
||
|
||
\begin{Verbatim}[]
|
||
\setlength{\parindent}{4em}
|
||
\end{Verbatim}
|
||
|
||
To insert a space that is the same width as your paragraph indentation, you can use:
|
||
|
||
\begin{Verbatim}[]
|
||
\hspace{\parindent}
|
||
\end{Verbatim}
|
||
|
||
|
||
\chapter{Formatting Pages}
|
||
|
||
\section{Page Size}
|
||
|
||
The usual way to define a page size is to pass it as an option to the document class:
|
||
|
||
\begin{verbatim}
|
||
\documentclass[letterpaper]{article}
|
||
\end{verbatim}
|
||
|
||
\noindent{}The widths and heights of the predefined page sizes in \LaTeX{} are:\footnote{I have included the ratio, because you can see how metric sizes are related. The United States really needs to get its shit together and adopt the metric system. There is not a printer or a filing cabinet available that cannot handle metric sized paper.}
|
||
|
||
\begin{longtblr}
|
||
[
|
||
caption = {Default Paper Sizes in \LaTeX{} },
|
||
label = {tbl:defpapersizes}
|
||
]{
|
||
width = {114.3mm},
|
||
colspec = { X[1.4,l] X[1,c] X[1,c] X[0.6,c] },
|
||
hlines = {0.75pt,solid},
|
||
vline{1,5} = {0.75pt,solid},
|
||
rows = {5mm, m, rowsep=1.5pt},
|
||
row{1} = {font=\bfseries},
|
||
}
|
||
Option & Width & Height & Ratio \\
|
||
a4paper & 210 mm & 297 mm & 1.4\\
|
||
a5paper & 148 mm & 210 mm & 1.4\\
|
||
b5paper & 176 mm & 250 mm & 1.4 \\
|
||
letterpaper & 8.5 in & 11 in & 1.30\\
|
||
legalpaper & 8.5 in & 14 in & 1.64 \\
|
||
executivepaper & 7.25 in & 10.5 in & 1.45 \\
|
||
\end{longtblr}
|
||
|
||
|
||
\section{Customizing Page Sizes Using \texttt{geometry}}
|
||
|
||
The \texttt{geometry} package provides highly granular detail over your page layout. Its use is not highly intuitive, however. I use it on almost every single document I create, but I am still unsure that I am using it properly. Experimentation is always a good thing, and I suggest changing one parameter at a time when experimenting.
|
||
|
||
You can add options in the usual way:
|
||
|
||
\begin{verbatim}
|
||
\usepackage[
|
||
paperheight=8.5in,
|
||
paperwidth=5.5in,
|
||
margin=0.5in
|
||
]{geometry}
|
||
\end{verbatim}
|
||
|
||
\noindent{}but you can also add options using the \verb|\geometry| option:
|
||
|
||
\begin{verbatim}
|
||
\usepackage{geometry}
|
||
\geometry{
|
||
paperheight=8.5in,
|
||
paperwidth=5.5in,
|
||
margin=0.5in
|
||
}
|
||
\end{verbatim}
|
||
|
||
\section{Customizing Pages}
|
||
|
||
\subsection{Omitting Headers and Footers on a Page}
|
||
|
||
To \textit{omit} the headers and footers on a given page, include the \texttt{titlesec} package in the preamble, and add this somewhere \textit{after} the start of the page.
|
||
|
||
\begin{verbatim}
|
||
\thispagestyle{empty}
|
||
\end{verbatim}
|
||
|
||
\subsection{Removing Page Numbers from ``Part'' Pages}
|
||
|
||
Chapters that are grouped into parts will have a ``Part'' page at the front of them. Surprisingly, these pages still have page numbers. You can remove them by adding the \texttt{nonumonpart} package.
|
||
|
||
\subsection{Adding Additional Text to ``Part'' Pages}
|
||
|
||
In actual books, a ``part'' pages often contain some sort of epigraph. You can make the text an optional argument to the \verb|\part| command by adding this to the preamble:\footnote{As described by \href{https://tex.stackexchange.com/users/1090/david-carlisle}{David Carlisle} at \kref{https://tex.stackexchange.com/questions/336361/how-to-write-text-after-part}{https://tex.stackexchange.com/questions/336361/\\how-to-write-text-after-part}.}
|
||
|
||
\begin{verbatim}
|
||
\makeatletter
|
||
\let\old@endpart\@endpart
|
||
\renewcommand\@endpart[1][]{%
|
||
\begin{quote}#1\end{quote}%
|
||
\old@endpart}
|
||
\makeatother
|
||
\end{verbatim}
|
||
|
||
To use this, add whatever text you want on the part page in square brackets:
|
||
|
||
\begin{Verbatim}[frame=lines, framesep=6mm, breaklines=true, label=\fbox{Text on Part Pages Example}]
|
||
\part[TOC Title]{A New Hope…}[
|
||
\vspace{3em}
|
||
\begin{center}
|
||
\textit{A long time ago, in a galaxy far, far away…}
|
||
\end{center}
|
||
]
|
||
\end{Verbatim}
|
||
|
||
Which gives us something like this:
|
||
|
||
\begin{center}
|
||
\fbox{\includegraphics[scale=0.8]{part}}
|
||
\end{center}
|
||
|
||
Note that everything gets wrapped in a \texttt{quote} environment, but that environment accepts additional commands and environments which will give you a great deal of control over how this text is displayed.
|
||
|
||
\paragraph{If you are wondering how this works…}\texttt{makeatletter} changes the \texttt{@} to the ``letter'' category code so that the current document has access to package internal macros. \texttt{makeatother} changes it back to a letter so you can use it in your document.\footnote{This gets into the internal workings of LaTeX and so is far beyond the scope of this book.\par{}\hspace{3mm} However, there is some good information at \href{https://tex.stackexchange.com/questions/8351/what-do-makeatletter-and-makeatother-do}{\texttt{https://tex.stackexchange.com/questions/8351/wh\\at-do-makeatletter-and-makeatother-do}} and at \href{https://www.tug.org/pipermail/tugindia/2002-January/000178.html}{\texttt{https://www.tug.org/pipermail/tugindia/2002-\\January/000178.html}} if you are interested. A complete list of category codes can be found at \href{https://en.wikibooks.org/wiki/TeX/catcode}{\texttt{https://en.wikibooks.org/wiki/TeX/catcode}}}
|
||
|
||
\verb|\let\old@endpart\@endpart| says ``take the old value for \texttt{endpart} (which is part of the \texttt{part} function) and give it this new value that I'm about to describe''.
|
||
|
||
The rest of it (that is, the \texttt{renewcommand} part) redefines the \texttt{endpart} to now include a \verb|\quote| environment, which is quite appropriate for an epigraph.
|
||
|
||
\subsection{Including Page Numbers on ``Chapter'' Pages}
|
||
|
||
In most document classes, the ``chapter'' pages do not contain page numbers. If you would like them to have page numbers, add this to the preamble:
|
||
|
||
\begin{verbatim}
|
||
\usepackage[]{titlesec}
|
||
\assignpagestyle{\chapter}{fancy}
|
||
\end{verbatim}
|
||
|
||
\subsection{Miscellaneous Items}
|
||
|
||
\begin{itemize}[noitemsep]
|
||
\item Notice that your footnotes are floating above the footer on some pages? Try adding \verb+\usepackage[bottom]{footmisc}+ to your preamble.
|
||
\item Need to control the gap between the header and the rest of the text? Pass the \verb|headsep| argument to the \texttt{geometry} package and set it equal to the amount of space you need (i.e., \texttt{headsep=12pt}).
|
||
\end{itemize}
|
||
|
||
|
||
\chapter{Basic List Environments}\label{listenv}
|
||
|
||
A list is a series of items that are related solely by being a subset of something else. Their relationship may be ordered or unordered. Ordered lists are usually numbered (although other items can be used, such as letters), and unordered lists usually use a symbol, such as a bullet, to denote each items.
|
||
|
||
Lists in \LaTeX{} can be nested, as the following examples will show.
|
||
|
||
\section{Enumerate}
|
||
|
||
\texttt{enumerate} is used to create numbered lists. They can be nested to create an outline. To prevent \LaTeX{} from adding a lot of space between the item numbers, add the \texttt{enumitem} package and pass the \texttt{[noitemsep]} to the environment.
|
||
|
||
For example, this code:
|
||
|
||
\begin{Verbatim}[frame=lines, label=\fbox{Enumerate Example}, framesep=6mm]
|
||
\paragraph{The First Punic War}
|
||
\begin{enumerate}[noitemsep]
|
||
\item Carthage and Rome
|
||
\begin{enumerate}
|
||
\item Beginning of Foreign Conquests
|
||
\item The Origin of Carthage
|
||
\item Government of Carthage
|
||
\end{enumerate}
|
||
\item Operations in the First Punic War
|
||
\begin{enumerate}
|
||
\item Outbreak of the War in Sicily
|
||
\item Capture of Messana and Agrigentum
|
||
\end{enumerate}
|
||
\item Events Following the War
|
||
\end{enumerate}
|
||
\end{Verbatim}
|
||
|
||
\noindent{} produces this output:
|
||
|
||
\newpage
|
||
|
||
\klab{0pt}{Enumerate Example}{0pt}
|
||
|
||
\paragraph{The First Punic War}
|
||
\begin{spacing}{0.7}
|
||
\begin{enumerate}[noitemsep]
|
||
\item Carthage and Rome
|
||
\begin{enumerate}
|
||
\item Beginning of Foreign Conquests
|
||
\item The Origin of Carthage
|
||
\item Government of Carthage
|
||
\end{enumerate}
|
||
\item Operations in the First Punic War
|
||
\begin{enumerate}
|
||
\item Outbreak of the War in Sicily
|
||
\item Capture of Messana and Agrigentum
|
||
\end{enumerate}
|
||
\item Events Following the War
|
||
\end{enumerate}
|
||
\end{spacing}
|
||
\vspace{2mm} \hrule
|
||
|
||
\section{Itemize}
|
||
|
||
Similar to the \texttt{enumerate} environment, the \texttt{itemize} environment creates bulleted lists, which can also be indented.
|
||
|
||
As an example, we'll use the above example, but in a bulleted list:
|
||
|
||
\begin{Verbatim}[frame=lines, label=\fbox{Itemize Example}, framesep=6mm]
|
||
\paragraph{The First Punic War}
|
||
\begin{itemize}[noitemsep]
|
||
\item Carthage and Rome
|
||
\begin{itemize}
|
||
\item Beginning of Foreign Conquests
|
||
\item The Origin of Carthage
|
||
\item Government of Carthage
|
||
\end{itemize}
|
||
\item Operations in the First Punic War
|
||
\begin{itemize}
|
||
\item Outbreak of the War in Sicily
|
||
\item Capture of Messana and Agrigentum
|
||
\end{itemize}
|
||
\item Events Following the War
|
||
\end{itemize}
|
||
\end{Verbatim}
|
||
|
||
\newpage
|
||
|
||
\noindent{} produces this output:
|
||
|
||
\klab{0pt}{Itemize Example}{0pt}
|
||
|
||
\paragraph{The First Punic War}
|
||
\begin{spacing}{0.7}
|
||
\begin{itemize}[noitemsep]
|
||
\item Carthage and Rome
|
||
\begin{itemize}
|
||
\item Beginning of Foreign Conquests
|
||
\item The Origin of Carthage
|
||
\item Government of Carthage
|
||
\end{itemize}
|
||
\item Operations in the First Punic War
|
||
\begin{itemize}
|
||
\item Outbreak of the War in Sicily
|
||
\item Capture of Messana and Agrigentum
|
||
\end{itemize}
|
||
\item Events Following the War
|
||
\end{itemize}
|
||
\end{spacing}
|
||
\vspace{2mm} \hrule \vspace{4mm}
|
||
|
||
\section{Customizing List Environments}
|
||
|
||
You can replace the bullets with any math symbol availabe in \LaTeX{} like this:
|
||
|
||
\begin{Verbatim}[frame=lines, label=\fbox{Bullets Example}, framesep=6mm]
|
||
\begin{itemize}[noitemsep]
|
||
\item[$\Box$] First item
|
||
\item[$\aleph$] Second item
|
||
\item[$\triangle$] Third item
|
||
\end{itemize}
|
||
\end{Verbatim}
|
||
|
||
\noindent{} which produces this output:
|
||
|
||
\klab{8pt}{Bullets Example}{0pt}
|
||
|
||
\begin{itemize}[noitemsep]
|
||
\item[$\Box$] First item
|
||
\item[$\aleph$] Second item
|
||
\item[$\triangle$] Third item
|
||
\end{itemize}
|
||
\krule{0mm}{2mm}
|
||
|
||
\chapter{Special Environments}\label{specenv}
|
||
|
||
\LaTeX{} includes a number of built-in environments which are useful out-of-the-box, but can often be improved upon by adding additional packages. In this chapter, we'll take a look at some of them, and examine how other packages extend their functionality.
|
||
|
||
\section{Code Blocks}\label{codeexp}
|
||
|
||
You have a few different options when trying to display code. For code which is not executable, you can always format it as typewriter text by wrapping it in \verb+\texttt{<code>}+. This will, generally, display it in a monospaced font.
|
||
|
||
The problem with this approach is that \LaTeX{} will attempt to execute any commands that you have included in that wrapper. An alternative to this is to use the \verb+\verb+ command. \verb+\verb+ does not need to use curly brackets (i.e., \\texttt{{} and \\texttt{}}) to contain its argument. Rather, it can contain its argument in between any two symbols which are \textit{not} contained it its argument. Two common options are the pipe symbol (\texttt{|}) and the plus sign (\texttt{+}). For example, to write \verb+\verb+ in our document, we could include either \verb+\verb|\verb|+ in our file or \verb|\verb+\verb+|. We could just as easily write this as \verb2\verb4\verb42. In this case, the character ``4'' is used as a delimiter to indicate what should be output directly to the document.
|
||
|
||
As useful as \verb+\verb+ is, it has one drawback: it does not wrap. That is, if whatever you place between the delimiters is longer than the line length, it will simply go off the page. Here's an example: \verb+verb|This text is longer than the line length and will simply go off the page|+.
|
||
|
||
The only way around that is to break that text into two parts like this:
|
||
|
||
\begin{Verbatim}[breaklines=true]
|
||
\verb|This text is longer than the line length| \\ \verb| and will simply go off the page|
|
||
\end{Verbatim}
|
||
|
||
It works, but it's clunky. If you change anything around those two \texttt{verb} commands, you'll need to adjust what is contained within each of them.
|
||
|
||
For longer code examples, you will need to use the built-in environment \texttt{verbatim}, which makes use of the \verb|\begin{verbatim}| and \verb|\end{verbatim}| commands to define the environment.
|
||
|
||
To gain more control over those environments, you can use the package \texttt{fancyvrb} (which uses the \texttt{Verbatim} environment—note the capital letter). You can add options in square brackets after the \texttt{begin} command. For example, to format the example blocks in this document, I am using this code:
|
||
|
||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, label=\fbox{Verbatim Example}, framesep=6mm, breaklines=true, commandchars=\+\(\)]
|
||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, label=\fbox{Bullets Example}, framesep=6mm]
|
||
\begin{itemize}[noitemsep]
|
||
\item[$\Box$] First item
|
||
\item[$\aleph$] Second item
|
||
\item[$\triangle$] Third item
|
||
\end{itemize}
|
||
\ +!+!+!+!+!+! end{Verbatim}
|
||
\end{Verbatim}
|
||
|
||
Here's a brief breakdown of what those options do:
|
||
|
||
\begin{itemize}[noitemsep]
|
||
\item \texttt{frame=lines} puts a line at the top and bottom of the code block. Other options are \texttt{leftline}, \texttt{topline}, \texttt{bottomline}, and \texttt{single} (which puts a box around the code block).
|
||
\item \texttt{numbers=left} adds line numbers to the left side of the code block.
|
||
\item \texttt{xleftmargin=5mm} adds a five millimeter margin to the left side, so that the line numbers are not hanging off into space.
|
||
\item \texttt{label=} adds a label to the top of the code block. Putting it in an \texttt{fbox} adds a border around it.
|
||
\end{itemize}
|
||
|
||
There are numerous other options in this package; please see the package documentation for more details
|
||
|
||
The \texttt{fvextra} package adds even more options for the \texttt{Verbatim} environment. Again, there are too many to list here; please see the package documentation, which is extensive. It does have the handy \texttt{Verb} command (note the capitalization), which works inside of tables.
|
||
|
||
If you still need even more options, you can try the \texttt{listings} package, which I have yet to try.
|
||
|
||
\section{Quotations}
|
||
|
||
I like using quotations\footnote{And here I'm going to be persnickety and point out that the \textit{noun} is, properly, ``quotation'' and the \textit{verb} is ``quote''. This is a battle which I will eventually lose.} in my work, and \LaTeX{} does indeed provide two different—and often misunderstood—environments for using quotations. \footnote{For much of this information, I am indebted to the \LaTeX{} WikiBook at \kref{https://en.wikibooks.org/wiki/LaTeX/Paragraph_Formatting}{https://en.wikibooks.org/\\wiki/LaTeX/Paragraph\_Formatting}}
|
||
|
||
Both of them are list environments, so they start with a \texttt{begin} command and end with an \texttt{end} command, and use \verb+\item+ to delineate their contents.
|
||
|
||
\subsection{\texttt{quote}}
|
||
|
||
The \texttt{quote} environment is meant to be used for a short quotation, or a series of small quotations, separated by blank lines. For example, this code:
|
||
|
||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{quote Example}]
|
||
\begin{quote}
|
||
\item A rose by any other name would smell as sweet. \\ —William Shakespeare
|
||
\item \textit{He travels the fastest who travels alone.} \\ \hspace*{\fill} —Rudyard Kipling
|
||
\end{quote}
|
||
\end{Verbatim}
|
||
|
||
\noindent{}produces this example:
|
||
|
||
\begin{quote}
|
||
\item A rose by any other name would smell as sweet. \\ —William Shakespeare
|
||
\item \textit{He travels the fastest who travels alone.} \\ \hspace*{\fill} —Rudyard Kipling
|
||
\end{quote}
|
||
|
||
|
||
\subsection{\texttt{quotation}}
|
||
|
||
The \texttt{quotation} environment indents the first line of each paragraph and also adds space between paragraphs, so it is meant for longer quotations of more than one paragraph.
|
||
|
||
\begin{quotation}
|
||
\item You don’t know about me without you have read a book by the name of The Adventures of Tom Sawyer; but that ain’t no matter. That book was made by Mr. Mark Twain, and he told the truth, mainly. There was things which he stretched, but mainly he told the truth. That is nothing. I never seen anybody but lied one time or another, without it was Aunt Polly, or the widow, or maybe Mary. Aunt Polly—Tom’s Aunt Polly, she is—and Mary, and the Widow Douglas is all told about in that book, which is mostly a true book, with some stretchers, as I said before.
|
||
\item Now the way that the book winds up is this: Tom and me found the money that the robbers hid in the cave, and it made us rich. We got six thousand dollars apiece—all gold. It was an awful sight of money when it was piled up. Well, Judge Thatcher he took it and put it out at interest, and it fetched us a dollar a day apiece all the year round—more than a body could tell what to do with. The Widow Douglas she took me for her son, and allowed she would sivilize me; but it was rough living in the house all the time, considering how dismal regular and decent the widow was in all her ways; and so when I couldn’t stand it no longer I lit out. I got into my old rags and my sugar-hogshead again, and was free and satisfied. But Tom Sawyer he hunted me up and said he was going to start a band of robbers, and I might join if I would go back to the widow and be respectable. So I went back.
|
||
\item —from \textit{The Adventures of Huckleberry Finn} by Mark Twain
|
||
\end{quotation}
|
||
|
||
\subsection{Customizing Quotations with the \texttt{quoting} Package}
|
||
|
||
As you can see in the above examples, the indentation is not consistent in those environments, and neither of them provide a good means of providing an attribution, which is commonly typeset as right-justified. The \texttt{quoting} package provides a number of options which are not available within the default environments of \LaTeX{}. However, it still does not provide a means of attributing the quotations. The best way may be to do it outside of whichever quotation environment you end up using, or to use the command \Verb+\hspace*{\fill}+ as in the previous example.
|
||
|
||
For example, this code:
|
||
|
||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{Quoting Example}]
|
||
\begin{quoting}[
|
||
indentfirst=false,
|
||
font=itshape,
|
||
begintext={\includegraphics[scale=0.5]{left-quote}},
|
||
endtext=''
|
||
]
|
||
\item Once more unto the breach, dear friends, once more;
|
||
\end{quoting}
|
||
\begin{flushright}
|
||
—William Shakespeare, \textit{Henry V}, Act III, Scene 1
|
||
\end{flushright}
|
||
|
||
\end{Verbatim}
|
||
|
||
|
||
produces this example:
|
||
|
||
\begin{quoting}[
|
||
indentfirst=false,
|
||
font=itshape,
|
||
begintext={\includegraphics[scale=0.5]{left-quote}},
|
||
endtext=''
|
||
]
|
||
\item Once more unto the breach, dear friends, once more;
|
||
\end{quoting}
|
||
\begin{flushright}
|
||
—William Shakespeare, \textit{Henry V}, Act II, Scene 1
|
||
\end{flushright}
|
||
|
||
\noindent{}I can probably live with that. Probably.
|
||
|
||
|
||
\chapter{Tables}
|
||
|
||
Tables in \LaTeX{} are often confusing to beginners, because there are two environments that are not quite what they seem. The \texttt{tabular} environment is used to create a table, (i.e., it contains \textit{tabular} data) while the \texttt{table} environment is a float that surrounds the table and can contain a caption.
|
||
|
||
\section{Built-in Table Environments}
|
||
|
||
Let's use both of those commands to build a simple table The following code will produce the result see in table \ref{tb:sampletable}:
|
||
|
||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{Sample of a Basic Table}]
|
||
\begin{table}
|
||
\caption{Sample of a Basic Table in \LaTeX{} }
|
||
\label{tb:sampletable}
|
||
\begin{tabular}{ | c l r | }
|
||
\hline
|
||
beans & greens & tomatoes \\
|
||
\hline
|
||
potatoes & lamb & rams \\
|
||
\hline
|
||
hogs & maws & chicken turkey \\
|
||
\hline
|
||
\end{tabular}
|
||
\end{table}
|
||
\end{Verbatim}
|
||
|
||
\begin{table}
|
||
\caption{Sample of a Basic Table in \LaTeX{} }
|
||
\label{tb:sampletable}
|
||
\begin{tabular}{ | c l r | }
|
||
\hline
|
||
beans & greens & tomatoes \\
|
||
\hline
|
||
potatoes & lamb & rams \\
|
||
\hline
|
||
hogs & maws & chicken turkey \\
|
||
\hline
|
||
\end{tabular}
|
||
\end{table}
|
||
|
||
Note that I did not say ``in the table below'' because the \texttt{table} container is a float. That is, it allows \LaTeX{} to find what it thinks is the best location for the table in your document. This is often a point of confusion for beginners, because they assume that the table will appear in the same location in their document that it appears in their file.
|
||
|
||
The code is fairly straightforward:
|
||
|
||
\begin{itemize}[noitemsep]
|
||
\item \texttt{caption} provides a title for the table. See chapter \ref{ch:referencing} for more information. (This \textbf{must} occur inside the \texttt{table} environment.)
|
||
\item \verb+\begin{tabular}+ begins the actual table we are building.
|
||
\item \verb+{ | c l r | }+ defines the table's columns and vertical lines. ``c'' is a center-aligned column, ``l'' a left-aligned column, and ``r'' a right-aligned column. The two pipe symbols represent vertical lines on either side of the table. (We could also put them between columns, as well.)
|
||
\item \verb+\hline+ inserts a horizontal line.
|
||
\item \verb+\\+ ends a row.
|
||
\end{itemize}
|
||
|
||
Typesetting tables in \LaTeX{} is straightforward, but it is not without its issues. In particular, tables that float can cause a lot of issues for users, and controlling the width of both the table and individual columns can be a challenge. However, if you do not wrap your table in a \texttt{table}, you cannot add a caption, as \LaTeX{} will give you a ``caption outside float'' error.
|
||
|
||
As you can see in our sample table, \LaTeX{} has automatically sized the columns and table to fit our content, but that does not always make for an aesthetically pleasing table. Additionally, the table is not centered (although that can be fixed fairly easily by wrapping it in a \texttt{center} environment). It can also be difficult to easily break lines in a table cell, for which you would need to use \verb+\newline+ or add the \texttt{makecell} package.
|
||
|
||
There are solutions to this, and Klaus Höppner pointed out many of them in his ``Typesetting tables with \LaTeX{}'' article, which I recommend reading. (You can find it at \kref{https://tug.org/TUGboat/tb28-3/tb90hoeppner.pdf}{https://tug.org/TUGboat/tb28-3/tb90hoeppner.pdf}.)
|
||
|
||
\section{The \texttt{tabularray} Package}
|
||
|
||
I have found a solution to all of my table problems by using the \texttt{tabularray} package, which seems to combine the best features of all the various table packages out there.
|
||
|
||
\texttt{tabularray} offers two table environments: \texttt{tblr} and \texttt{longtblr}. I prefer the latter as it both offers the option to add a caption, and will break across pages, adding a very nice ``continued on next page'' message. (See table \ref{tb:expsizcom} in chapter \ref{ch:math} for an example.)
|
||
|
||
The package actually has far more options than the few I discuss in this chapter. These are merely the ones that I use most often. If you are having difficulty constructing a table, I urge you to read the package documentation, as the chances are high that you will find a solution there.
|
||
|
||
This is the basic format of a \texttt{longtblr} table that I use on a regular basis:\footnote{I actually have this set up as a template that I can pull into any \LaTeX{} file.}
|
||
|
||
\newpage
|
||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{longtblr Example}]
|
||
\begin{longtblr}
|
||
[
|
||
caption = {Sample \texttt{longtblr} Table},
|
||
label = {tbl:longtblr}
|
||
]{
|
||
width = {\textwidth},
|
||
colspec = { X[1,l] X[1,l] },
|
||
hlines = {0.75pt,solid},
|
||
vline{1,3} = {0.75pt,solid},
|
||
rows = {5mm, m, rowsep=1.5pt}
|
||
}
|
||
Lemons & Limes \\
|
||
Oranges & Grapefruit
|
||
\end{longtblr}
|
||
\end{Verbatim}
|
||
|
||
\noindent{}which produces the table we see below:
|
||
|
||
\begin{longtblr}
|
||
[
|
||
caption = {Sample \texttt{longtblr} Table},
|
||
label = {tbl:longtblr}
|
||
]{
|
||
width = {\textwidth},
|
||
colspec = { X[1,l] X[1,l] },
|
||
hlines = {0.75pt,solid},
|
||
vline{1,3} = {0.75pt,solid},
|
||
rows = {5mm, m, rowsep=1.5pt}
|
||
}
|
||
Lemons & Limes \\
|
||
Oranges & Grapefruit
|
||
\end{longtblr}
|
||
|
||
Most of this should be fairly straightforward. \texttt{caption} and \texttt{label} provide a caption (which will be carried over onto the next page should the table extend over to a second page or beyond) and a label we can refer to later.
|
||
|
||
The \texttt{width} does not need to specified explicitly; if you omit it, the table will be the full width of your page. I include it in my template because I may want to make a table less than a full page width, as I do in table \ref{tb:localsizecommands} on page \pageref{tb:localsizecommands}.
|
||
|
||
The \texttt{colspec} requires some explaining. Although \texttt{tabularray} supports ordinary \texttt{c}, \texttt{l}, and \texttt{r} columns, it also supports an \texttt{X}-type column which allows you to control the width. I am specifying a width of 1 for each column, so both columns will have the same width. If I wanted one column to be twice as wide as the other one, I could simply change its width to 2. (Unlike the \texttt{tabularx} package, there is no need to ensure that your width values add up to the number of columns. You could easily do this as a percentage by specifying a width of 67 for the wider column and 33 for the narrower column.)
|
||
|
||
To specify horizontal lines between each row, I only need to add \verb+hlines = {0.+ \verb+75pt,solid}+. This adds a solid line (other options are \texttt{dashed} and \texttt{dotted}) between each row and at the top and bottom of the table.
|
||
|
||
To specify vertical lines, I added \verb+vline{1,3} = {0.75pt,solid}+. Note that this is singular (\texttt{vline}) rather than plural (\texttt{hlines}). That's because I only want the first and third vertical lines to appear in my table. (The \texttt{booktabs} package recommends against using vertical lines inside your table, and I tend to agree in most cases. This document certainly contains some exceptions.) If I had five columns, and only wanted to have vertical lines on the outside of the table, I would specify \verb+vline{1,6}+.
|
||
|
||
You can also specify line colors by using the color codes listed in the \texttt{ninecolors} package documentation. To specify blue horizontal lines, you would use something like \verb+hlines = {0.75pg,solid,blue7}+.
|
||
|
||
The rows are specified with \verb+rows = {5mm, m, rowsep=1.5pt}+. \texttt{5mm} specifies a minimum height of 5 millimeters for each row. \texttt{m} specifies that the content should be centered vertically (i.e., in the \textit{m}iddle) in each row. (Other options are \texttt{t} to put everything at the top and \texttt{b} to put everything at the bottom.) \texttt{rowsep} specifies vertical padding for each row. (Columns have a similar feature called, naturally enough, \texttt{colspec}.)
|
||
|
||
\subsection{Changing Row Types in \texttt{tabularray}}
|
||
|
||
The advantage of this system is that we can ensure that all our rows are typeset the same. However, we can also use a \texttt{rowspec} with a primitive \texttt{Q}-type row to change rows. For example, this code:
|
||
|
||
\begin{Verbatim}[]
|
||
rowspec = {Q[t], Q[b]}
|
||
\end{Verbatim}
|
||
|
||
\noindent{}allows us to have two rows with different qualities. In this case, the first row would be vertically aligned to the top of each cell, while the second row would be vertically aligned to the bottom of each cell.
|
||
|
||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{tabularray Example with rowspec}]
|
||
\begin{longtblr}
|
||
[
|
||
caption = {\texttt{tabularray} Table with \texttt{rowspec}},
|
||
label = {tb:rowspec}
|
||
]{
|
||
width = {0.6\textwidth},
|
||
colspec = { X[1,l] X[2,r] },
|
||
rowspec = { Q[t,azure9] Q[b,yellow9] },
|
||
hlines, vlines
|
||
}
|
||
This is some incredibly long text that is going to wrap around in this cell. & This is at the top.\\
|
||
This is at the bottom & This is some more incredibly long text that is going to wrap around in this cell. Gosh, this is an awful lot of meaningless text.
|
||
\end{longtblr}
|
||
\end{Verbatim}
|
||
|
||
\begin{longtblr}
|
||
[
|
||
caption = {\texttt{tabularray} Table with \texttt{rowspec}},
|
||
label = {tb:rowspec}
|
||
]{
|
||
width = {0.6\textwidth},
|
||
colspec = { X[1,l] X[2,r] },
|
||
rowspec = { Q[t] Q[b] },
|
||
hlines, vlines
|
||
}
|
||
This is some incredibly long text that is going to wrap around in this cell. & This is at the top.\\
|
||
This is at the bottom & This is some more incredibly long text that is going to wrap around in this cell. Gosh, this is an awful lot of meaningless text.
|
||
\end{longtblr}
|
||
|
||
Note that we also added color to each row, which I have omitted in the compiled example, since it would merely show up as shades of grey. (Colors could be added to each column in the \texttt{colspec} as well.) The \texttt{tabularray} package does recommend to use \texttt{colspec} for horizontal alignment, and \texttt{rowspec} for vertical alignment.
|
||
|
||
We've also simplified the line specification by using \texttt{hlines, vlines}. And we've made the table narrower by specifying \Verb+width = {0.6\textwidth}+.
|
||
|
||
The disadvantage of using \texttt{rowspec} is that we must include every row in the table, so if we have long tables, we will end up with a fairly extensive \texttt{rowspec}.
|
||
|
||
\subsection{Multiline Cells in \texttt{tabularray}}
|
||
|
||
If you want to break text in a cell, you can surround the cell contents with curly braces and use \Verb+\\+ where you want the break.
|
||
|
||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{tabularray Example with multiline cells}]
|
||
\begin{longtblr}
|
||
[
|
||
caption = {\texttt{tabularray} Table with Multiline Cells},
|
||
label = {tb:multiline}
|
||
]{
|
||
width = {0.6\textwidth},
|
||
colspec = { X[1,c] X[2,c] },
|
||
rows = {5mm, m, rowsep=1.5pt},
|
||
hlines, vlines
|
||
}
|
||
{ Red \\ Green \\ Blue } & Red Green Blue\\
|
||
{ Cyan \\ Magenta \\ Yellow } & Cyan Magenta Yellow\\
|
||
\end{longtblr}
|
||
\end{Verbatim}
|
||
|
||
\begin{longtblr}
|
||
[
|
||
caption = {\texttt{tabularray} Table with Multiline Cells},
|
||
label = {tb:multiline}
|
||
]{
|
||
width = {0.6\textwidth},
|
||
colspec = { X[1,c] X[2,c] },
|
||
rows = {5mm, m, rowsep=1.5pt},
|
||
hlines, vlines
|
||
}
|
||
{ Red \\ Green \\ Blue } & Red Green Blue\\
|
||
{ Cyan \\ Magenta \\ Yellow } & Cyan Magenta Yellow\\
|
||
\end{longtblr}
|
||
|
||
\subsection{Spanning Multiple Rows or Columns in \texttt{tabularray}}
|
||
|
||
It is also possible to have cells span multiple rows or columns by using the \Verb+\SetCell+ command.
|
||
|
||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{\texttt{tabularray} Table with Multi Rows and Columns}]
|
||
\begin{longtblr}
|
||
[
|
||
caption = {\texttt{tabularray} Table with Multi Rows and Columns},
|
||
label = {tb:multirow}
|
||
]{
|
||
width = {0.6\textwidth},
|
||
colspec = { X[1,c] X[2,c] X[1,c] },
|
||
rows = {5mm, m, rowsep=1.5pt},
|
||
hlines, vlines
|
||
}
|
||
\SetCell[r=2]{l}Pasta & \SetCell[c=2]{r} Sauce & Meatballs \\
|
||
Fish & Chips & Mushy Peas \\
|
||
\end{Verbatim}
|
||
|
||
\begin{longtblr}
|
||
[
|
||
caption = {\texttt{tabularray} Table with Multi Rows and Columns},
|
||
label = {tb:multirow}
|
||
]{
|
||
width = {0.6\textwidth},
|
||
colspec = { X[1,c] X[2,c] X[1,c] },
|
||
rows = {5mm, m, rowsep=1.5pt},
|
||
hlines, vlines
|
||
}
|
||
\SetCell[r=2]{l} Pasta & \SetCell[c=2]{r} Sauce & Meatballs \\
|
||
Fish & Chips & Mushy Peas \\
|
||
\end{longtblr}
|
||
|
||
The typical way of doing this requires use of the \Verb+\multicolumn+ command (which requires you to load the \texttt{multirow} package), and it requires that omitted cells must be empty. This is not the case with \texttt{tabularray}, however. As you can see from the source code, the words ``Meatballs'' and ``Fish'' have simply been omitted from the resulting table. We are also able to change the horizontal alignment by specifying it after we specify how many rows or columns to span. (I have found that if you do not specify an alignment, you still need to include an empty set of curly brackets or \LaTeX{} will throw out an error.)
|
||
|
||
|
||
\chapter{Math in \LaTeX{}}\label{ch:math}
|
||
|
||
\LaTeX{} has two environments that are useful for typesetting math: (\texttt{align} and \texttt{array}. In addition, there are other packages (in particular \texttt{amsmath} and \texttt{mathtools}) that greatly extend the power of LaTeX to handle mathematical typesetting, but they are beyond the scope of this book.
|
||
|
||
\section{Math Entry Modes}\label{math-entry-modes}
|
||
|
||
There are two types of \textit{entry modes} for math in \LaTeX{}. The first is \textbf{in-line mode}, which begins and ends with a dollar sign, and renders the math in the same line of text as the rest of the paragraph. For example,
|
||
|
||
\begin{Verbatim}[frame=lines, label=\fbox{In-Line Math Example}, framesep=3mm]
|
||
The Pythagorean Theorem is $x^2 + y^2 = z^2$.
|
||
\end{Verbatim}
|
||
|
||
\noindent{}renders as \\
|
||
|
||
\noindent{} The Pythagorean Theorem is $x^2 + y^2 = z^2$. \\
|
||
|
||
This is particularly useful if you want to include Greek characters in your text, because the code for the letter is simply the letter itself. For example, \verb+&\alpha$+ renders as $\alpha$. Need capital letters?\footnote{At least for the characters where the Greek and Latin alphabets \textit{don't} share a common character} Just capitalize it: \verb+$\Gamma$+ $\rightarrow \, \Gamma$.
|
||
|
||
Math in \LaTeX{} can also be shown in \textbf{display mode}, which renders the mathematics on a separate line. The entry mode begins with \verb+\[+ and ends with \verb+\]+. If we change our example up above to this:
|
||
|
||
\begin{Verbatim}[frame=lines, label=\fbox{Display Mode Math Example}, framesep=3mm]
|
||
The Pythagorean Theorem is \[x^2 + y^2 = z^2\]
|
||
\end{Verbatim}
|
||
|
||
\noindent{} we get this: \\
|
||
|
||
The Pythagorean Theorem is \[x^2 + y^2 = z^2\]
|
||
|
||
\section{Brackets and Parentheses}
|
||
|
||
Brackets and parentheses are common in mathematical formulas, so it is natural that \LaTeX{} has a number of ways of typesetting these.
|
||
|
||
\begin{longtblr}
|
||
[
|
||
caption = {Brackets and Parentheses in Math Mode},
|
||
label = {tb:brackpar}
|
||
]{
|
||
width = {114.3mm},
|
||
colspec = { X[2,l] X[2,l] X[1,l] },
|
||
hlines = {0.75pt,solid},
|
||
vline{1,4} = {0.75pt,solid},
|
||
rows = {5mm, m, rowsep=1.5pt},
|
||
row{1} = {font=\bfseries},
|
||
}
|
||
Type & Code & Example \\
|
||
Parentheses; round brackets & \Verb|(a+b)| & $(a+b)$ \\
|
||
Brackets; square brackets & \Verb|[a+b]| & $[a+b]$ \\
|
||
Braces; curly brackets & \Verb|\{a+b\}| & \{a+b\} \\
|
||
Angle brackets & \Verb|\langle a+b \rangle| & $\langle a+b \rangle$ \\
|
||
Pipes & \Verb:|a+b|: & $|a+b|$ \\
|
||
Double Pipes & \Verb:\|a+b\|: & $\|a+b\|$ \\
|
||
\end{longtblr}
|
||
|
||
|
||
\subsection{Adjusting Size Dynamically}
|
||
|
||
To dynamically size brackets and parentheses, you can use \verb+\left+ and \verb+\right+ commands. For example, this code
|
||
|
||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm]
|
||
\[
|
||
F=G \left( \frac{m_1 m_2}{r^2} \right)
|
||
\]
|
||
\end{Verbatim}
|
||
|
||
\noindent{}produces this output:
|
||
|
||
\[
|
||
F=G \left( \frac{m_1 m_2}{r^2} \right)
|
||
\]
|
||
|
||
\noindent{}Note that \textit{both} commands are required.
|
||
|
||
If you are writing a multi-line equations in an \texttt{align}, \texttt{align*}, or \texttt{aligned} environment, you must balance \verb+\left+ and \verb+\right+ both on each line, and on the same side of the \texttt{\&} delimiter. If an opening or closing bracket is not required, you can use an invisible bracket to balance them, i.e., \verb+\left.+ and \verb+\right.+.
|
||
|
||
\subsection{Adjusting Size Explicitly}
|
||
|
||
You can also control the size of brackets and parentheses explicitly:
|
||
|
||
\medskip
|
||
|
||
% Provide some additional spacing in this table; may move this to preamble later
|
||
%\setlength{\tabcolsep}{10pt}
|
||
%\renewcommand{\arraystretch}{1}
|
||
|
||
\noindent{}
|
||
\begin{longtblr}
|
||
[
|
||
caption = {Explicit Size Commands},
|
||
label = {tb:expsizcom}
|
||
]{
|
||
colspec = { X[7,l] X[2,c] },
|
||
hlines = {0.75pt,solid},
|
||
vlines = {0.75pt,solid},
|
||
rows = {12mm, m, rowsep=1.5pt},
|
||
row{1} = {6mm, font=\bfseries},
|
||
rowhead = 1
|
||
}
|
||
\textbf{Markup} & \textbf{Renders as} \\
|
||
|
||
\Verb+\bigl( \Bigl( \biggl( \Biggl(+ & $\bigl( ~\Bigl( ~\biggl( ~\Biggl($ \\
|
||
|
||
\Verb+\bigr] \Bigr] \biggr] \Biggr]+ & $\bigr] ~\Bigr] ~\biggr] ~\Biggr]$ \\
|
||
|
||
\Verb+\bigl\{ \Bigl\{ \biggl\{ \Biggl\{+ & $\bigl\{ ~\Bigl\{ ~\biggl\{ ~\Biggl\{$ \\
|
||
|
||
{ \Verb+\bigl \langle+ \hspace{2mm} \Verb+\Bigl \langle+ \\ \Verb+\biggl \langle+ \hspace{2mm} \Verb+\Biggl \langle+ } & $\bigl \langle ~\Bigl \langle ~\biggl \langle ~\Biggl \langle$ \\
|
||
|
||
{ \Verb+\bigr \rangle+ \hspace{2mm} \Verb+\Bigr \rangle+ \\ \Verb+\biggr \rangle+ \hspace{2mm} \Verb+\Biggr \rangle+ } & $\bigr \rangle ~\Bigr \rangle ~\biggr \rangle ~\Biggr \rangle$ \\
|
||
|
||
\Verb+\big| \Big| \bigg| \Bigg|+ & $\big| ~\Big| ~\bigg| ~\Bigg|$ \\
|
||
|
||
\Verb+\big\| \Big\| \bigg\| \Bigg\|+ & $\big\| ~\Big\| ~\bigg\| ~\Bigg\|$ \\
|
||
|
||
{ \Verb+\bigl \lceil+ \hspace{2mm} \Verb+\Bigl \lceil+ \\ \Verb+\biggl \lceil+ \hspace{2mm} \Verb+\Biggl \lceil+ } & $\bigl \lceil ~\Bigl \lceil ~\biggl \lceil ~\Biggl \lceil$ \\
|
||
|
||
{ \Verb+\bigr \rceil+ \hspace{2mm} \Verb+\Bigr \rceil+ \\ \Verb+\biggr \rceil+ \hspace{2mm} \Verb+\Biggr \rceil+ } & $\bigr \rceil ~\Bigr \rceil ~\biggr \rceil ~\Biggr \rceil$ \\
|
||
|
||
{ \Verb+\bigl \lfloor+ \hspace{2mm} \Verb+\Bigl \lfloor+ \\ \Verb+\biggl \lfloor+ \hspace{2mm} \Verb+\Biggl \lfloor+ } & $\bigl \lfloor ~\Bigl \lfloor ~\biggl \lfloor ~\Biggl \lfloor$ \\
|
||
|
||
{ \Verb+\bigr \rfloor+ \hspace{2mm} \Verb+\Bigr \rfloor+ \\ \Verb+\biggr \rfloor+ \hspace{2mm} \Verb+\Biggr \rfloor+ } & $\bigr \rfloor ~\Bigr \rfloor ~\biggr \rfloor ~\Biggr \rfloor$ \\
|
||
\end{longtblr}
|
||
|
||
|
||
\section{The \texttt{align} Environment}
|
||
|
||
You can use the \texttt{align} environment to typeset long equations and formulas and get them to line up nicely. This is great for solving equations and proofs.
|
||
|
||
Break your lines with \verb+\\+ and use \texttt{\&} to show where the equations should align.
|
||
|
||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{align Example}]
|
||
\begin{align}
|
||
a_1 & = b_1+c_1\\
|
||
a_2 & = b_2+c_2-d_2+e_2\\
|
||
a_2+d_2-e_2 & = b_2+c_2
|
||
\end{align}
|
||
|
||
\begin{align*}
|
||
a_1 & = b_1+c_1\\
|
||
a_2 & = b_2+c_2-d_2+e_2\\
|
||
a_2+d_2-e_2 & = b_2+c_2
|
||
\end{align*}
|
||
\end{Verbatim}
|
||
|
||
\begin{align}
|
||
a_1 & = b_1+c_1\\
|
||
a_2 & = b_2+c_2-d_2+e_2\\
|
||
a_2+d_2-e_2 & = b_2+c_2
|
||
\end{align}
|
||
|
||
\begin{align*}
|
||
a_1 & = b_1+c_1\\
|
||
a_2 & = b_2+c_2-d_2+e_2\\
|
||
a_2+d_2-e_2 & = b_2+c_2
|
||
\end{align*}
|
||
|
||
\bigskip
|
||
|
||
A couple of things to note:
|
||
|
||
\begin{itemize}[noitemsep]
|
||
\item \texttt{align} is itself a math environment, so you don't need to use a separate math entry mode as described previously.
|
||
\item \texttt{align} (no asterisk) produces numbered equations, whereas \texttt{align*} produces unnumbered equations.
|
||
\end{itemize}
|
||
|
||
|
||
\section{The \texttt{array} Environment}
|
||
|
||
You can typeset matrices and other similar objects using an \texttt{array} environment. A couple of things to note:
|
||
|
||
\begin{itemize}[noitemsep]
|
||
\item \texttt{array} can only be used in a math environment.
|
||
\item You must declare the number and alignment of the columns by using something like this:\vspace{0.5em} \\ \vspace{0.5em} \verb+\begin{array}{crl}+ \\ In this instance, we are declaring one centered column, one right-aligned column, and one left-aligned column.
|
||
\end{itemize}
|
||
|
||
In the example below, I've chosen animal names to make the column alignment more explicit.
|
||
|
||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{array Example}]
|
||
\[ % Begin math environment
|
||
Zoo~animals = \left\{ \begin{array}{crl}
|
||
lion & hippopotamus & gnu \\
|
||
elephant & zebra & kangaroo \\
|
||
bear & camel & naked~mole~rats
|
||
\end{array}\right\}
|
||
\] % End math environment
|
||
\end{Verbatim}
|
||
|
||
\[ % Begin math environment
|
||
Zoo~animals = \left\{ \begin{array}{crl}
|
||
lion & hippopotamus & gnu \\
|
||
elephant & zebra & kangaroo \\
|
||
bear & camel & naked~mole~rats
|
||
\end{array}\right\}
|
||
\] % End math environment
|
||
|
||
\paragraph{Note:} Because the \texttt{array} environment is designed for math applications, rather than a text application like our example, I had to use a $\sim$ to add the spaces in ``Zoo animals'' and ``naked mole rats''.
|
||
|
||
If the built-in \texttt{array} environment cannot do all that you want, use the \texttt{amsmath} package and its \texttt{matrix} environment, which provides more options.
|
||
|
||
\section{Special Math Environments}
|
||
|
||
You can use the \texttt{nicefrac} package to get fractions with a diagonal slash. This is an ordinary fraction inline (using the \texttt{frac} command): $\frac{3}{4}$, and this is a ``nice'' fraction inline (using the \texttt{nicefrac} command): $\nicefrac{3}{4}$.
|
||
|
||
The following array shows the difference between ordinary and ``nice'' fractions in display mode:
|
||
|
||
\[\begin{array}{ccc}
|
||
|
||
\frac{3}{4} & & \nicefrac{3}{4}
|
||
|
||
\end{array}\]
|
||
|
||
|
||
\chapter{Images}\label{ch:images}
|
||
|
||
You can use images in \LaTeX{}, but it requires the \texttt{graphicx} package, as this is not something that \LaTeX{} can handle on its own. You will need to include this line in your preamble:
|
||
|
||
\begin{Verbatim}[]
|
||
\usepackage{graphicx}
|
||
\end{Verbatim}
|
||
|
||
\section{The Folder Path to Images}
|
||
|
||
The \texttt{graphicx} allows you to specify where your images are located by using the \texttt{graphicspath} command in the preamble. You can specify multiple paths with this command.
|
||
|
||
\begin{Verbatim}[]
|
||
\graphicspath{ {./images/}, {./standalone/build/} }
|
||
\end{Verbatim}
|
||
|
||
The above command will specify two paths \textit{relative} to the directory your \texttt{.tex} file is located. Technically speaking the relative delimiter (\texttt{./}) is not required, but it's a best practice to include it if you are going to include other \texttt{.tex} files that are located in folders within your working directory, because \LaTeX{} can become confused about the location of images.
|
||
|
||
You can also specify absolute paths to your files. For example, on a Windows system, you would use something like
|
||
|
||
\begin{Verbatim}[]
|
||
\graphicspath{ {c:/user/latex/images/} }
|
||
\end{Verbatim}
|
||
|
||
\noindent{}and on Unix-type systems (Linux, MacOS), you would use something like
|
||
|
||
\begin{Verbatim}[]
|
||
\graphicspath{ {/home/user/latex/images/} }
|
||
\end{Verbatim}
|
||
|
||
\section{Adding and Scaling an Image}
|
||
|
||
To include an image, use the \texttt{includgraphics} command:
|
||
|
||
\begin{Verbatim}[]
|
||
\includegraphics{birb}
|
||
\end{Verbatim}
|
||
|
||
\noindent{}which includes our ``birb'' picture:
|
||
|
||
\includegraphics{birb}
|
||
|
||
A couple of things to note: First, because of our \texttt{graphicspath}, this file could be located either in \texttt{images} or \texttt{standalone/build}. Second, we did not need to specify the file extension.
|
||
|
||
We can also scale the image by using a \texttt{scale} option, where 1 is equivalent to 100%:
|
||
|
||
\begin{Verbatim}[]
|
||
\includegraphics[scale=0.5]{birb}
|
||
\includegraphics[scale=0.9]{birb}
|
||
\includegraphics[scale=1.5]{birb}
|
||
\end{Verbatim}
|
||
|
||
\includegraphics[scale=0.5]{birb}
|
||
\includegraphics[scale=0.9]{birb}
|
||
\includegraphics[scale=1.5]{birb}
|
||
|
||
While it may be tempting to start with a huge image and simply scale it down, the entire image will be included in the final pdf document and can greatly increase its size. If you intend to distribute your document electronically, it helps to scale your image as close as possible to the size you actually need before including it in your file.
|
||
|
||
Note that images act like words—they neither float, and follow each other on the same line. This means that we could use something like this \Verb+\includegraphics[sca+ \Verb+le=1]{seahorse}+ \includegraphics[scale=1]{seahorse} to include inline graphics. However, this can affect the line spacing in our paragraph, as our ``seahorse'' image shows. We can adjust this a little bit by scaling the image appropriately, as in this example: \includegraphics[scale=0.4]{seahorse}, which I've inserted using \Verb+\includegraphics[scale=0.4]{seahorse}+.
|
||
|
||
You can also scale the x and y dimensions separately:
|
||
|
||
\begin{Verbatim}[]
|
||
\includegraphics[width=0.5\textwidth, height=1cm]{birb}
|
||
\end{Verbatim}
|
||
|
||
\includegraphics[width=0.5\textwidth, height=1cm]{birb}
|
||
|
||
\section{Rotating Images}
|
||
|
||
We can also use an \texttt{angle} option to rotate our images:
|
||
|
||
\begin{Verbatim}[]
|
||
\includegraphics[angle=0]{seahorse}
|
||
\includegraphics[angle=90]{seahorse}
|
||
\includegraphics[angle=180]{seahorse}
|
||
\includegraphics[angle=270]{seahorse}
|
||
\includegraphics[angle=360]{seahorse}
|
||
\end{Verbatim}
|
||
|
||
\includegraphics[angle=0]{seahorse}
|
||
\includegraphics[angle=90]{seahorse}
|
||
\includegraphics[angle=180]{seahorse}
|
||
\includegraphics[angle=270]{seahorse}
|
||
\includegraphics[angle=360]{seahorse}
|
||
|
||
\section{Captions and Floats}
|
||
|
||
To add a caption, we need to wrap our image in a \texttt{figure} environment:
|
||
|
||
\begin{Verbatim}[]
|
||
\begin{figure}[h]
|
||
\includegraphics[scale=0.5]{birb}
|
||
\caption{Birb.}
|
||
\end{figure}
|
||
\end{Verbatim}
|
||
|
||
\begin{figure}[h]
|
||
\includegraphics[scale=0.5]{birb}
|
||
\caption{Birb.}
|
||
\end{figure}
|
||
|
||
A couple of things to note here: First, while the actual image is not very large, the \texttt{figure} environment is the width of the page, meaning that the caption does not actually align with the image. Second, we passed the \texttt{[h]} option to the \texttt{figure} environment, because it is a float, allowing \LaTeX{} to put the image where it thinks it best fits. This is not always a good thing.
|
||
|
||
\begin{longtblr}
|
||
[
|
||
caption = {\texttt{figure} Positioning Parameters},
|
||
label = {tb:figpospar}
|
||
]{
|
||
width = {\textwidth},
|
||
colspec = { X[1,l] X[6,l] },
|
||
hlines = {0.75pt,solid},
|
||
vline{1,3} = {0.75pt,solid},
|
||
rows = {5mm, m, rowsep=1.5pt}
|
||
}
|
||
h & Place the float \textbf{here}, approximately where it appears in the file. \\
|
||
t & At the top of the page \\
|
||
b & At the bottom of the page \\
|
||
p & On a special page for floats only \\
|
||
! & Override \LaTeX{}'s parameters for determining the float position
|
||
\end{longtblr}
|
||
|
||
Note that the \texttt{!} parameter can be combine with the \texttt{h} parameter. The \texttt{float} package also introduces the \texttt{[H]} parameter, which is roughly equivalent to \texttt{h!}, but can be problematic.
|
||
|
||
\section{Wrapping Text Around Figures}
|
||
|
||
If you have a small figure, it's often better to wrap text around it by placing it in a \texttt{wrapfigure} environment.
|
||
|
||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{Wrapping Text Around an Image}]
|
||
\begin{wrapfigure}[9]{r}{0.25\textwidth}
|
||
\centering
|
||
\includegraphics[scale=0.5]{birb}
|
||
\caption{Birb.}
|
||
\label{img:birb3}
|
||
\end{wrapfigure}
|
||
\end{Verbatim}
|
||
|
||
\begin{wrapfigure}[9]{r}{0.25\textwidth}
|
||
\centering
|
||
\includegraphics[scale=0.5]{birb}
|
||
\caption{The same birb.}
|
||
\label{img:birb3}
|
||
\end{wrapfigure}
|
||
|
||
The \texttt{wrapfigure} environment requires the \texttt{wrapfig} package to be loaded in the preamble. It has two required options: a position parameter that tells it where to place the image relative to the text, and a width parameter than tells it how wide to make container that will hold your image. If your image is larger than the width of the \texttt{wrapfigure} environment, it will simply skip to the next available space, which means it probably won't fit where you want it. Be sure to scale your images appropriately. (The options for the \texttt{position} parameter is shown in table \ref{tb:wrapfigpospar} on page \pageref{tb:wrapfigpospar}.)
|
||
|
||
\begin{wrapfigure}[6]{l}[5mm]{0.25\textwidth}
|
||
\centering
|
||
\includegraphics[scale=0.5]{birb}
|
||
\caption{Birb with overhang.}
|
||
\label{img:birb4}
|
||
\end{wrapfigure}
|
||
|
||
We've also used the \Verb+\centering+ command to center the image over the caption. In this case, you should avoid using a \texttt{centering} environment, because that will introduce additional space above and below the figure.
|
||
|
||
It also has an optional \texttt{lineheight} parameter, for those instances where you need to eliminate some extra space from beneath the figure. I've used \texttt{[9]} in the example above to eliminate some extra white space underneath Figure \ref{img:birb3}. There is an additional optional \texttt{overhang} parameter which can be used to push an image out into the margin. Notice that the bird on the left has an overhang of 5 millimeters.
|
||
|
||
The options are this order (and be sure to note the alternating use of curly brackets and square brackets):
|
||
|
||
\begin{Verbatim}[]
|
||
\begin{wrapfigure}[<lineheight>]{<placement>}[<overhang>]{<width>}
|
||
\end{wrapfigure}
|
||
\end{Verbatim}
|
||
|
||
The complete code for image \ref{img:birb4} looks like:
|
||
|
||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{\texttt{wrapfigure} Example with all Parameters}]
|
||
\begin{wrapfigure}[6]{l}[5mm]{0.25\textwidth}
|
||
\centering
|
||
\includegraphics[scale=0.5]{birb}
|
||
\caption{Birb with overhang.}
|
||
\label{img:birb4}
|
||
\end{wrapfigure}
|
||
\end{Verbatim}
|
||
|
||
Note that I've changed the \texttt{lineheight} parameter from 9 to 6 lines to avoid having the image overflowing onto the new page. (You can see that the caption actually sits below the last line of text, which was causing the first line of text on this page to be pushed to the right the width of the image. This can be a fiddly process, especially with images at the bottom of a page.)
|
||
|
||
If the \texttt{wrapfigure} package is not working for you, there is also the much older \texttt{picins} package.
|
||
|
||
\begin{longtblr}
|
||
[
|
||
caption = {\texttt{wrapfig} Position Parameters},
|
||
label = {tb:wrapfigpospar}
|
||
]{
|
||
width = {\textwidth},
|
||
colspec = { X[1,c] X[1,c] X[7,l] },
|
||
hlines = {0.75pt,solid},
|
||
vline{1,3,4} = {0.75pt,solid},
|
||
rows = {5mm, m, rowsep=1.5pt}
|
||
}
|
||
r & R & Right side of text \\
|
||
l & L & Left side of text \\
|
||
i & I & Inside edge of a \texttt{twoside} document \\
|
||
o & O & Outside edge of a \texttt{twoside} document
|
||
\end{longtblr}
|
||
|
||
\noindent{}Use the lowercase version of the parameter when you want to place the figure at the same point in your document that it is in your file. Use the uppercase version when you want to let it float.
|
||
|
||
|
||
\chapter{References}\label{ch:referencing}
|
||
|
||
\section{Internal (Cross) References}
|
||
|
||
To refer to something somewhere else in your document, you first have to label it using the \verb+\label{}+ command:\label{example1}
|
||
|
||
\begin{Verbatim}
|
||
This is a line of text. \label{example1}
|
||
\end{Verbatim}
|
||
|
||
To refer to it, you can use \verb+\ref{example1}+. This will insert either the section number, the page number, the equation number, or the figure number, depending on what you attached the label to.
|
||
|
||
If you \textbf{must} refer to a page number, use \verb+\pageref{example1}+.
|
||
|
||
\begin{Verbatim}[frame=lines,framesep=3mm, breaklines=true, label=\fbox{Cross-Referencing Example}]
|
||
Internal references (i.e., cross-references) are explained in section \ref{example1} on page \pageref{example1}.
|
||
\end{Verbatim}
|
||
|
||
\noindent{}produces this output:
|
||
|
||
\klab{8pt}{Cross-Referencing Example}{8pt}
|
||
|
||
\noindent{}Internal references (i.e., cross-references) are explained in section \ref{example1} on page \pageref{example1}.
|
||
|
||
\krule{8pt}{8pt}
|
||
|
||
I very rarely use cross references and so I am not terribly adept at their many uses. They are a powerful feature of \LaTeX{} though, so if you are interested, I urge you to visit \kref{https://en.wikibooks.org/wiki/LaTeX/Labels_and_Cross-referencing}{https://en.wikibooks.org/wiki/LaTeX/Labels\_and\_Cross-referencing} for more detailed information.
|
||
|
||
Keep in mind that you will need to compile your document \textbf{twice}. The first time \LaTeX{} will figure out which page each \texttt{label} is on. The second time, it will plug those pages numbers into the \texttt{ref} and \texttt{pageref} commands.
|
||
|
||
\section{Bibliographies}
|
||
|
||
\LaTeX{} has two major ways of handling bibliographies: an embedded system using the \texttt{bibitem} command, and an external system using \texttt{BibTeX}. Both systems have their advantages and disadvantages.
|
||
|
||
The advantage of using the embedded system is that it is simpler and therefore easier to understand and use. It also compiles faster. The disadvantage is that it is not as powerful as \texttt{BibTex}. But it will suffice quite nicely if you are writing a limited number of documents.
|
||
|
||
The advantage of using \texttt{BibTex} is that it is much more powerful, and if you are writing longer documents, or related groups of documents that pull from the same group of references, it greatly simplifies managing your bibliography. That power comes at a price, however, as it is more complicated (thus the ways to make mistakes are more numerous) and it does take longer to compile.
|
||
|
||
Describing either system is beyond the scope of this booklet. However, Wikibooks has an excellent tutorial at \kref{https://en.wikibooks.org/wiki/LaTeX/Bibliography_Management}{https://en.wikibooks.org/wiki/LaTeX/Biblio\\graphy\_Management}.
|
||
|
||
\bigskip
|
||
|
||
\noindent{}Keep in mind that the command you will need to build that bibliography is\footnote{I am adding this here for my own reference more than anything else.}
|
||
|
||
\begin{verbatim}
|
||
bibtex build/lbol
|
||
\end{verbatim}
|
||
|
||
\paragraph{Note:} If the bibliography tools that are built into \LaTeX{} seem like overkill to you, consider whether or not your document actually \textit{needs} a bibliography. I could have done it for this book, but it made much more sense to me to simply add links in footnotes. If you are writing for a publication, or writing a thesis or dissertation, you will need to follow the style guide provide. But in most other circumstances, the choice will be yours.
|
||
|
||
|
||
\chapter{Macros}
|
||
|
||
\section{New Commands}
|
||
|
||
If you often use a group of commands together, you can group them into a single command by using the \verb+\newcommand[]{}+ command in the preamble.
|
||
|
||
The square brackets contains a number that indicates the number of variables you are going to pass to the new command. The curved brackets contain the new command. For example, this code in the preamble:
|
||
|
||
\begin{verbatim}
|
||
\newcommand\krule[2]{\vspace{#1}\hrule\vspace{#2}}
|
||
\end{verbatim}
|
||
|
||
\noindent{}defines a new command ``krule'' that places a horizontal line (\verb+\hrule+) with a vertical space (\verb+\vspace+) above and below it. It contains two variables, one for the height of the first vertical space and one for the height of the second vertical space. In practice, this rule would be used like this:
|
||
|
||
\begin{verbatim}
|
||
\krule{12pt}{6pt}
|
||
\end{verbatim}
|
||
|
||
\paragraph{Note:} In this format, you must always pass the units to the new command when you execute it. You can also define this rule to have the units built into the new command like this:
|
||
|
||
\begin{verbatim}
|
||
\newcommand\krule[2]{\vspace{#1pt}\hrule\vspace{#2pt}}
|
||
\end{verbatim}
|
||
|
||
and to use it, you would enter
|
||
|
||
\begin{verbatim}
|
||
\krule{12}{6}
|
||
\end{verbatim}
|
||
|
||
This means less typing, but you are always restricted to using the same units.
|
||
|
||
\chapter{Installation}
|
||
|
||
\section{Installing \LaTeX{}}
|
||
|
||
Nope. I'm not going to discuss this subject, because this would make this a very long book, and it would also make it a quickly outdated and inaccurate book. Your best approach would be to do a web search for your operating system + ``\texttt{install latex}''. If you want a GUI (and who doesn't?), search for your operating system + ``\texttt{install latex gui}''.
|
||
|
||
\section{Installing \LaTeX{} Packages on Ubuntu}
|
||
|
||
\paragraph{Caveat:} This worked for me on Ubuntu 22.04. I cannot guarantee it will work for you. I cannot even guarantee that it will work for me again.
|
||
|
||
\subsubsection{Method 1}
|
||
|
||
Every once in a while I run into a package that I want to use with \LaTeX{} that is not installed on my system. Alas, there is no easy way to do this, at least that I found. \textit{Later}, I always thought. I'll figure that out later.
|
||
|
||
\textit{Later} became \textit{today} when I wanted to use the \texttt{harmony} package to produce some music symbols but couldn't, because it wasn't installed on my system. It took some doing, but I finally figured it out. Here's what I did:
|
||
|
||
First, I downloaded the \texttt{harmony} package from \href{https://www.ctan.org/pkg/harmony}{\texttt{https://www.ctan.org \\ /pkg/harmony}} and unpacked the archive. That was easy enough.
|
||
|
||
Next, I had to figure out where to put it. I ran this command:
|
||
|
||
\begin{verbatim}
|
||
$ kpsewhich -var-value TEXMFLOCAL
|
||
\end{verbatim}
|
||
|
||
which gave me this location:
|
||
|
||
\begin{verbatim}
|
||
/usr/local/share/texmf
|
||
\end{verbatim}
|
||
|
||
Following the directions I found at \href{https://jvgomez.github.io/pages/manually-install-latex-packages-in-ubuntu.html}{\texttt{https://jvgomez.github.io/pages/manu\\ally-install-latex-packages-in-ubuntu.html}} I entered that directory using \texttt{sudo} and created the following directory structure:
|
||
|
||
\begin{verbatim}
|
||
/usr/local/share/texmf/tex/latex/harmony
|
||
\end{verbatim}
|
||
|
||
I then copied my files over from the unpacked \texttt{harmony} files:
|
||
|
||
\begin{verbatim}
|
||
$ sudo cp * /usr/local/share/texmf/tex/latex/harmony
|
||
\end{verbatim}
|
||
|
||
I then had to update the search path to make my system aware of the new package:
|
||
|
||
\begin{verbatim}
|
||
$ sudo mktexlsr
|
||
\end{verbatim}
|
||
|
||
This should have been the end of it, but the \texttt{harmony} package requires a certain set of fonts to do its work. After a bit of searching, I found them at \href{https://ctan.org/tex-archive/fonts/musixtex-fonts}{\texttt{https://ctan.org/tex-archive/fonts/musixtex-fonts}}.
|
||
|
||
Fortunately, that package had a pdf document that described how to install the fonts. I started by copying the ``fonts'' folder over the \texttt{texmf} directory:
|
||
|
||
\begin{verbatim}
|
||
$ cp fonts /usr/local/share/texmf
|
||
\end{verbatim}
|
||
|
||
And then I updated the search path and then the font-map files with these commands:
|
||
|
||
\begin{verbatim}
|
||
$ sudo mktexlsr
|
||
$ sudo udpmap-user --enable MixedMap musix.map
|
||
\end{verbatim}
|
||
|
||
Like I've said elsewhere, I'm running a recently updated Ubuntu 22.04 system, and this worked for me. It may work for you, it may not. I can't even guarantee that it will work for me next time. (I suspect having a generic folder name like ``fonts'' may cause me issues down the road if I ever want to install some other LaTeX fonts.) But if I got it to work once, I'm pretty sure I can get it to work again. We shall see.
|
||
|
||
\subsubsection{Method 2}
|
||
|
||
A perhaps easier (and certainly more \textit{portable}) way of installing \LaTeX{} packages is to add them to a local directory along the lines of:
|
||
|
||
\begin{verbatim}
|
||
/home/user/texmf
|
||
\end{verbatim}
|
||
|
||
This is how I installed the \textit{musixtex} package, and it far simpler than what I have described in method 1.
|
||
|
||
First, I downloaded the package and unpacked it. Then I copied its contents into my \texttt{texmf} directory, and finally updated the filename database:
|
||
|
||
\begin{verbatim}
|
||
$ cp * ~/texmf
|
||
$ texhash ~/texmf
|
||
\end{verbatim}
|
||
|
||
|
||
\chapter{Miscellaneous}
|
||
|
||
\section{Special Characters in \LaTeX{}}
|
||
|
||
There are ten characters that have special meaning in \LaTeX{}. To typeset:
|
||
|
||
\begin{center}
|
||
\& \; \% \; \$ \; \# \; \_ \; \{ \; \}
|
||
\end{center}
|
||
|
||
\noindent{}you have to prepend them with a backslash (\textbackslash).
|
||
|
||
\medskip
|
||
|
||
\noindent{}To typeset:
|
||
|
||
\begin{center}
|
||
\textasciitilde \hspace{2mm} \textasciicircum \hspace{2mm} \textbackslash
|
||
\end{center}
|
||
|
||
\noindent{}you have to use the macros \verb|\textasciitilde|, \verb|\textasciicircum|, and \\ \verb|\textbackslash|.
|
||
|
||
You can also dip in and out of math mode to get these characters, but the font will be different, and so they will have a different appearance to the rest of your text. See the next section for some examples.
|
||
|
||
\section{\LaTeX{} Units}
|
||
|
||
\LaTeX{} is pretty loose about which unit you use. You can use any of the following pretty much interchangeably, depending on what you are measuring.
|
||
|
||
\begin{longtblr}
|
||
[
|
||
caption = {\LaTeX{} Units and Lengths},
|
||
label = {tb:units}
|
||
]{
|
||
width = {0.8\textwidth},
|
||
colspec = { X[1,l] X[3,l] },
|
||
hlines = {0.75pt,solid},
|
||
vline{1,3} = {0.75pt,solid},
|
||
rows = {5mm, m, rowsep=1.5pt}
|
||
}
|
||
pt & point, the default length unit, equal to approximately 0.3515mm \\
|
||
mm & millimeters \\
|
||
cm & centimeters \\
|
||
in & inches \\
|
||
ex & the height of the letter \texttt{x} in the current font \\
|
||
em & the width of the letter \texttt{m} in the current font \\
|
||
\Verb+\columnsep+ & the distance between columns \\
|
||
\Verb+\columnwidth+ & the width of the column \\
|
||
\Verb+\linewidth+ & the width of the line in the current environment \\
|
||
\Verb+\paperwidth+ & the width of the page \\
|
||
\Verb+\paperheight+ & the height of the page \\
|
||
\Verb+\textwidth+ & the width of the text \\
|
||
\Verb+\textheight+ & the height of the text \\
|
||
\Verb+\unitlength+ & the unit of length in the \texttt{picture} environment
|
||
\end{longtblr}
|
||
|
||
\section{Symbols}
|
||
|
||
As you might expect, \LaTeX{} excels at typesetting symbols. Below is a \textbf{short} list of the symbols available in \LaTeX{}. Keep in mind that they may have different commands in text mode than in math mode, and that they will also appear differently in those two modes due to the different fonts those modes use.
|
||
|
||
For additional information, consult the \textit{very} extensive ``Comprehensive \LaTeX{} Symbol List'' which you can find at \kref{https://ctan.org/pkg/comprehensive?lang=en}{https://ctan.org/pkg/comprehensive?lang=\\en}.
|
||
|
||
\begin{longtblr}
|
||
[
|
||
caption = {Miscellaneous Symbols in \LaTeX{} },
|
||
label = {tb:miscsym},
|
||
theme = {custom1}
|
||
]{
|
||
width = {\textwidth},
|
||
colspec = {
|
||
X[1.5,l]
|
||
X[1,c]
|
||
X[1,c]
|
||
X[1,c]
|
||
},
|
||
hlines = {0.75pt,solid},
|
||
vline{1,5} = {0.75pt,solid},
|
||
rows = {5mm, m, rowsep=1.5pt, },
|
||
row{1} = {font=\bfseries},
|
||
rowhead = 1,
|
||
}
|
||
Description & Appearance & Text Mode & Math Mode \\
|
||
Asterisk & $\ast$ & & \Verb+\ast+ \\
|
||
Bowtie & $\bowtie$ & & \Verb+\bowtie+ \\
|
||
Bullet & $\bullet$ & \Verb+\textbullet+ & \Verb+\bullet+ \\
|
||
Circle & $\circ$ & & \Verb+\circ+ \\
|
||
Circle within a circle & $\circledcirc$ & & \Verb+\circledcirc+ \\
|
||
Copyright & \copyright & \copyright & \copyright \\
|
||
Degree symbol & <Example>$^{\circ}$ & \Verb+$^{\circ}$+ & \\
|
||
Dot & $\centerdot$ & & \Verb+\centerdot+ \\
|
||
Dots, diagonal & $\ddots$ & & \Verb+\ddots+ \\
|
||
Dots, vertical & $\vdots$ & & \Verb+\vdots+ \\
|
||
Infinity & $\infty$ & & \Verb+\infty+ \\
|
||
Left multiply & $\ltimes$ & & \Verb+\ltimes+ \\
|
||
Perpendicular & $\perp$ & & \Verb+\perp+ \\
|
||
Proportional to & $\propto$ & & \Verb+\propto+ \\
|
||
Right multiply & $\rtimes$ & & \Verb+\rtimes+ \\
|
||
Square, empty & $\square$ & & \Verb+\square+ \\
|
||
Square, solid & $\blacksquare$ & & \Verb+\blacksquare+ \\
|
||
Star & $\star$ & & \Verb+\star+ \\
|
||
Star, large & $\bigstar$ & & \Verb+\bigstar+ \\
|
||
Suit, club\ & $\clubsuit$ & & \Verb+\clubsuit+ \\
|
||
Suit, diamond & $\diamondsuit$ & & \Verb+\diamondsuit+ \\
|
||
Suit, heart & $\heartsuit$ & & \Verb+\heartsuit+ \\
|
||
Suit, space & $\spadesuit$ & & \Verb+\spadesuit+ \\
|
||
Variable sized proportional to & $\varpropto$ & & \Verb +\varpropto+ \\
|
||
Wedge & $\wedge$ & & \Verb+\wedge+ \\
|
||
& $ $ & & \Verb++ \\
|
||
& $ $ & & \Verb++ \\
|
||
& $ $ & & \Verb++ \\
|
||
\end{longtblr}
|
||
|
||
|
||
|
||
|
||
\chapter{Troubleshooting}
|
||
|
||
\section{Minimal Working Examples}
|
||
|
||
In particular with \LaTeX{}, it can help if you create an MWE (minimal working example) when working with new things, to rule out interference from other bits of code.
|
||
|
||
For example, the preamble to this document is currently 135 lines. (This includes blank lines to make it easy to scan.) But if I were trying to diagnose some page layout issues with the \texttt{geometry} package, an MWE might look like this:
|
||
|
||
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{MWE Example}]
|
||
\documentclass[twoside, 9pt]{extreport}
|
||
\usepackage[
|
||
paperheight=8.5in,
|
||
paperwidth=5.5in,
|
||
margin=0.5in
|
||
]{geometry}
|
||
\usepackage{lipsum}
|
||
|
||
\begin{document}
|
||
\lipsum[1-20]
|
||
\end{document}
|
||
\end{Verbatim}
|
||
|
||
I now have 11 lines to deal with instead of the current 1,603 lines I have. This means I am focused solely on solving this issue with the \texttt{geometry} package and nothing else. If I suspect that another package is causing the problem, I can always add in that package and run a test with it. And because I am only loading two packages, the pdf compiles very quickly.
|
||
|
||
\section{\texttt{\}\%} is Your Best Friend}
|
||
|
||
If you are getting an error in a long line (long because it has a lot of commands in it), you can try commenting out the entire line by placing a \texttt{\%} at the beginning of it. If that clears up the problem, you can isolate which command is causing the issue by placing \texttt{\}\%} at the end of next to the last command and recompiling. If the error goes away then you know the problem lies in the last command.
|
||
|
||
If it doesn't, move the to the end of the second next to the last command and try again. In this way, you can determine which command is causing the problem.
|
||
|
||
Keep in mind that the error may not be in the line in question. The line where \LaTeX{} is indicating where it is stumbling. The error may be in a variable you called somewhere else, or in how you loaded the package in the preamble.
|
||
|
||
\section{Learn How to Ask Good Questions}
|
||
|
||
If you get serious about learning anything, you'll eventually find yourself with a problem which you can't solve, which means that you will need to ask for help, most likely in one of forums listed on page \pageref{othersources}. If you spend any amount of time on those forums, you will quickly learn (if you are observant) that there are good ways to ask questions and bad ways to ask a question.
|
||
|
||
In general, a good question has three parts:
|
||
|
||
\begin{enumerate}[noitemsep]
|
||
\item A statement of what you are trying to achieve.
|
||
\item What you have already done to achieve that.
|
||
\item What results you are actually getting.
|
||
\end{enumerate}
|
||
|
||
\noindent{}Examples of bad questions include:
|
||
|
||
\begin{itemize}[noitemsep]
|
||
\item Questions without an MWE.
|
||
\item Saying ``it doesn't work'' but not explaining what you were expecting and/or what results you are getting.
|
||
\item Homework questions that are basically ``how do you do \texttt{<thing>}?'' but for which it is quite apparent that you have done no actual research yourself, much less tried to do yourself.
|
||
\item Thinly disguised complaints about how \LaTeX{} works, or the structure of the forum, or how a package is documented, etc.\footnote{To be fair, not all packages are documented equally. \LaTeX{} has contributors from all over the globe, and the package documentation which \textit{you are reading in English} may well have been written by someone for whom English is a second, third, or fourth language. Asking for \textit{clarification} about something in the documentation is perfectly fine; \textit{complaining} about it is not.}
|
||
\item Questions which could be very easily answered by simply reading the package documentation.
|
||
\end{itemize}
|
||
|
||
\end{document}
|