FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Feature request: mathtext support for \displaystyle · Issue #1888 · matplotlib/matplotlib · GitHub

Repository navigation

Feature request: mathtext support for \displaystyle #1888

Closed

Description

When I give matplotlib a annotation string such as

$\frac{A}{B} = C$

and I specify a fontsize of 18, the A and B are rendered at 12.6 pt, while the C is rendered at 18 pt. I want A, B, and C to all be the same size.

In a LaTeX document, if you give the commands

\begin{equation}
\frac{A}{B} = C
\end{equation}

you get a fraction, where A, B, and C are all the same size, but if you do

$\frac{A}{B} = C$

inline with text, you get the A and B rendered at 12.6 pt, while the C is rendered at 18 pt. Thus it appears matplotlib's mathtext is emulating LaTeX's inline mode. In LaTeX you can write

$\displaystyle\frac{A}{B} = C$

and then A, B, and C are all the same size, even in inline mode. I tried this in matplotlib, but mathtext did not recognize the command \displaystyle. =(

I am aware I can use \displaystyle if I change text.usetex to true in my .matplotlibrc file, but I would like to stay with mathtext since it is a lot faster. Is there a chance of implementing \displaystyle in math text? If not, does anyone have a work around?

My setup: matplotlib v1.2.0, python 2.7, OS X 10.8.3

Activity

  1. mdboom commented on Apr 9, 2013

    Member

    I agree it would be nice to have this. mathtext has always been a subset of TeX, just because time is finite, but we gradually add new features on a sort of "as needed" basis. If you want to tackle this yourself, I'd be happy to provide some pointers -- getting yourself a copy of The TeX Reference: Volume B (there are freely available PDFs online) is a good start...

  2. breedlun commented on Apr 10, 2013

    ContributorAuthor

    Thanks for your reply. While I definitely have an interest in diving into Matplotlib and LaTeX to add this functionality, I currently lack the time. I am already overextended right now from all the time it has taken me to switch from Matlab to Python. Hopefully I will be able to get out from under my mountain of work to help more in the future.

  3. breedlun commented on Sep 21, 2013

    ContributorAuthor

    Ok. The lack of \displaystyle is starting to drive me nuts. I'm not sure how much help I will be, but I thought I should at least try to tackle this. I just looked for "The TeX Reference: Volume B" and found nothing that matched that title. Any other advice you can lend would be much appreciated.

  4. mdboom commented on Sep 24, 2013

    Member

    If you just want it to work, the path of least resistance here is going to be to turn text.usetex on and use a real TeX backend.

    However, if you're game on extending matplotlib, the book I meant was (sorry I didn't have the title exactly right):

    http://www.amazon.com/Computers-Typesetting-Volume-TeX-Program/dp/0201134373/ref=sr_1_2?ie=UTF8&qid=1380049773&sr=8-2&keywords=tex%3A+the+program

    This is the same text I used to implement the existing mathtext support. You can also build that book from the source code to TeX (I did it so many years ago, I can't remember how, but it's not too difficult on a Linux system with cweb installed).

  5. breedlun commented on Sep 25, 2013

    ContributorAuthor

    Yeah, I found that using TeX (via text.usetex) to typeset every figure was too slow for me. I would rather get it done right. Is there a reason you went with \textstyle rather than \displaystyle? I was thinking it might make sense to create an option in matplotlib.rcParams that allows the user to decide which is the default.

    I tried to find pdfs of "Computers & Typesetting, Volume B: TeX: The Program" online, but I did not come up with anything. I did find http://www.ctan.org/tex-archive/systems/knuth/dist/tex, but it looks like people are not supposed to typeset the source without Knuth's direct permission.

  6. mdboom commented on Sep 25, 2013

    Member

    Ah -- I didn't see that license restriction earlier. Looks like purchasing or library-borrowing the book is probably the only way to go (and I do own the book, FWIW, and had typeset it myself while it was in transit).

  7. added this to the milestone on Aug 17, 2014
  8. petehuang commented on Dec 31, 2016

    Contributor

    This hasn't been updated in a while. I'm wondering about the priority of this issue given that there's a good workaround. I guess it depends on how far we want MPL to go into this territory

  9. breedlun commented on Dec 31, 2016

    ContributorAuthor

    I am obviously biased, but this issue still matters to me. I realize it would be a large effort for mathtext to recreate everything in LaTeX, but I think \displaystyle fractions are one feature that deserves to be implemented. I have been using matplotlib intensively for three years now and I have not run into any other shortcoming in mathtext that gets in my way more than this one. Any time I want to normalize a variable by another variable, I have to use a / b instead of \frac{a}{b}.

    If no one has made any headway on this issue by this summer, I should have some time to work on it. I am a newbie when it comes to heavy duty TeX, but I am willing to learn.

  10. watkinrt commented on Jan 25, 2017

    Contributor

    I just ran into this problem and would be interested in a fix. Like breedlun, I thought I could get over it, but I can't (maybe its because we both had the same thesis adviser who broke us). It appears that my library has Knuth's "METAFONT : the program" book (i.e., Volume C), but sadly not "TeX: The Program". If I were to get the book, how intensive would it be for me to implement this feature? I've meddled around with the underbelly of matplotlib some, so I am familiar with much of its structure. I also have extensive experience with LaTeX and some with TeX.

  11. breedlun commented on Jan 26, 2017

    ContributorAuthor
  12. watkinrt commented on Feb 7, 2017

    Contributor

    Just poking around in mathtex.py, I think it should be pretty easy to implement this functionality. It looks like the tex macro \genfrac had been implement, which is the base macro for making things like \frac, \binom, \stackrel, etc; the usage of \genfrac is { \genfrac #1 #2 #3 #4 #5 #6 }, where #1 is left delimiter, #2 is the right delimiter, #3 is the fraction bar thickness, #4 is the style (0: displaystyle, 1: textstyle, 2: scriptstyle, 3: scriptscriptstyle), #5 is the numerator, and #6 is the denominator. It looks like the current implementation of the child macros \frac, \binom, etc all are hard coded to use the \textstyle style (i.e., \displaystyle is ignored). If I have time this weekend, I'll see if I can get the style to depend on the input style.

  13. added a commit that references this issue on Jul 26, 2017
  14. modified the milestones: , on Oct 3, 2017
  15. anntzer commented on Aug 8, 2019

    Contributor

    #8151 implemented \dfrac, which covers the initial request. That doesn't cover all of \displaystyle, but I'll close this until there are other concrete points to implement.

  16. removed this from the future releases milestone on Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL