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

Skip to content

Adding a dynamically resize of mathtext symbol table #26183

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
72 changes: 38 additions & 34 deletions doc/sphinxext/math_symbol_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,23 @@

symbols = [
["Lower-case Greek",
6,
r"""\alpha \beta \gamma \chi \delta \epsilon \eta \iota \kappa
\lambda \mu \nu \omega \phi \pi \psi \rho \sigma \tau \theta
\upsilon \xi \zeta \digamma \varepsilon \varkappa \varphi
\varpi \varrho \varsigma \vartheta"""],
(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",
8,
r"""\Delta \Gamma \Lambda \Omega \Phi \Pi \Psi \Sigma \Theta
\Upsilon \Xi \mho \nabla"""],
(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 \beth \daleth \gimel"""],
(r"\aleph", r"\beth", r"\gimel", r"\daleth")],
["Delimiters",
6,
r"""| \{ \lfloor / \Uparrow \llcorner \vert \} \rfloor \backslash
\uparrow \lrcorner \| \langle \lceil [ \Downarrow \ulcorner
\Vert \rangle \rceil ] \downarrow \urcorner"""],
_mathtext.Parser._delims],
["Big symbols",
6,
r"""\bigcap \bigcup \bigodot \bigoplus \bigotimes \biguplus
\bigvee \bigwedge \coprod \oint \prod \sum \int"""],
_mathtext.Parser._overunder_symbols | _mathtext.Parser._dropsub_symbols],
["Standard function names",
6,
r"""\arccos \csc \ker \min \arcsin \deg \lg \Pr \arctan \det \lim
\gcd \ln \sup \cot \hom \log \tan \coth \inf \max \tanh
\sec \arg \dim \liminf \sin \cos \exp \limsup \sinh \cosh"""],
{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 @@ -62,9 +51,8 @@
\lneqq \gneqq \ntriangleright \lnsim \gnsim \ntrianglerighteq
\coloneq \eqsim \nequiv \napprox \nsupset \doublebarwedge \nVdash
\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 @@ -85,33 +73,50 @@
\nrightarrow \nLeftarrow \nRightarrow \nleftrightarrow
\nLeftrightarrow \to \Swarrow \Searrow \Nwarrow \Nearrow
\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
\heartsuit \jmath \Game \spadesuit \ell \hbar \vartriangle \cdots
\hslash \vdots \blacksquare \ldots \blacktriangle \ddots \sharp
\prime \blacktriangledown \Im \flat \backprime \Re \natural
\circledS \P \copyright \ss \circledR \S \yen \AA \checkmark \$
\iiint \iint \oiiint"""]
\cent \triangle \QED \sinewave \nabla \mho""".split()]
]


def run(state_machine):
def render_symbol(sym):

def render_symbol(sym, ignore_variant=False):
if ignore_variant and sym != r"\varnothing":
sym = sym.replace(r"\var", "\\")
if sym.startswith("\\"):
sym = sym[1:]
sym = sym.lstrip("\\")
if sym not in (_mathtext.Parser._overunder_functions |
_mathtext.Parser._function_names):
sym = chr(_mathtext_data.tex2uni[sym])
return f'\\{sym}' if sym in ('\\', '|') else sym

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

return columns

lines = []
for category, columns, syms in symbols:
syms = sorted(syms.split())
columns = min(columns, len(syms))
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 = columns_calculation(syms)
lines.append("**%s**" % category)
lines.append('')
max_width = max(map(len, syms)) * 2 + 16
Expand Down Expand Up @@ -155,7 +160,6 @@ def setup(app):
for category, columns, syms in symbols:
if category == "Standard Function Names":
continue
syms = syms.split()
for sym in syms:
if len(sym) > 1:
all_symbols[sym[1:]] = None
Expand All @@ -165,4 +169,4 @@ def setup(app):
print("SYMBOLS NOT IN TABLE:")
for sym in _mathtext_data.tex2uni:
if sym not in all_symbols:
print(sym)
print(sym)
5 changes: 5 additions & 0 deletions doc/users/next_whats_new/mathtext_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`.
2 changes: 1 addition & 1 deletion lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1818,4 +1818,4 @@ def thumbnail(infile, thumbfile, scale=0.1, interpolation='bilinear',
frameon=False, xticks=[], yticks=[])
ax.imshow(im, aspect='auto', resample=True, interpolation=interpolation)
fig.savefig(thumbfile, dpi=dpi)
return fig
return fig