Notepad++ > jN



jN (JavaScript for Notepad++) → 問題が発生する場合は NppExec を使用する

jN (JavaScript for Notepad++) を使うと LaTeX 環境を簡単に作ることができます.

plugins\jN\includes\ フォルダーに js ファイルを作成すると JavaScript が実行できます.

License

GPLv3

ChangeLog

Typeset.js

plugins\jN\includes\Typeset.js を作成します.
メニューの [Typeset] から実行できます.


(function(){
    var pdfupLaTeX = {
        text: "upLaTeX (ptex2pdf)",
        cmd: function(){
            var fso = new ActiveXObject("Scripting.FileSystemObject");
            var currentTeXFile = Editor.currentView.files[Editor.currentView.file];
            var c = fso.GetParentFolderName(currentTeXFile);
            var b = fso.GetBaseName(currentTeXFile);
            var cd = "cd /d " + ["\"", c, "\""].join("");
            var ptex2pdf = "ptex2pdf -u -l -ot \"-synctex=1 -no-guess-input-enc -kanji=utf8 -sjis-terminal\"" + " " + ["\"", b, "\""].join("");
            var cmd = "cmd /c " + cd + " && " + ptex2pdf;
            execute(cmd);
        }
    };
    var luaLaTeX = {
        text: "LuaLaTeX",
        cmd: function(){
            var fso = new ActiveXObject("Scripting.FileSystemObject");
            var currentTeXFile = Editor.currentView.files[Editor.currentView.file];
            var c = fso.GetParentFolderName(currentTeXFile);
            var b = fso.GetBaseName(currentTeXFile);
            var cd = "cd /d " + ["\"", c, "\""].join("");
            var pdflatex = "lualatex -synctex=1" + " " + ["\"", b, "\""].join("");
            var cmd = "cmd /c " + cd + " && " + pdflatex;
            execute(cmd);
        }
    };
    var sumatraPDF = {
        text: "SumatraPDF",
        cmd: function(){
            var fso = new ActiveXObject("Scripting.FileSystemObject");
            var wshShell = new ActiveXObject("WScript.Shell");
            var npp = Editor.nppDir + "\\notepad++.exe";
            var currentTeXFile = Editor.currentView.files[Editor.currentView.file];
            var suffix = /\.[^.]*$/;
            var pdfFile = currentTeXFile.replace(suffix, ".pdf");
            var line = Editor.currentView.line + 1;
            var sumatraPDF = "C:\\Program Files\\SumatraPDF\\SumatraPDF.exe";
            var existSumatraPDF = true;

            try {
                sumatraPDF = wshShell.RegRead("HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\SumatraPDF.exe\\");
            } catch (e) {
                if (!fso.FileExists(sumatraPDF)) {
                    sumatraPDF = "SumatraPDF.exe";
                    existSumatraPDF = false;
                }
            }

            if (existSumatraPDF) {
                sumatraPDF = ["\"", sumatraPDF, "\""].join("");
            }

            var mainTeXDir = fso.GetParentFolderName(pdfFile);
            var cd = "cd /d " + ["\"", mainTeXDir, "\""].join("");
            currentTeXFile = ["\"", currentTeXFile, "\""].join("");
            pdfFile = ["\"", pdfFile, "\""].join("");

            var args = "-reuse-instance " + pdfFile + " -inverse-search \"\\\"" + npp + "\\\" \\\"%f\\\" -n%l -c%c\"" + " -forward-search " + currentTeXFile + " " + line;
            new ActiveXObject("Shell.Application").ShellExecute(sumatraPDF, args, "", "open", 1);
        }
    };
    var fwdsumatrapdf = {
        text: "fwdsumatrapdf",
        cmd: function(){
            var fso = new ActiveXObject("Scripting.FileSystemObject");
            var wshShell = new ActiveXObject("WScript.Shell");
            var currentTeXFile = Editor.currentView.files[Editor.currentView.file];
            var suffix = /\.[^.]*$/;
            var pdfFile = currentTeXFile.replace(suffix, ".pdf");
            var line = Editor.currentView.line + 1;
            var fwdsumatrapdf = "fwdsumatrapdf";

            var mainTeXDir = fso.GetParentFolderName(pdfFile);
            var cd = "cd /d " + ["\"", mainTeXDir, "\""].join("");
            currentTeXFile = ["\"", currentTeXFile, "\""].join("");
            pdfFile = ["\"", pdfFile, "\""].join("");

            var args = pdfFile + " " + currentTeXFile + " " + line;
            new ActiveXObject("Shell.Application").ShellExecute(fwdsumatrapdf, args, "", "open", 1);
        }
    };
    function execute(commandLine) {
        Editor.saveAll();
        new ActiveXObject("WScript.Shell").Run(commandLine, 1, true);
    }
    var typesetMenu = Editor.addMenu("Typeset");
    typesetMenu.addItem(pdfupLaTeX);
    typesetMenu.addItem(luaLaTeX);
    typesetMenu.addItem(sumatraPDF);
    typesetMenu.addItem(fwdsumatrapdf);
})();

SumatraPDF との連携

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

[Typeset]-[SumatraPDF] を実行します.

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

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

[Typeset]-[fwdsumatrapdf] を実行します.

inverse search

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


Last-modified: 2018-04-01 (日) 01:29:09 (292d)