Skip to main content

Appendix D — LaTeX Mathematics Reference Guide

This appendix provides portable mathematical source for Quarto authors. Each example presents literal source followed by the intended rendered expression. The examples are mathematical notation, not executable R or Python. Use $...$ for inline math and $$...$$ for display math. Avoid raw LaTeX environments outside math delimiters when targeting multiple formats.

D.1 Foundations and delimiters

Use inline mathematics for symbols that belong to a sentence and display mathematics for expressions that deserve their own line. Keep punctuation consistent with the surrounding sentence. Braces group an entire exponent or subscript; without them only the next token is affected. Do not leave blank lines inside a display equation.

Group a multi-character subscript.

x_{i+1}^2

\[ x_{i+1}^2 \]

Group numerator and denominator.

\frac{a+b}{c-d}

\[ \frac{a+b}{c-d} \]

Use an optional root index.

\sqrt[3]{x}

\[ \sqrt[3]{x} \]

Match scalable delimiters.

\left(\frac{x}{y}\right)^2

\[ \left(\frac{x}{y}\right)^2 \]

D.2 Sets, logic and number systems

Distinguish membership from subset relations. A variable is usually italic, while standard named operators are upright. Use explicit quantifiers when stating a theorem; identify the domain before manipulating an expression.

Membership in the real numbers.

x\in\mathbb{R}

\[ x\in\mathbb{R} \]

Subset, possibly equal.

A\subseteq B

\[ A\subseteq B \]

Intersection and union.

A\cap B,\quad A\cup B

\[ A\cap B,\quad A\cup B \]

A universally quantified statement.

\forall x\in\mathbb{R},\quad x^2\ge 0

\[ \forall x\in\mathbb{R},\quad x^2\ge 0 \]

Logical implication.

P\implies Q

\[ P\implies Q \]

D.3 Algebra and functions

Use cases for piecewise definitions and align for multi-step derivations. The equals signs should express genuine equality, not merely a transition to a new step. Include domain restrictions when dividing or taking logarithms.

Piecewise definition.

f(x)=\begin{cases}x^2 & x\ge 0\\-x & x<0\end{cases}

\[ f(x)=\begin{cases}x^2 & x\ge 0\\-x & x<0\end{cases} \]

Align successive equalities.

\begin{aligned}2x+3&=11\\2x&=8\\x&=4\end{aligned}

\[ \begin{aligned}2x+3&=11\\2x&=8\\x&=4\end{aligned} \]

Change of base; x>0, b>0, b not equal to 1.

\log_b x=\frac{\ln x}{\ln b}

\[ \log_b x=\frac{\ln x}{\ln b} \]

Quadratic formula for nonzero a.

x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}

\[ x=\frac{-b\pm\sqrt{b^2-4ac}}{2a} \]

D.4 Trigonometry and precalculus

Use named commands for trigonometric functions so their letters are upright. Specify radians for calculus applications. Parentheses clarify the argument of a function, especially when powers or inverse functions are involved.

Pythagorean identity.

\sin^2\theta+\cos^2\theta=1

\[ \sin^2\theta+\cos^2\theta=1 \]

Inverse tangent, not reciprocal tangent.

\arctan\left(\frac{y}{x}\right)

\[ \arctan\left(\frac{y}{x}\right) \]

Sinusoidal model.

A\sin(\omega t+\phi)+D

\[ A\sin(\omega t+\phi)+D \]

Euler identity.

e^{i\theta}=\cos\theta+i\sin\theta

\[ e^{i\theta}=\cos\theta+i\sin\theta \]

D.5 Single-variable calculus

Use a differential with a small space before it. State the variable of differentiation, and distinguish an indefinite integral from a definite integral. A limit requires a direction or destination; a derivative evaluated at a point is a number, not a function.

Derivative definition.

\lim_{h\to0}\frac{f(x+h)-f(x)}{h}

\[ \lim_{h\to0}\frac{f(x+h)-f(x)}{h} \]

Second derivative.

\frac{d^2y}{dx^2}

\[ \frac{d^2y}{dx^2} \]

Definite integral.

\int_a^b f(x)\,dx

\[ \int_a^b f(x)\,dx \]

Evaluation at a point.

\left.\frac{d}{dx}x^3\right|_{x=2}=12

\[ \left.\frac{d}{dx}x^3\right|_{x=2}=12 \]

Exponential series.

\sum_{n=0}^{\infty}\frac{x^n}{n!}=e^x

\[ \sum_{n=0}^{\infty}\frac{x^n}{n!}=e^x \]

