usetex w/ preview.sty

Hello,

I committed a patch to optionally use preview.sty with usetex=True.
This is to support a baseline alignment.

A summary of changes:

* added a get_text_width_height_descent() method in the TexManager
class, and modified the agg, ps and pdf backends to utilize this
method.

* added a new rc parameter, 'text.latex.preview'. If True,
preview.sty is used to generate dvi files and baseline information of
each dvi file is stored in a separate file.
TexManager.get_text_width_height_descent() method uses this
information.

* If text.latex.preview==False,
TexManager.get_text_width_height_descent() method uses dviread module
(this is what the pdf backend has been using), but the returned
descent value of the text is sometimes incorrect.

* added an example ("usetex_baseline_test.py" ). The output is
attached with this email.

If you have a preview.sty installed, please test this (set
"text.latex.preview=True" in you rc file) and report any problems.
Regards,

-JJ

usetex_baseline_test.png

Very nice!

I'm currently getting this traceback with the PDF backend, whether "text.latex.preview" is True or False -- so it may be unrelated to your change, but I'm unable to test PDF at the moment.

Traceback (most recent call last):
  File "usetex_baseline_test.py", line 75, in <module>
    plt.savefig("test.pdf")
  File "/home/mdroe/usr/lib/python2.5/site-packages/matplotlib/pyplot.py", line 345, in savefig
    return fig.savefig(*args, **kwargs)
  File "/home/mdroe/usr/lib/python2.5/site-packages/matplotlib/figure.py", line 990, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/home/mdroe/usr/lib/python2.5/site-packages/matplotlib/backend_bases.py", line 1429, in print_figure
    **kwargs)
  File "/home/mdroe/usr/lib/python2.5/site-packages/matplotlib/backend_bases.py", line 1323, in print_pdf
    return pdf.print_pdf(*args, **kwargs)
  File "/home/mdroe/usr/lib/python2.5/site-packages/matplotlib/backends/backend_pdf.py", line 1911, in print_pdf
    file.close()
  File "/home/mdroe/usr/lib/python2.5/site-packages/matplotlib/backends/backend_pdf.py", line 440, in close
    self.writeFonts()
  File "/home/mdroe/usr/lib/python2.5/site-packages/matplotlib/backends/backend_pdf.py", line 521, in writeFonts
    fontdictObject = self.embedType1(filename, self.dviFontInfo[filename])
  File "/home/mdroe/usr/lib/python2.5/site-packages/matplotlib/backends/backend_pdf.py", line 553, in embedType1
    t1font = type1font.Type1Font(fontinfo.fontfile)
  File "/home/mdroe/usr/lib/python2.5/site-packages/matplotlib/type1font.py", line 55, in __init__
    file = open(input, 'rb')

Also, it seems like the text alignment in the PS output is too low by a small constant factor.

Assuming those issues can be resolved, is there now any reason to use dviread, assuming preview.sty is installed? If the preview.sty approach is superior, I wonder if we could:

a) Determine if preview.sty is installed, and if so, use it, otherwise fallback to dviread? (Then we could be a default "auto" setting for the rcParam).

b) Or better, include preview.sty with matplotlib and use it instead of a system installed copy, so that it's always available. (This is both a licensing and version-compatibility question, really...)

It would be great to make this new behavior with the proper baseline more automatic.

Cheers,
Mike

Jae-Joon Lee wrote:

···

Hello,

I committed a patch to optionally use preview.sty with usetex=True.
This is to support a baseline alignment.

A summary of changes:

* added a get_text_width_height_descent() method in the TexManager
class, and modified the agg, ps and pdf backends to utilize this
method.

* added a new rc parameter, 'text.latex.preview'. If True,
preview.sty is used to generate dvi files and baseline information of
each dvi file is stored in a separate file.
TexManager.get_text_width_height_descent() method uses this
information.

* If text.latex.preview==False,
TexManager.get_text_width_height_descent() method uses dviread module
(this is what the pdf backend has been using), but the returned
descent value of the text is sometimes incorrect.

* added an example ("usetex_baseline_test.py" ). The output is
attached with this email.

If you have a preview.sty installed, please test this (set
"text.latex.preview=True" in you rc file) and report any problems.
Regards,

-JJ
  
------------------------------------------------------------------------

------------------------------------------------------------------------

------------------------------------------------------------------------------
  ------------------------------------------------------------------------

_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
  
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

I'm not quite sure why this is happening. My guess is that it has
something to with the usage of psfrag in the ps backend, e.g., the
different descent values between the original text and the substituted
text. I personally think it is better (for the ps backend) to use the
dviread module (as in the pdf backend) instead of using the psfrag.

Regards,

-JJ

···

On Mon, Jan 5, 2009 at 9:06 AM, Michael Droettboom <mdroe@...31...> wrote:

Also, it seems like the text alignment in the PS output is too low by a
small constant factor.