-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add substack cmd for mathtext #26151
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
Conversation
@@ -134,7 +134,7 @@ | |||
r'$\sum x\quad\sum^nx\quad\sum_nx\quad\sum_n^nx\quad\prod x\quad\prod^nx\quad\prod_nx\quad\prod_n^nx$', # GitHub issue 18085 | |||
r'$1.$ $2.$ $19680801.$ $a.$ $b.$ $mpl.$', | |||
r'$\text{text}_{\text{sub}}^{\text{sup}} + \text{\$foo\$} + \frac{\text{num}}{\mathbf{\text{den}}}\text{with space, curly brackets \{\}, and dash -}$', | |||
|
|||
r'$\sum_{\substack{k = 1}{k \neq \lfloor n/2\rfloor}}^{n}P(i,j) \sum_{\substack{i \neq 0}{-1 \leq i \leq 3}{1 \leq j \leq 5}} F^i(x,y)$', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I believe that your syntax makes very much sense, it appears as if the existing \substack
command is simply using \\
for next line.
r'$\sum_{\substack{k = 1}{k \neq \lfloor n/2\rfloor}}^{n}P(i,j) \sum_{\substack{i \neq 0}{-1 \leq i \leq 3}{1 \leq j \leq 5}} F^i(x,y)$', | |
r'$\sum_{\substack{k = 1\\ k \neq \lfloor n/2\rfloor}}^{n}P(i,j) \sum_{\substack{i \neq 0\\ -1 \leq i \leq 3\\ 1 \leq j \leq 5}} F^i(x,y)$', |
Apart from that, the outcome looks good! Maybe one would like to test with \left \lfloor \frac{n}{2} \right\rfloor
as well to see how that behaves?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really sure how to go about adding the \\
as next-line behavior to the substack
input due to the python's handling of escape characters, I'm currently still looking into it.
Added the \left \lfloor \frac{n}{2} \right\rfloor
as a test with the current implemention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the parser expert @anntzer has some input?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect pyparsing's DelimitedList
would be helpful here
Note, however, that it looks like it is in a slightly awkward transition from the delimited_list
function to the DelimitedList
class, the former being deprecated upon the introduction of the latter in pyparsing 3.1.0 (which we are incompatible with for other reasons right now, but should fix)
As such may need something like:
if pyparsing.__version__info__ < (3, 1):
from pyparsing import delimited_list as DelimitedList
else:
from pyparsing import DelimitedList
lib/matplotlib/_mathtext.py
Outdated
thickness = state.get_current_underline_thickness() | ||
vlist = [] | ||
|
||
max_width = sorted(toks[1:], key= lambda c: c.width)[-1].width |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this could be written using max
, which also takes a key
argument.
max_width = max(toks[1:], key=lambda c: c.width).width
Something like that? Or even simpler:
max_width = max(map(lambda c: c.width, toks[1:]))
which seems more readable to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! That was neat
lib/matplotlib/_mathtext.py
Outdated
vlist = [x for l in (vlist[i:i+1] + | ||
[Vbox(0, thickness * 2.0)] * | ||
(i < len(vlist) - 1) | ||
for i in range(0, len(vlist), 1)) for x in l] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took me an embarrassingly long time to understand!:sweat_smile: I think it separates each element of vlist
with Vbox(0, thickness * 2)
?
This is probably one of those instances I'd prioritise readability.
vlist_ = [None, Vbox(0, thickness * 2)] * len(vlist)
vlist_[::2] = vlist
vlist_.pop()
This should achieve this same thing. (Another option is to append the Vbox
es in the for
loop just above.)
@oscargus: I'd defer to your opinion here. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe one could just do:
vlist = [val for pair in zip(vlist, [Vbox(0, thickness * 2)]*len(vlist)) for val in pair]
del vlist[-1]
?
(But, yes, I find double (and triple) list comprehensions quite hard to follow to start with.)
42735be
to
2b85ec6
Compare
8694d6a
to
e5f318d
Compare
lib/matplotlib/_mathtext.py
Outdated
@@ -1700,6 +1700,7 @@ def names(elt): | |||
csname = expr.split("{", 1)[0] | |||
err = (csname + "".join("{%s}" % name for name in names(args)) | |||
if expr == csname else expr) | |||
print(csname, args, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I take it that there will be another update to this and @ksunden was only sorting out the parsing?
But this line should go.
@@ -134,7 +134,7 @@ | |||
r'$\sum x\quad\sum^nx\quad\sum_nx\quad\sum_n^nx\quad\prod x\quad\prod^nx\quad\prod_nx\quad\prod_n^nx$', # GitHub issue 18085 | |||
r'$1.$ $2.$ $19680801.$ $a.$ $b.$ $mpl.$', | |||
r'$\text{text}_{\text{sub}}^{\text{sup}} + \text{\$foo\$} + \frac{\text{num}}{\mathbf{\text{den}}}\text{with space, curly brackets \{\}, and dash -}$', | |||
|
|||
r'$\sum_{\substack{k = 1}{k \neq \lfloor n/2\rfloor}}^{n}P(i,j) \sum_{\substack{i \neq 0}{-1 \leq i \leq 3}{1 \leq j \leq 5}} F^i(x,y) \sum_{\substack{\left \lfloor \frac{n}{2} \right\rfloor}} F(n)$', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should then be modified to use \\
, but ideally there should be no need for other changes.
9dac091
to
ad02967
Compare
Co-Authored By: Kyle Sunden <git@ksunden.space>
Co-Authored By: Kyle Sunden <git@ksunden.space>
Co-authored-by: Kyle Sunden <git@ksunden.space>
PR summary
Fixes #14247
PR checklist