Generate a dvi file containing latex's layout of tex string. Return the file name.
(cls, tex, fontsize)
| 279 | |
| 280 | @classmethod |
| 281 | def make_dvi(cls, tex, fontsize): |
| 282 | """ |
| 283 | Generate a dvi file containing latex's layout of tex string. |
| 284 | |
| 285 | Return the file name. |
| 286 | """ |
| 287 | dvipath = cls._get_base_path(tex, fontsize).with_suffix(".dvi") |
| 288 | if not dvipath.exists(): |
| 289 | # Generate the tex and dvi in a temporary directory to avoid race |
| 290 | # conditions e.g. if multiple processes try to process the same tex |
| 291 | # string at the same time. Having tmpdir be a subdirectory of the |
| 292 | # final output dir ensures that they are on the same filesystem, |
| 293 | # and thus replace() works atomically. It also allows referring to |
| 294 | # the texfile with a relative path (for pathological MPLCONFIGDIRs, |
| 295 | # the absolute path may contain characters (e.g. ~) that TeX does |
| 296 | # not support; n.b. relative paths cannot traverse parents, or it |
| 297 | # will be blocked when `openin_any = p` in texmf.cnf). |
| 298 | with TemporaryDirectory(dir=dvipath.parent) as tmpdir: |
| 299 | Path(tmpdir, "file.tex").write_text( |
| 300 | cls._get_tex_source(tex, fontsize), encoding='utf-8') |
| 301 | cls._run_checked_subprocess( |
| 302 | ["latex", "-interaction=nonstopmode", "-halt-on-error", |
| 303 | "-no-shell-escape", "file.tex"], tex, cwd=tmpdir) |
| 304 | Path(tmpdir, "file.dvi").replace(dvipath) |
| 305 | # Also move the tex source to the main cache directory, but |
| 306 | # only for backcompat. |
| 307 | Path(tmpdir, "file.tex").replace(dvipath.with_suffix(".tex")) |
| 308 | return str(dvipath) |
| 309 | |
| 310 | @classmethod |
| 311 | def make_png(cls, tex, fontsize, dpi): |
no test coverage detected