latex in ps via psfrag

John, this is incredible. For those of you who haven't

    > tried the demo from CVS yet, it looks to naive me like
    > John's achieved the Holy Grail of putting arbitrary TeX
    > into labels in matplotlib. MATLAB doesn't do this,
    > probably never will. Wow.

Yes, this is the basic idea. While I like the idea of finding the
Holy Grail, in deference to those who came before me, I must admit
that this is not entirely novel. It is basically what psfrag was
written for. xmgrace has had the ability to do this for many years,
and the psfrag manual has an explicit example showing how to do this
with Matlab. The beauty of psfrag is that you can use it with almost
any plotting package -- all you have to do is set up a dictionary
mapping a sentinel string to a TeX string, eg
"replacethistext"->"\TeX", and figure out where to place the sentinel
strings (this is the hard part, see below), and psfrag will do the

Where the matplotlib implementation is a tiny bit clever is in the
layout. Since we support left/middle/right and bottom/middle/top
alignment as well as rotated strings, we have to have a good estimate
of the text bounding box to do the layout. What the mpl texmamanger
does is tex the string independently, call dvips on the tex output,
and then parse the generated postscript header to extract the bounding
box for layout. With caching using hashes on the TeX string for
efficiency, yada yada...

This is currently broken because it doesn't account properly for
font sizes or rotation, yet, but this is readily fixable...

Also, FYI, I have been working on integrating TeX with Agg via dvipng.
This is also experimental, but if you want to play with it, set the rc
param in .matplotlibrc CVS

  text.usetex : True # experimental, broken

and run the tex demo. Small font sizes don't render well because of
problems in the way I am handling alpha and antialiasing in the dvipng
output, but if you set your font size or dpi high enough these
problems are negligible. Again, rotation is not yet supported. The
Holy Grail, of course, is to support raster (Agg) and vector (PS) TeX
text for all text elements transparently, falling back on an improved
mathtext layout with better fonts when TeX is not available....