D.6 Multivariable and vector calculus

Use bold symbols for vectors consistently. Distinguish partial derivatives from total derivatives, and define the coordinate system. A surface integral requires an orientation when it represents flux; a scalar surface integral does not.

Gradient as a column vector.

\nabla f=\begin{bmatrix}f_x\\f_y\\f_z\end{bmatrix}

\[ \nabla f=\begin{bmatrix}f_x\\f_y\\f_z\end{bmatrix} \]

Differentiate first with respect to x, then y.

\frac{\partial^2 f}{\partial y\,\partial x}

\[ \frac{\partial^2 f}{\partial y\,\partial x} \]

Double integral.

\iint_D f(x,y)\,dA

\[ \iint_D f(x,y)\,dA \]

Circulation along a closed curve.

\oint_C \mathbf{F}\cdot d\mathbf{r}

\[ \oint_C \mathbf{F}\cdot d\mathbf{r} \]

Oriented flux.

\iint_S \mathbf{F}\cdot\mathbf{n}\,dS

\[ \iint_S \mathbf{F}\cdot\mathbf{n}\,dS \]

D.7 Linear algebra

Use matrix environments for rectangular arrays. Ampersands separate columns and double backslashes separate rows. Reserve determinant bars for square matrices and use a norm symbol for vector magnitude. State dimensions when introducing a linear transformation.

Two by two matrix.

A=\begin{bmatrix}2&1\\1&3\end{bmatrix}

\[ A=\begin{bmatrix}2&1\\1&3\end{bmatrix} \]

Determinant.

\det A=\begin{vmatrix}2&1\\1&3\end{vmatrix}=5

\[ \det A=\begin{vmatrix}2&1\\1&3\end{vmatrix}=5 \]

Linear system.

A\mathbf{x}=\mathbf{b}

\[ A\mathbf{x}=\mathbf{b} \]

Eigenvalue equation.

A\mathbf{v}=\lambda\mathbf{v},\quad \mathbf{v}\ne\mathbf{0}

\[ A\mathbf{v}=\lambda\mathbf{v},\quad \mathbf{v}\ne\mathbf{0} \]

Euclidean norm.

\lVert\mathbf{x}\rVert_2=\sqrt{\sum_{i=1}^n x_i^2}

\[ \lVert\mathbf{x}\rVert_2=\sqrt{\sum_{i=1}^n x_i^2} \]

D.8 Probability and statistical inference

Distinguish random variables from observed values and parameters from estimates. Conditional probability uses a vertical separator, preferably mid for spacing. Define the sampling assumptions before presenting a confidence interval or test statistic.

Conditional probability for positive P(B).

P(A\mid B)=\frac{P(A\cap B)}{P(B)}

\[ P(A\mid B)=\frac{P(A\cap B)}{P(B)} \]

Normal model with variance sigma squared.

X\sim\mathcal{N}(\mu,\sigma^2)

\[ X\sim\mathcal{N}(\mu,\sigma^2) \]

Sample mean.

\bar{x}=\frac{1}{n}\sum_{i=1}^n x_i

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

Sample variance.

s^2=\frac{1}{n-1}\sum_{i=1}^n(x_i-\bar{x})^2

\[ s^2=\frac{1}{n-1}\sum_{i=1}^n(x_i-\bar{x})^2 \]

Two-sided one-sample t interval under its assumptions.

\bar{x}\pm t_{1-\alpha/2,n-1}\frac{s}{\sqrt n}

\[ \bar{x}\pm t_{1-\alpha/2,n-1}\frac{s}{\sqrt n} \]

D.9 Biostatistics and regression

Define the outcome and units of each predictor. Use hats for fitted coefficients, not for population parameters. A logistic coefficient is a change in log odds, whereas its exponential is an odds ratio for a unit change in the predictor with other predictors held fixed.

Simple linear regression.

Y_i=\beta_0+\beta_1x_i+\varepsilon_i

\[ Y_i=\beta_0+\beta_1x_i+\varepsilon_i \]

Fitted response.

\widehat{y}=\hat\beta_0+\hat\beta_1x

\[ \widehat{y}=\hat\beta_0+\hat\beta_1x \]

Logistic regression.

\log\left(\frac{p}{1-p}\right)=\beta_0+\beta_1x

\[ \log\left(\frac{p}{1-p}\right)=\beta_0+\beta_1x \]

Odds ratio.

\mathrm{OR}=e^{\beta_1}

\[ \mathrm{OR}=e^{\beta_1} \]

Survival function.

