Skip to content
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
39 changes: 22 additions & 17 deletions doc/sphinxext/math_symbol_table.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
from docutils.parsers.rst import Directive

from sphinx.util.docutils import SphinxDirective

from matplotlib import _mathtext, _mathtext_data

Expand Down Expand Up @@ -32,7 +33,7 @@
5,
_mathtext.Parser._overunder_symbols | _mathtext.Parser._dropsub_symbols],
["Standard function names",
5,
4,
{fr"\{fn}" for fn in _mathtext.Parser._function_names}],
["Binary operation symbols",
4,
Expand Down Expand Up @@ -87,38 +88,42 @@ def render_symbol(sym, ignore_variant=False):

lines = []
for category, columns, syms in symbols:
lines.append(f'**{category}**')
lines.append('')
lines.append(f'.. grid:: 1 1 {columns} {columns}')
if category == "Hebrew": # Hebrew is rtl
lines.append(' :reverse:')
lines.append('')
syms = sorted(syms,
# Sort by Unicode and place variants immediately
# after standard versions.
key=lambda sym: (render_symbol(sym, ignore_variant=True),
sym.startswith(r"\var")),
reverse=(category == "Hebrew")) # Hebrew is rtl
rendered_syms = [f"{render_symbol(sym)} ``{sym}``" for sym in syms]
columns = min(columns, len(syms))
lines.append("**%s**" % category)
lines.append('')
max_width = max(map(len, rendered_syms))
header = (('=' * max_width) + ' ') * columns
lines.append(header.rstrip())
for part in range(0, len(rendered_syms), columns):
row = " ".join(
sym.rjust(max_width) for sym in rendered_syms[part:part + columns])
lines.append(row)
lines.append(header.rstrip())
sym.startswith(r"\var")))
size = 'sd-fs-4' if category == 'Standard function names' else 'sd-fs-1'
for sym in syms:
rendered = render_symbol(sym)
lines.append(f' .. grid-item-card:: {rendered}')
lines.append(f' :class-title: {size}')
lines.append(' :shadow: none')
lines.append(' :text-align: center')
lines.append('')
lines.append(f' ``{sym}``')
lines.append('')
lines.append('')

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


class MathSymbolTableDirective(Directive):
class MathSymbolTableDirective(SphinxDirective):
has_content = False
required_arguments = 0
optional_arguments = 0
final_argument_whitespace = False
option_spec = {}

def run(self):
self.env.note_dependency(__file__)
return run(self.state_machine)


Expand Down
Loading