Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8fe5cb2

Browse files
committed
Refactor math_symbol_table.py to dynamically determine column number for symbol tables(Issue#26143)
- Remove hardcoded column numbers; now columns are auto-calculated based on symbol length and page width constraints. Future changes to symbol lists require no manual column adjustment.
1 parentdef8fa4 commit8fe5cb2

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

‎doc/sphinxext/math_symbol_table.py

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,57 +9,42 @@
99

1010
symbols= [
1111
["Lower-case Greek",
12-
4,
1312
(r"\alpha",r"\beta",r"\gamma",r"\chi",r"\delta",r"\epsilon",
1413
r"\eta",r"\iota",r"\kappa",r"\lambda",r"\mu",r"\nu",r"\omega",
1514
r"\phi",r"\pi",r"\psi",r"\rho",r"\sigma",r"\tau",r"\theta",
1615
r"\upsilon",r"\xi",r"\zeta",r"\digamma",r"\varepsilon",r"\varkappa",
1716
r"\varphi",r"\varpi",r"\varrho",r"\varsigma",r"\vartheta")],
1817
["Upper-case Greek",
19-
4,
2018
(r"\Delta",r"\Gamma",r"\Lambda",r"\Omega",r"\Phi",r"\Pi",r"\Psi",
2119
r"\Sigma",r"\Theta",r"\Upsilon",r"\Xi")],
2220
["Hebrew",
23-
6,
2421
(r"\aleph",r"\beth",r"\gimel",r"\daleth")],
2522
["Latin named characters",
26-
6,
2723
r"""\aa \AA \ae \AE \oe \OE \O \o \thorn \Thorn \ss \eth \dh \DH""".split()],
2824
["Delimiters",
29-
5,
3025
_mathtext.Parser._delims],
3126
["Big symbols",
32-
5,
3327
_mathtext.Parser._overunder_symbols|_mathtext.Parser._dropsub_symbols],
3428
["Standard function names",
35-
5,
3629
{fr"\{fn}"forfnin_mathtext.Parser._function_names}],
3730
["Binary operation symbols",
38-
4,
3931
_mathtext.Parser._binary_operators],
4032
["Relation symbols",
41-
4,
4233
_mathtext.Parser._relation_symbols],
4334
["Arrow symbols",
44-
4,
4535
_mathtext.Parser._arrow_symbols],
4636
["Dot symbols",
47-
4,
4837
r"""\cdots \vdots \ldots \ddots \adots \Colon \therefore \because""".split()],
4938
["Black-board characters",
50-
6,
5139
[fr"\{symbol}"forsymbolin_mathtext_data.tex2uni
5240
ifre.match(bb_pattern,symbol)]],
5341
["Script characters",
54-
6,
5542
[fr"\{symbol}"forsymbolin_mathtext_data.tex2uni
5643
ifre.match(scr_pattern,symbol)]],
5744
["Fraktur characters",
58-
6,
5945
[fr"\{symbol}"forsymbolin_mathtext_data.tex2uni
6046
ifre.match(frak_pattern,symbol)]],
6147
["Miscellaneous symbols",
62-
4,
6348
r"""\neg \infty \forall \wp \exists \bigstar \angle \partial
6449
\nexists \measuredangle \emptyset \sphericalangle \clubsuit
6550
\varnothing \complement \diamondsuit \imath \Finv \triangledown
@@ -73,6 +58,28 @@
7358
]
7459

7560

61+
defcalculate_best_columns(
62+
symbols_list,max_line_length,max_columns
63+
):
64+
"""
65+
Calculate the best number of columns to fit the symbols within the
66+
given constraints.
67+
68+
Parameters
69+
----------
70+
symbols_list (list): A list of symbols to be displayed.
71+
max_line_length (int): The maximum allowed length of a line.
72+
min_columns (int): The minimum number of columns to consider.
73+
max_columns (int): The maximum number of columns to consider.
74+
75+
Returns
76+
-------
77+
int: The best number of columns that fits within the constraints.
78+
"""
79+
max_cell_width=max(len(sym)forsyminsymbols_list)
80+
returnmin(max_columns,len(symbols_list),max_line_length//max_cell_width)
81+
82+
7683
defrun(state_machine):
7784

7885
defrender_symbol(sym,ignore_variant=False):
@@ -86,15 +93,19 @@ def render_symbol(sym, ignore_variant=False):
8693
returnf'\\{sym}'ifsymin ('\\','|','+','-','*')elsesym
8794

8895
lines= []
89-
forcategory,columns,symsinsymbols:
96+
forcategory,symsinsymbols:
9097
syms=sorted(syms,
9198
# Sort by Unicode and place variants immediately
9299
# after standard versions.
93100
key=lambdasym: (render_symbol(sym,ignore_variant=True),
94101
sym.startswith(r"\var")),
95102
reverse=(category=="Hebrew"))# Hebrew is rtl
96103
rendered_syms= [f"{render_symbol(sym)} ``{sym}``"forsyminsyms]
97-
columns=min(columns,len(syms))
104+
columns=calculate_best_columns(
105+
rendered_syms,
106+
max_line_length=96,
107+
max_columns=6
108+
)
98109
lines.append("**%s**"%category)
99110
lines.append('')
100111
max_width=max(map(len,rendered_syms))
@@ -128,13 +139,12 @@ def setup(app):
128139
metadata= {'parallel_read_safe':True,'parallel_write_safe':True}
129140
returnmetadata
130141

131-
132142
if__name__=="__main__":
133143
# Do some verification of the tables
134144

135145
print("SYMBOLS NOT IN STIX:")
136146
all_symbols= {}
137-
forcategory,columns,symsinsymbols:
147+
forcategory,symsinsymbols:
138148
ifcategory=="Standard Function Names":
139149
continue
140150
forsyminsyms:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp