# Using Markdown and LaTeX > *Note: This document is indended for students enrolled in H611 at IU – Indianapolis, but it can be applicable universally.* ## Markdown [Markdown Guide](https://www.markdownguide.org/getting-started/) provides a great introduction to Markdown and how to use it. I recommend that you use the [cheat sheet](https://www.markdownguide.org/cheat-sheet/) as a quick reference, and the [basic syntax page](https://www.markdownguide.org/basic-syntax/) for more involved descriptions. ### Images in HackMD I **highly** encourage you to find ways to draw diagrams (not math), and [upload the images](https://hackmd.io/c/tutorials/%2F%40docs%2Finsert-image-in-team-note) to your HackMD notebooks. ## LaTeX [LaTeX](https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes#What_is_LaTeX?) is a more involved markup language for rendering complex characters and objects such as math symbols in the form of SVG graphics. ### Generating vs. Writing LaTeX **Generating it:** As a start, you can try a tool like ChatGPT to estimate the LaTeX code you're looking for. Just type (in words) what you want to code, and test it out as you like. Alternatively, you can use a "drawing-to-LaTeX" tool like the [Mathpix snipping tool](https://mathpix.com/snipping-tool) *(note, with your IU email, you only get to use this 20 times per month)*. **Writing it:** LaTeX generation is definitely improving every day, but I find that learning the real thing is often much more efficient as you get better at it. There are some good [cheatsheets](https://quickref.me/latex.html) and [tutorials](https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes) out there to help, but I recommend that you **use this [online LaTeX editor](https://editor.codecogs.com/home)** to help you navigate the notation. 1. Navigate to [the LaTeX editor](https://editor.codecogs.com/home). 2. In the top menu, hover over the type of math symbol you're looking for. 3. Click the symbol you're interested in. Test it out to make sure it is what you want. - You can adjust the rendering settings at the bottom of the box, if you like. 5. Copy/Paste the code into hackmd.io. Below are some other common implementations of LaTeX code which might not be mentioned in the editor. ### Inline Math LaTeX can be rendered within a markdown paragraph using single dollar signs. So, `$x + 2$` (typed in the paragraph) would render as $x + 2$. Sometimes, the inline rendering is "small", and you might want it to be larger, or "**display style**". In these cases, you'll use the code `/displaystyle`. So, instead of $\frac{1}{2}$ (`$\frac{1}{2}$`), you could have $\displaystyle\frac{1}{2}$ (`$\displaystyle\frac{1}{2}$`). ### Basic Syntax **Brackets and Left/Right** To keep symbol "types" separated, you'll need to use curly brackets `{}`. Also, if you want to use parentheses (or other "containers") around "big" characters, you'll need to use `\left` and `\right` followed by the symbol in question. **Spaces** Unfortunately, LaTeX does not read 'spaces' as we usually would. I.e., spaces `" "` are ignored, as in `$before after$` will render as $before after$. So, you need to explicitly call them out. There are a few ways to do that, the first being the explicit `\text` functionality, and the last being the `\quad`, for [quadrat](https://en.wikipedia.org/wiki/Quad_(typography)). LaTeX | Math --- | --- `\text{before after}` | $\text{before after}$ `x \, y` | $x \, y$ `x \; y` | $x \; y$ `x \quad y` | $x \quad y$ **Over/Under-writing and Sub/Super-scripting** Some functions require a notion of above and below. For example, exponentiation (super-scripting) is done with a `^` symbol, and subscripts are done using `_`. This is relatively universal across LaTeX symbols. LaTeX | Math --- | --- `e^{x + 2}` | $e^{x + 2}$ `x_1` | $x_1$ `\left(\displaystyle\frac{1}{2}\right)` | $\left(\displaystyle\frac{1}{2}\right)$ Sometimes, the `^` is interpreted as "on top" as with summation. And sometimes the `_` is interpreted as "below" as with limits. But, if you want to explicitly make this happen for a general symbol, you'll need to use `\overset` or `\underset`. LaTeX | Math --- | --- `\displaystyle\sum_{i=1}^N` | $\displaystyle\sum_{i=1}^N$ `\lim_{x\to 0} f(x)` | $\displaystyle\lim_{x\to 0} f(x)$ `\overset{?}{=}` | $\overset{?}{=}$ ### Equations If you want to render an equation separately, you'll need to make a new line in markdown, and wrap your code in double dollar signs. E.g., in hackmd.io, you would write: ```latex $$ f(x) = x^2 + x + 1 $$ ``` --- $$ f(x) = x^2 + x + 1 $$ --- If you plan to stack multiple equations, you'll want to use the following syntax, with the `&` acting as a sort of "alignment" indicator and `\\` as a "new line". Next to the `\\`, you can use something like `[5pt]` to indicate a specific vertical break. Lastly, you can also use the `\text` command to write "math font" text, and the `\quad` command to indicate a horizontal break. ```latex \begin{align} 2x + 2 &= 6 \\ 2x &= 4 \\[8pt] x &= 2 \quad \text{is the answer} \end{align} ``` --- $$ \begin{align} 2x + 2 &= 6 \\ 2x &= 4 \\[8pt] x &= 2 \quad \text{is the answer} \end{align} $$ --- ### Augmented Matrices Augmented matrices are created using the following syntax, with `ccc|c` indicating three *centered* columns before a bar, then another centered column: ```latex $$ \left[ \begin{array}{ccc|c} 1 & 2 & 3 & 4 \\ 5 & 6 & 7 & 8 \\ 9 & 10 & 11 & 12 \\ \end{array} \right] $$ ``` --- $$ \left[ \begin{array}{ccc|c} 1 & 2 & 3 & 4 \\ 5 & 6 & 7 & 8 \\ 9 & 10 & 11 & 12 \\ \end{array} \right] $$ --- ### General Matrices Sometimes, you need to represent more than you can show all at once ... **General Matrix** ```latex= $$ \begin{bmatrix} a_{11} & \dots & a_{1n} \\ a_{21} & \dots & a_{2n} \\ \vdots & \ddots & \vdots \\ a_{m1} & \dots & a_{mn} \end{bmatrix} $$ ``` --- $$ \begin{bmatrix} a_{11} & \dots & a_{1n} \\ a_{21} & \dots & a_{2n} \\ \vdots & \ddots & \vdots \\ a_{m1} & \dots & a_{mn} \end{bmatrix} $$ --- **General Diagonal Matrix** ```latex= $$ \begin{bmatrix} \sigma_1 & \ & \ & \ \\ \ & \sigma_2 & & \ \\ \ & \ & \ddots & \ \\ \ & \ & \ & \sigma_r \end{bmatrix} $$ ``` --- $$ \begin{bmatrix} \sigma_1 & \ & \ & \ \\ \ & \sigma_2 & & \ \\ \ & \ & \ddots & \ \\ \ & \ & \ & \sigma_r \end{bmatrix} $$ --- **General Matrix Vectors** ```latex= $$ \begin{bmatrix} \bigm| & \bigm| & & \bigm| \\ \mathbf{v_1} & \mathbf{v_2} & \cdots & \mathbf{v_n} \\ \bigm| & \bigm| & & \bigm| \\ \end{bmatrix} $$ ``` --- $$ \begin{bmatrix} \bigm| & \bigm| & & \bigm| \\ \mathbf{v_1} & \mathbf{v_2} & \cdots & \mathbf{v_n} \\ \bigm| & \bigm| & & \bigm| \\ \end{bmatrix} $$ --- **General Matrix Rows** ```latex= $$ \begin{bmatrix} \rule{1cm}{0.5pt} & \mathbf{v}_1 &\rule{1cm}{0.5pt} \\ \rule{1cm}{0.5pt} & \mathbf{v}_2 &\rule{1cm}{0.5pt} \\ \vdots & \vdots & \vdots \\ \rule{1cm}{0.5pt} & \mathbf{v}_m &\rule{1cm}{0.5pt} \end{bmatrix} $$ ``` --- $$ \begin{bmatrix} \rule{1cm}{0.5pt} & \mathbf{v}_1 &\rule{1cm}{0.5pt} \\ \rule{1cm}{0.5pt} & \mathbf{v}_2 &\rule{1cm}{0.5pt} \\ \vdots & \vdots & \vdots \\ \rule{1cm}{0.5pt} & \mathbf{v}_m &\rule{1cm}{0.5pt} \end{bmatrix} $$ --- ### Other Resources - For *plotting* 2-dimensional graphs, I recommend the [desmos calculator](https://www.desmos.com/calculator/tn0jj0hxct). - For plotting in 3D, you can use the [3D desmos calculator](https://www.desmos.com/3d).