S(t)=P(T>t)

\[ S(t)=P(T>t) \]

Cox proportional hazards model.

h(t\mid\mathbf{x})=h_0(t)e^{\boldsymbol\beta^\top\mathbf{x}}

\[ h(t\mid\mathbf{x})=h_0(t)e^{\boldsymbol\beta^\top\mathbf{x}} \]

D.10 Numbering and cross-references

Use a unique eq- identifier after the closing display delimiter. Refer to the identifier rather than typing a number by hand. This lets Quarto adjust references when equations are inserted or removed. Avoid using \tag or raw \label as a substitute for Quarto’s portable mechanism.

$$
C(t)=80e^{-0.2t}
$$ {#eq-appd-decay}

See @eq-appd-decay.

\[ C(t)=80e^{-0.2t} \tag{D.1}\]

The hypothetical concentration in Equation D.1 has a half-life of \(\ln(2)/0.2\approx3.466\) hours. This is a mathematical illustration, not a dosing recommendation.

D.11 Theorems, definitions and proofs

Use Quarto fenced divs with semantic identifiers. For example:

::: {#thm-appd-square}
## Nonnegative squares
For every real number $x$, $x^2\ge 0$.
:::

::: {.proof}
If $x\ge0$, then $x\cdot x\ge0$. Otherwise $-x>0$ and
$x^2=(-x)^2>0$.
:::

Keep theorem statements separate from their proofs. For a definition use a def- identifier. Check theorem numbering in each output format, especially Word, where styling may differ.

D.12 Custom commands and output formats

Prefer standard notation commands when distributing HTML, PDF and Word editions. For HTML with MathJax, a hidden display block can define macros; PDF can load a TeX header through include-in-header. Word converts supported mathematics to native equation markup and does not generally execute arbitrary TeX preambles. A macro working in one format is not evidence that it works in another. Expand custom commands in portable source when necessary.

For example, use \mathcal{C}^k for a class of functions with continuous derivatives through order k, and \operatorname{Var}(X) for variance. These do not require a custom macro.

Format Rendering considerations
HTML MathJax or another configured math renderer; inspect browser output.
PDF TeX engine and packages; inspect compilation log and line breaks.
Word Native equations for supported expressions; inspect in Word.
EPUB Reader-dependent math support; test on intended devices.

D.13 Troubleshooting

Symptom Likely cause Repair
Formula appears as source Missing math delimiters Add matching dollar delimiters.
Only one digit is superscripted Missing grouping Use x^{12}.
Matrix columns are misaligned Missing ampersand Separate each column with &.
Unknown command Typo or unsupported macro Use a standard command and test formats.
Unresolved equation reference Identifier mismatch Match @eq-name to {#eq-name} exactly.
Long equation overflows Unbroken expression Use aligned and split at meaningful operators.

D.14 Worked computational example

Verify the decay model rather than transcribing numerical results without checking them. The following listings are intentionally nonexecuting in the book. The companion scripts provide independent calculations.

k <- 0.2
half <- log(2)/k
stopifnot(abs(80*exp(-k*half)-40)<1e-10)
print(half)
from math import log, exp, isclose
k = 0.2
half = log(2)/k
assert isclose(80*exp(-k*half), 40)
print(half)

D.15 Guided practice

  1. Typeset a fraction with numerator \(x+1\) and denominator \(x-1\).
  2. Express membership of a vector in three-dimensional real space.
  3. Typeset a piecewise absolute-value function.
  4. Write the derivative of sine with respect to its argument.
  5. Typeset the fundamental theorem of calculus for continuous f.
  6. Write a three-component gradient as a column vector.
  7. Typeset a two-by-two identity matrix.
  8. Express Bayes’ theorem for two events with positive conditioning probability.
  9. Write the standard error of a sample mean using sample SD.
  10. Express the inverse-logit function.
  11. Create a numbered equation and refer to it in prose.
  12. Explain why a PDF-only macro may fail in Word.

D.16 Applied project: a mathematical reference sheet

Create a standalone Quarto document containing an algebraic derivation, a calculus equation, a matrix equation, a statistical model, and a numbered equation with a prose reference. Define every symbol and include one independent numerical verification. Render HTML and Word; if a TeX engine is available, also render PDF. Inspect the results rather than relying solely on successful exit codes.

Criterion Points
Mathematical correctness and defined symbols 5
Source syntax and readable alignment 5
Numbering and cross-references 5
Independent computational verification 5
Cross-format inspection and documented limitations 5
Total 25

D.17 Further reading