Markdown and LaTeX#

Following the Markdown and LaTeX introduction, Markdown allows you to write using an easy-to-read, easy-to-write plain text format containing text formatting, embedded graphics, source codes and LaTex formula. LaTeX is a high-quality typesetting system; it includes features designed to produce technical and scientific documentation. Basic knowledge about Markdown and LaTeX allows us to create high-quality documents and reports quickly. This tutorial provides a quick reference to use Markdown and LaTeX. This text is written in Markdown; you can see the original text by clicking on the download button on the top-right corner of this page.

You need to submit your coursework on Crowdmark in Markdown.

The following provides a quick reference to the most commonly used Markdown syntax.

Emphasis#

Text can be emphasised as follows:

  • *Italic* and **Bold** becomes Italic and Bold

To quote test, use >. For example,

> Imagination is more important than knowledge.
>
> Albert Einstein

gives

Imagination is more important than knowledge.

Albert Einstein

For manual line break, use

  • <br />

Headers#

Lines containing headers and document titles begin with hashes. More hashes indicate a lower rank:

# H1
## H2
### H3
#### H4
##### H5
###### H6

Lists#

Markdown recognises lists from dashes - and stars * as well as numbering, e.g. 1..

- Item 1
- Item 2
    - Item 2a (2 tabs)
    - Item 2b
        - Item 2b-1 (4 tabs)
        - Item 2b-2

turns into

  • Item 1

  • Item 2

    • Item 2a (2 tabs)

    • Item 2b

      • Item 2b-1 (4 tabs)

      • Item 2b-2

1. Item 1
2. Item 2
3. Item 3
    - Item 3a
    - Item 3b

turns into

  1. Item 1

  2. Item 2

  3. Item 3

    • Item 3a

    • Item 3b

Tables#

One can also add tables. For example

1st Header|2nd Header|3rd Header
---|:---:|---:
col 1 is|left-aligned|1
col 2 is|center-aligned|2
col 3 is|right-aligned|3

turns into

1st Header

2nd Header

3rd Header

col 1 is

left-aligned

1

col 2 is

center-aligned

2

col 3 is

right-aligned

3

Code blocks#

In Markdown, we can simply add plain code blocks to display (not evaluating) by inserting triple back quote i.e. ```. Double click on the text cell to understand the example:

import matplotlib.pyplot as plt
import numpy as np

One can add syntax highlighting by specifying the programming language behind the first set of ```:

import matplotlib.pyplot as plt
import numpy as np

LaTeX and adding mathematics to Markdown#

LaTeX is a sophisticated typesetting system for mathematical texts. Markdown borrows from LaTeX to typeset mathematical formulas without going into the full complexity of LaTeX. For more information about LaTeX see for example Learn LaTeX in 30 minutes and Wikibooks.

We switch to inline formulas with a single $ and to a display formula with a double $$.

While $f(x) \ne g(y)$ is space-saving, this if often clearer:

$$
f(x) \ne g(x)
$$

gives


While \(f(x) \ne g(y)\) is space-saving, this if often clearer:

\[ f(x) \ne g(x) \]

Symbols#

Operators

- $x + y$
- $x - y$
- $x \times y$
- $x \div y$
- $\dfrac{x}{y}$
- $\sqrt{x}$

gives

  • \(x + y\)

  • \(x - y\)

  • \(x \times y\)

  • \(x \div y\)

  • \(\dfrac{x}{y}\)

  • \(\sqrt{x}\)

Symbols

- $\pi \approx 3.14159$
- $\pm \, 0.2$
- $\dfrac{0}{1} \neq \infty$
- $0 < x < 1$
- $0 \leq x \leq 1$
- $x \geq 10$
- $\forall \, x \in (1,2)$
- $\exists \, x \notin [0,1]$
- $A \subset B$
- $A \subseteq B$
- $A \cup B$
- $A \cap B$
- $X \implies Y$
- $X \impliedby Y$
- $a \to b$
- $a \longrightarrow b$
- $a \Rightarrow b$
- $a \Longrightarrow b$
- $a \propto b$

gives

  • \(\pi \approx 3.14159\)

  • \(\pm \, 0.2\)

  • \(\dfrac{0}{1} \neq \infty\)

  • \(0 < x < 1\)

  • \(0 \leq x \leq 1\)

  • \(x \geq 10\)

  • \(\forall \, x \in (1,2)\)

  • \(\exists \, x \notin [0,1]\)

  • \(A \subset B\)

  • \(A \subseteq B\)

  • \(A \cup B\)

  • \(A \cap B\)

  • \(X \implies Y\)

  • \(X \impliedby Y\)

  • \(a \to b\)

  • \(a \longrightarrow b\)

  • \(a \Rightarrow b\)

  • \(a \Longrightarrow b\)

  • \(a \propto b\)

