Notepad++ > Python Script

  ◆CONTENTS◆  

Python Script → 問題が発生する場合は NppExec または jN を使用する

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 に追加できます.

License

GPLv3

pdfupLaTeX.py


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()

pdfupLaTeX2.py


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())
        uplatex = 'uplatex -no-guess-input-enc -kanji=utf8 -synctex=1 "' + b + '"'
        dvips = 'dvips -Ppdf -z -f "' + b + '.dvi" | convbkmk -u > "' + b + '.ps"'
        ps2pdf = 'ps2pdf.exe "' + b + '.ps"'
        uplatex_dvips_ps2pdf = uplatex + ' && ' + dvips + ' && ' + ps2pdf
        notepad.save()
        os.chdir(c)
        console.clear()
        console.show()
        console.run(r'cmd /c ' + uplatex_dvips_ps2pdf)

if __name__ == '__main__':
    Command().run()

pLaTeX-ng.py


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 = 'platex-ng -synctex=1 "' + b + '"'
        notepad.save()
        os.chdir(c)
        console.clear()
        console.show()
        console.run(pdflatex)

if __name__ == '__main__':
    Command().run()

pdfLaTeX.py


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 = 'pdflatex -synctex=1 "' + b + '"'
        notepad.save()
        os.chdir(c)
        console.clear()
        console.show()
        console.run(pdflatex)

if __name__ == '__main__':
    Command().run()

LuaLaTeX.py


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()

LuajitLaTeX.py


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 = 'luajitlatex -synctex=1 "' + b + '"'
        notepad.save()
        os.chdir(c)
        console.clear()
        console.show()
        console.run(pdflatex)

if __name__ == '__main__':
    Command().run()

XeLaTeX.py


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 = 'xelatex -synctex=1 "' + b + '"'
        notepad.save()
        os.chdir(c)
        console.clear()
        console.show()
        console.run(pdflatex)

if __name__ == '__main__':
    Command().run()

SumatraPDF との連携

forward and inverse search (SumatraPDF を前面に表示したい場合)

SumatraPDF.py


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()

forward search (SumatraPDF を前面に表示したくない場合)

SumatraPDF/fwdsumatrapdf の fwdsumatrapdf.exe を使用します.

fwdsumatrapdf.py


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()

inverse search

Notepad++#SumatraPDF との連携 を参照.


Last-modified: 2018-04-13 (金) 22:09:58 (98d)