|
1 | 1 | import re |
2 | | -from docutils.parsers.rst import Directive |
| 2 | + |
| 3 | +from sphinx.util.docutils import SphinxDirective |
3 | 4 |
|
4 | 5 | from matplotlib import _mathtext, _mathtext_data |
5 | 6 |
|
|
32 | 33 | 5, |
33 | 34 | _mathtext.Parser._overunder_symbols | _mathtext.Parser._dropsub_symbols], |
34 | 35 | ["Standard function names", |
35 | | - 5, |
| 36 | + 4, |
36 | 37 | {fr"\{fn}" for fn in _mathtext.Parser._function_names}], |
37 | 38 | ["Binary operation symbols", |
38 | 39 | 4, |
@@ -87,38 +88,42 @@ def render_symbol(sym, ignore_variant=False): |
87 | 88 |
|
88 | 89 | lines = [] |
89 | 90 | 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('') |
90 | 97 | syms = sorted(syms, |
91 | 98 | # Sort by Unicode and place variants immediately |
92 | 99 | # after standard versions. |
93 | 100 | 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('') |
108 | 112 | lines.append('') |
109 | 113 |
|
110 | 114 | state_machine.insert_input(lines, "Symbol table") |
111 | 115 | return [] |
112 | 116 |
|
113 | 117 |
|
114 | | -class MathSymbolTableDirective(Directive): |
| 118 | +class MathSymbolTableDirective(SphinxDirective): |
115 | 119 | has_content = False |
116 | 120 | required_arguments = 0 |
117 | 121 | optional_arguments = 0 |
118 | 122 | final_argument_whitespace = False |
119 | 123 | option_spec = {} |
120 | 124 |
|
121 | 125 | def run(self): |
| 126 | + self.env.note_dependency(__file__) |
122 | 127 | return run(self.state_machine) |
123 | 128 |
|
124 | 129 |
|
|
0 commit comments