4  Mathematics

Published

January 26, 2025

4.1 Typesetting math

You can do latex inline like this:

Euler's formula is remarkable: $e^{i\pi} + 1 = 0$.

Euler’s formula is remarkable: \(e^{i\pi} + 1 = 0\).

You can use $$ to make an equation block like this:

$$ \frac{\partial \rho}{\partial t} + \nabla \cdot \vec{j} = 0 \,. $$ {#eq-continuity}

\[ \frac{\partial \rho}{\partial t} + \nabla \cdot \vec{j} = 0 \,. \tag{4.1}\]

Stokes’ theorem is pretty cool:

$$ \int_{\partial\Omega} \omega = \int_{\Omega} \mathrm{d}\omega \,. $$ {#eq-stokes}

\[ \int_{\partial\Omega} \omega = \int_{\Omega} \mathrm{d}\omega \,. \tag{4.2}\]

You can also refer to labeled equations, such as eq. 4.2, with the syntax:

... such as @eq-stokes,

The align environment can also be used. Maxwell’s equations, eq. 4.3, are also tough to beat:

$$
\begin{align}
    \nabla \cdot  \vec{E} &= \rho \nonumber \\
    \nabla \cdot  \vec{B} &= 0    \nonumber \\
    \nabla \times \vec{E} &= - \frac{\partial \vec{B}}{\partial t} \\
    \nabla \times \vec{B} &= \vec{j} + \frac{\partial \vec{E}}{\partial t} \nonumber \,. 
\end{align}
$$ {#eq-maxwell}

\[ \begin{align} \nabla \cdot \vec{E} &= \rho \nonumber \\ \nabla \cdot \vec{B} &= 0 \nonumber \\ \nabla \times \vec{E} &= - \frac{\partial \vec{B}}{\partial t} \\ \nabla \times \vec{B} &= \vec{j} + \frac{\partial \vec{E}}{\partial t} \nonumber \,. \end{align} \tag{4.3}\]

NOTE: The above equation with nested $$ and align environments does not work when making a pdf. See this issue. Instead, for pdf we use align directly in the following with quarto conditional content:

::: {.content-visible when-format="pdf"}
\begin{align}
    \nabla \cdot  \vec{E} &= \rho \nonumber \\
    \nabla \cdot  \vec{B} &= 0    \nonumber \\
    \nabla \times \vec{E} &= - \frac{\partial \vec{B}}{\partial t} \label{eq-maxwell} \\
    \nabla \times \vec{B} &= \vec{j} + \frac{\partial \vec{E}}{\partial t} \nonumber \,. 
\end{align}
:::

FIXME: But notice that the previous time we refrenced Maxwell’s equations (eq. 4.3), and this time, the references work for html but are broken in pdf.

4.2 Mathjax

When doing md \(\rightarrow\) tex \(\rightarrow\) pdf, LaTeX takes care of the math, but to render the math in html, we use MathJax.

Note that our _quarto.yml has set html-math-method: mathjax.