| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Sorry, something went wrong.
|
This looks like really good work, bt I feel un-able to properly review it. Who is our resident expert in mathtext? |
Sorry, something went wrong.
There was a problem hiding this comment.
Were you able to check this against the texbook that @anntzer suggested in the issue? I think sub/superscripts are defined around program 756 on page 280 there. This might be difficult to use though if the nucleus is not accessible.
Sorry, something went wrong.
No point running the tests if we are absolutely sure they are going to fail.
Sorry, something went wrong.
Sorry, something went wrong.
Shortcuts I took for the algorithm
|
Sorry, something went wrong.
|
Closing. Superseded by #22852. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
PR Summary
Tries to improve the positioning of sub- and superscripts attached to fractions (fix #18086).
PR Checklist
Tests and Styling
Documentation
Details
import matplotlib.pyplot as plt s = r'$\left(\dfrac{n}{d}\right)_p^q$ $\left(\dfrac{n}{d}\right)^q$ $\left(\dfrac{n}{d}\right)_p$' fig = plt.figure() fig.text(0.1, 0.5, s) plt.show()Before
After
Notes
I added a new production rule for the tokenisation of expressions containing subscripts and superscripts.
p.subsuper <<= Group( (Optional(p.placeable) + OneOrMore(p.subsuperop - p.placeable) + Optional(p.apostrophe)) | (p.placeable + Optional(p.apostrophe)) | p.apostrophe | (p.auto_delim + OneOrMore(p.subsuperop - p.placeable)) )This should be considered suboptimal, but with my extremely limited knowledge of languages, grammars and parsing, this is the best idea I could come up with. This addition has the effect of making the nucleus (i.e. the expression to which a subscript and/or superscript are/is attached) available for the calculation of shift_up and shift_down.
I hate magic constants (0.4 and 1.4) as much as the next person, but can't think of anything better to differentiate nuclei which are and aren't fractions. This works for Dejavu Sans, but not for Computer Modern or STIX or Dejavu Serif. So, I'll leave this as a draft. Would appreciate experts weighing in.
LaTeX uses a wide assortment of font parameters (stored in font_info, an array) to calculate shift_up and shift_down, so the results of this will not exactly match what LaTeX gives us, but it will be close. Nevertheless, this will have to be tested extensively.
Needless to say, sub- and superscripts can be nested.
import matplotlib.pyplot as plt s = r'$\left(\dfrac{\mathrm{Numerator}}{\mathrm{Denominator}}\right)_{y_{i^2}}^{\frac{y_k^{2^w}}{4^3}}$' fig = plt.figure() fig.text(0.1, 0.5, s, size=50) plt.show()Another point to note is that this will be affected by #20627, so a rebase may be required later.