diff --git a/doc/sphinxext/math_symbol_table.py b/doc/sphinxext/math_symbol_table.py index 6609f91bbd10..01fa07990f7b 100644 --- a/doc/sphinxext/math_symbol_table.py +++ b/doc/sphinxext/math_symbol_table.py @@ -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 @@ -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 @@ -85,9 +73,8 @@ \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 @@ -95,23 +82,41 @@ \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 @@ -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 @@ -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) \ No newline at end of file diff --git a/doc/users/next_whats_new/mathtext_symbols.rst b/doc/users/next_whats_new/mathtext_symbols.rst new file mode 100644 index 000000000000..0df7e131f9d9 --- /dev/null +++ b/doc/users/next_whats_new/mathtext_symbols.rst @@ -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`. \ No newline at end of file diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index 135934a244a8..08c70f562b1f 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -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 \ No newline at end of file