|
81 | 81 | "```" |
82 | 82 | ] |
83 | 83 | }, |
| 84 | + { |
| 85 | + "cell_type": "markdown", |
| 86 | + "metadata": {}, |
| 87 | + "source": [ |
| 88 | + "### Defining LaTeX Macros\n", |
| 89 | + "\n", |
| 90 | + "LaTeX users will be familiar with defining new macros by using\n", |
| 91 | + "`\\newcommand` or the more low-level `\\def` command .\n", |
| 92 | + "\n", |
| 93 | + "If you want to use that for both HTML and LaTeX output,\n", |
| 94 | + "you have to take some extra care.\n", |
| 95 | + "You should make your definitions like this:\n", |
| 96 | + "\n", |
| 97 | + "```\n", |
| 98 | + "<div hidden>\n", |
| 99 | + "\n", |
| 100 | + "$\\gdef\\vec#1{\\boldsymbol{#1}}$\n", |
| 101 | + "\n", |
| 102 | + "\\vskip-\\parskip\n", |
| 103 | + "\\vskip-\\baselineskip\n", |
| 104 | + "\n", |
| 105 | + "</div>\n", |
| 106 | + "```\n", |
| 107 | + "\n", |
| 108 | + "<div hidden>\n", |
| 109 | + "\n", |
| 110 | + "$\\gdef\\vec#1{\\boldsymbol{#1}}$\n", |
| 111 | + "\n", |
| 112 | + "\\vskip-\\parskip\n", |
| 113 | + "\\vskip-\\baselineskip\n", |
| 114 | + "\n", |
| 115 | + "</div>\n", |
| 116 | + "\n", |
| 117 | + "This makes sure that the definition itself is not visible in HTML output\n", |
| 118 | + "(by using `<div hidden>`).\n", |
| 119 | + "In LaTeX output, the definition creates an empty equation in a new paragraph.\n", |
| 120 | + "To get rid of the additional vertical spacing, `\\vskip` is used.\n", |
| 121 | + "\n", |
| 122 | + "Using `\\def` inside math mode is supported in MathJax,\n", |
| 123 | + "but in LaTeX, it doesn't have any effect on later math expressions.\n", |
| 124 | + "Using `\\gdef` works in both.\n", |
| 125 | + "Sadly, `\\gdef` isn't activated by default in MathJax,\n", |
| 126 | + "therefore we need some additional configuration in our `conf.py` file:\n", |
| 127 | + "\n", |
| 128 | + "```python\n", |
| 129 | + "mathjax_config = {\n", |
| 130 | + " 'TeX': {\n", |
| 131 | + " 'extensions': ['newcommand.js', 'begingroup.js'],\n", |
| 132 | + " },\n", |
| 133 | + "}\n", |
| 134 | + "\n", |
| 135 | + "```\n", |
| 136 | + "\n", |
| 137 | + "With the above definition and the `conf.py` setting in place,\n", |
| 138 | + "you can use your new macro like this:\n", |
| 139 | + "\n", |
| 140 | + "```\n", |
| 141 | + "$2 \\vec{a} + \\vec{b}$\n", |
| 142 | + "```\n", |
| 143 | + "\n", |
| 144 | + "... which looks like this: $2 \\vec{a} + \\vec{b}$" |
| 145 | + ] |
| 146 | + }, |
84 | 147 | { |
85 | 148 | "cell_type": "markdown", |
86 | 149 | "metadata": {}, |
|
100 | 163 | "\n", |
101 | 164 | "```python\n", |
102 | 165 | "mathjax_config = {\n", |
103 | | - " 'TeX': {'equationNumbers': {'autoNumber': 'AMS', 'useLabelIds': True}},\n", |
| 166 | + " 'TeX': {\n", |
| 167 | + " 'equationNumbers': {'autoNumber': 'AMS', 'useLabelIds': True},\n", |
| 168 | + " },\n", |
104 | 169 | "}\n", |
105 | 170 | "```\n", |
106 | 171 | "\n", |
|
491 | 556 | "name": "python", |
492 | 557 | "nbconvert_exporter": "python", |
493 | 558 | "pygments_lexer": "ipython3", |
494 | | - "version": "3.7.1" |
| 559 | + "version": "3.7.2+" |
495 | 560 | } |
496 | 561 | }, |
497 | 562 | "nbformat": 4, |
|
0 commit comments