Notepad++ > Python Script
◆CONTENTS◆
Python Script を使うと LaTeX 環境を簡単に作ることができます.
[プラグイン]-[Plugin Manager]-[Show Plugin Manager] で Python Script を選択してインストールできます.
[プラグイン]-[Python Script]-[Configuration] で Python Script の設定をします.
plugins\Config\PythonScript\scripts\ フォルダーに Pyhton Script を作成すると Machine Scripts に Python Script が表示されます.
表示された Python Script は Menu items に追加できます.
import os import os.path class Command: def run(self): b = os.path.splitext(os.path.basename(notepad.getCurrentFilename()))[0] c = os.path.dirname(notepad.getCurrentFilename()) ptex2pdf = 'ptex2pdf -u -l -ot "-no-guess-input-enc -kanji=utf8 -synctex=1" "' + b + '"' notepad.save() os.chdir(c) console.clear() console.show() console.run(ptex2pdf) if __name__ == '__main__': Command().run()
import os import os.path class Command: def run(self): b = os.path.splitext(os.path.basename(notepad.getCurrentFilename()))[0] c = os.path.dirname(notepad.getCurrentFilename()) pdflatex = 'lualatex -synctex=1 "' + b + '"' notepad.save() os.chdir(c) console.clear() console.show() console.run(pdflatex) if __name__ == '__main__': Command().run()
import sys import os.path if sys.version_info >= (3, 0, 0): from winreg import * else: from _winreg import * class Command: def run(self): npp = r'\"' + notepad.getNppDir() + r'\notepad++.exe' + r'\"' tex = notepad.getCurrentFilename() pdf = os.path.splitext(tex)[0] + '.pdf' line = str(editor.lineFromPosition(editor.getCurrentPos()) + 1) regValue = None with OpenKeyEx(HKEY_LOCAL_MACHINE, r'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\SumatraPDF.exe') as key: regValue = QueryValue(key, None) sumatraPDF = None if os.path.exists(regValue): sumatraPDF = '"' + regValue + '" -reuse-instance "' + pdf + '" -inverse-search "' + npp + r' \"%f\" -n%l" -forward-search "' + tex + '" ' + line else: inputValue = notepad.prompt('Input the path to SumatraPDF.exe', 'Notepad++', 'SumatraPDF.exe') if os.path.exists(inputValue): sumatraPDF = '"' + inputValue + '" -reuse-instance "' + pdf + '" -inverse-search "' + npp + r' \"%f\" -n%l" -forward-search "' + tex + '" ' + line else: sumatraPDF = 'rundll32 shell32,ShellExec_RunDLL SumatraPDF -reuse-instance "' + pdf + '" -inverse-search "' + npp + r' \"%f\" -n%l -c%c" -forward-search "' + tex + '" ' + line cmd = 'cmd /c echo ' + sumatraPDF + ' | cmd' console.clear() console.show() console.run(cmd) if __name__ == '__main__': Command().run()
SumatraPDF/fwdsumatrapdf の fwdsumatrapdf.exe を使用します.
import os.path class Command: def run(self): fwdsumatrapdf = 'fwdsumatrapdf' tex = notepad.getCurrentFilename() pdf = os.path.splitext(tex)[0] + '.pdf' line = str(editor.lineFromPosition(editor.getCurrentPos()) + 1) cmd = fwdsumatrapdf + ' ' + pdf + ' ' + tex + ' ' + line console.clear() console.show() console.run(cmd) if __name__ == '__main__': Command().run()
Notepad++#SumatraPDF との連携 を参照.