Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,10 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble,
# multiple
if sys.platform == 'win32': precmd = '%s &&'% os.path.splitdrive(tmpdir)[0]
else: precmd = ''
#Replace \\ for / so latex does not think there is a function call
latexfile = latexfile.replace("\\", "/")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a fix to on unrelated problem to the one reported in #5923 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand the latex stuff, it is needed because otherwise the next line would be interpreted as introducing a new directory "break":

c:\something\short~1\tempfile -> c:/something/short~1/tempfile -> c:/something/short\\string~1/tempfile

Without the first step, the dirs would read c: - something - short - string~1 - tempfile.

@Grillard can you confirm that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So has the ps backend just always been broken on windows?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No: you can also specify all slashes as backlashes: the name is passed to a program and either used as filename with backlashes but no ~ allowed (is probably internally converted to forwards slashes) or as a latex input with / as path separator which can contain \string~ but no backlashes.

-> It was only broken when you use a short name as tempfile which contains ~ because latex has that as a special character which needs to be escaped.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will probably be also broken on unix, if you add a testcase where you set TMP, TMPDIR and TEMP (whatever mkstemp used first is probably enough) to a path with a ~ in it. As far as I know, these are valid filenames on unix?!

Would probably enough to do that in the ps tests by simply adding a testcase which sets that in os.environ before doing the mpl calls...

# Replace ~ so Latex does not think it is line break
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is for the wrong line now.

latexfile = latexfile.replace("~", "\\string~")
command = '%s cd "%s" && latex -interaction=nonstopmode "%s" > "%s"'\
%(precmd, tmpdir, latexfile, outfile)
verbose.report(command, 'debug')
Expand Down