Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: How to define LaTeX macros #288

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 68 additions & 2 deletions doc/markdown-cells.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,70 @@
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Defining LaTeX Macros\n",
"\n",
"LaTeX users will be familiar with defining new macros by using\n",
"`\\newcommand` or the more low-level `\\def` command .\n",
"\n",
"If you want to use that for both HTML and LaTeX output,\n",
"you have to take some extra care.\n",
"You should make your definitions like this:\n",
"\n",
"```\n",
"<div hidden>\n",
"\n",
"\\def\\require#1{}\n",
"$\\require{begingroup}\\require{newcommand}$\n",
"$\\gdef\\vec#1{\\boldsymbol{#1}}$\n",
"$\\gdef\\i{\\mathrm{i}}$\n",
"\n",
"\\vskip-\\parskip\n",
"\\vskip-\\baselineskip\n",
"\n",
"</div>\n",
"```\n",
"\n",
"<div hidden>\n",
"\n",
"\\def\\require#1{}\n",
"$\\require{begingroup}\\require{newcommand}$\n",
"$\\gdef\\vec#1{\\boldsymbol{#1}}$\n",
"$\\gdef\\i{\\mathrm{i}}$\n",
"\n",
"\\vskip-\\parskip\n",
"\\vskip-\\baselineskip\n",
"\n",
"</div>\n",
"\n",
"This makes sure that the definition itself is not visible in HTML output\n",
"(by using `<div hidden>`).\n",
"In LaTeX output, the definition creates an empty equation in a new paragraph.\n",
"To get rid of the additional vertical spacing, `\\vskip` is used.\n",
"\n",
"Using `\\def` inside math mode is supported in MathJax,\n",
"but in LaTeX, it doesn't have any effect on later math expressions.\n",
"Using `\\gdef` works in both.\n",
"Sadly, `\\gdef` isn't activated by default in MathJax,\n",
"so we have to use `\\require` to activate the `newcommand` and `begingroup` extensions.\n",
"Since `\\require` is a MathJax feature that's unknown to LaTeX,\n",
"we'll have to provide a dummy definition to not confuse LaTeX\n",
"\n",
"With the above definitions,\n",
"you can use your new macro like this:\n",
"\n",
"```\n",
"$2 \\vec{a} + \\vec{b}$\n",
"```\n",
"\n",
"... which looks like this: $2 \\vec{a} + \\vec{b}$.\n",
"\n",
"You can of course use as many `\\gdef` lines as you want."
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -100,7 +164,9 @@
"\n",
"```python\n",
"mathjax_config = {\n",
" 'TeX': {'equationNumbers': {'autoNumber': 'AMS', 'useLabelIds': True}},\n",
" 'TeX': {\n",
" 'equationNumbers': {'autoNumber': 'AMS', 'useLabelIds': True},\n",
" },\n",
"}\n",
"```\n",
"\n",
Expand Down Expand Up @@ -491,7 +557,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
"version": "3.7.3rc1"
}
},
"nbformat": 4,
Expand Down