-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Whitespace in mathtext is too large and inconsistent with LaTeX #4335
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
Comments
I just want to notate the possible similarity to #4333 (not exactly the same issue, but they are related). |
@u55 Thank you for the very detailed report! |
@mdboom I have no idea on the time involved in this, but would it be reasonable to address this with the color overhaul (as we may have to regenerate lots of test images anyway). |
mdboom
added a commit
to mdboom/matplotlib
that referenced
this issue
May 4, 2015
mdboom
added a commit
to mdboom/matplotlib
that referenced
this issue
May 4, 2015
Conflicts: lib/matplotlib/tests/test_mathtext.py
jenshnielsen
added a commit
that referenced
this issue
May 8, 2015
Fix #4335: mathtext whitespacing commands
There is a fix for this on the wrong branch, it just needs to be ported over. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi matplotlib developers,
As a user quite familiar with LaTeX, I am constantly frustrated with the display size of the whitespace commands in matplotlib's mathtext mode with
'text.usetex':False
. The matplotlib mathtext spacing commands are much larger than their LaTeX equivalents. Here is a minimal working example:Tested with matplotlib 1.4.3, python 2.7 on Windows 7 and Linux.
The
\thinspace
command and the\enspace
command are handled as Unicode characters, so this requires a true Unicode font, such as "DejaVu Sans", not the builtin default "Bitstream Vera Sans".In the example shown above, the spacing between the series of "M" characters is much much bigger than expected for the commands
\,
and\;
and\quad
and\qquad
. Also, the spacing should be monotonically increasing from top to bottom, but it clearly does not.For instance, in LaTeX, the
\,
command is equivalent to\thinspace
, and should be 0.16667em wide, but in matplotlib,\,
is not thin at all, and is much larger than\thinspace
. This means that\,
is useless when one wants to create a truly-thin space in math mode.Similarly,
\;
should be much smaller than\enspace
.@mdboom After poking around in the source code, I discovered that the default values of these mathtext lengths are defined in "mathtext.py" by this dictionary:
where the dictionary values are the fractional width of the font (in "em" units).
I don't know where these numbers came from, but they are very different than the LaTeX specification, which can be found here:
http://tex.stackexchange.com/a/74354
or if you can find a copy of the "TeXbook" by Donald Knuth himself, or there are probably many other source on the web.
I propose to change this dictionary to the same values used by LaTeX:
And while, we are at it, we can add the LaTeX commands for
\>
and\:
, and we can remove the Unicode dependency for\thinspace
and\enspace
by adding definitions to this dictionary.(I don't think
\/
is normally used by LaTeX in math mode, but in earlier versions of matplotlib it was defined to be equal to0.1
em, so it was originally intended to be a thin space.)After making this change, the spacing behaves as expected:
However, I realize that this is a backwards incompatible change that will affect users out in the wild, but I think that it is worth the change to more sensible defaults, as long as it is well documented.
I imagine that lots of people, besides myself, expect matplotlib's mathtext to behave like LaTeX.
Today I discovered the undocumented
\hspace{float}
command in matplotlib's mathtext, that is similar to the LaTeX command by the same name (except that lengths in LaTeX have units). This provides a temporary workaround for me, but is annoying to have to use for such a common task as creating a thin space in math mode.Thanks for the consideration.
The text was updated successfully, but these errors were encountered: