LaTeX Guide
An Introduction to LaTeX in Quarto
LaTeX is a mark-up language and document preparation system that allows for (easier) typesetting of mathematical symbols, notation, and equations. Quarto allows for integration of LaTeX code alongside text and R code!
Getting Started
To indicate to the document compiler that we want to start typesetting math equations, we offset LaTeX code using dollar signs: $your LaTeX code here$. For example, the code $y=mx+b$ produces \(y=mx+b\).
Common Math Commands
Most LaTeX math commands are relatively intuitive and obey common mathematical order. We’ll illustrate some of the most common symbols you might use in an SDS course below!
Superscripts and Subscripts: we can use underscores to obtain subscripts (e.g.,
$x_iyields \(x_i\)) and carets to obtain superscripts (e.g.,$e_i^2$yields \(e_i^2\)).Hats for Estimated and Predicted Values: we can use the
\widehat{}command to place hats on top of values that are estimated or predicted from the observed data (e.g.,$\widehat{y}_i$yields \(\widehat{y}_i\)).Overbars for the Sample Mean: we can use the command
$\overline{}$to denote the sample average (e.g.,$\overline{x}$yields \(\overline{x}\)).Fractions: we can use the command
\frac{}{}to typeset fractions; anything in the first set of brackets will go in the numerator, and anything in the second set of brackets will go in the denominator (e.g.,$\frac{1}{2}$yields \(\frac{1}{2}\)).Summations: we can use the command
$\sum_{}^{}$to typeset the summation notation we’ve been using in class; the first set of brackets sets up the indexing that goes below/on the bottom of the summation sign while the second set of brackets specifies the upper limit on the sum, which goes above/on top of the summation sign (e.g.,$\sum_{i=1}^{n}x_i$yields \(\sum_{i=1}^{n}x_i\)).Multiplication: by convention, we typically do not write a multiplication symbol at all (such as when writing \(y=mx+b\)); alternatives include indicating multiplication using parentheses (such as when writing \((4)(3)=12\)) or using the
$\cdot$or$\times$commands (which yield \(\cdot\) and \(\times\), respectively).Inequalities: we can use the commands
$<$,$\leq$,$>$, and$\geq$to typeset \(<\), \(\leq\), \(>\), and \(\geq\), respectively.
The Spinelli Center maintains an extensive guide to LaTeX and list of LaTeX-related resouces, accessible here should you be interested in learning more!
Typesetting Population Parameters and Population Regression Lines
In statistics, the convention is to represent all population parameters by lowercase Greek letters; here is a list of the most common letters used and the corresponding LaTeX code:
- Alpha: \(\alpha\) (
\alpha) - Beta: \(\beta\) (
\beta) - Gamma: \(\gamma\) (
\gamma) - Delta: \(\delta\) (
\delta) - Epsilon: \(\epsilon\) (
\epsilon) or \(\varepsilon\) (\varepsilon) - Theta: \(\theta\) (
\theta) - Lambda: \(\lambda\) (
\lambda) - Mu: \(\mu\) (
\mu) - Pi: \(\pi\) (
\pi) - Rho: \(\rho\) (
\rho) - Sigma: \(\sigma\) (
\sigma) - Chi: \(\chi\) (
\chi)
Equations and Formulas
If we want to typeset full equations that are important enough (or long enough) to be offset from the main text in their own centered paragraph (like the equations for the population or fitted linear regression line), we can do so using display math mode. Display mode is achieved by either (a) wrapping the LaTeX code in two sets of double dollar signs $$code for your offset equation here$$ or (b) wrapping the LaTeX code in \begin{equation} and \end{equation}.
Here we demonstrate both of those approaches; the following code (when rendered) should produce the population regression line as a centered equation on its own line in the document twice: \[E[Y|X] = \beta_0 + \beta_1 X\] \[\begin{equation} E[Y|X] = \beta_0 + \beta_1 X \end{equation}\] The fitted regression line based on the observed values of \(y_i\) and \(x_i\) in our sample is given by \[\widehat{y}_i = \widehat{\beta}_0 + \widehat{\beta}_1 x_i.\]
Typesetting Probability Equations and Formulas
In the coming weeks, we introduce several core concepts from probability theory (as well as their corresponding mathematical notation) in order to support our study of statistics.
The formal language of probability theory is that of sets and the relationships between them. With that in mind, the following LaTeX commands will be helpful once we reach this component of the course:
Unions: the LaTeX command for typesetting unions is
\cup. As mentioned previously, you will want to place all of your math expressions inside a pair of dollar signs,$your LaTeX code here$, which in this case produces the symbol \(\cup\).Intersections: the LaTeX command for typesetting intersections is
\cap. Once we place this command inside a pair of dollar signs, we get the symbol \(\cap\).Complements: the LaTeX command for typesetting the complement of an event is
^c, where the caret^is used to indicate that we wish to formatcas a superscript. For example, if we put the codeA^cinside a pair of dollar signs, we get the output \(A^c\).Conditioning: the LaTeX command for typesetting conditioning is
\vert, though you can also simply use the vertical line keyboard key,|. After typesetting\vertinside a pair of dollar signs, we get the symbol \(\vert\); after placing the vertical line keyboard key inside two dollar signs, we also get the symbol \(|\).