owned this note
owned this note
Published
Linked with GitHub
[Markdown](https://hackmd.io/c/codimd-documentation/%2F%40codimd%2Fmarkdown-syntax) is so-called *markup language*, along with [HTML](https://www.w3schools.com/html/) and [$\LaTeX$](https://www.latex-project.org/), meaning that it is a syntax for marking up text documents (making words bold, making large headers, etc.). However, it is much easier to read than HTML or pure Latex, although it allows embedded Latex for using mathematical notation.
Here's a DFA $D$
```mermaid
graph LR
_ --> a
a((a)) --0--> b
a --1--> c
b --0--> c
b --1--> b
c((c)) --0--> c
c --1--> b
```
The above is not standard Markdown, but uses a library called [mermaid](https://mermaid-js.github.io/mermaid/#/) for drawing graphs. Note that [Gradescope](https://www.gradescope.com/) does not support mermaid, but it does permit Latex in free-response answers for online assignments, so everything on this page except the above drawing should also work on Gradescope. Gradescope will also support Markdown in the future, but this is currently [on hold](https://trello.com/c/J4huJs47/267-latex-support-for-online-assignment-responses#comment-5e7b538279c3d303fd77265f).
The formal definition of the DFA above is $D=(Q,\Sigma,\delta,s,F)$, where
- $Q = \{a,b,c\}$
- $\Sigma = \{0,1\}$
- $s = a$
- $F = \{b\}$
- $\delta$ is defined as
| |0|1|
|-|-|-|
|a|b|c|
|b|c|b|
|c|c|b|
hackmd supports copying and pasting images directly into the browser;
here's an image pasted from my lecture notes: ![](https://i.imgur.com/ZhEMk20.png)
source code:
```python
def square(n: int) -> int:
return n*n
```
If you prefer editing offline, Visual Studio Code supports Markdown, with extensions for [Latex](https://marketplace.visualstudio.com/items?itemName=goessner.mdmath), [mermaid](https://marketplace.visualstudio.com/items?itemName=bierner.markdown-mermaid), and [pasting images](https://marketplace.visualstudio.com/items?itemName=telesoho.vscode-markdown-paste-image).
## More examples of $\LaTeX$
You can put math in the same line as the text like this: $x=5.$
Or you can put it on its own line like this: $$x=5.$$
Multiline equations are also useful:
\begin{eqnarray*}
x & = & y+z
\\
& \leq & 2y
\\
& < & 3y \qquad \text{if $y > 0$}
\end{eqnarray*}
Here's a list of common useful math symbols:
- $x^2$, $y_2$. Use curly braces to group multiple characters, so you get $x^{100}$ instead of $x^100$.
- $n_2$, $x_{n^2}$, $x_n^2$, $O(n \log n)$, $\hat{x}$, $\widehat{x}$, $\overline{A}$, $x_1'$, $x_n''$
- Plain text in math mode: $\{ p \in \mathbb{N} \mid p \text{ is prime} \}$ ($Please Please Please Do Not Just Type Words In Math Mode$ without the ``\text{}`` command, or it looks ugly and unreadable.)
- Spaces in math mode: $\{ \ p \in \mathbb{N} \mid p \text{ is prime} \ \}$
- $\frac{\pi^2}{6} = \sum_{n=1}^{\infty} \frac{1}{n^2}$
- $\zeta(z) = \prod\limits_{n=1}^{\infty} \frac{1}{1 - p_n^{-z}}$
- $\mathbb{N} = \{ 0, 1, 2, \ldots \} = \mathbb{Z} \setminus \{-1, -2, \ldots \} \subseteq \mathbb{Z} \subset \mathbb{Q} \subset \mathbb{R} \not\subseteq \mathbb{R}^+$
- Greek letters: $\alpha, \beta, \gamma, \Gamma, \delta, \Delta, \epsilon, \zeta, \eta, \theta, \Theta, \kappa, \lambda, \Lambda, \mu, \nu, \xi, \Xi, \pi, \Pi, \rho, \sigma, \tau, \phi, \Phi, \chi, \psi, \Psi, \omega, \Omega$
- complexity classes: $\mathsf{P}, \mathsf{NP}, \mathsf{EXP}, \mathsf{DTIME}(n^3)$
- $\Sigma^*,a^*$
- $\delta: Q \times \Sigma \to Q$
- $(\forall X)\ |\mathcal{P}(X)| > |X|$
- $\lim_{n \to \infty} \frac{1}{n} = 0$, $\lim\limits_{n \to \infty} \frac{1}{n} = 0$
- $(\forall n \in \mathbb{N})(\exists m \in X)\ m > n \iff |X|=\infty \implies |X| \geq |\mathbb{N}|$
- $A \cup (B \cap C) = (A \cup B) \cap (A \cup C)$
- $\Sigma^* = \bigcup_{i=0}^{\infty} \Sigma^i$
- regex's: $010^* \cup 1^∗ (01^+ \cup 10)^∗$ and $00(0|1)^*$
- CFG's:
$A \to 0A1 \ | \ \varepsilon$
$A \to BB$
$B \to 1B0 \ | \ 0B \ | \ \varepsilon$
Note how ugly this looks:
$$
( \frac{1}{n^2} )
$$
Use `\left` and `\right` to make pairs of matching delimiters, like parentheses, big enough for the text they contain:
$$
\left( \frac{1}{n^2} \right)
$$
For defining sets where you want the vertical line in the middle to scale with the text size, it is useful to have a "phantom delimiter" (represented by a period paired with the `\left` or `\right`):
$$
X = \left\{ \left. \frac{n^2}{2^{n^3}} \right| n \in \mathbb{N} \right\}
$$
Of course this only works if you guess properly whether the left or right is bigger, which failed here:
$$
X = \left\{ \left. n \right| \frac{n^2}{2^{n^3}} \geq \frac{1}{10} \right\}
$$
For an example of a full Latex document (this page is snippets of Latex embedded in Markdown), see [sample.tex](https://web.cs.ucdavis.edu/~doty/fall2015ecs120/sample.tex) at my [Latex help page](https://web.cs.ucdavis.edu/~doty/fall2015ecs120/latex.html).
# Gradescope Markdown/Latex
Gradescope supports Latex in your responses to questions (and may support Markdown eventually), but with slight different syntax than is used on this page. The main difference is that you use a double-dollar-sign for inline equations, e.g., $$x = 2y$$, and you use a triple-dollar-sign for equations on their own line, e.g., $$$x = 2y.$$$
What appears below is the same content as the text above, and it won't look good on hackmd.io, but it will render properly on Gradescope.
$$1^{2p+k}0^p$$
**Note:** Gradescope has [temporarily disabled](https://trello.com/c/J4huJs47/267-latex-support-for-online-assignment-responses#comment-5e7b538279c3d303fd77265f) rendering of Markdown. So the non-Latex parts below will appear un-rendered in plain text, as they do on the left side of the screen.
## Markdown and simple $$\LaTeX$$
[Markdown](https://hackmd.io/c/codimd-documentation/%2F%40codimd%2Fmarkdown-syntax) is so-called *markup language*, along with [HTML](https://www.w3schools.com/html/) and [$$\LaTeX$$](https://www.latex-project.org/), meaning that it is a syntax for marking up text documents (making words bold, making large headers, etc.). However, it is much easier to read than HTML or pure Latex, although it allows embedded Latex for using mathematical notation.
Here's a DFA $$D$$
```mermaid
graph LR
_--> a
a((a)) --0--> b
a --1--> c
b --0--> c
b --1--> b
c((c)) --0--> c
c --1--> b
```
The above is not standard Markdown, but uses a library called [mermaid](https://mermaid-js.github.io/mermaid/#/) for drawing graphs. [Gradescope](https://www.gradescope.com/) does not support mermaid, but it does support Latex in free-response answers for online assignments, so everything on this page except the above drawing should also work on Gradescope. Gradescope will also support Markdown in the future, but this is currently [on hold](https://trello.com/c/J4huJs47/267-latex-support-for-online-assignment-responses#comment-5e7b538279c3d303fd77265f).
The formal definition of the DFA is $$D=(Q,\Sigma,\delta,s,F)$$, where
- $$Q = \{a,b,c\}$$
- $$\Sigma = \{0,1\}$$
- $$s = a$$
- $$F = \{a,c\}$$
- $$\delta$$ is defined as (note that unlike hackmd, there are no leading spaces in the table below)
| |0|1|
|-|-|-|
|a|b|c|
|b|c|b|
|c|c|a|
hackmd supports copying and pasting images directly into the browser (note that Gradescope allows one to upload images, but it is not as straightforward to simply paste them via Ctrl/Cmd+V, but since pasting into hackmd.io created this URL for the image, the same link can be used on Gradescope);
here's an image pasted from my lecture notes: ![](https://i.imgur.com/ZhEMk20.png)
source code:
```python
def square(n):
return n*n
```
If you prefer editing offline, Visual Studio Code supports Markdown, with extensions for Latex (https://marketplace.visualstudio.com/items?itemName=goessner.mdmath), mermaid (https://marketplace.visualstudio.com/items?itemName=bierner.markdown-mermaid), and pasting images (https://marketplace.visualstudio.com/items?itemName=telesoho.vscode-markdown-paste-image).
More examples of $$\LaTeX$$
===
You can put math in the same line as the text like this: $$x=5.$$
Or you can put it on its own line like this: $$$x=5.$$$
Multiline equations don't work in Gradescope.
Here's a list of common useful math symbols:
* $$x^2, y_2$$. Use curly braces to group multiple characters, so you get $$x^{100}$$ instead of $$x^100$$.
- $$n_2, x_{n^2}, x_n^2, O(n \log n), \hat{x}, \overline{A}, x_1', x_n''$$
- Plain text in math mode: $$\{ p \in \mathbb{N} \mid p \text{ is prime} \}$$
- Spaces in math mode: $$\{ \ p \in \mathbb{N} \mid p \text{ is prime} \ \}$$
- $$\frac{\pi^2}{6} = \sum_{n=1}^{\infty} \frac{1}{n^2}$$
- $$\zeta(z) = \prod\limits_{n=1}^{\infty} \frac{1}{1 - p_n^{-z}}$$
- $$\mathbb{N} = \{ 0, 1, 2, \ldots \} = \mathbb{Z} \setminus \{-1, -2, \ldots \} \subseteq \mathbb{Z} \subset \mathbb{Q} \subset \mathbb{R} \not\subseteq \mathbb{R}^+$$
- Greek letters: $$\alpha, \beta, \gamma, \Gamma, \delta, \Delta, \epsilon, \zeta, \eta, \theta, \Theta, \kappa, \lambda, \Lambda, \mu, \nu, \xi, \Xi, \pi, \Pi, \rho, \sigma, \tau, \phi, \Phi, \chi, \psi, \Psi, \omega, \Omega$$
- complexity classes: $$\mathsf{P}, \mathsf{NP}, \mathsf{DTIME}(n^3)$$
- $$\Sigma^*, \{0,1\}^*$$
- $$\delta: Q \times \Sigma \to Q$$
- $$(\forall X)\ |\mathcal{P}(X)| > |X|$$
- $$\lim_{n \to \infty} \frac{1}{n} = 0$$
- $$(\forall n \in \mathbb{N})(\exists m \in X)\ m > n \iff |X|=\infty \implies |X| \geq |\mathbb{N}|$$
- $$A \cup (B \cap C) = (A \cup B) \cap (A \cup C)$$
- $$\Sigma^* = \bigcup_{i=0}^{\infty} \Sigma^i$$
- regex's: $$010^* \cup 1^* (01^+ \cup 10)^*$$, $$010^* \cup 1^* (01^+ \cup 10)^*$$
- CFG's:
$$A \to 0A1 | \varepsilon$$
$$A \to BB$$
$$B \to 1B0 | 0B | \varepsilon$$
Note how ugly this looks:
$$$
( \frac{1}{n^2} )
$$$
Use `\left` and `\right` to make pairs of matching delimiters big enough for the text they contain:
$$$
\left( \frac{1}{n^2} \right)
$$$
For defining sets where you want the vertical line in the middle to scale with the text size, it is useful to have a "phantom delimiter" (represented by a period):
$$$
X = \left\{ \left. \frac{n^2}{2^{n^3}} \right| n \in \mathbb{N} \right\}
$$$
Of course this only works if you guess properly whether the left or right is bigger, which failed here:
$$$
X = \left\{ \left. n \right| \frac{n^2}{2^{n^3}} \geq \frac{1}{10} \right\}
$$$
For an example of a full Latex document (this page is snippets of Latex embedded in Markdown), see [sample.tex](https://web.cs.ucdavis.edu/~doty/fall2015ecs120/sample.tex) at my [Latex help page](https://web.cs.ucdavis.edu/~doty/fall2015ecs120/latex.html).