mirror of
https://github.com/TeachBooks/template.git
synced 2026-11-12 22:25:52 +00:00
128 lines
5.1 KiB
Markdown
128 lines
5.1 KiB
Markdown
# Use equations
|
|
|
|
In this exercise, you will learn how to write and format mathematical equations in your TeachBook, both inline and as standalone blocks.
|
|
|
|
::::::{topic} Exercise objective
|
|
Can you write and format equations correctly in your book?
|
|
::::::
|
|
|
|
```{tip}
|
|
Using properly formatted equations makes mathematical expressions clearer and more professional. More details can be found in the [JupyterBook documentation](https://jupyterbook.org/v1/content/math.html).
|
|
```
|
|
|
|
## Writing equations
|
|
|
|
1. Open a new or existing Markdown file where you want to include an equation.
|
|
2. Start with a simple block equation using double dollar signs. Try adding the following equation in your Markdown file:
|
|
|
|
```md
|
|
$$ F_{res} = m \cdot a $$
|
|
```
|
|
|
|
```{tip}
|
|
The syntax used for creation equations is TeX, a markup language for math. It's often part of the software-system LaTeX, which allows to create full documents in this language. There's plenty of documentation online on how to use it, including graphical interfaces (for example [this one](https://latexeditor.lagrida.com/))
|
|
```
|
|
|
|
3. Now let's add another equation with an error:
|
|
|
|
```md
|
|
$$ E = m \ccdot c^2 $$
|
|
```
|
|
|
|
4. Check whether the equations renders correctly by clicking `preview` if you're making this edit in the GitHub single file editor. Make sure you already defined the file type as `<title>.md` to enable rendering. Note that all ill-formatted equation are indicated in red, i.e. $\red{\text{\ccdot}}$
|
|
|
|
5. As an alternative you try and use the 'math directive'. This will have the same results + adds a equation number which can be used for referencing (refer to [](011.md)):
|
|
|
|
````md
|
|
```{math}
|
|
v = a \cdot t
|
|
```
|
|
````
|
|
|
|
6. Click on `preview` again. Note that these equations don't render. That's because these 'directives' is a MyST feature (an extension of markdown), which is not supported by the GitHub previewer that only support markdown.
|
|
|
|
7. Now, add an inline equation by enclosing the equation with single dollar signs. Try this example:
|
|
|
|
|
|
```md
|
|
The displacement can be found using the equation $s = v \cdot t$.
|
|
```
|
|
|
|
## Formatting mathematical symbols
|
|
|
|
8. In this step we will experiment with different TeX symbols. Use the following table and test each example in your Markdown file:
|
|
|
|
|
|
| Name | Script |
|
|
|---|---|
|
|
| Square root | `\sqrt{4}` |
|
|
| Power | `^{2x}` |
|
|
| Fraction | `\frac{2}{3}` |
|
|
| Subscript | `_{gem}` |
|
|
| Superscript | `^{N}` |
|
|
| Multiplication | `\cdot` |
|
|
|
|
9. Extend this exercise by trying more advanced mathematical expressions:
|
|
|
|
| Name | Script |
|
|
|---|---|
|
|
| Derivative | `\frac{\Delta f}{\Delta t}` |
|
|
| Integral | `\int_a^b dx` |
|
|
| Sine function | `\sin(x)` |
|
|
|
|
10. Test your understanding by adding a new equation of your choice, ideally one that requires many LaTex symbols!
|
|
|
|
|
|
## Adding colours to equations
|
|
|
|
11. The TeachBooks template includes the `sphinx-named-colors` extension, which lets you add colours to parts of your equations using LaTeX. Look at the [CSS named colours](https://developer.mozilla.org/en-US/docs/Web/CSS/named-color) to explore the possible colour options.
|
|
|
|
12. It is also possible to use custom colours! Look [here](https://teachbooks.io/manual/external/Sphinx-Named-Colors/README.html#) for documentation about the TeachBook extension which allows custom colours.
|
|
|
|
13. Colours are added to equations using `\namedcolour{...}`, replacing `namedcolour` with the colour of choice. Test this out with the examples in the table below:
|
|
|
|
::::{list-table}
|
|
:widths: auto
|
|
:header-rows: 1
|
|
* - Color
|
|
- $\LaTeX$ Code
|
|
* - olive
|
|
- `\olive{\int_a^bf(x)dx}`
|
|
* - hotpink
|
|
- `1.\hotpink{\mathbf{49}}`
|
|
* - darkturquoise
|
|
- `\dfrac{\darkturquoise{\partial}f}{\darkturquoise{\partial}x}`
|
|
::::
|
|
|
|
|
|
14. For colours with hyphens we use need to use the class-based command `\class{named-colour}{...}. Try this using the format shown below:
|
|
|
|
```md
|
|
$$ \class{hyphen-color}{\sum}_{n=1}^\infty $$
|
|
```
|
|
|
|
15. Test your understanding by creating a block equation where each term is a different colour!
|
|
|
|
```{tip}
|
|
This is especially helpful for highlighting changes between equations or focusing attention on specific terms!
|
|
```
|
|
|
|
16. When you are ready, commit your changes to the repository by clicking on the green `Commit changes` button.
|
|
|
|
17. Add a commit message.
|
|
|
|
18. To see your changes, go to {octicon}`play` `Actions` - The most recent workflow run `overview.md / the commit message of the commit you just made` - Wait for it to finish - In the summary, click on the link of your book shown in the table `Branches deployed` and under `Primary book at root` (getting bored of waiting? There'll be exercising on doing this locally which prevents you from waiting).
|
|
|
|
19. Do you see your change? If you don't see it click `CTRL`+`F5`/`Control`+`F5`to refresh the page.
|
|
|
|
|
|
```{admonition} Check your understanding
|
|
:class: note
|
|
|
|
Before moving on to the next exercise, make sure you understand the following:
|
|
- What is the difference between inline and block equations?
|
|
- How do you use TeX formatting for different mathematical symbols?
|
|
- What is the purpose of using single vs. double dollar signs for equations?
|
|
- How do you troubleshoot if your equations are not rendering correctly?
|
|
```
|
|
|