Skip to content

Commit c84c867

Browse files
story645meeseeksmachine
authored andcommitted
Backport PR matplotlib#32250: DOC: Convert math symbol table to sphinx-design cards
1 parent 38cdc70 commit c84c867

1 file changed

Lines changed: 22 additions & 17 deletions

File tree

doc/sphinxext/math_symbol_table.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import re
2-
from docutils.parsers.rst import Directive
2+
3+
from sphinx.util.docutils import SphinxDirective
34

45
from matplotlib import _mathtext, _mathtext_data
56

@@ -32,7 +33,7 @@
3233
5,
3334
_mathtext.Parser._overunder_symbols | _mathtext.Parser._dropsub_symbols],
3435
["Standard function names",
35-
5,
36+
4,
3637
{fr"\{fn}" for fn in _mathtext.Parser._function_names}],
3738
["Binary operation symbols",
3839
4,
@@ -87,38 +88,42 @@ def render_symbol(sym, ignore_variant=False):
8788

8889
lines = []
8990
for category, columns, syms in symbols:
91+
lines.append(f'**{category}**')
92+
lines.append('')
93+
lines.append(f'.. grid:: 1 1 {columns} {columns}')
94+
if category == "Hebrew": # Hebrew is rtl
95+
lines.append(' :reverse:')
96+
lines.append('')
9097
syms = sorted(syms,
9198
# Sort by Unicode and place variants immediately
9299
# after standard versions.
93100
key=lambda sym: (render_symbol(sym, ignore_variant=True),
94-
sym.startswith(r"\var")),
95-
reverse=(category == "Hebrew")) # Hebrew is rtl
96-
rendered_syms = [f"{render_symbol(sym)} ``{sym}``" for sym in syms]
97-
columns = min(columns, len(syms))
98-
lines.append("**%s**" % category)
99-
lines.append('')
100-
max_width = max(map(len, rendered_syms))
101-
header = (('=' * max_width) + ' ') * columns
102-
lines.append(header.rstrip())
103-
for part in range(0, len(rendered_syms), columns):
104-
row = " ".join(
105-
sym.rjust(max_width) for sym in rendered_syms[part:part + columns])
106-
lines.append(row)
107-
lines.append(header.rstrip())
101+
sym.startswith(r"\var")))
102+
size = 'sd-fs-4' if category == 'Standard function names' else 'sd-fs-1'
103+
for sym in syms:
104+
rendered = render_symbol(sym)
105+
lines.append(f' .. grid-item-card:: {rendered}')
106+
lines.append(f' :class-title: {size}')
107+
lines.append(' :shadow: none')
108+
lines.append(' :text-align: center')
109+
lines.append('')
110+
lines.append(f' ``{sym}``')
111+
lines.append('')
108112
lines.append('')
109113

110114
state_machine.insert_input(lines, "Symbol table")
111115
return []
112116

113117

114-
class MathSymbolTableDirective(Directive):
118+
class MathSymbolTableDirective(SphinxDirective):
115119
has_content = False
116120
required_arguments = 0
117121
optional_arguments = 0
118122
final_argument_whitespace = False
119123
option_spec = {}
120124

121125
def run(self):
126+
self.env.note_dependency(__file__)
122127
return run(self.state_machine)
123128

124129

0 commit comments

Comments
 (0)