Quick guide: LaTeX basics in Markdown

A Step-by-Step Guide to Basic LaTeX in Markdown

This guide explains how to write mathematical notation in Markdown using LaTeX.

The most important concept is the delimiter (the character that starts and ends the math).

  1. Inline Mode: Uses single dollar signs ($...$). This keeps your math inside the same line, e.g. $1 + 1 = 2$, of text. Inline mode can also be initiated using \(...\), e.g. (1 + 1 = 2)which is functionally equivalent to $...$.
  2. Display Mode: Uses double dollar signs ($$...$$). This puts your math on its own line, e.g. $$1 + 1 = 2$$, and the text is displayed centered and usually larger.

In detail

a. Subscripts

  • Raw Code: $x_i$
  • Rendered Output: $x_i$
  • Explanation: The underscore (_) creates a subscript. It tells LaTeX to put the very next character (in this case, i) slightly below the 6.

b. Superscripts

  • Raw Code: $6^2$
  • Rendered Output: $6^2$
  • Explanation: The caret (^) creates a superscript. It tells LaTeX to put the very next character (in this case, 2) slightly above the 6. This is used for exponents.

c. Grouping (for sub- and superscripts)

  • Raw Code: $x^{i,j}$ and $6^{1+1}
  • Explanation: This is a combination of concepts.
    • The underscore (_) still means “subscript.”
    • Curly Braces ({...}) are used for grouping.
    • If you just wrote $6_i,j$, it would render as $6_i,j$ (only the i is a subscript).
    • By using {i,j}, you are telling LaTeX to treat the entire sequence “i,j” as the subscript.
  • Rendered Output: $6_{i,j}$, $6^{1+1}$

d. Fractions

  • Raw Code: $\frac{\text{Numerator}}{\text{Denominator}}$
    • Explanation: Write down fractions using \frac{...}{...}
      • The first set of curly braces {...} contains the numerator.
      • The second set of curly braces {...} contains the denominator.
      • Write text within the LaTeX math notation using \text{…}
  • Rendered Output: $\frac{\text{Numerator}}{\text{Denominator}}$

e. Symbols

  • Raw Code: $\alpha, \beta, \gamma, \sum, \mathcal{L}, \times$
  • Explanation: You can use \symbolname to insert mathematical symbols, greek letters etc.
    • \alpha = $\alpha$, \beta = $\beta$, \gamma = $\gamma$, etc.
    • To denote a likelihood function, use the symbol for Lagrangian functions: \mathcal{L} = $\mathcal{L}$
    • Other symbols include, e.g.: \sum = $\sum$ (summation symbol), \times = $\times$ (multiplication sign)
    • Some common LaTeX Math mode functions are summarized here: wch.github.io/latexsheet/latexsheet-1.png
  • Rendered Output: $\alpha, \beta, \gamma, \sum, \mathcal{L}, \times$

f. LaTeX Math mode functions

  • Raw Code: $$\sqrt{x} \sqrt{k}{x}$$ $$\log(x), \sin(x)$$ $$\sum_{k=1}^{x}$$ $$\hat{y_j} \neq \hat{y}_j$$ $$\hat{y}_{i,k}$$
    • Explanation: You can initiate symbols and other functions starting with a backslash: \
  • Rendered Output: $$\sqrt{x}, \sqrt[k]{x}$$ $$\log(x), \sin(x)$$ $$\sum_{k=1}^{x}$$ $$\hat{y_j} \neq \hat{y}j$$ $$\hat{y}{i,k}$$

g. Example: Linear regression equation

  • Raw Code: $\hat{y} = x_1\beta_1 + x_2\beta_2 + x_2^2\beta_3$
  • Rendered Output: $\hat{y} = x_1\beta_1 + x_2\beta_2 + x_2^2\beta_3$

h. Other Math environments

  • Raw Code:
\begin{equation}
y_{i=1} = x_1\beta_1 + x_2\beta_2 
\end{equation}

\begin{align}
y_{i=1} &= x_1\beta_1 + x_2\beta_2 = 2,1*\beta_1 + 1*\beta_2 + \varepsilon \\
y_{i=1} &= 2,1*\beta_1 + 1*\beta_2 + \varepsilon
\end{align}

\begin{align*}
y_{i=1} &= x_1\beta_1 + x_2\beta_2 = 2,1*\beta_1 + 1*\beta_2 + \varepsilon \\
y_{i=1} &= 2,1*\beta_1 + 1*\beta_2 + \varepsilon
\end{align*}
  • Explanation: You can also use other LaTeX math environments like equation and align for more complex formatting.
    • equation supports single-lined equations (but not multiple lines)
    • Use & to denote where equations should align, e.g. &=.
    • Usually, using * when declaring an environment suppresses numbering of equations, e.g. \begin{align*} ... \end{align*} instead of \begin{align} ... \end{align}.
  • Rendered Output:

\begin{equation} y_{i=1} = x_1\beta_1 + x_2\beta_2 \end{equation}

\begin{align} y_{i=1} &= x_1\beta_1 + x_2\beta_2 = 2.1\beta_1 + 1\beta_2 + \varepsilon \ y_{i=1} &= 2.1\beta_1 + 1\beta_2 + \varepsilon \end{align}

\begin{align*} y_{i=1} &= x_1\beta_1 + x_2\beta_2 + = 2.1\beta_1 + 1\beta_2 + \varepsilon \ y_{i=1} &= 2.1\beta_1 + 1\beta_2 + \varepsilon \end{align*}

Previous
Next