Introduction to LaTeX and Overleaf
- We can use Overleaf to edit and render LaTeX documents.
- An Overleaf project can contain many files.
File Structure
- We can use Overleaf to edit and render LaTeX documents.
- 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.
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
\[ ... \]
Fonts 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.
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
Fonts and Encodings
- Use
.md
files for episodes when you want static content - Use
.Rmd
files for episodes when you need to generate output - Run
sandpaper::check_lesson()
to identify any issues with your lesson - Run
sandpaper::build_lesson()
to preview your lesson locally
Error Handling
- Use
.md
files for episodes when you want static content - Use
.Rmd
files for episodes when you need to generate output - Run
sandpaper::check_lesson()
to identify any issues with your lesson - Run
sandpaper::build_lesson()
to preview your lesson locally
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
Loading and Manipulating Data
- Use
.md
files for episodes when you want static content - Use
.Rmd
files for episodes when you need to generate output - Run
sandpaper::check_lesson()
to identify any issues with your lesson - Run
sandpaper::build_lesson()
to preview your lesson locally