はじめに
Windows の Inkscape を使っていて、拡張機能で WSL の pdflatex を使うときのメモです。
標準の拡張機能の pdflatex.inx
と pdflatex.py
を複製・編集しました。
インストール先は %USERPROFILE%/AppData/Roaming/inkscape/extensions/...
です。
環境
ソースなど
元のソース
編集したもの
変更箇所(抜粋)
diff -u pdflatex.py wsl_pdflatex.py - call('pdflatex', tex_file,\ - output_directory=self.tempdir,\ - halt_on_error=True, oldie=True) + # get the temporary path in wsl style + wsl_tex_file = subprocess.Popen( + 'wsl.exe -- wslpath -u {}'.format(tex_file.replace(os.sep, '/')), + cwd=self.tempdir, + stdout=subprocess.PIPE, + shell=True + ).communicate()[0].rstrip() + if isinstance(wsl_tex_file, bytes): + wsl_tex_file = wsl_tex_file.decode(sys.stdout.encoding or 'utf-8') + + wsl_tempdir = subprocess.Popen( + 'wsl.exe -- wslpath -u {}'.format(self.tempdir.replace(os.sep, '/')), + cwd=self.tempdir, + stdout=subprocess.PIPE, + shell=True + ).communicate()[0].rstrip() + if isinstance(wsl_tempdir, bytes): + wsl_tempdir = wsl_tempdir.decode(sys.stdout.encoding or 'utf-8') + + # instant script in inkex/command.py + process = subprocess.Popen( + 'wsl.exe -- $HOME/.local/bin/pdflatex {} -output-directory={} -halt-on-error'.format( + wsl_tex_file, + wsl_tempdir + ), + cwd=self.tempdir, + shell=False, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + (stdout, stderr) = process.communicate() + + if process.returncode != 0: + raise ProgramRunError(f"Return Code: {process.returncode}: {stderr}\n{stdout}") + if isinstance(stdout, bytes): + stdout = stdout.decode(sys.stdout.encoding or 'utf-8')