Skip to content

Commit 708cd25

Browse files
committed
Improved tex handling of text in backend_ps and texmanager, added tex/latex
option in rc. svn path=/trunk/matplotlib/; revision=1415
1 parent 03f2755 commit 708cd25

File tree

5 files changed

+48
-15
lines changed

5 files changed

+48
-15
lines changed

.matplotlibrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,15 @@ font.sans-serif : Lucida Grande, Verdana, Geneva, Lucida, Bitstream Vera San
116116
font.cursive : Apple Chancery, Textile, Zapf Chancery, Sand, cursive
117117
font.fantasy : Comic Sans MS, Chicago, Charcoal, Impact, Western, fantasy
118118
font.monospace : Andale Mono, Bitstream Vera Sans Mono, Nimbus Mono L, Courier New, Courier, Fixed, Terminal, monospace
119-
119+
font.latex.package : type1cm # This must be an available LaTeX font package, like 'times' or 'pslatex'
120120

121121
### TEXT
122122
# text properties used by text.Text. See
123123
# http://matplotlib.sourceforge.net/matplotlib.text.html for more
124124
# information on text properties
125125
text.color : black
126126
text.usetex : False # use tex for all text handling. See http://matplotlib.sf.net/matplotlib.texmanager.html
127+
text.tex.engine : latex # tex is faster, but latex is required to use special font packages
127128

128129
### AXES
129130
# default face and edge color, default tick sizes,

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
New entries should be added at the top
22

3+
2005-06-03 Improved support for tex handling of text in backend_ps. - DSD
4+
5+
2005-06-03 Added rc options to render text with tex or latex, and to select
6+
the latex font package. - DSD
7+
38
2005-06-03 Fixed a bug in ticker.py causing a ZeroDivisionError
49

510
2005-06-02 backend_gtk.py remove DBL_BUFFER, add line to expose_event to

lib/matplotlib/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,13 @@ def validate_ps_papersize(s):
465465
return s
466466
else:
467467
raise ValueError('ps.papersize must be one of: %s'% ', '.join(papertypes))
468+
469+
470+
def validate_tex_engine(s):
471+
if s.lower() in ['tex', 'latex']:
472+
return s
473+
else:
474+
raise ValueError('text.tex.engine must be one of: tex, latex')
468475

469476

470477
# a map from key -> value, converter
@@ -511,10 +518,12 @@ def validate_ps_papersize(s):
511518
'font.cursive' : ['cursive', validate_comma_sep_str],
512519
'font.fantasy' : ['fantasy', validate_comma_sep_str],
513520
'font.monospace' : ['monospace', validate_comma_sep_str],
521+
'font.latex.package': ['type1cm', str], # LaTeX font package: txfonts, pslatex, ...
514522

515523
# text props
516524
'text.color' : ['k', validate_color], # black
517-
'text.usetex' : [False, validate_bool], # black
525+
'text.usetex' : [False, validate_bool],
526+
'text.tex.engine' : ['tex', validate_tex_engine], # TeX or LaTeX
518527
'text.fontstyle' : ['normal', str],
519528
'text.fontangle' : ['normal', str],
520529
'text.fontvariant' : ['normal', str],

lib/matplotlib/backends/backend_ps.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,8 +1038,8 @@ def print_figure(self, outfile, dpi=72,
10381038
'Defaulting to letter.')
10391039
latexPaperType = 'letterpaper'
10401040
print >>latexh, r"""\documentclass[%s]{article}
1041+
\usepackage{%s}
10411042
\usepackage{psfrag}
1042-
\usepackage{type1cm}
10431043
\usepackage[dvips]{graphicx}
10441044
\usepackage{color}
10451045
\pagestyle{empty}
@@ -1051,18 +1051,20 @@ def print_figure(self, outfile, dpi=72,
10511051
\end{center}
10521052
\end{figure}
10531053
\end{document}
1054-
"""% (latexPaperType, '\n'.join(renderer.psfrag), epsfile)
1054+
"""% (latexPaperType, rcParams['font.latex.package'],
1055+
'\n'.join(renderer.psfrag), epsfile)
10551056

10561057
latexh.close()
10571058

1058-
command = 'latex %s' % texfile
1059+
command = command = "latex -interaction=nonstopmode '%s'" % texfile
10591060
os.system(command)
1060-
command = 'dvips -o %s %s' % (psfile, basename+'.dvi')
1061+
os.system(command)
1062+
command = 'dvips -q -o %s %s' % (psfile, basename+'.dvi')
10611063
os.system(command)
10621064
if ext.startswith('.ep'):
1063-
command = 'ps2epsi %s %s' % (psfile, outfile)
1064-
msg = os.system(command)
1065-
if msg==32512: raise 'ps2epsi: command not found! Please install Ghostscript.'
1065+
command = 'gs -dBATCH -dNOPAUSE -dSAFER -q -r6000 -sDEVICE=epswrite ' + \
1066+
'-dLanguageLevel=3 -dEPSFitPage -sOutputFile=%s %s'% (outfile, psfile)
1067+
os.system(command)
10661068
os.remove(psfile)
10671069
os.remove(texfile)
10681070
os.remove(basename+'.dvi')

lib/matplotlib/texmanager.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"""
3232

3333
import os, sys, md5, shutil
34-
from matplotlib import get_home, get_data_path
34+
from matplotlib import get_home, get_data_path, rcParams
3535
from matplotlib._image import readpng
3636
from matplotlib.numerix import ravel, where, array, \
3737
zeros, Float, absolute, nonzero, sqrt
@@ -66,16 +66,32 @@ def make_dvi(self, tex, force=0):
6666

6767
logfile = prefix + '.log'
6868
fh = file(fname, 'w')
69-
s = r"""\def\frac#1#2{ {#1 \over #2} }
69+
if rcParams['text.tex.engine'] == 'latex':
70+
s = r"""\documentclass{article}
71+
\usepackage{%s}
72+
\setlength{\paperwidth}{72in}
73+
\setlength{\paperheight}{72in}
74+
\pagestyle{empty}
75+
\begin{document}
76+
%s
77+
\end{document}
78+
""" % (rcParams['font.latex.package'], tex)
79+
fh.write(s)
80+
fh.close()
81+
command = "latex -interaction=nonstopmode '%s'"%fname
82+
try: os.remove(prefix + '.aux')
83+
except OSError: pass
84+
else:
85+
s = r"""\def\frac#1#2{ {#1 \over #2} }
7086
\nopagenumbers
7187
\hsize=72in
7288
\vsize=72in
7389
%s
7490
\bye
7591
""" % tex
76-
fh.write(s)
77-
fh.close()
78-
command = 'tex %s'%fname
92+
fh.write(s)
93+
fh.close()
94+
command = 'tex %s'%fname
7995

8096
if force or not os.path.exists(dvifile):
8197
#sin, sout = os.popen2(command)
@@ -117,7 +133,7 @@ def make_ps(self, tex, dpi, force=0):
117133
psfile = os.path.join(self.texcache, '%s_%d.epsf'% (prefix, dpi))
118134

119135
if not os.path.exists(psfile):
120-
command = "dvips -E -D %d -o %s %s"% (dpi, psfile, dvifile)
136+
command = "dvips -q -E -D %d -o %s %s"% (dpi, psfile, dvifile)
121137
os.system(command)
122138

123139
return psfile

0 commit comments

Comments
 (0)