Dear All,
I have hacked a bit at texmanager.py and backend_ps.py in order to
generate "superior" text output using LaTeX.
It involves "including" a user specific "low level font command" input
file useing some "new" rcParams and the savefig command with the PS
backend in you main "pylab" script:
...
rcParams['font.latex.inputfile']='True'
rcParams['font.latex.inputfile.filename']='mypresentation.llfc'
savefig('myeps.eps')
...
The "low level font command" input file has the following included:
\fontencoding{T1} % T1 - Latin 1, etc.
\fontfamily{phv} % cmr - Computer Modern Roman, ptm -
Times-Roman, phv - Helvetica, etc.
\fontseries{m} % m - Medium, b - Bold, bc - Bold Condensed, bx
- Bold Expanded
\fontshape{n} % n - Upright (Normal), it - Italic, sl -
Slanted,
% sc - Small Caps, ui - Upright Italics,
ol - Outline
\selectfont % Above font changes will now become
effective
or for those who know all the abreviations by hart:
\usefont{T1}{phv}{m}{n}
Attached are examples of three "low level font command" files for
different "application", e.g. a Thesis, a Presentation or an Article...
In texmanager.py the "TexManager.get_tex_command" needs to be changed
to:
...
def get_tex_command(self, tex, fname):
fh = file(fname, 'w')
if rcParams['text.tex.engine'] == 'latex':
print >>fh, r"""\documentclass{article}
\usepackage{%s}
\setlength{\paperwidth}{72in}
\setlength{\paperheight}{72in}
\pagestyle{empty}
\begin{document}""" % (rcParams['font.latex.package'])
if rcParams['font.latex.inputfile']:
inputfile = rcParams['font.latex.inputfile.filename']
if os.path.exists(inputfile):
print >>fh, r"\input{%s}" % inputfile
print >>fh, r"""%s
\end{document}""" % tex
fh.close()
command = 'latex -interaction=nonstopmode "%s"'%fname
else:
s = r"""\def\frac#1#2{ {#1 \over #2} }
\nopagenumbers
\hsize=72in
\vsize=72in
%s
\bye
""" % tex
fh.write(s)
fh.close()
command = 'tex "%s"'%fname
return command
...
(or see attached)
And in backend_ps.py, from line 1059:
...
if rcParams['text.usetex']:
if rcParams['text.tex.engine'] == 'latex':
fontpackage = rcParams['font.latex.package']
else:
fontpackage = 'type1cm'
pw, ph = defaultPaperSize
if width>pw-2 or height>ph-2: pw,ph =
_get_papersize(width,height)
print >>latexh, r"""\documentclass{scrartcl}
\usepackage{%s}
\usepackage{psfrag}
\usepackage[dvips]{graphicx}
\usepackage{color}
\pagestyle{empty}
\setlength{\paperheight}{%fin}
\setlength{\paperwidth}{%fin}
\setlength{\textwidth}{%fin}
\setlength{\textheight}{%fin}
\special{papersize=%fin,%fin}
\begin{document}
\begin{figure}[th!]""" % (fontpackage, pw, ph, pw-2, ph-2, pw, ph)
if rcParams['font.latex.inputfile']:
usefontfile = rcParams['font.latex.inputfile.filename']
if os.path.exists(usefontfile):
print >>latexh, r"\input{%s}" % usefontfile
print >>latexh, r"""%s
\begin{center}
\includegraphics{%s}
\end{center}
\end{figure}
\end{document}
"""% ('\n'.join(renderer.psfrag), epsfile)
latexh.close()
...
(or see attached)
Hope someone (else) finds it usefull.
Vriendelik die uwe,
Peter-Jan Randewijk
Senior Lektor - Drywingselektronika & Elektriese Aandrywing
-oOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOo-
Departement E&E. Ingenieurswese
Universiteit Stellenbosch
Privaatsak X1
Matieland, 7603
Suid-Afrika
Tel: +27 (0) 21 808 4457 (w)
Faks: +27 (0) 21 808 3951 (w)
Tel: +27 (0) 21 883 8592 (h)
Sel: +27 (0) 83 556 5809 (h)
-oOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOo-
backend_ps.py (40.3 KB)
texmanager.py (11.3 KB)
myarticle.llfc (1006 Bytes)
mypresentation.llfc (1005 Bytes)
mythesis.llfc (1006 Bytes)