@@ -232,6 +232,8 @@ def _cleanup_remaining_instances():
232232 latex_manager ._cleanup ()
233233
234234 def _stdin_writeln (self , s ):
235+ if self .latex is None :
236+ self ._setup_latex_process ()
235237 self .latex .stdin .write (s )
236238 self .latex .stdin .write ("\n " )
237239 self .latex .stdin .flush ()
@@ -245,6 +247,8 @@ def _expect(self, s):
245247 if chars [- len (s ):] == s :
246248 break
247249 if not c :
250+ self .latex .kill ()
251+ self .latex = None
248252 raise LatexError ("LaTeX process halted" , "" .join (chars ))
249253 return "" .join (chars )
250254
@@ -281,6 +285,10 @@ def __init__(self):
281285 raise LatexError ("LaTeX returned an error, probably missing font "
282286 "or error in preamble:\n %s" % stdout )
283287
288+ self .latex = None # Will be set up on first use.
289+ self .str_cache = {} # cache for strings already processed
290+
291+ def _setup_latex_process (self ):
284292 # open LaTeX process for real work
285293 self .latex = subprocess .Popen (
286294 [self .texcommand , "-halt-on-error" ],
@@ -292,9 +300,6 @@ def __init__(self):
292300 self ._expect ("*pgf_backend_query_start" )
293301 self ._expect_prompt ()
294302
295- # cache for strings already processed
296- self .str_cache = {}
297-
298303 @cbook .deprecated ("3.3" )
299304 def latex_stdin_utf8 (self ):
300305 return self .latex .stdin
@@ -408,10 +413,10 @@ def __init__(self, figure, fh, dummy=False):
408413 else :
409414 # if fh does not belong to a filename, deactivate draw_image
410415 if not hasattr (fh , 'name' ) or not os .path .exists (fh .name ):
411- cbook . _warn_external ( "streamed pgf-code does not support "
412- "raster graphics, consider using the "
413- "pgf-to-pdf option" , UserWarning )
414- self . __dict__ [ "draw_image" ] = lambda * args , ** kwargs : None
416+ self . __dict__ [ "draw_image" ] = \
417+ lambda * args , ** kwargs : cbook . _warn_external (
418+ "streamed pgf-code does not support raster graphics, "
419+ "consider using the pgf-to-pdf option" )
415420
416421 @cbook .deprecated ("3.2" )
417422 def latexManager (self ):
0 commit comments