My LaTeX cheatsheet for writing a computer programming book

I’m currently writing my new book, Functional Programming, Simplified (Updated for Scala 3) directly in LaTeX, and this is my “LaTeX cheatsheet” that I keep open all the time so I can copy and paste the LaTeX stuff I need while I write.

Note that I don’t use any LaTeX formula stuff, so most of this is pretty basic LaTeX stuff, though there are a few custom commands/functions that probably won’t make sense to anyone unless I share some more details.

Here’s my current LaTeX cheatsheet:

\introquote{``The quote yada''}{Albert Einstein}


--------------
% COMMON STUFF
--------------

\begin{verbatim}
CODE GOES HERE
\end{verbatim}

\begin{aside}
This is an aside, yada
\end{aside}

\begin{quote}
Yada
\end{quote}

\texttt{
\texttt{wc\ -l}

\begin{itemize}
\tightlist
\item
  Bullet point 1
\item
  Bullet point 2
\end{itemize}

\index{Learning Cliff}%



% CHAPTERS & SECTIONS
---------------------
\mychapter{2}{Who This Book is For}{who-this-book-is-for}

\longchaptername{8}{The TOC Name Here}{The Long\\Name Here}{the-long-index-label}

% using TT in a section:
\mysection{Note 1: The empty \SectionTextTT{List}}{rec-list-note-1-the-empty-list}

\mysection{The section title}{the-section-title}
\mysection{\texorpdfstring{Problematic title}{Simpler title}}{the-title-ref}

\mysubsection{Problem \#2: It's not algebra}{211-its-not-algebra}

\mysubsection{``Update as you copy'' gets worse with
nested objects}{update-as-you-copy-gets-worse-with-nested-objects}


% INDEXING
----------
The audiences\index{book!audience} yada yada
this book\index{book!goals}
\index{Learning Cliff}%    % i use this before sentences


% CODE / PRE
------------
\begin{verbatim}
CODE GOES HERE
\end{verbatim}

% NOTE: this uses a different font:
\begin{Verbatim}[samepage=true]
val x = 1
\end{Verbatim}

\begin{Verbatim}[formatcom=\color{dark-gray}, frame=single, framesep=5mm]
/**
 * Mix together some flour, butter, eggs, sugar,
 * and chocolate chips. Shape the dough into
 * little cookies, and bake them at 350 degrees
 * for 10 minutes.
 */
\end{Verbatim}

\begin{Verbatim}[formatcom=\color{dark-gray}]
...


% TEXT
------
\textit{ZIO}
\textbf{created}

the \texttt{{[}A,\ B{]}} part          // [A, B]
\texttt{sum(tail)}                     // this is okay
\texttt{"\_xform"}                     // _xform

\texttt{Some{[}YourDataTypeHere{]}}  // Some[YourDataTypeHere]


\texttt{return\ 1\ +\ sum(2,3)}      // blank spaces

\textasciitilde{}    // “~” character
\ldots{}             // ...

Martin~Odersky       // don't separate these words

\textasciitilde{} From the book, \href{https://amzn.to/3jizrZg}{Coders at Work}



% QUOTES/NOTES/ASIDES
---------------------
\begin{aside}
This is an aside, yada
\end{aside}

\centeredquote{\large “One learns by doing the thing.”}

\begin{quote}
Yada
\end{quote}

\begin{aside}
{\large One More Thing: Viewing and Setting the JVM stack size}
...


% MISC/ESCAPES
--------------
\fnurl{THEURL}{The_text}
100\%
\&
F\#

the \texttt{{[}A,\ B{]}} part          // [A, B]
\texttt{sum(tail)}                     // this is okay


\\
\newline
\newpage

\sout{Hello world}



% LISTS
-------
% numbers
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
  Item 1
\item
  Item 2
\end{enumerate}

% BULLETS
---------
\begin{itemize}
\tightlist
\item
  How do I write database code?
\item
  How do I write RESTful code?
\end{itemize}


\vskip1cm
\vfill



% LIST WITH A PRESET COUNTER
----------------------------
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{7}
\tightlist
\item
  Being able to (a) treat functions as values and (b) use anonymous
  functions makes code more concise, and still readable
\item
  Scala syntax generally makes function signatures easy to read
\item
  The Scala collections' classes have a very functional API
\item
  Scala runs on the JVM, so you can still use the wealth of JVM-based
  libraries and tools with your Scala/FP applications
\end{enumerate}



% FIGURES
---------

As shown in Figure~\ref{fig:linkedListDepiction} ...

\begin{figure}[htbp]
\centering
\includegraphics[width=0.4\textwidth]{images/recursion-2-linked-list-with-nil.png}
\caption{An accurate depiction of a linked list, as a series of cells.}
\label{fig:linkedListDepiction}
\end{figure}


% URLS (normally \href)
-----------------------
\fnurl{https://alvinalexander.com/scala/functional-programming-simplified-book}{Functional Programming, Simplified}
\fnurl{https://amzn.to/3WRp6Cs}{Land of Lisp}
\fnurl{https://amzn.to/3HhB3w1}{Learn You a Haskell for Great Good}

In summary, if you ever need a little LaTeX cheatsheet when writing a computer programming book, I hope this is helpful.