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

Skip to content

Commit cd30a70

Browse files
committed
DOC: Fix some bugs in math symbol tables.
Limit math symbol table columns to number of symbols. In Hebrew, there are only 4 symbols, but the table is 6 columns with two extra empty columns. Fix Delimiters table as pipe and backslash need to be escaped. Replace the `get_n` function with a simpler `range` operation.
1 parent 89b6314 commit cd30a70

1 file changed

Lines changed: 13 additions & 23 deletions

File tree

doc/sphinxext/math_symbol_table.py

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -100,38 +100,28 @@
100100

101101

102102
def run(state_machine):
103-
def get_n(n, l):
104-
part = []
105-
for x in l:
106-
part.append(x)
107-
if len(part) == n:
108-
yield part
109-
part = []
110-
yield part
103+
def render_symbol(sym):
104+
if sym.startswith("\\"):
105+
sym = sym[1:]
106+
if sym not in {*mathtext.Parser._overunder_functions,
107+
*mathtext.Parser._function_names}:
108+
sym = chr(mathtext.tex2uni[sym])
109+
return f'\\{sym}' if sym in ('\\', '|') else sym
111110

112111
lines = []
113112
for category, columns, syms in symbols:
114113
syms = sorted(syms.split())
114+
columns = min(columns, len(syms))
115115
lines.append("**%s**" % category)
116116
lines.append('')
117117
max_width = max(map(len, syms)) * 2 + 16
118118
header = " " + (('=' * max_width) + ' ') * columns
119119
lines.append(header)
120-
for part in get_n(columns, syms):
121-
line = (
122-
" " +
123-
" ".join(
124-
"{} ``{}``".format(
125-
sym
126-
if not sym.startswith("\\")
127-
else sym[1:]
128-
if (sym[1:] in mathtext.Parser._overunder_functions
129-
or sym[1:] in mathtext.Parser._function_names)
130-
else chr(mathtext.tex2uni[sym[1:]]),
131-
sym)
132-
.rjust(max_width)
133-
for sym in part))
134-
lines.append(line)
120+
for part in range(0, len(syms), columns):
121+
row = " ".join(
122+
f"{render_symbol(sym)} ``{sym}``".rjust(max_width)
123+
for sym in syms[part:part + columns])
124+
lines.append(f" {row}")
135125
lines.append(header)
136126
lines.append('')
137127

0 commit comments

Comments
 (0)