Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2f93f50

Browse files
authored
Merge pull request #13680 from eendebakpt/latex_rendering_tempdir
Use relative filename in latex and dvips commands of latex_to_png_dvipng
2 parents bc543bc + e41930d commit 2f93f50

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

IPython/lib/latextools.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ def latex_to_png_dvipng(s, wrap, color='Black', scale=1.0):
146146
return None
147147
try:
148148
workdir = Path(tempfile.mkdtemp())
149-
tmpfile = workdir.joinpath("tmp.tex")
150-
dvifile = workdir.joinpath("tmp.dvi")
151-
outfile = workdir.joinpath("tmp.png")
149+
tmpfile = "tmp.tex"
150+
dvifile = "tmp.dvi"
151+
outfile = "tmp.png"
152152

153-
with tmpfile.open("w", encoding="utf8") as f:
153+
with workdir.joinpath(tmpfile).open("w", encoding="utf8") as f:
154154
f.writelines(genelatex(s, wrap))
155155

156156
with open(os.devnull, 'wb') as devnull:
@@ -181,7 +181,7 @@ def latex_to_png_dvipng(s, wrap, color='Black', scale=1.0):
181181
stderr=devnull,
182182
)
183183

184-
with outfile.open("rb") as f:
184+
with workdir.joinpath(outfile).open("rb") as f:
185185
return f.read()
186186
except subprocess.CalledProcessError:
187187
return None
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Relative filenames in Latex rendering
2+
=====================================
3+
4+
The `latex_to_png_dvipng` command internally generates input and output file arguments to `latex` and `dvipis`. These arguments are now generated as relative files to the current working directory instead of absolute file paths.
5+
This solves a problem where the current working directory contains characters that are not handled properly by `latex` and `dvips`.
6+
There are no changes to the user API.
7+

0 commit comments

Comments
 (0)