Skip to content

Rogue mathtext rendered spaces #4333

Closed
Closed

Description

@ndevenish

I'm aware that the built in mathtext rendered is not expected to be perfectly identical to tex, but I'm seeing some egregious behavior with spacing that I cannot seem to explain. With:

import matplotlib.pyplot as plt
plt.figure()
plt.figtext(0.1, 0.9, r"1. ($a^2$)", size=20)
plt.figtext(0.1, 0.8, r"2. $(a^2)$", size=20)
plt.figtext(0.1, 0.7, r"3. $\left(a^2\right)$", size=20)
plt.show()

In both 1.4.2 and a recent development version I get a rogue space before the bracket in all three cases:
screen shot 2015-04-13 at 22 16 54
Compared with turning text.usetex on:
screen shot 2015-04-13 at 23 06 26

Using a negative space (\!) fixes the issue rendering with matplotlib, but screws up the latex output.

Activity

  1. added this to the milestone on Apr 14, 2015
  2. tacaswell commented on Apr 14, 2015

    @tacaswell
    Member

    attn @mdboom Could this be related to the recent spacing changes?

  3. u55 commented on Apr 18, 2015

    @u55
    Contributor

    I get slightly more-reasonable whitespace after the exponent if I enclose the exponent in curly brackets.

    import matplotlib.pyplot as plt
    s = 0.13
    plt.figure(figsize=(3,2.5))
    plt.figtext(0.1, 0.9-1*s, r"1a. ($a^2$)", size=20)
    plt.figtext(0.1, 0.9-2*s, r"1b. ($a^{2}$)", size=20)
    plt.figtext(0.1, 0.9-3*s, r"2a. $(a^2)$", size=20)
    plt.figtext(0.1, 0.9-4*s, r"2b. $(a^{2})$", size=20)
    plt.figtext(0.1, 0.9-5*s, r"3a. $\left(a^2\right)$", size=20)
    plt.figtext(0.1, 0.9-6*s, r"3b. $\left(a^{2}\right)$", size=20)
    plt.show()

    whitespace

  4. jason-sachs commented on Apr 24, 2015

    @jason-sachs

    another example:

    plt.text(0.2,0.5,"$d^2 \\leq K^2(q^2 - q_0^2)$",fontsize=30)
    

    image

    vs. MathJax $d^2 \leq K^2(q^2 - q_0^2)$

    image

  5. WeatherGod commented on Apr 25, 2015

    @WeatherGod
    Member

    In that example, I would wonder if the kerning is being turned off for
    exponents, somehow.
    On Apr 24, 2015 6:26 PM, "Jason Sachs" [email protected] wrote:

    another example:

    plt.text(0.2,0.5,"$d^2 \leq K^2(q^2 - q_0^2)$",fontsize=30)

    [image: image]
    https://cloud.githubusercontent.com/assets/10506541/7329623/193182b2-ea96-11e4-980c-ffd0a56223c5.png

    vs. MathJax $d^2 \leq K^2(q^2 - q_0^2)$

    [image: image]
    https://cloud.githubusercontent.com/assets/10506541/7329629/2e21b156-ea96-11e4-939e-82f77ab64dd1.png

    —
    Reply to this email directly or view it on GitHub
    #4333 (comment)
    .

  6. ndevenish commented on May 3, 2015

    @ndevenish
    ContributorAuthor

    That's an awful-looking example also - spacing screwed up next to the K and the contraction of the spacing in front of the q_0, along with the same spacing before the close bracket.

  7. added 2 commits that reference this issue on May 4, 2015
    698b054
    1886bc2
  8. self-assigned this
    on May 4, 2015
  9. added a commit that references this issue on May 8, 2015
    e0c5379
  10. zblz commented on Aug 7, 2015

    @zblz
    Member

    @ndevenish , @jason-sachs , @u55 : I have been finetuning the super/subscript spacing in mathtext in PR #4873, and applied a fix suggested by @mdboom to the symbol spacing in PR #4872. Applying these two PRs, the examples mention in this thread render like this:
    issue4333
    The strings are:

    $d^2 \\leq K^2(q^2 - q_0^2)$
    ($a^2$) $(a^2)$ $\left(a^2\right)$
    

    It would be great if you could take a look at PR #4873 and make any comments you have on how the new script kerning works before it is merged. Thanks!

  11. jason-s commented on Aug 14, 2015

    @jason-s

    It would be great if you could take a look at PR #4873 and make any comments you have on how the new script kerning works before it is merged.

    Scanned it briefly. You've gone much more in depth than I have -- thanks, I trust your judgment!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions