Numerous updates and corrections

This commit is contained in:
Kenneth John Odle 2023-11-01 09:55:59 -04:00
parent 3ad1329911
commit 1850763fe4

View File

@ -190,7 +190,7 @@ I may do a second volume of this, or I may simply do a second edition. If I do,
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{A Caveat} 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.
\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:
@ -201,7 +201,7 @@ Second, some things will look differently and behave differently for you dependi
\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 flatted 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.
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.
@ -450,7 +450,7 @@ You can also change the size of a portion of text locally. These are the default
label = {tb:localsizecommands}
]{
width = {10cm},
colspec = { X[1,l] X[1,c] },
colspec = { X[1,c] X[1,c] },
hlines = {0.75pt,solid},
vlines = {0.75pt,solid},
rows = {5mm, m, rowsep=1.5pt}
@ -582,7 +582,7 @@ The usual way to define a page size is to pass it as an option to the document c
label = {tbl:defpapersizes}
]{
width = {114.3mm},
colspec = { X[1.4,l] X[1,l] X[1,l] X[0.8,l] },
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}
@ -668,7 +668,7 @@ Which gives us something like this:
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{} 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/what-\\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-Jan\\uary/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}}}
\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''.
@ -684,7 +684,7 @@ In most document classes, the ``chapter'' pages do not contain page numbers. If
\end{verbatim}
\chapter{List Environments}\label{listenv}
\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.
@ -696,7 +696,7 @@ Lists in \LaTeX{} can be nested, as the following examples will show.
For example, this code:
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, label=\fbox{Enumerate Example}, framesep=6mm]
\begin{Verbatim}[frame=lines, label=\fbox{Enumerate Example}, framesep=6mm]
\paragraph{The First Punic War}
\begin{enumerate}[noitemsep]
\item Carthage and Rome
@ -716,6 +716,8 @@ For example, this code:
\noindent{} produces this output:
\newpage
\klab{0pt}{Enumerate Example}{0pt}
\paragraph{The First Punic War}
@ -743,7 +745,7 @@ Similar to the \texttt{enumerate} environment, the \texttt{itemize} environment
As an example, we'll use the above example, but in a bulleted list:
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, label=\fbox{Itemize Example}, framesep=6mm]
\begin{Verbatim}[frame=lines, label=\fbox{Itemize Example}, framesep=6mm]
\paragraph{The First Punic War}
\begin{itemize}[noitemsep]
\item Carthage and Rome
@ -790,7 +792,7 @@ As an example, we'll use the above example, but in a bulleted list:
You can replace the bullets with any math symbol availabe in \LaTeX{} like this:
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, label=\fbox{Bullets Example}, framesep=6mm]
\begin{Verbatim}[frame=lines, label=\fbox{Bullets Example}, framesep=6mm]
\begin{itemize}[noitemsep]
\item[$\Box$] First item
\item[$\aleph$] Second item
@ -807,7 +809,7 @@ You can replace the bullets with any math symbol availabe in \LaTeX{} like this:
\item[$\aleph$] Second item
\item[$\triangle$] Third item
\end{itemize}
\krule{0mm}{2mm}
\chapter{Special Environments}\label{specenv}
@ -815,11 +817,11 @@ You can replace the bullets with any math symbol availabe in \LaTeX{} like this:
\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 sans-serif font.
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., { and }) 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.
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 usefule 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|+.
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:
@ -866,11 +868,20 @@ Both of them are list environments, so they start with a \texttt{begin} command
\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.
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.} \\ —Rudyard Kipling
\item \textit{He travels the fastest who travels alone.} \\ \hspace*{\fill} —Rudyard Kipling
\end{quote}
@ -886,7 +897,7 @@ The \texttt{quotation} environment indents the first line of each paragraph and
\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.
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:
@ -920,16 +931,16 @@ produces this example:
—William Shakespeare, \textit{Henry V}, Act II, Scene 1
\end{flushright}
\noindent{}I can probably live with that.
\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, while the \texttt{table} environment is a float that surrounds the table and can contain a caption.
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}
For example, the following code will produce the result see in table \ref{tb:sampletable}:
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}
@ -966,7 +977,7 @@ Note that I did not say ``in the table below'' because the \texttt{table} contai
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.
\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.
@ -1036,7 +1047,7 @@ To specify vertical lines, I added \verb+vline{1,3} = {0.75pt,solid}+. Note tha
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 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}.)
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}}
@ -1071,16 +1082,16 @@ This is at the bottom & This is some more incredibly long text that is going to
]{
width = {0.6\textwidth},
colspec = { X[1,l] X[2,r] },
rowspec = { Q[t,azure9] Q[b,yellow9] },
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. (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.
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 specifcation by using \texttt{hlines, vlines}. And we've made the table narrower by specifying \Verb+width = {0.6\textwidth}+.
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}.
@ -1151,16 +1162,16 @@ Fish & Chips & Mushy Peas \\
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 up an error.)
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 a couple of different environments that are useful for typesetting math (\texttt{align} and \texttt{array}, but they get a little beyond what I want to cover here. 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 again, they are beyond the scope of this book.
\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,
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$.
@ -1217,13 +1228,13 @@ F=G \left( \frac{m_1 m_2}{r^2} \right)
\]
\end{Verbatim}
produces this output:
\noindent{}produces this output:
\[
F=G \left( \frac{m_1 m_2}{r^2} \right)
\]
Note that \textit{both} commands are required.
\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.+.
@ -1276,7 +1287,7 @@ You can also control the size of brackets and parentheses explicitly:
\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.
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.
@ -1561,9 +1572,9 @@ o & O & Outside edge of a \texttt{twoside} document
\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{Referencing}\label{ch:referencing}
\chapter{References}\label{ch:referencing}
\section{Internal References}
\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}
@ -1656,7 +1667,7 @@ Nope. I'm not going to discuss this subject, because this would make this a very
\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.
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:
@ -1711,7 +1722,7 @@ Like I've said elsewhere, I'm running a recently updated Ubuntu 22.04 system, an
\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:
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
@ -1825,7 +1836,6 @@ Wedge & $\wedge$ & & \Verb+\wedge+ \\
\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}).
\item If you want to add a degree symbol\index{degree symbol} to inline text, the simplest way I've found (so far) is to just pop in and out of math mode with this: \verb|$^{\circ}$| which gives you this: $^{\circ}$
\end{itemize}
@ -1837,7 +1847,7 @@ In particular with \LaTeX{}, it can help if you create an MWE (minimal working e
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=MWE Example]
\begin{Verbatim}[frame=lines, numbers=left, xleftmargin=5mm, framesep=3mm, breaklines=true, label=\fbox{MWE Example}]
\documentclass[twoside, 9pt]{extreport}
\usepackage[
paperheight=8.5in,