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

Skip to content

Dynamically calculating columns on Math symbols #26191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
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
23 changes: 12 additions & 11 deletions doc/sphinxext/math_symbol_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,23 @@

symbols = [
["Lower-case Greek",
4,
(r"\alpha", r"\beta", r"\gamma", r"\chi", r"\delta", r"\epsilon",
r"\eta", r"\iota", r"\kappa", r"\lambda", r"\mu", r"\nu", r"\omega",
r"\phi", r"\pi", r"\psi", r"\rho", r"\sigma", r"\tau", r"\theta",
r"\upsilon", r"\xi", r"\zeta", r"\digamma", r"\varepsilon", r"\varkappa",
r"\varphi", r"\varpi", r"\varrho", r"\varsigma", r"\vartheta")],
["Upper-case Greek",
4,
(r"\Delta", r"\Gamma", r"\Lambda", r"\Omega", r"\Phi", r"\Pi", r"\Psi",
r"\Sigma", r"\Theta", r"\Upsilon", r"\Xi")],
["Hebrew",
6,
(r"\aleph", r"\beth", r"\gimel", r"\daleth")],
["Delimiters",
5,
_mathtext.Parser._delims],
["Big symbols",
5,
_mathtext.Parser._overunder_symbols | _mathtext.Parser._dropsub_symbols],
["Standard function names",
5,
{fr"\{fn}" for fn in _mathtext.Parser._function_names}],
["Binary operation and relation symbols",
4,
r"""\ast \pm \slash \cap \star \mp \cup \cdot \uplus
\triangleleft \circ \odot \sqcap \triangleright \bullet \ominus
\sqcup \bigcirc \oplus \wedge \diamond \oslash \vee
Expand Down Expand Up @@ -60,7 +53,6 @@
\Doteq \nsubset \eqcolon \ne
""".split()],
["Arrow symbols",
4,
r"""\leftarrow \longleftarrow \uparrow \Leftarrow \Longleftarrow
\Uparrow \rightarrow \longrightarrow \downarrow \Rightarrow
\Longrightarrow \Downarrow \leftrightarrow \updownarrow
Expand All @@ -83,7 +75,6 @@
\leftsquigarrow
""".split()],
["Miscellaneous symbols",
4,
r"""\neg \infty \forall \wp \exists \bigstar \angle \partial
\nexists \measuredangle \eth \emptyset \sphericalangle \clubsuit
\varnothing \complement \diamondsuit \imath \Finv \triangledown
Expand All @@ -107,15 +98,25 @@ def render_symbol(sym, ignore_variant=False):
sym = chr(_mathtext_data.tex2uni[sym])
return f'\\{sym}' if sym in ('\\', '|') else sym

def columns_calculation(my_list):
remainder = max_columns = columns = 10
max_remainder = 0
for columns_number in range(max_columns - 1, 3, -1):
remainder = len(my_list) % columns_number
if remainder > max_remainder:
columns = columns_number

return columns

lines = []
for category, columns, syms in symbols:
for category, syms in symbols:
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
columns = min(columns, len(syms))
columns = columns_calculation(syms)
lines.append("**%s**" % category)
lines.append('')
max_width = max(map(len, syms)) * 2 + 16
Expand Down
5 changes: 5 additions & 0 deletions doc/users/next_whats_new/math_symbols.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
``mathtext`` documentation improvements
---------------------------------------

The documentation is updated to create all the tables of symbols
by calculating the number of columns in dynamic way in order to have as full of elements rows as possible :ref:`mathtext`.