Skip to content

Support partial usetex in ps output #7741

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

Open
pfigliozzi opened this issue Jan 4, 2017 · 8 comments
Open

Support partial usetex in ps output #7741

pfigliozzi opened this issue Jan 4, 2017 · 8 comments
Labels
backend: ps keep Items to be ignored by the “Stale” Github Action New feature topic: text/usetex

Comments

@pfigliozzi
Copy link

pfigliozzi commented Jan 4, 2017

I am trying to save some figures I made as .ps or .eps but I am getting an error. I narrowed the error down to the fact that I am using Latex for some of the text in my figure but using rc.params['text.usetex'] = False. Here is some code that reproduces the bug:

import matplotlib
import matplotlib.pyplot as plt
fig = plt.figure()
plt.text(0.5, 0.5, 'Here is some text, $math mode$', ha='center', va='center', usetex=True)
fig.savefig('test.ps')

The error you get is AttributeError: 'RendererPS' object has no attribute 'textcnt'

When looking at this code in in the RendererPS class the textcnt attribute is only added when rc.params['text.usetex'] = True. However I am just using Latex for specific text objects with the option usetex=True. Is there a way to save these figures as .ps or .eps?

I am using Matplotlib 1.5.1 installed via conda on Windows with python 2.7. I also tested it with Matplotlib 2.0.0b4 which also produced the same error, however I would prefer a solution for 1.5.1 if possible.

HaranN pushed a commit to ibnIrshad/matplotlib that referenced this issue Mar 4, 2017
@HaranN
Copy link

HaranN commented Mar 4, 2017

The issue seems to stem from 2 problems related to the setting of usetex.

The first one is in line 638 of matplotlib/lib/matplotlib/axes/_axes.py where we create a new Text object, but we don't pass in the usetex boolean from the kwargs. Due to this, Text.set_usetex() in line 221 of matplotlib/lib/matplotlib/text.py would make the value of self._usetex default to rcParams['text.usetex'] which is always False.

This leads into the second problem which was that even though you set usetex=True, rcParams['text.usetex'] was not being updated to True. This means when RendererPS was initialized, the textcnt attribute would not be initialized, causing the AttributeError.

@jmlarson1
Copy link

Any update for this issue?

@oscargus
Copy link
Member

This currently does not error, but gives the following message:

The PS backend determines usetex status solely based on rcParams['text.usetex'] and does not support having usetex=True only for some elements; this element will thus be rendered as if usetex=False.

@timhoffm
Copy link
Member

Thanks @oscargus.

I think this warning is good enough so I'll close the issue. Please report back if this is not good enough.

@anntzer
Copy link
Contributor

anntzer commented Apr 25, 2022

@timhoffm I think this is still a reasonable feature request ("support partial usetex in ps output" -- like all other backends do), and could therefore be kept open?

@timhoffm
Copy link
Member

Sure - reopening with adapted title.

@timhoffm timhoffm reopened this Apr 26, 2022
@timhoffm timhoffm changed the title AttributeError when saving figure with partial Latex elements as a postscript. Support partial usetex in ps output Apr 26, 2022
Copy link

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Apr 19, 2024
@tacaswell tacaswell removed the status: inactive Marked by the “Stale” Github Action label Apr 19, 2024
Copy link

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Apr 21, 2025
@rcomer rcomer added keep Items to be ignored by the “Stale” Github Action and removed status: inactive Marked by the “Stale” Github Action labels Apr 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: ps keep Items to be ignored by the “Stale” Github Action New feature topic: text/usetex
Projects
None yet
9 participants