Patch to fix stale tex cache issues [Was: using different font families with?LaTeX-generated text]

Darren Dale <dd55@...163...> writes:

You should also make your rc changes before importing pylab. That might be
considered a bug, and would take some work to fix.

I think I've fixed the bug (well, mostly see TODO), as well as a few other
minor bugs:

- ``__init__.py``
  * defaultParams value tuple[0] ought to be the parsed value, as
    far as I can see, but the fonts are given as comma-seperated string, which
    will result in texmanager treating individual chars as 'fonts'

- ``texmanager.py``
  * 'Computer Modern Sans serif' rather than 'Computer Modern Sans-serif' as
    on wiki; I haven't changed it because I don't know which spelling is
    desired -- I'd personally prefer two, because it's consistent with the
    most common spelling of 'sans-serif' and the spelling elsewhere in MPL
  * condensed `TexManger.__init__` and fixed the undeclare var bug in the
    warning; also added check that rcParams['font.*'] is not a string (see
    above)
  * `TexManger.get_font_config` now checks that font configuration is in
    synch with rcParams and if not re-initialized `self` to recompute it
  * changed ``self._font_config -> self.get_font_config()`` and added it to the key
    generation for TexManger.get_rgba -- so now every change the relevant
    rcParams font entries will now recompute or select the *correct* cached
    value (Note I think for get_rgba ._font_config would suffice, but since it
    looks like it needs to be modified anyway and .get_font_config is safer I
    opted for the latter).
  * added a few consistency checks

This is the first time I've really looked at (and hacked) the MPL code, so my
solution might have issues, I'm certainly not aware of the big picture.
However I'm pretty sure that parts of the patch should be useful and that I've
correctly identified some small bugs.

TODO

test_tex_caching.py (1.85 KB)

init.py.PATCH|attachment (6.35 KB)

texmanager.py.PATCH (9.04 KB)

···

----

A) the wiki page still needs to be corrected; I'm happy to do it, but it would
   be useful to know:
   1. what exactly I should change to ``rcParams`` (all ``rc`` calls?)
   2. how the 'Computer Modern Sans'-'/' 'serif' thing will be resolved
   3. if this patch is likely to be accepted in some form (because then I'll
      also mention that the need to import pylab afterwards will go away in
      svn/future versions)

B) TexManger.get_rgba needs to deal with font-properties other than size to do
   its job properly (i.e. return the *correct* cached text); that means that 2
   places in backend_agg.py will also need changs since it uses insufficient
   info to find the right cached text (no properites). How to do this involves
   making design decisions that I think one of the developers has to take, so
   I didn't do anything about it. I got the impression that just passing
   ``prop.font_family`` together with ``size`` might handle most cases, but I
   have no idea how latex-font-properties are really meant to be handled.

In addition to the patch, I've appended some file to test and demonstrate the
new (hopefully better); behavior (just %run) -- the patch currently is full of
print-DEBUG statements, I've left them in because it makes easier to verify
what's going on and B) still ought to be fixed; they're easy to take remove
(grep DEBUG), but if it's an issue I'm happy to supply the patch without them.

hope this is useful,

'as

I just commited Alexander Schmolck's patch to make usetex respect changes to
rc settings. TexManager used to configure its support for latex at load time,
and ignored later changes to rc settings. Thank you Alexander for the patch.

Alexander - I am sorry it took so long to commit this patch. I couldn't
directly apply it, because it conflicted with some changes to support
unicode. Also, the recent addition of validating changes to rcParams helped
simplify things somewhat.

Darren

···

On Friday 18 May 2007 12:02:30 pm Alexander Schmolck wrote:

> You should also make your rc changes before importing pylab. That might
> be considered a bug, and would take some work to fix.

I think I've fixed the bug (well, mostly see TODO), as well as a few other
minor bugs:

- ``__init__.py``
  * defaultParams value tuple[0] ought to be the parsed value, as
    far as I can see, but the fonts are given as comma-seperated string,
which will result in texmanager treating individual chars as 'fonts'

- ``texmanager.py``
  * 'Computer Modern Sans serif' rather than 'Computer Modern Sans-serif'
as on wiki; I haven't changed it because I don't know which spelling is
desired -- I'd personally prefer two, because it's consistent with the most
common spelling of 'sans-serif' and the spelling elsewhere in MPL *
condensed `TexManger.__init__` and fixed the undeclare var bug in the
warning; also added check that rcParams['font.*'] is not a string (see
above)
  * `TexManger.get_font_config` now checks that font configuration is in
    synch with rcParams and if not re-initialized `self` to recompute it
  * changed ``self._font_config -> self.get_font_config()`` and added it to
the key generation for TexManger.get_rgba -- so now every change the
relevant rcParams font entries will now recompute or select the *correct*
cached value (Note I think for get_rgba ._font_config would suffice, but
since it looks like it needs to be modified anyway and .get_font_config is
safer I opted for the latter).
  * added a few consistency checks

This is the first time I've really looked at (and hacked) the MPL code, so
my solution might have issues, I'm certainly not aware of the big picture.
However I'm pretty sure that parts of the patch should be useful and that
I've correctly identified some small bugs.

TODO
----

A) the wiki page still needs to be corrected; I'm happy to do it, but it
would be useful to know:
   1. what exactly I should change to ``rcParams`` (all ``rc`` calls?)
   2. how the 'Computer Modern Sans'-'/' 'serif' thing will be resolved
   3. if this patch is likely to be accepted in some form (because then
I'll also mention that the need to import pylab afterwards will go away in
svn/future versions)

B) TexManger.get_rgba needs to deal with font-properties other than size to
do its job properly (i.e. return the *correct* cached text); that means
that 2 places in backend_agg.py will also need changs since it uses
insufficient info to find the right cached text (no properites). How to do
this involves making design decisions that I think one of the developers
has to take, so I didn't do anything about it. I got the impression that
just passing ``prop.font_family`` together with ``size`` might handle most
cases, but I have no idea how latex-font-properties are really meant to be
handled.

In addition to the patch, I've appended some file to test and demonstrate
the new (hopefully better); behavior (just %run) -- the patch currently is
full of print-DEBUG statements, I've left them in because it makes easier
to verify what's going on and B) still ought to be fixed; they're easy to
take remove (grep DEBUG), but if it's an issue I'm happy to supply the
patch without them.

hope this is useful,

'as

--
Darren S. Dale, Ph.D.
Staff Scientist
Cornell High Energy Synchrotron Source
Cornell University
275 Wilson Lab
Rt. 366 & Pine Tree Road
Ithaca, NY 14853

dd55@...163...
office: (607) 255-3819
fax: (607) 255-9001
http://www.chess.cornell.edu