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

Feature request: allow mathtext fallback font other than Computer Modern for custom mathtext setup · Issue #8619 · matplotlib/matplotlib · GitHub

Repository navigation

Feature request: allow mathtext fallback font other than Computer Modern for custom mathtext setup #8619

Closed

Description

Feature request

Feature summary

Allow users to specify a mathtext fallback font when custom mathtext font lacks a needed character.

More detail

Currently, a user can choose a font for the mathtext. For example, to use Open Sans for text and math, you can do:

rcParams['font.sans-serif'] = 'open sans'
rcParams['mathtext.fontset'] = 'custom'
rcParams['mathtext.it'] = 'sans:italic'

Open Sans has pretty good coverage of the characters needed for plots, including the Greek alphabet, but it's missing, for example, a character that maps to the latex command $\phi$ (it's phi maps to $\varphi$). If you use the above configuration with textbox containing $\phi$, the system falls back to computer modern, in accordance with the fallback_to_cm rc parameter. It would be nice, however, to be able to fall back to a similar font for that character, preferable a sans serif font in a comparable weight.

This is already implemented for the default DejaVu Sans. It falls back to Stix Sans instead of CM to get a more uniform look. (In the DejaVuFonts class, the line

self.cm_fallback = StixSansFonts(*args, **kwargs)

sets this.)

In my example with Open Sans, I can get a better result by changing the line

self.cm_fallback = BakomaFonts(*args, **kwargs)

to

self.cm_fallback = DejaVuSansFonts(*args, **kwargs)

in the UnicodeFonts class. That way, the fallback is a sans-serif font similar to the main font.

It seems like it would be fairly easy to allow users to set the fallback to one of the built-in fonts (cm, dejavuserif, dejavusans, stix, stixsans). It would be nice to also allow custom fallbacks (but then we might need to have a fallback for the fallback in case the custom choice lacks a needed character). In my example, you might want to set the main font in Open Sans, but the fallback to Noto Sans (a very similar Google font with more characters).

There are many high-quality free (and not free) fonts that would benefit from a fallback that's not computer modern. This feature would therefore increase the number of usable custom fontsets.

Implementation questions
I'd be happy to try implementing this myself, but I'm a new contributor, and I'm sure I'd mess some things up. Here are a few questions that come to mind:

  1. Is this feature worth implementing?
  2. It would probably require a change to the rc parameters. Is there a policy in place for doing so?
  3. Like I mentioned above, allowing users to choose from one of the built-in fonts would be pretty straightforward. Is it worth also allowing custom fallbacks?

Activity

  1. anntzer commented on Feb 13, 2020

    Contributor

    @geib7592 Sorry this fell through the cracks and didn't get a response for so long. There is a PR for this at #11644 which implements this for stix. How does that look for you? Do you have thoughts as to whether #11644 should also support other fallback families?

  2. geib7592 commented on Feb 14, 2020

    Author

    Great, I didn't realize this was being worked on. It seems like extending #16144 to also allow fallback to DejaVu Sans should be straightforward, and I think worthwhile for flexibility in using custom sans-serif fonts.

    I just want to add one more point about why this PR is important, because so far it does not seem to be said in the other thread(s). Major scientific publishing companies like Nature and Science explicitly prefer Helvetica for the text of their figures. For Greek letters and symbols, they seem to use a similar weight serif font used in their main text. When I posted the original feature request, I was finding it surprisingly difficult to get results close to these professional standards, and I ended up having to tweak matplotlib internals to get what I was looking for. The PR as it stands really helps move in the right direction, and I hope to see more motion toward "industry standard" design principles in the future. I've thought a fair amount about this problem, so if the matplotlib folks are interested, I'd be happy to discuss and get more involved.

    Cheers!

  3. anntzer commented on Feb 14, 2020

    Contributor

    #11644 (sorry I typed the number wrong the first time) is getting revived at #16509; definitely please do share your thoughts on that PR as you likely have thought more about the problem than any of the current core devs :)

  4. anntzer commented on Mar 10, 2020

    Contributor

    Closed by #16509, AFAICT.

  5. added this to the v3.3.0 milestone on Mar 10, 2020
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL