# LaTeX Cheat Sheet

Since 3 decades, LaTeX is the state of the art typesetting system for professional publishing. Its fonts are of unmatched beauty, and its features leave nothing to be desired. I use LaTeX for more than 2 decades now. This cheat sheet gets you jump started for more than 80% of what is needed for a professional publication.

Author:
Christian Hujer, Software Crafter and CEO / CTO of Nelkinda Software Craft Private Limited
First Published:
by Nelkinda Software Craft Private Limited
by Christian Hujer

## 1 Introduction

I have high standards when it comes to documentation and publishing. Something worth doing is worth doing properly. This applies to multiple levels. I want nice fonts and nice layout because that makes reading easier. But I also want other features, such as lots of cross-references of different kinds, to make handling technical books easier. A full-text search doesn't always cut it, and a full-text search is also slower than designed, built-in hyperlinks. The cheat sheet in this article provides nothing less than:

• Title page
• List of Figures, Tables, and Listings
• Bibliography
• Frontmatter with roman page numbers, for preface and foreword
• Multiple parts to group chapters
• Chapters (obviously), with epigraphs
• Appendix
• Backmatter with acronyms, glossary, and index
• Output as PDF, with Hyperlinks

## 2 Basic Document Structure

Makefile
.ONESHELL:
SHELL:=/bin/bash

book.pdf: book.tex data/*.tex chapters/*.tex data/book.bib
-pdflatex $< -bibtex book.aux -makeindex book -makeglossaries book -pdflatex$<
-makeindex book
-makeglossaries book
pdflatex $< .PHONY: clean clean::$(RM) {,*/}*.{aux,dvi,log,bbl,blg,lof,lol,lot,toc,idx,ilg,ind,out,ist,glo,acn,acr,alg,glg,gls}

.PHONY: distclean
distclean:: clean
$(RM) *.pdf book.tex \documentclass{memoir} \usepackage{graphics} \usepackage{hyperref} \usepackage{listings} \usepackage{color} \usepackage{makeidx} \usepackage[acronym,toc]{glossaries} \usepackage{longtable} \usepackage{todonotes} \include{data/acronyms} \include{data/glossary} \makeindex \makeglossaries \title{Title of the Book} \date{2018-05-09} \author{Christian Hujer} \stockaiv \begin{document} \frontmatter \pagenumbering{roman} \maketitle \newpage \tableofcontents \newpage \listoffigures \newpage \listoftables \newpage \lstlistoflistings \include{chapters/preface} \mainmatter \part{Introduction} \include{chapters/part1/chapter1} \include{chapters/part1/chapter2} \part{Integration} \include{chapters/part2/chapter3} \include{chapters/part2/chapter4} \appendix \include{chapters/appendix1} \include{chapters/appendix2} \backmatter \printglossary[type=\acronymtype] \printglossary \bibliographystile{ieeetr} \bibliography{data/book} \printindex \end{document} ## 3 Acronyms book.tex \usepackage{hyperref} \usepackage[acronym,toc]{glossaries} \include{data/acronyms} \makeglossaries \printglossary[type=\acronymtype] data/acronyms.tex \newacronym{acronym:GNU}{GNU}{GNU is Not Unix} chapters/chapter.tex \acrshort{acronym:GNU} ## 4 Glossary book.tex \usepackage{hyperref} \usepackage[acronym,toc]{glossaries} \include{data/glossary} \makeglossaries \printglossary data/glossary.tex \newglossaryentry{agile} { name=agile, description={ A style of organizing software development described by the Agile Manifesto. } } chapters/chapter.tex \Gls{agile} or \gls{agile} ## 5 Unordered List (<ul/>-style) chapters/chapter.tex \begin{itemize} \item Item 1 \item Item 2 \end{itemize} ## 6 Ordered List (<ol/>-style) chapters/chapter.tex \begin{enumerate} \item Item 1 \item Item 2 \end{enumerate} ## 7 Index Makefile book.pdf: book.tex -pdflatex$<
-makeindex book
pdflatex \$<
book.tex
\usepackage{makeidx}
\makeindex
\printindex
chapters/chapter.tex
\index{Maven}Maven
\index{Ritchie, Dennis M.}Dennis M. Ritchie
\index{Hello, World!make}Hello, World in make
\index{Hello, World!C}Hello, World in C
\index{printf@\texttt{printf}}\texttt{printf}

The \index{} tag should be before the text that is to be indexed.

The expression that is to be indexed may be subject to a page break. The index page should be the first of the two pages of a broken expression. Therefore, the reference should be to the start of the expression. To achieve that, the \index{} tag should be before the text that is to be indexed.

## 8 Listings

book.tex
\usepackage{listings}
\lstlistoflistings
chapter/chapter.tex
\lstinputlisting[caption={Hello, World!\index{Hello, World!C} in C}, label={lst:hello.c}]{src/hello.c}

## 9 Epigraphs

chapters/chapter.tex
\chapter{Introduction to C}
\epigraph{C is quirky, flawed, and an enormous success.''}{\em Dennis M. Ritchie\index{Ritchie, Dennis M.}\em}
\chapter{Text Editors}
\epigraph{\includegraphics[width=\textwidth]{gfx/real_programmers}}{xkcd}

## 10 Bibliography

book.bib
@book{latexcompanion,
author    = "Michel Goossens and Frank Mittelbach and Alexander Samarin",
title     = "The \LaTeX\ Companion",
year      = "1993",
}
book.tex
\backmatter
\printglossary[type=\acronymtype]
\printglossary
\bibliographystile{ieeetr}
\bibliography{data/book}
chapters/chapter.tex
The \LaTeX\ Companion\cite{latexcompanion}

Multiple authors are separated with and.

## 11 Miscellaneous

• LaTeX logo: \LaTeX