Accents

- $\bar a$
- $\tilde a$
- $\breve a$
- $\hat a$
- $a^ \prime$
- $a^ \dagger$
- $a^ \ast$
- $a^ \star$
- $\mathcal A$
- $\mathrm a$
- $\cdots$
- $\vdots$
- $\#$
- $\$$
- $\%$
- $\&$
- $\{ \}$
- $\_$

gives

  • \(\bar a\)

  • \(\tilde a\)

  • \(\breve a\)

  • \(\hat a\)

  • \(a^ \prime\)

  • \(a^ \dagger\)

  • \(a^ \ast\)

  • \(a^ \star\)

  • \(\mathcal A\)

  • \(\mathrm a\)

  • \(\cdots\)

  • \(\vdots\)

  • \(\#\)

  • \(\$\)

  • \(\%\)

  • \(\&\)

  • \(\{ \}\)

  • \(\_\)

Greek letters

$$
\alpha, \beta, \gamma, \delta, \epsilon, \pi,\\
\Gamma,\Sigma,\Upsilon,\Pi,\Theta
$$

gives

\[\begin{split} \alpha, \beta, \gamma, \delta, \epsilon, \pi,\\ \Gamma,\Sigma,\Upsilon,\Pi,\Theta \end{split}\]

Spaces#

  • Horizontal space: \quad

  • Large horizontal space: \qquad

  • Small space: \,

  • Medium space: \:

  • Large space: \;

  • Negative space: \!

For example, $a \; + \! b$ gives \(a \; + \! b\).

Matrices#

To investigate the Markdown code for matrices, download this page’s Markdown version by clicking the download button on the top right.

\[\begin{split} \begin{matrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{matrix} \end{split}\]
\[\begin{split} M = \begin{bmatrix} \frac{5}{6} & \frac{1}{6} & 0 \\[0.3em] \frac{5}{6} & 0 & \frac{1}{6} \\[0.3em] 0 & \frac{5}{6} & \frac{1}{6} \end{bmatrix} \end{split}\]
\[\begin{split} M = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} \end{split}\]
\[\begin{split} M = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} \end{split}\]
\[\begin{split} A_{m,n} = \begin{pmatrix} a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\ a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m,1} & a_{m,2} & \cdots & a_{m,n} \end{pmatrix} \end{split}\]

Functions#

Special function names such as trigonometic functions are traditionally written in non-italic font. To achieve this, write f(x) = \sin(x) instead of f(x) = sin(x), which gives \(f(x) = \sin(x)\) instead of \(f(x) = sin(x)\).

Similarly, \cos(x) \qquad \log(x) \qquad \exp(x) gives

\[ \cos(x) \qquad \log(x) \qquad \exp(x). \]

Sub and superscripts#

  • Subscripts: $a_i$ or $a_{ij}$ gives \(a_i\) or \(a_{ij}\)

  • Superscripts: $a^i$ or $a^{ij}$ gives \(a^i\) or \(a^{ij}\)

Sums and products#

A sum is written S_n = \sum_{i=1}^n X^i:

\[ S_n = \sum_{i=1}^n X^i \]

A product is written P_n = \prod_{i=1}^n X_i:

\[ P_n = \prod_{i=1}^n X_i \]

Derivatives and integrals#

Derivatives f'(x) = \frac{df}{dx}:

\[ f'(x) = \frac{df}{dx} \]

Partial derivatives f(a,b) = f(0,b) + \frac{\partial f}{\partial x} a + \text{higher-order terms}:

\[ f(a,b) = f(0,b) + \frac{\partial f}{\partial x} a + \text{higher-order terms} \]

Integrals \int_0^1 f(x) \, dx:

\[ \int_0^1 f(x) \, dx \]

Examples#

Investigate the Markdown code for matrices by double-clicking on the text cell.

\[ \forall x \in X\quad \exists y \subset \Sigma \]
\[ x_n \rightarrow 0 \mbox{ as } n \rightarrow \infty \]
\[ \|A\|_p := \sup_{x \in R^n \setminus \{0\}} \frac{\|Ax\|_p}{\|x\|_p} \]

Question: Find the roots of

\[ x^2+p x + q = 0 \]

Solution:

\[ x_\pm = -\frac{p}{2} \pm \sqrt{\Big(\frac{p}{2}\Big)^2 - q} \]

Converting LaTeX to Markdown#

If you have already written a text in LaTeX and need it in Markdown, you can use tools like Pandoc to convert from one format to another.