Conversation
|
Looks good! I think it makes sense to add a brief What's new for this to make users aware that it is added. Also, I think it may be enough to have a "lightweight" test for this as it doesn't seem very dependent on the font: matplotlib/lib/matplotlib/tests/test_mathtext.py Lines 124 to 132 in ecba9d2 |
|
@anntzer I think you as our TeX expert should review this. |
|
Sure, l'll need a couple of days though. |
|
This seems reasonable, but 1) do you know why the overline() implementation is so different, using a fill instead? (which seems inconsistent with the TeXbook); 2) the TeXbook (rules G9/G10 p443) add an extra |
|
Could the differences have to do with the rule being incorrectly rendered inverted? #31046 (comment) |
[skip ci]
\underline in Mathtext.|
As pointed out by QuLogic and anntzer, the rendering issue is now resolved. Time to bring this back.😴 Preliminary Checkimport string
import matplotlib.pyplot as plt
plt.rcdefaults()
fig, ax = plt.subplots(figsize=(20, 5))
ax.text(
.5, .5, " ".join(f"${c}\\underline{{{c}}}$" for c in string.ascii_lowercase),
size=30, ha="center", va="baseline",
)
ax.axhline(.5)
fig.savefig("underline.png")
fig.savefig("underline.svg")
plt.show()The underlines are drawn as described in TEX: The Program. Thus, text with descenders will push the underline lower. This is the expected behaviour; see exercise 18.26 on page 178 of The TeXbook.
Caveats
|
I can make a guess. The line above the body of a radical must touch the top of the radical (a tick mark), so it is imperative that the line be rendered at the correct height. This combined with the fact that the text under radicals (and overlines) is supposed to be rendered in cramped style might explain why the space between it and the body was not calculated but filled up with stretchable glue. You can see this in the
I am now fairly sure that this was done to give the line some space between it and the previous or next lines. I suppose the same could be done here, but it is not clear why he set the depth directly instead of adding a vertical space. |
|
Comparing with But the inconsistency with the underline thickness does make me wonder if we should disable snapping on all mathtext boxes. Any thoughts @anntzer @tacaswell? Unfortunately, this would cause about 120 test image changes. |



PR Summary
#15624 hasn't seen any activity for a while, so I went ahead with this.
Note that the underline is drawn below the lowest descender. This is consistent with TeX. (The PNG images suffer from what I assume is pixel rounding.)
Fixes #14235.
Closes #15624
PR Checklist
Tests and Styling
pytestpasses).flake8-docstringsand runflake8 --docstring-convention=all).Documentation
doc/users/next_whats_new/(follow instructions in README.rst there).doc/api/next_api_changes/(follow instructions in README.rst there).