| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
WRT the original #22852 (comment):
Also unsure about this one; it appears that one square root sign is sized a bit different?
Seems to be the case, but apostrophes are handled by the subsuper method, so this seems okay.
This is no longer failing; I think this may be one of the rounding issues for the initial character found (and fixed) in #30059. |
Sorry, something went wrong.
|
TODO: Since the height of fractions is a little bigger, I think I may need to tweak the AutoHeightChar tests to ensure that all sizes are correctly included. |
Sorry, something went wrong.
|
I've gone through the sub/super script changes and they seem fine as well, other than a couple known shortcuts. I'm only uncertain about the constants; they may have only been chosen to minimize image changes instead of matching TeX. For CM, it was also calculated with our current hinting settings and not the defaults that have been switched to in the text-overhaul branch. |
Sorry, something went wrong.
There was a problem hiding this comment.
Modulo re basing and shortening the constants.
Sorry, something went wrong.
|
While looking at the TeX algorithms, I found out about tftopl which can show some metrics from TFM files. For Computer Modern, I looked at the output for cmsy10: (FAMILY CMSY) (FACE O 352) (CODINGSCHEME TEX MATH SYMBOLS) (DESIGNSIZE R 10.0) (COMMENT DESIGNSIZE IS IN POINTS) (COMMENT OTHER SIZES ARE MULTIPLES OF DESIGNSIZE) (CHECKSUM O 4110426232) (FONTDIMEN (SLANT R 0.25) (SPACE R 0.0) (STRETCH R 0.0) (SHRINK R 0.0) (XHEIGHT R 0.430555) (QUAD R 1.000003) (EXTRASPACE R 0.0) (NUM1 R 0.676508) (NUM2 R 0.393732) (NUM3 R 0.443731) (DENOM1 R 0.685951) (DENOM2 R 0.344841) (SUP1 R 0.412892) (SUP2 R 0.362892) (SUP3 R 0.288889) (SUB1 R 0.15) (SUB2 R 0.247217) (SUPDROP R 0.386108) (SUBDROP R 0.05) (DELIM1 R 2.389999) (DELIM2 R 1.01) (AXISHEIGHT R 0.25) ) Comparing the values, we have:
Remember that we multiply everything by x-height, so here I've divided that metric out in the last column. Also, we use subdrop in for both sub/superscripts, so it appears as the current values for both. So, the numbers we have for sub1, sub2, are fairly close. subdrop / subdrop are quite different from what we have, and sup1 is also a bit bigger, but if we change the code to apply each separately, then it's mostly that superscripts drop by another pixel or so. If we make this change, about 100 test images are affected. For the fraction metrics (num1, num2, num3, denom1, denom2) there is a quite a bit of a difference in some of them. If we apply those, it affects about 70 test images, and mostly fractions "close up" a bit, but this is closer to how TeX does it. Before we had this (with usetex=True on the right): I haven't found any corresponding TFM files with the same metrics in them for the other fonts we have. I believe modern LaTeX can synthesize these directly from the font, and I do see some embedded MATH tables in there, but I haven't worked out the conversions for those yet. I've pushed the changes to the Computer Modern constants as two commits for ease of review. |
Sorry, something went wrong.
Vlists containing Hrules don't render vertical spaces correctly. The code for reproduction given in #23763 still works!
I reported this as a bug back then (#23474). Changing the script rendering logic is what exposed it. After merging a fix (#23482), the test passed even with the updated logic.
🎯💯
I remember being puzzled that using the same constants (from either Computer Modern or Latin Modern—I can't remember which one I had checked) didn't yield neatly aligned denominators. The multiplication by the x-height appears to be the key, which didn't strike me then. |
Sorry, something went wrong.
| sup1 = 0.79716796875 | ||
| sub1 = 0.354296875 | ||
| sub2 = 0.5314453125 | ||
| supdrop = 0.386108 / 0.430555 |
There was a problem hiding this comment.
You can get more accurate (effectively fixed-point representation) values from the tfm file, as tftopl prints values after scaling and drops some decimal points, e.g. for cmsy10 I get
slant=262144, space=0, space_stretch=0, space_shrink=0, x_height=451470, quad=1048579, extra_space=0 num1=709370, num2=412858, num3=465286, denom1=719272, denom2=361592, sup1=432949, sup2=380520, sup3=302922, sub1=157286, sub2=259226, supdrop=404864, subdrop=52429, delim1=2506096, delim2=1059062, axis_height=262144
(values need to be scaled by 2**20).
I extended the Tfm class to read these values at anntzer@a360989 if you want to try your hand at it (we don't need to decide now whether we actually want to integrate this functionality into the Tfm class).
Note that this also allows reading the actual definition of 1em and 1ex ("quad" and "x_height"), which should be better than the current approach of trying to guess the values (see @tfpf's comment
I reported this as a bug back then (#23474). Changing the script rendering logic is what exposed it. After merging a fix (#23482), the test passed even with the updated logic.
the linked threads (#23474 (comment)), and https://tex.stackexchange.com/a/98139).
Perhaps also worth fixing this properly?
Sorry, something went wrong.
There was a problem hiding this comment.
Ah, that's very useful, and might be something to implement along with stuff needed for #31048. For now, I've just put the numbers you have read directly into the file. They're very close and it only affects one image.
For quad / x_height, I can take a look, but we can also make that change independently from this one, I think?
Sorry, something went wrong.
There was a problem hiding this comment.
Sure (though it'll probably again break all images, so it has to be done in the text-overhaul branch too).
Sorry, something went wrong.
There was a problem hiding this comment.
BTW, I just noticed that fontTools has a TFM parser; I'm not sure how extensive it is.
Sorry, something went wrong.
There was a problem hiding this comment.
From a very quick look it looks complete; you can run python -mfontTools.tfmLib foo.tfm and in particular the params above will be printed (again they are scaled by 2**20 but all the decimal points are given so you can just remultiply back).
Sorry, something went wrong.
It appears to me that this specific issue has been fixed by #30059, can you confirm? (I haven't looked carefully yet at how this interacts with the fraction rendering.) |
Sorry, something went wrong.
|
By the way, https://www.tug.org/TUGboat/tb27-1/tb86jackowski.pdf has some nice figures explaining fraction layout, and https://www.tug.org/~vieth/papers/bachotex2008/math-font-paper.pdf some more discussion on inferring font parameters (though neither the x-height nor the axis-height...). |
Sorry, something went wrong.
|
According to The LaTeX Font Catalogue, I don't think DejaVu Sans provides math support in LaTeX, so I'm a bit uncertain how to compare our math constants with it. Opening up the MATH table with fontTools and picking out the values from https://ntg.nl/maps/38/03.pdf it seems that pretty much all of them are 0 and thus useless. Instead, I've managed to find values in FontForge's TeX tables in a slightly-hidden settings page, then dividing by the xheight in that same setting page (1120), we get:
supdrop/subdrop are quite different, but that's because they used to be one constant. num2/num3/denom2 all shrunk quite a bit, but the same thing happened with Computer Modern above. Before, we had: Note that the right side of the figure is usetex=True with \usepackage{arev} for the preamble. These are both from the same lineage of Bitstream Vera Sans, but I'm not sure if they're comparable if DejaVu Sans never had math support, so take those with a grain of salt, especially since the x doesn't really look the same style. DejaVu Serif has the same metrics, except the xheight is 1063 instead, so I won't post the table over again. Instead, just before and after images: |
Sorry, something went wrong.
|
There is a dejavu math font: https://www.gust.org.pl/projects/e-foundry/tex-gyre-dejavu-math / https://ctan.org/pkg/tex-gyre-math-dejavu?lang=en but it's only a serif font :/ not sure how well the constants would compare? |
Sorry, something went wrong.
|
Well, we do have DejaVu Serif as well with almost the same metrics; only the xheight is different at 1063 instead of 1120 (updated above with those images as well.) But it looks like the TeX Gyre fonts are for unicode-math and would require the other LaTeX engines to plug in to our usetex setup, too. |
Sorry, something went wrong.
#31064 enables to use the TeX Gyre fonts from within usetex. Currently, it does not dynamically set the "constants" but uses the defaults, but one could in principle read the otf MATH table. |
Sorry, something went wrong.
Sorry, something went wrong.
|
Squashed into fewer commits and rebased on the latest text-overhaul with just the test images that are relevant here. I'll see about merging tomorrow. |
Sorry, something went wrong.
As described in *TeX: the Program* by Don Knuth. New font constants are set to the nearest integral multiples of 0.1 for which numerators and denominators containing normal text do not have to be shifted beyond their default shift amounts at font size 30 in display and text styles. To better process superscripts and subscripts, the x-height is now always calculated instead of being retrieved from the font table (which was the case for Computer Modern); the affected font constants have been changed. A duplicate test was also fixed in the process.
At the call site https://github.com/matplotlib/matplotlib/blob/51fbfc4eb0e882ef7e95ceab9777c7047f4db819/lib/matplotlib/_mathtext.py#L1706-L1709 the box should clearly go from `cur_v + off_v` to `cur_v + off_v - rule_height` (this is why `cur_v` is shifted by `+ rule_height` just before; also at that point some print debugging indicates that y's go *downwards*), so `Rule.render` should indeed call `render_rect_filled` from `y - h` to `y`.
Computer Modern values are taken from `cmsy10.tfm`, and divided by the x-height in that output to match the scale used in Matplotlib. DejaVu Sans/Serif and STIX constants are taken from the embedded TeX table extracted with FontForge.
|
OK, going to merge, but the text-overhaul branch is still open if anything major comes up. |
Sorry, something went wrong.
|
|
||
|
|
||
| class STIXSansFontConstants(FontConstantsBase): | ||
| # These values are extracted from the TeX table of STIXGeneral.ttf using FreeType, |
There was a problem hiding this comment.
This should have said FontForge, not FreeType; I'll fix it in a followup.
Sorry, something went wrong.
…cal-align Implement TeX's fraction and script alignment
This includes images changes for the following pull requests / commits: * [Fix center of rotation with rotation_mode='anchor'](matplotlib#29199) (c44db77) * [Remove ttconv backwards-compatibility code](matplotlib#30145) (8caff88) * [Remove kerning_factor from tests](matplotlib#29816) (7b4d725) * [Set text hinting to defaults](matplotlib#29816) (8255ae2) * [Update FreeType to 2.13.3](matplotlib#29816) (89c054d) * [Implement text shaping with libraqm](matplotlib#30000) (b0ded3a, 9813523) * [Add language parameter to Text objects](matplotlib#29794) (7ce8eae) * [Fix auto-sized glyphs with BaKoMa fonts](matplotlib#29936) (3ba2c13) * [pdf: Improve text with characters outside embedded font limits](matplotlib#30512) (b70fb88, 6cedcf7) * [Prepare `CharacterTracker` for advanced font features](matplotlib#30608) (8274e17, 70dc388, df670cf, ed5e074) * [Add font feature API to Text](matplotlib#29695) (972a688) * [Fix spacing in r"$\max f$"](matplotlib#30715) (4a99a83) * [Implement libraqm for vector outputs](matplotlib#30607) (bd17cd4) * [Drop the FT2Font intermediate buffer](matplotlib#30059) (9d7d7b4) * [Rasterize dvi files without dvipng](matplotlib#30039) (7627118) * [Update bundled FreeType and HarfBuzz libraries](matplotlib#30938) (a161658, 9619bcc) * [Fix positioning of wide mathtext accents](matplotlib#31069) (c2fa7ba) * [Refactor RendererAgg.draw_{mathtext,text,tex} to use same base algorithm](matplotlib#31085) (931bcf3) * [Implement TeX's fraction and script alignment](matplotlib#31046) (94ff452, 4bfa0f9, 1cd8510) * [Fix confusion between text height and ascent in metrics calculations](matplotlib#31107) (60f2310) * [mathtext: Fetch quad width & axis height from font metrics](matplotlib#31110) (692df3f, 383028b) * [mathtext: add mathnormal and distinguish between normal and italic family](matplotlib#31121) (a6913f3) * [ENH: Ignore empty text for tightbbox](matplotlib#31285) (d772043) * [Drop axis_artist tickdir image compat, due to text-overhaul merge](matplotlib#31281) (2057583) * [text: Use font metrics to determine line heights](matplotlib#31291) (3ab6a27, d961462, 97f4943) * [ps/pdf: Override font height metrics to support AFM files](matplotlib#31371) (e0913d4) * [TST: Cleanup back-compat code in tests touched by text overhaul](matplotlib#31295) (7c33379) * [TST: Set tests touched by text overhaul to mpl20 style](matplotlib#31300) (41c4d8d)
| Back | FazBrowse Home | New Git URL |
PR summary
This is a rebase of #22852 by @tfpf. However, since we are planning to refresh the test images already, this reverts the change to move many mathtext images to SVG only (and I believe fixes some duplicated tests due to incorrect conflict resolution). Now, the only test change is to a nested-\frac test that is a duplicate and now is a nested-\dfrac test.
This is based on #30059 plus all the current test image changes, so that you can look at the second-last commit for this change and the last commit to review image changes from only this PR. I believe it does a fairly good job of fixing the fraction bar alignment issue that came up in #30059.
I have reviewed the fraction and sub/super script implementation with reference to the TeX book, but have not yet finished reviewing the font constants.
Fixes #18086
Fixes #18389
Fixes #22172
PR checklist