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
pdflatexorlualatexcommand.
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
enumerateanditemizeenvironments.
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
\newcommandcommand.
Using Graphics
- The
graphicxpackage allows us to include images in our LaTeX document. - We can adjust the appearance of images using options in the
\includegraphicscommand. - We can position images manually or automatically using environments
like
centerandfigure. - 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
figureenvironment. - We can add captions to floating images using the
\captioncommand.
Tables
- Tables in LaTeX are created using the
tabularenvironment. - The
arraypackage provides additional functionality for creating tables. - The
booktabspackage provides commands for creating horizontal lines in tables. - The
\multicolumncommand can be used to merge cells in a table. - The
\multirowcommand in themultirowpackage 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
parskippackage to add space between paragraphs - Force a new line with
\\ - Add explicit space with
\hspaceand\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
natbibandbiblatex. - We can use the
\citecommand 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
biblatexinside 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\appendixcommands help structure your document
Loading and Manipulating Data
- The
datatoolpackage allows us to load and manipulate data in LaTeX documents. - We can load data from a CSV file using the
\DTLreadcommand. - We can display data in a table using the
\DTLdisplaydbcommand. - We can filter data using the
\DTLforeachcommand 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