|
From: John H. <jdh...@ac...> - 2005-05-17 22:44:43
|
In honor of Darren trying to get his thesis printed using mpl figures,
and encountering a lot of pain with fonts and mathtext, I added a
psfrag latex backend today. psfrag is a latex package that enables
you to substitute sentinel strings in an eps figure with latex
expressions (eg as in xfig). You create an eps with a bunch of marker
strings like "psmarker0" or "psmarker1" and then write a latex file
that does the substitutions
\psfrag{psmarker0}[bl][bl][2.000000][0.000000]{\TeX\ is Number $e^{-i\pi}$!}
\psfrag{psmarker1}[bl][bl][1.000000][0.000000]{0}
The LaTeX backend generates a *.eps file and a *.tex file. You can
then latex and dvips the tex file to get a true ps, or just embed the
generated latex commands directly into your document. This uses latex
for all text elements, giving a unified font look and feel.
Here is an example
> python examples/tex_demo.py -dLaTeX
> latex tex_demo.tex
> dvips -o tex_demo.ps tex_demo.dvi
> ggv tex_demo.ps
There are a few problems
* the page width and figure placement in the latex document are off
center
* the text color is not being respected
* to get the width and height of the string, I tex the individual
strings separately, run dvips on them, and get the bounding box
from the generated file. This all happens with caching in
matplotlib.texmanager. Right now the fontsize is being ignored in
this process so the layout will be off for nonstandard font sizes
-- anything other than the default design size of latex which
defaults to 10pt I think.
* the text doesn't scale right if you provide a size arg to
includegraphics, eg [width=4.in]
I'm sure these details can be worked out by someone who has the
patience to read the psfrag manual closely and knows a bit about tex
and dvips -- the backend is only 180 lines of code. I'm kind of busy
right now with other work, so I was hoping some enterprising soul
would like to take this and run with it, polish it, fix it and test
it.... Darren? If not, I'll get to it as I can.
Changes in CVS
JDH
|
|
From: Darren D. <dd...@co...> - 2005-05-17 23:17:13
|
On Tuesday 17 May 2005 6:44 pm, John Hunter wrote:
> In honor of Darren trying to get his thesis printed using mpl figures,
> and encountering a lot of pain with fonts and mathtext, I added a
> psfrag latex backend today. psfrag is a latex package that enables
> you to substitute sentinel strings in an eps figure with latex
> expressions (eg as in xfig). You create an eps with a bunch of marker
> strings like "psmarker0" or "psmarker1" and then write a latex file
> that does the substitutions
>
> \psfrag{psmarker0}[bl][bl][2.000000][0.000000]{\TeX\ is Number
> $e^{-i\pi}$!} \psfrag{psmarker1}[bl][bl][1.000000][0.000000]{0}
>
> The LaTeX backend generates a *.eps file and a *.tex file. You can
> then latex and dvips the tex file to get a true ps, or just embed the
> generated latex commands directly into your document. This uses latex
> for all text elements, giving a unified font look and feel.
I don't know what to say, except, Thank you.
> Here is an example
>
> > python examples/tex_demo.py -dLaTeX
> > latex tex_demo.tex
> > dvips -o tex_demo.ps tex_demo.dvi
> > ggv tex_demo.ps
>
> There are a few problems
>
> * the page width and figure placement in the latex document are off
> center
>
> * the text color is not being respected
>
> * to get the width and height of the string, I tex the individual
> strings separately, run dvips on them, and get the bounding box
> from the generated file. This all happens with caching in
> matplotlib.texmanager. Right now the fontsize is being ignored in
> this process so the layout will be off for nonstandard font sizes
> -- anything other than the default design size of latex which
> defaults to 10pt I think.
>
> * the text doesn't scale right if you provide a size arg to
> includegraphics, eg [width=3D4.in]
>
> I'm sure these details can be worked out by someone who has the
> patience to read the psfrag manual closely and knows a bit about tex
> and dvips -- the backend is only 180 lines of code. I'm kind of busy
> right now with other work, so I was hoping some enterprising soul
> would like to take this and run with it, polish it, fix it and test
> it.... Darren? If not, I'll get to it as I can.
>
> Changes in CVS
I'll be on a bus 24 of the next 60 hours, to get to my brother's graduation=
=2E=20
I'll print out what is in cvs and the psfrag manual for the trip, and can't=
=20
wait to get my hands on the code when I get back.
Darren
|
|
From: Stephen W. <ste...@cs...> - 2005-05-21 00:00:04
|
John Hunter wrote: >In honor of Darren trying to get his thesis printed using mpl figures, >and encountering a lot of pain with fonts and mathtext, I added a >psfrag latex backend today. > 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. OK, enough groveling. |
|
From: John H. <jdh...@ac...> - 2005-05-21 04:05:27
|
>>>>> "Stephen" == Stephen Walton <ste...@cs...> writes:
Stephen> John, this is incredible. For those of you who haven't
Stephen> tried the demo from CVS yet, it looks to naive me like
Stephen> John's achieved the Holy Grail of putting arbitrary TeX
Stephen> into labels in matplotlib. MATLAB doesn't do this,
Stephen> 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
rest.
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....
JDH
|
|
From: Darren D. <dd...@co...> - 2005-05-22 04:25:24
|
I played with the new latex backend tonight, and made some incremental=20
improvements. texmanager now calls latex instead of tex, so we can make use=
=20
of some of the more complex layout commands, \frac{}{} for instance. A new=
=20
version of tex_demo.py is in cvs, try running:
> > python examples/tex_demo.py -dLaTeX
> > latex tex_demo.tex
> > dvips -o tex_demo.ps tex_demo.dvi
> > ggv tex_demo.ps
On a related subject, tex layout via text.usetex does not appear to be work=
ing=20
at the moment. I tried undoing my changes but was not able to get the old=20
results back. Did I break this or did I catch it in transition?
>
> There are a few problems
>
> * the page width and figure placement in the latex document are off
> center
>
> * the text color is not being respected
>
> * to get the width and height of the string, I tex the individual
> strings separately, run dvips on them, and get the bounding box
> from the generated file. This all happens with caching in
> matplotlib.texmanager. Right now the fontsize is being ignored in
> this process so the layout will be off for nonstandard font sizes
> -- anything other than the default design size of latex which
> defaults to 10pt I think.
The horizontal placement appears to be fixed in CVS. I haven't gone searchi=
ng=20
for trouble in the vertical layout yet.
>
> * the text doesn't scale right if you provide a size arg to
> includegraphics, eg [width=3D4.in]
Darren
|
|
From: John H. <jdh...@ac...> - 2005-05-22 17:28:10
|
>>>>> "Darren" == Darren Dale <dd...@co...> writes:
Darren> On a related subject, tex layout via text.usetex does not
Darren> appear to be working at the moment. I tried undoing my
Darren> changes but was not able to get the old results back. Did
Darren> I break this or did I catch it in transition?
This is totally experimental and will break all backends except agg --
I will handle this more elegantly once I figure out how I want to do
it, but right now am trying to fix low level problems like getting the
alpha channel right (am working with dvipng author for the next dvipng
release to get proper access to alpha channel) and then to handle
rotation. Once all of that is working I can work out the interface so
that it plays nicely with other backend.
With the revision I just checked into CVS, you should get TeX rasters
in agg if you set usetex (they will look crappy because of the alpha
problem). But I'm optimistic that I can clear up all these problems
in a couple of weeks time. If you get psfrag in decent shape, we'll
be in good shape for a TeX enabled 0.81 release...
Darren> The horizontal placement appears to be fixed in CVS. I
Darren> haven't gone searching for trouble in the vertical layout
Darren> yet.
Unless you fixed it, I would be surprised...
JDH
|
|
From: Darren D. <dd...@co...> - 2005-05-24 21:22:36
|
On Tuesday 17 May 2005 6:44 pm, John Hunter wrote: > The LaTeX backend generates a *.eps file and a *.tex file. You can > then latex and dvips the tex file to get a true ps, or just embed the > generated latex commands directly into your document. This uses latex > for all text elements, giving a unified font look and feel. > > Here is an example > > > python examples/tex_demo.py -dLaTeX > > latex tex_demo.tex > > dvips -o tex_demo.ps tex_demo.dvi > > ggv tex_demo.ps > > There are a few problems > > * the page width and figure placement in the latex document are off > center Maybe not. If you use a latex centering environment, I think the figure is= =20 centered. Even in a centering environment, it may still appear to be off=20 center, since the axes+labels may not have been centered in the figure wind= ow=20 in the first place. =20 > * the text color is not being respected =46ixed in cvs. > * to get the width and height of the string, I tex the individual > strings separately, run dvips on them, and get the bounding box > from the generated file. This all happens with caching in > matplotlib.texmanager. Right now the fontsize is being ignored in > this process so the layout will be off for nonstandard font sizes > -- anything other than the default design size of latex which > defaults to 10pt I think. This really is fixed now, for both horizontal and vertical alignment. > * the text doesn't scale right if you provide a size arg to > includegraphics, eg [width=3D4.in] This is expected behavior for PSfrag. You should instead wrap \includegraph= ics=20 in either a \resizebox or a \scalebox to rescale the text with the figure.= =20 It looks like tex_demo.py, without caching, takes about 30% longer with LaT= eX=20 than it does for Tex (3 seconds vs 2.3 seconds on my computer). So CVS is=20 back to using TeX. We may want to include a link (or a copy) of this pdf on= =20 the MPL website: http://www.csit.fsu.edu/~mimi/tex/tex-refcard.pdf, the=20 source declares it to be freely distributed. Darren |
|
From: John H. <jdh...@ac...> - 2005-05-24 21:28:14
|
>>>>> "Darren" == Darren Dale <dd...@co...> writes:
Darren> This is expected behavior for PSfrag. You should instead
Darren> wrap \includegraphics in either a \resizebox or a
Darren> \scalebox to rescale the text with the figure.
Can you do this?
Darren> It looks like tex_demo.py, without caching, takes about
Darren> 30% longer with LaTeX than it does for Tex (3 seconds vs
Darren> 2.3 seconds on my computer). So CVS is back to using
Darren> TeX. We may want to include a link (or a copy) of this pdf
Darren> on the MPL website:
Darren> http://www.csit.fsu.edu/~mimi/tex/tex-refcard.pdf, the
Darren> source declares it to be freely distributed.
Can tex|latex be an rc param?
JDH
|
|
From: Darren D. <dd...@co...> - 2005-05-24 21:50:08
|
On Tuesday 24 May 2005 5:27 pm, you wrote:
> >>>>> "Darren" =3D=3D Darren Dale <dd...@co...> writes:
>
> Darren> This is expected behavior for PSfrag. You should instead
> Darren> wrap \includegraphics in either a \resizebox or a
> Darren> \scalebox to rescale the text with the figure.
>
> Can you do this?
Yes. backend_latex writes this command to the .tex file, hopefully to guide=
=20
users on how to scale their images:
\scalebox{1}{\includegraphics{<myfile.eps>}}
>
> Darren> It looks like tex_demo.py, without caching, takes about
> Darren> 30% longer with LaTeX than it does for Tex (3 seconds vs
> Darren> 2.3 seconds on my computer). So CVS is back to using
> Darren> TeX. We may want to include a link (or a copy) of this pdf
> Darren> on the MPL website:
> Darren> http://www.csit.fsu.edu/~mimi/tex/tex-refcard.pdf, the
> Darren> source declares it to be freely distributed.
>
> Can tex|latex be an rc param?
I'm guessing TeX will meet most layout needs. For example, I just discovere=
d=20
the \over command, which will generate fractions in TeX and LaTeX. \frac on=
ly=20
works for LaTeX. I will make tex/latex an rc param if you want. Let me know.
Darren
|
|
From: John H. <jdh...@ac...> - 2005-05-24 21:52:57
|
>>>>> "Darren" == Darren Dale <dd...@co...> writes:
Darren> I'm guessing TeX will meet most layout needs. For example,
Darren> I just discovered the \over command, which will generate
Darren> fractions in TeX and LaTeX. \frac only works for LaTeX. I
Darren> will make tex/latex an rc param if you want. Let me know.
frac was the only use case I thought important. If over can do it I
am fine leaving it as TeX. We can generalize later if need be.
JDH
|
|
From: Darren D. <dd...@co...> - 2005-06-10 19:42:25
|
Hi everyone, On Wednesday 08 June 2005 11:42 am, Fernando Perez wrote: > Darren Dale wrote: > > > Would you send me a copies of the bad eps and the fixed version, and al= so > > a copy of ps2eps? I don't have that program on my system, and was not > > able to find it on the web. > > Here goes. As it turns out, ps2eps is a simple perl script which I got god > knows when. So people won't actually have it on their systems, it's > something that lives in /usr/local/bin on my box, sorry. > > But no worries. I can lie with using ps2eps for now, until I can upgrade > to a moer current ghostscript. I am still unhappy with the bitmapped fonts that result from the conversion= to=20 eps, using ghostscript's epswrite. They look ok in Adobe Reader, but not so= =20 in kpdf or ggv. (I was inspired to look at this today after discovering tha= t=20 Adobe Reader for linux does not display correctly when I run in 1024x768=20 resolution on my native 1680x1050 laptop. Kpdf displays correctly, but the= =20 fonts are terrible.) I looked into ps2eps some more today, to see if it would generate a file th= at=20 I could embed in a latex document. The short answer is no.=20 The long answer is that PSFrag was not designed to do what I am trying to d= o:=20 generate an eps file that can later be embedded in a document. It uses a=20 number of PostScript operators that are illegal in an eps file: setglobal,= =20 statusdict and userdict. Here is the blurb from PostScript Language=20 Reference, Second Edition, Appendix I: setglobal disrupts page independence= =20 and nesting of included documents. [...] Creation and modification of globa= l=20 objects are uneffected by save-restore operators. I think it might be worth looking into the way PyX is dealing with TeX/LaTe= X,=20 as someone recently suggested. PyX's eps output looks just like standard (n= o=20 tex) MPL output, where these nesting issues do not exist. They even have th= e=20 same issue of dumping entire font definitions into the output. Darren |