Introduction to the LaTeX Workflow
- We can use the TeXworks editor to write and compile LaTeX documents.
- The TeXworks interface is divided into three main sections: the editor, the preview pane, and the menu bar.
- We can compile a LaTeX document by clicking the “Typeset” button in the TeXworks editor.
- We can also compile a LaTeX document from the command line using the
pdflatex
orlualatex
command.
File Structure
- The
%
character is used to add comments to a LaTeX document. - LaTeX documents are a mixture of text and commands.
- Commands start with a backslash
\
and sometimes have arguments in curly braces{}
. - We can view errors by either clicking on the “Logs and output files” or hovering over the red circle in the text editor.
Error Handling
- Errors are common! Don’t be discouraged by them.
- The first error message is usually the most important one to fix.
- Read the error messages carefully, they often tell you exactly what the problem is.
The Structure of a Document
- LaTeX documents are structured using section commands.
- There are many different section commands in LaTeX, including
\subsubsection{...}
,\paragraph{...}
,\chapter{...}
, and more. - Lists in LaTeX are created using the
enumerate
anditemize
environments.
Using Document Classes
- LaTeX document classes set the general layout of the document
- The base document classes are
article
,report
,book
,letter
, andslides
- Third-party classes can provide additional features
Extending LaTeX
- We can extend LaTeX’s functionality by adding packages to our document.
- We can define custom commands in LaTeX using the
\newcommand
command.
Using Graphics
- The
graphicx
package allows us to include images in our LaTeX document. - We can adjust the appearance of images using options in the
\includegraphics
command. - We can position images manually or automatically using environments
like
center
andfigure
. - Floating images can move around the page as text is added or removed.
- We can control the position of floating images using parameters in
the
figure
environment. - We can add captions to floating images using the
\caption
command.
Tables
- Tables in LaTeX are created using the
tabular
environment. - The
array
package provides additional functionality for creating tables. - The
booktabs
package provides commands for creating horizontal lines in tables. - The
\multicolumn
command can be used to merge cells in a table. - The
\multirow
command in themultirow
package can be used to merge rows in a table.
Adding Cross References
- The
\label{}
command marks a spot in the document. - The
\ref{}
command refers to a marked spot in the document.
Mathematics
- Inline math mode is marked with
$ ... $
or\(...\)
- Display math mode is marked with
\[ ... \]
- Use
\qty{}{}
or\unit{}
for properly writing numbers with their scientific unit.
Fonts, Formatting and Spacing
- Use the
parskip
package to add space between paragraphs - Force a new line with
\\
- Add explicit space with
\hspace
and\vspace
- Format text explicitly with
\textbf
,\textit
, etc. - Align text with
\centering
,\raggedright
, and\raggedleft
Citations and References
- References are stored in a reference database, seperate from the LaTeX document.
- BiBTeX files are used to store references in a processing-friendly
format and have the extension
.bib
. - There are multiple libraries available to manage references in LaTeX
documents, including
natbib
andbiblatex
. - We can use the
\cite
command or one of its variants to cite references in our document.
Context Sensitive QuotationsVarious Types of QuotationReferencing Source of Quote to BibLaTeX-EntryForeign Language QuotesAuxiliary CommandsAdjust Default Settings
- Use
\enquote{…}
for semantic, language-aware inline quotes. - Use
\blockquote{…}
for automatic block formatting and citation. - Integrate with
biblatex
inside quotes for full bibliographic support. - Switch quote styles per language with
\foreign(c)quote
. - Customize nesting, spacing, and thresholds to match publisher or style-guide requirements.
Structuring Sources
- LaTeX projects can contain many files that reference each other
- The
\input{filename}
and\include{filename}
commands allow you to include the contents of other files in your document - The
\frontmatter
,\mainmatter
,\backmatter
, and\appendix
commands help structure your document
Loading and Manipulating Data
- The
datatool
package allows us to load and manipulate data in LaTeX documents. - We can load data from a CSV file using the
\DTLread
command. - We can display data in a table using the
\DTLdisplaydb
command. - We can filter data using the
\DTLforeach
command and conditions. - We can aggregate data using commands like
\DTLmeanforkeys
,\DTLsumforkeys
, etc.
Documentation and Finding Help
- CTAN is a large archive of LaTeX packages and documentation
- Texdoc is a website & command line tool for searching LaTeX documentation