Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a101de7

Browse files
committed
Fix mathtext tutorial for build with Sphinx 1.8.
Sphinx 1.8 relies on MathJax for HTML math rendering, but a lot of symbols provided by Matplotlib's mathtext come from somewhat obscure packages that MathJax does not support. Instead of trying to patch MathJax, just display the symbols as unicode.
1 parent a43fd85 commit a101de7

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

doc/sphinxext/math_symbol_table.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from matplotlib import mathtext
2+
3+
14
symbols = [
25
["Lower-case Greek",
36
6,
@@ -112,9 +115,19 @@ def get_n(n, l):
112115
header = " " + (('=' * max_width) + ' ') * columns
113116
lines.append(header)
114117
for part in get_n(columns, syms):
115-
line = " " + " ".join(
116-
":math:`{0}` ``{0}``".format(sym).rjust(max_width)
117-
for sym in part)
118+
line = (
119+
" " +
120+
" ".join(
121+
"{} ``{}``".format(
122+
sym
123+
if not sym.startswith("\\")
124+
else sym[1:]
125+
if (sym[1:] in mathtext.Parser._overunder_functions
126+
or sym[1:] in mathtext.Parser._function_names)
127+
else chr(mathtext.tex2uni[sym[1:]]),
128+
sym)
129+
.rjust(max_width)
130+
for sym in part))
118131
lines.append(line)
119132
lines.append(header)
120133
lines.append('')

tutorials/text/mathtext.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,13 @@
179179
180180
r's(t) = \mathcal{A}\/\sin(2 \omega t)'
181181
182+
.. Here we cheat a bit: for HTML math rendering, Sphinx relies on MathJax which
183+
doesn't actually support the italic correction (\/); instead, use a thin
184+
space (\,) which is supported.
185+
182186
.. math::
183187
184-
s(t) = \mathcal{A}\/\sin(2 \omega t)
188+
s(t) = \mathcal{A}\,\sin(2 \omega t)
185189
186190
The choices available with all fonts are:
187191

0 commit comments

Comments
 (0)