31
31
from matplotlib .mathtext import MathTextParser
32
32
from matplotlib ._mathtext_data import uni2type1
33
33
from matplotlib .path import Path
34
+ from matplotlib .texmanager import TexManager
34
35
from matplotlib .transforms import Affine2D
35
36
from matplotlib .backends .backend_mixed import MixedModeRenderer
36
37
from . import _backend_pdf_ps
@@ -1263,65 +1264,32 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble,
1263
1264
file that includes the actual text.
1264
1265
"""
1265
1266
tmpdir = os .path .split (tmpfile )[0 ]
1266
- epsfile = tmpfile + '.eps'
1267
- shutil .move (tmpfile , epsfile )
1268
- latexfile = tmpfile + '.tex'
1269
- dvifile = tmpfile + '.dvi'
1270
- psfile = tmpfile + '.ps'
1271
-
1272
- if orientation == 'landscape' :
1273
- angle = 90
1274
- else :
1275
- angle = 0
1267
+ psfile = tmpfile + '.ps'
1276
1268
1277
- if rcParams ['text.latex.unicode' ]:
1278
- unicode_preamble = """\\ usepackage{ucs}
1279
- \\ usepackage[utf8x]{inputenc}"""
1280
- else :
1281
- unicode_preamble = ''
1282
-
1283
- s = r"""\documentclass{article}
1284
- %s
1285
- %s
1286
- %s
1287
- \usepackage[
1288
- dvips, papersize={%sin,%sin}, body={%sin,%sin}, margin={0in,0in}]{geometry}
1289
- \usepackage{psfrag}
1290
- \usepackage[dvips]{graphicx}
1291
- \usepackage{color}
1292
- \pagestyle{empty}
1293
- \begin{document}
1294
- \begin{figure}
1295
- \centering
1296
- \leavevmode
1297
- %s
1298
- \includegraphics*[angle=%s]{%s}
1299
- \end{figure}
1300
- \end{document}
1301
- """ % (font_preamble , unicode_preamble , custom_preamble ,
1302
- paper_width , paper_height , paper_width , paper_height ,
1303
- '\n ' .join (psfrags ), angle , os .path .split (epsfile )[- 1 ])
1304
-
1305
- try :
1306
- pathlib .Path (latexfile ).write_text (
1307
- s , encoding = 'utf-8' if rcParams ['text.latex.unicode' ] else 'ascii' )
1308
- except UnicodeEncodeError :
1309
- _log .info ("You are using unicode and latex, but have not enabled the "
1310
- "Matplotlib 'text.latex.unicode' rcParam." )
1311
- raise
1312
-
1313
- # Replace \\ for / so latex does not think there is a function call
1314
- latexfile = latexfile .replace ("\\ " , "/" )
1315
- # Replace ~ so Latex does not think it is line break
1316
- latexfile = latexfile .replace ("~" , "\\ string~" )
1269
+ with mpl .rc_context ({
1270
+ "text.latex.preamble" :
1271
+ rcParams ["text.latex.preamble" ] +
1272
+ r"\usepackage{psfrag,color}"
1273
+ r"\usepackage[dvips]{graphicx}"
1274
+ r"\PassOptionsToPackage{dvips}{geometry}" }):
1275
+ dvifile = TexManager ().make_dvi (
1276
+ r"\newgeometry{papersize={%(width)sin,%(height)sin},"
1277
+ r"body={%(width)sin,%(height)sin}, margin={0in,0in}}" "\n "
1278
+ r"\begin{figure}"
1279
+ r"\centering\leavevmode%(psfrags)s"
1280
+ r"\includegraphics*[angle=%(angle)s]{%(epsfile)s}"
1281
+ r"\end{figure}"
1282
+ % {
1283
+ "width" : paper_width , "height" : paper_height ,
1284
+ "psfrags" : "\n " .join (psfrags ),
1285
+ "angle" : 90 if orientation == 'landscape' else 0 ,
1286
+ "epsfile" : pathlib .Path (tmpfile ).resolve ().as_posix (),
1287
+ },
1288
+ fontsize = 10 ) # tex's default fontsize.
1317
1289
1318
1290
cbook ._check_and_log_subprocess (
1319
- ["latex" , "-interaction=nonstopmode" , '"%s"' % latexfile ],
1291
+ ['dvips' , '-q' , '-R0' , '-o' , os . path . basename ( psfile ), dvifile ],
1320
1292
_log , cwd = tmpdir )
1321
- cbook ._check_and_log_subprocess (
1322
- ['dvips' , '-q' , '-R0' , '-o' , os .path .basename (psfile ),
1323
- os .path .basename (dvifile )], _log , cwd = tmpdir )
1324
- os .remove (epsfile )
1325
1293
shutil .move (psfile , tmpfile )
1326
1294
1327
1295
# check if the dvips created a ps in landscape paper. Somehow,
@@ -1332,10 +1300,7 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble,
1332
1300
# information. The return value is used in pstoeps step to recover
1333
1301
# the correct bounding box. 2010-06-05 JJL
1334
1302
with open (tmpfile ) as fh :
1335
- if "Landscape" in fh .read (1000 ):
1336
- psfrag_rotated = True
1337
- else :
1338
- psfrag_rotated = False
1303
+ psfrag_rotated = "Landscape" in fh .read (1000 )
1339
1304
1340
1305
if not debugPS :
1341
1306
for fname in glob .glob (tmpfile + '.*' ):
0 commit comments