8000 [Doc] alphabetize mathtext symbols by unicode by story645 · Pull Request #26142 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

[Doc] alphabetize mathtext symbols by unicode #26142

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

Merged
merged 1 commit into from
Jun 23, 2023
Merged
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
41 changes: 25 additions & 16 deletions doc/sphinxext/math_symbol_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@

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""".split()],
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",
8,
r"""\Delta \Gamma \Lambda \Omega \Phi \Pi \Psi \Sigma \Theta
\Upsilon \Xi \mho \nabla""".split()],
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 \beth \daleth \gimel""".split()],
(r"\aleph", r"\beth", r"\gimel", r"\daleth")],
["Delimiters",
6,
5,
_mathtext.Parser._delims],
Copy link
Member
@oscargus oscargus Jun 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the context (in case you've not seen it). We're trying to get rid of the explicit lists here that are already defined in _mathtext.py. In that way the documentation will always be "correct".

_mathtext.Parser._delims is a set, so should be sorted.

Copy link
Member Author
@story645 story645 Jun 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change it back since the actual sort happens in the loop, but here I'm sorting it this way because in Hebrew it's \aleph \beth \gimel \daleth

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sorting is OK. I was pointing out line 22 which gets the delimiters from _mathtext rather than explicitly specifying them.

My suggestion is to have the correct order and NOT sort in the loop. (And I have no idea about the correct order anyway, so I fully trust you there.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I made changes here to move the stuff that wasn't greek letters out into misc, taken from #26145, but your point about not knowing the correct order is exactly why I'd rather defer to the Unicode standard for sorting when possible.

["Big symbols",
6,
5,
_mathtext.Parser._overunder_symbols | _mathtext.Parser._dropsub_symbols],
["Standard function names",
6,
5,
{fr"\{fn}" for fn in _mathtext.Parser._function_names}],
["Binary operation and relation symbols",
4,
Expand Down Expand Up @@ -90,22 +91,30 @@
\hslash \vdots \blacksquare \ldots \blacktriangle \ddots \sharp
\prime \blacktriangledown \Im \flat \backprime \Re \natural
\circledS \P \copyright \ss \circledR \S \yen \AA \checkmark \$
\cent \triangle \QED \sinewave""".split()]
\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

lines = []
for category, columns, syms in symbols:
syms = sorted(list(syms))
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))
lines.append("**%s**" % category)
lines.append('')
Expand Down
0