Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add latex preamble to texmanager _fontconfig #4895

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

Merged
merged 3 commits into from
Aug 12, 2015

Conversation

zblz
Copy link
Member

@zblz zblz commented Aug 10, 2015

The contents of TexManager._fontconfig determines whether the png for a given string/dpi/font combination is rendered from TeX or reused from the cache. Right now, there is no information of the custom latex preamble in _fontconfig, so a second string with a different latex preamble will reuse the png from the first call. Note that the tex and dvi files are generated as generating this depends on the _rc_cache which includes the latex preamble, so the expensive call to TeX is made but then the png is not used. This PR adds a hash of the latex preamble to TexManager._fontconfig so that a new png is read if preamble changes.

A minimal example which should produce two different images:

import matplotlib.pyplot as plt
plt.rcParams['text.usetex'] = True
plt.rcParams['font.family'] = 'serif'
for font,preamble in zip(['cm','times'], [' ',r'\usepackage{txfonts}']):
    plt.rcParams['text.latex.preamble'] = preamble
    f = plt.figure(figsize=(3,1))
    f.text(0.5,0.5,'This is some test text $e^{-i\pi}=-1$', ha='center',va='center')
    f.savefig('texmanager_test_{0}.png'.format(font))

@WeatherGod
Copy link
Member

The explanation makes sense, but some of that should be added to the comments so that future devs will understand why this is being done. Would also be valuable to create a unit test to catch this situation (which, I suspect would have been rare, and thus very important to capture as a test).

A test comparing images is difficult because the metrics are taken from the tex
(which is correctly selected) so that even when the incorrect png is selected,
it will be shifted so an image comparison will always fail.
@zblz
Copy link
Member Author

zblz commented Aug 10, 2015

@WeatherGod: I added a test on the TexManager.get_font_config() string rather than doing an image comparison because even when the same png is selected it will be shifted on the final image. I suspect the metrics are taken from the (correct) tex or dvi, whereas the image is taken from the incorrect png. Therefore the image comparison will fail for both master and this PR.

WeatherGod added a commit that referenced this pull request Aug 12, 2015
Add latex preamble to texmanager _fontconfig
@WeatherGod WeatherGod merged commit 3f758ab into matplotlib:master Aug 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants