2929
3030import numpy as np
3131
32- from matplotlib import rcParams
32+ from matplotlib import cbook , rcParams
3333
3434_log = logging .getLogger (__name__ )
3535
@@ -990,6 +990,8 @@ def find_tex_file(filename, format=None):
990990 kpathsea. It is also available as part of MikTeX, a popular
991991 distribution on Windows.
992992
993+ *If the file is not found, an empty string is returned*.
994+
993995 Parameters
994996 ----------
995997 filename : string or bytestring
@@ -1015,11 +1017,16 @@ def find_tex_file(filename, format=None):
10151017 if format is not None :
10161018 cmd += ['--format=' + format ]
10171019 cmd += [filename ]
1018- _log .debug ('find_tex_file(%s): %s' , filename , cmd )
1019- pipe = subprocess .Popen (cmd , stdout = subprocess .PIPE )
1020- result = pipe .communicate ()[0 ].rstrip ()
1021- _log .debug ('find_tex_file result: %s' , result )
1022- return result .decode ('ascii' )
1020+ try : # Below: strip final newline.
1021+ result = cbook ._check_and_log_subprocess (cmd , _log )[:- 1 ]
1022+ except RuntimeError :
1023+ return ''
1024+ if os .name == 'nt' :
1025+ # On Windows only, kpathsea appears to use utf-8 output(?); see
1026+ # __win32_fputs in the kpathsea sources and mpl issue #11848.
1027+ return result .decode ('utf-8' )
1028+ else :
1029+ return os .fsdecode (result )
10231030
10241031
10251032@lru_cache ()
0 commit comments