|
39 | 39 | "source": [ |
40 | 40 | "## Equations\n", |
41 | 41 | "\n", |
42 | | - "Equations can be formatted really nicely, either inline, like $\\text{e}^{i\\pi} = -1$, or on a separate line, like\n", |
| 42 | + "Inline equations like $\\text{e}^{i\\pi} = -1$\n", |
| 43 | + "can be created by putting a LaTeX expression between two dollar signs, like this:\n", |
| 44 | + "`$\\text{e}^{i\\pi} = -1$`." |
| 45 | + ] |
| 46 | + }, |
| 47 | + { |
| 48 | + "cell_type": "markdown", |
| 49 | + "metadata": {}, |
| 50 | + "source": [ |
| 51 | + "<div class=\"alert alert-info\">\n", |
| 52 | + "\n", |
| 53 | + "**Note:**\n", |
| 54 | + "\n", |
| 55 | + "Avoid leading and trailing spaces around math expressions, otherwise errors like the following will occur when Sphinx is running:\n", |
| 56 | + "\n", |
| 57 | + " ERROR: Unknown interpreted text role \"raw-latex\".\n", |
| 58 | + "\n", |
| 59 | + "See also the [pandoc docs](http://pandoc.org/MANUAL.html#math):\n", |
| 60 | + "\n", |
| 61 | + "> Anything between two `$` characters will be treated as TeX math. The opening `$` must have a non-space character immediately to its right, while the closing `$` must have a non-space character immediately to its left, and must not be followed immediately by a digit.\n", |
| 62 | + "\n", |
| 63 | + "</div>" |
| 64 | + ] |
| 65 | + }, |
| 66 | + { |
| 67 | + "cell_type": "markdown", |
| 68 | + "metadata": {}, |
| 69 | + "source": [ |
| 70 | + "Equations can also be displayed on their own line like this:\n", |
| 71 | + "\\begin{equation}\n", |
| 72 | + "\\int_{-\\infty}^\\infty f(x) \\delta(x - x_0) dx = f(x_0).\n", |
| 73 | + "\\end{equation}\n", |
| 74 | + "\n", |
| 75 | + "This can be done by simply using one of the LaTeX math environments, like so:\n", |
43 | 76 | "\n", |
| 77 | + "```\n", |
44 | 78 | "\\begin{equation}\n", |
45 | 79 | "\\int_{-\\infty}^\\infty f(x) \\delta(x - x_0) dx = f(x_0)\n", |
46 | 80 | "\\end{equation}\n", |
| 81 | + "```" |
| 82 | + ] |
| 83 | + }, |
| 84 | + { |
| 85 | + "cell_type": "markdown", |
| 86 | + "metadata": {}, |
| 87 | + "source": [ |
| 88 | + "### Automatic Equation Numbering\n", |
| 89 | + "\n", |
| 90 | + "This is not automatically enabled in Jupyter notebooks,\n", |
| 91 | + "but you can install a notebook extension in order to enable equation numbering:\n", |
| 92 | + "https://jupyter-contrib-nbextensions.readthedocs.io/en/latest/nbextensions/equation-numbering/readme.html.\n", |
| 93 | + "\n", |
| 94 | + "Automatic Equation Numbering is enabled on http://nbviewer.jupyter.org/,\n", |
| 95 | + "see e.g. the latest version of this very notebook at the link http://nbviewer.jupyter.org/github/spatialaudio/nbsphinx/blob/master/doc/markdown-cells.ipynb.\n", |
| 96 | + "\n", |
| 97 | + "When using `nbsphinx`, you can use the following `mathjax_config` setting in your `conf.py` file\n", |
| 98 | + "to enable automatic equation numbering in HTML output.\n", |
| 99 | + "In LaTeX output, the equations are numbered by default.\n", |
| 100 | + "\n", |
| 101 | + "```python\n", |
| 102 | + "mathjax_config = {\n", |
| 103 | + " 'TeX': {'equationNumbers': {'autoNumber': 'AMS', 'useLabelIds': True}},\n", |
| 104 | + "}\n", |
| 105 | + "```\n", |
| 106 | + "\n", |
| 107 | + "You can use `\\label{...}` to give a unique label to an equation:\n", |
| 108 | + "\n", |
| 109 | + "\\begin{equation}\n", |
| 110 | + "\\phi = \\frac{1 + \\sqrt{5}}{2}\n", |
| 111 | + "\\label{golden-mean}\n", |
| 112 | + "\\end{equation}\n", |
47 | 113 | "\n", |
48 | | - "*Note:* Avoid leading and trailing spaces around math expressions, otherwise errors like the following will occur when Sphinx is running:\n", |
| 114 | + "```\n", |
| 115 | + "\\begin{equation}\n", |
| 116 | + "\\phi = \\frac{1 + \\sqrt{5}}{2}\n", |
| 117 | + "\\label{golden-mean}\n", |
| 118 | + "\\end{equation}\n", |
| 119 | + "```\n", |
49 | 120 | "\n", |
50 | | - " ERROR: Unknown interpreted text role \"raw-latex\".\n", |
| 121 | + "If automatic equation numbering is enabled,\n", |
| 122 | + "you can later reference that equation using its label.\n", |
| 123 | + "You can use `\\eqref{golden-mean}` for a reference with parentheses: \\eqref{golden-mean},\n", |
| 124 | + "or `\\ref{golden-mean}` for a reference without them: \\ref{golden-mean}.\n", |
51 | 125 | "\n", |
52 | | - "See also the [pandoc docs](http://pandoc.org/MANUAL.html#math):\n", |
| 126 | + "In HTML output, these equation references only work for equations within a single HTML page.\n", |
| 127 | + "In LaTeX output, equations from other notebooks can be referenced, e.g. \\eqref{fibonacci-recurrence}." |
| 128 | + ] |
| 129 | + }, |
| 130 | + { |
| 131 | + "cell_type": "markdown", |
| 132 | + "metadata": {}, |
| 133 | + "source": [ |
| 134 | + "### Manual Equation Numbering\n", |
| 135 | + "\n", |
| 136 | + "If you prefer to assign equation numbers (or some kind of names) manually,\n", |
| 137 | + "you can do so with `\\tag{...}`:\n", |
| 138 | + "\n", |
| 139 | + "\\begin{equation}\n", |
| 140 | + "a^2 + b^2 = c^2\n", |
| 141 | + "\\tag{99.4}\n", |
| 142 | + "\\label{pythagoras}\n", |
| 143 | + "\\end{equation}\n", |
| 144 | + "\n", |
| 145 | + "```\n", |
| 146 | + "\\begin{equation}\n", |
| 147 | + "a^2 + b^2 = c^2\n", |
| 148 | + "\\tag{99.4}\n", |
| 149 | + "\\label{pythagoras}\n", |
| 150 | + "\\end{equation}\n", |
| 151 | + "```\n", |
53 | 152 | "\n", |
54 | | - "> Anything between two `$` characters will be treated as TeX math. The opening `$` must have a non-space character immediately to its right, while the closing `$` must have a non-space character immediately to its left, and must not be followed immediately by a digit." |
| 153 | + "The above equation has the number \\ref{pythagoras}." |
55 | 154 | ] |
56 | 155 | }, |
57 | 156 | { |
|
0 commit comments