@@ -1166,9 +1166,7 @@ def _run_latex(self):
1166
1166
% (texcommand , e .output .decode ('utf-8' )))
1167
1167
1168
1168
# copy file contents to target
1169
- with open (self ._fname_pdf , "rb" ) as fh_src :
1170
- with open (self ._outputfile , "wb" ) as fh :
1171
- shutil .copyfileobj (fh_src , fh )
1169
+ shutil .copyfile (self ._fname_pdf , self ._outputfile )
1172
1170
1173
1171
def savefig (self , figure = None , ** kwargs ):
1174
1172
"""
@@ -1199,25 +1197,31 @@ def savefig(self, figure=None, **kwargs):
1199
1197
orig_canvas = figure .canvas
1200
1198
figure .canvas = FigureCanvasPgf (figure )
1201
1199
1200
+ width , height = figure .get_size_inches ()
1202
1201
if self ._n_figures == 0 :
1203
- self ._write_header (* figure . get_size_inches () )
1202
+ self ._write_header (width , height )
1204
1203
else :
1205
- if get_texcommand () == 'lualatex' :
1206
- if _get_lualatex_version () > (0 , 85 , 0 ):
1207
- np = r'\newpage\pagewidth={}in\pageheight={}in%'
1208
- else :
1209
- np = r'\newpage\pdfpagewidth={}in\pdfpageheight={}in%'
1210
- else :
1211
- np = r'\newpage\pdfpagewidth={}in\pdfpageheight={}in%'
1212
- self ._file .write (np .format (
1213
- * figure .get_size_inches ()
1214
- ).encode ('utf-8' ) + b'\n '
1215
- )
1204
+ self ._file .write (self ._build_newpage_command (width , height ))
1205
+
1216
1206
figure .savefig (self ._file , format = "pgf" , ** kwargs )
1217
1207
self ._n_figures += 1
1218
1208
finally :
1219
1209
figure .canvas = orig_canvas
1220
1210
1211
+ def _build_newpage_command (self , width , height ):
1212
+ '''LuaLaTeX from version 0.85 removed the `\pdf*` primitives,
1213
+ so we need to check the lualatex version and use `\pagewidth` if
1214
+ the version is 0.85 or newer
1215
+ '''
1216
+ texcommand = get_texcommand ()
1217
+ if texcommand == 'lualatex' and _get_lualatex_version () >= (0 , 85 , 0 ):
1218
+ cmd = r'\page'
1219
+ else :
1220
+ cmd = r'\pdfpage'
1221
+
1222
+ newpage = r'\newpage{cmd}width={w}in,{cmd}height={h}in%' + '\n '
1223
+ return newpage .format (cmd = cmd , w = width , h = height ).encode ('utf-8' )
1224
+
1221
1225
def get_pagecount (self ):
1222
1226
"""
1223
1227
Returns the current number of pages in the multipage pdf file.
0 commit comments