@@ -1166,9 +1166,7 @@ def _run_latex(self):
11661166 % (texcommand , e .output .decode ('utf-8' )))
11671167
11681168 # 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 )
11721170
11731171 def savefig (self , figure = None , ** kwargs ):
11741172 """
@@ -1199,25 +1197,31 @@ def savefig(self, figure=None, **kwargs):
11991197 orig_canvas = figure .canvas
12001198 figure .canvas = FigureCanvasPgf (figure )
12011199
1200+ width , height = figure .get_size_inches ()
12021201 if self ._n_figures == 0 :
1203- self ._write_header (* figure . get_size_inches () )
1202+ self ._write_header (width , height )
12041203 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+
12161206 figure .savefig (self ._file , format = "pgf" , ** kwargs )
12171207 self ._n_figures += 1
12181208 finally :
12191209 figure .canvas = orig_canvas
12201210
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+
12211225 def get_pagecount (self ):
12221226 """
12231227 Returns the current number of pages in the multipage pdf file.
0 commit comments