R07: LaTeX

Nicky Wakim

2024-10-30

Introduction to LaTeX in Quarto

  • Quarto allows LaTeX syntax for math expressions.
  • Supports inline math, display equations, and complex formatting.
  • Useful for scientific writing, presentations, and reports.

 

  • What is LaTeX?
    • It is a form of coding within qmd files (and many other types of files) that helps us write equations in an easily readable format

Open a new qmd file

  • You can follow along in the file
  • Source vs. Visual: Source is often easier when using LaTeX, but it works in Visual
  • LaTeX is written in the text portion of a qmd, NOT the code portion
  • We use $’s to tell our Quarto doc where we are writing LaTeX code

Inline Math

  • To include inline math, wrap your LaTeX code in $...$
  • Example: \(a^2 + b^2 = c^2\) is written as $a^2 + b^2 = c^2$
  • This is great for brief equations within text

Display Equations

  • For equations that should be centered on their own line, use $$...$$.

  • Example: We can make an equation with a new line using $$E = mc^2$$

    \[E = mc^2\]

  • This makes the equation stand out

Symbols and Greek Letters

  • Quarto LaTeX can include Greek letters and other symbols

Greek letters

  • mu (\(\mu\)): \mu
  • sigma (\(\sigma\)): \sigma
  • beta (\(\beta\)): \beta
  • lambda (\(\lambda\)): \lambda

Math symbols

  • Greater than (\(>\)): >
  • Greater than or equal to (\(\geq\)): \geq
  • Not equal to (\(\neq\)): \neq
  • Multiplication
    • \(\cdot\) from \cdot
    • \(\times\) from \times

Subscripts and Superscripts in LaTeX

  • To create subscripts, use _ (underscore).
    • Example: $x_1$, $y_{ij}$ render as \(x_1\), \(y_{ij}\)
  • To create superscripts, use ^ (caret).
    • Example: $x^2$, $e^{5i}$ render as \(x^2\), \(e^{i5i}\)
  • Use {} for multiple characters in subscripts or superscripts

 

LaTeX:

$$x_i^2 + y_j^3$$

Output in html:

\[x_i^2 + y_j^3\]

$\sum_{i=1}^n x_i^2$

\(\sum_{i=1}^n x_i^2\)

$$\sum_{i=1}^n x_i^2$$

\[\sum_{i=1}^n x_i^2\]

Fractions in LaTeX

  • To create fractions, use the \frac{numerator}{denominator} command


LaTeX:

$$\frac{a}{b}$$

Output in html:

\[\frac{a}{b}\]

$$\frac{\sqrt{a^2 + b^2}}{c}$$

\[\frac{\sqrt{a^2 + b^2}}{c}\]

$$\frac{\sum_{i=1}^n x_i}{n}$$

\[\frac{\sum_{i=1}^n x_i}{n}\]

  • Fractions can be used in both inline and display modes.

Text within LaTeX

  • LaTeX allows you to insert text within mathematical expressions using \text{...}.
  • This is useful for labeling variables or adding context to equations


LaTeX:

$$y = mx + \text{intercept}$$

Output:

\[ y = mx + \text{intercept} \]

$$P(A) = \frac{\text{Number of favorable outcomes}}{\text{Total outcomes}}$$

\[ P(A) = \frac{\text{Number of favorable outcomes}}{\text{Total outcomes}} \]

Aligning Equations

  • To align multiple equations, use the align environment

 

LaTeX:

$$

\begin{align}

x + y &= 10 \\

x - 3y &= 6

\end{align}

$$

Output in html:

\[ \begin{align} x + y &= 10 \\ x - 3y &= 6 \end{align} \]

What you might use in Homework 5

LaTeX:

$$SE = \frac{\sigma}{\sqrt{n}}$$

Output in html:

\[SE = \frac{\sigma}{\sqrt{n}}\]

$$z = \frac{x - \mu}{\sigma}$$

\[z = \frac{x - \mu}{\sigma}\]

Practical Uses of LaTeX in Quarto

  • Writing technical documents with lots of math
  • Formatting statistics for reports and papers
  • Presenting mathematical concepts in presentations like this one

Resources