[[gPad]] > マクロ

*マクロ [#w9b67570]
マクロを使うと LaTeX 環境を簡単に作ることができます.

**pdfpLaTeX.js [#b88feabd]
----
 function main()
 {
   var fso = new ActiveXObject("Scripting.FileSystemObject");
   var c = document.Path;
   var b = fso.GetBaseName(document.Name);
   var cd = "cd /d " + ["\"", c, "\""].join("");
   var latex = "platex -synctex=1 -guess-input-enc -sjis-terminal";
   latex += " " + "-jobname=" + ["\"", b, "\""].join("") + " " + ["\"", b, "\""].join("");
   var dvipdfm = "dvipdfmx" + " " + ["\"", b, "\""].join("");
   var cmd = "cmd /c " + cd + " && " + latex + " && " + dvipdfm;
 
   var ok = confirm(cmd);
   if (ok) {
     document.Save();
     new ActiveXObject("WScript.Shell").Run(cmd, 1, true);
   }
 }
 
 main();
----

:ショートカット|Ctrl+Alt+J

**pdfpLaTeX2.js [#ledbb00b]

----
 function main()
 {
   var fso = new ActiveXObject("Scripting.FileSystemObject");
   var c = document.Path;
   var b = fso.GetBaseName(document.Name);
   var cd = "cd /d " + ["\"", c, "\""].join("");
   var latex = "platex -synctex=1 -guess-input-enc -sjis-terminal";
   latex += " " + "-jobname=" + ["\"", b, "\""].join("") + " " + ["\"", b, "\""].join("");
   var dvips = "dvips -Ppdf -z -f" + " " + ["\"", b, ".dvi", "\""].join("") + " | convbkmk -g > " + ["\"", b, ".ps", "\""].join("");
   var ps2pdf = "ps2pdf.bat" + " " + ["\"", b, ".ps", "\""].join("");
   var cmd = "cmd /c " + cd + " && " + latex + " && " + dvips + " && " + ps2pdf;
 
   var ok = confirm(cmd);
   if (ok) {
     document.Save();
     new ActiveXObject("WScript.Shell").Run(cmd, 1, true);
   }
 }
 
 main();
----

:ショートカット|Ctrl+Alt+K

**pdfupLaTeX.js [#d1ed0d34]

----
 function main()
 {
   var fso = new ActiveXObject("Scripting.FileSystemObject");
   var c = document.Path;
   var b = fso.GetBaseName(document.Name);
   var cd = "cd /d " + ["\"", c, "\""].join("");
   var latex = "uplatex -synctex=1 -no-guess-input-enc -kanji=utf8" + " " + ["\"", b, "\""].join("");
   var dvipdfm = "dvipdfmx" + " " + ["\"", b, "\""].join("");
   var cmd = "cmd /c " + cd + " && " + latex + " && " + dvipdfm;
 
   var ok = confirm(cmd);
   if (ok) {
     document.Save();
     new ActiveXObject("WScript.Shell").Run(cmd, 1, true);
   }
 }
 
 main();
----

:ショートカット|Shift+Alt+J

**pdfupLaTeX2.js [#vb3b2bff]

----
 function main()
 {
   var fso = new ActiveXObject("Scripting.FileSystemObject");
   var c = document.Path;
   var b = fso.GetBaseName(document.Name);
   var cd = "cd /d " + ["\"", c, "\""].join("");
   var latex = "uplatex -synctex=1 -no-guess-input-enc -kanji=utf8" + " " + ["\"", b, "\""].join("");
   var dvips = "dvips -Ppdf -z -f" + " " + ["\"", b, ".dvi", "\""].join("") + " | convbkmk -u > " + ["\"", b, ".ps", "\""].join("");
   var ps2pdf = "ps2pdf.bat" + " " + ["\"", b, ".ps", "\""].join("");
   var cmd = "cmd /c " + cd + " && " + latex + " && " + dvips + " && " + ps2pdf;
 
   var ok = confirm(cmd);
   if (ok) {
     document.Save();
     new ActiveXObject("WScript.Shell").Run(cmd, 1, true);
   }
 }
 
 main();
----

:ショートカット|Shift+Alt+K

**pdfLaTeX.js [#d94b29c5]

----
 function main()
 {
   var fso = new ActiveXObject("Scripting.FileSystemObject");
   var c = document.Path;
   var b = fso.GetBaseName(document.Name);
   var cd = "cd /d " + ["\"", c, "\""].join("");
   var pdflatex = "pdflatex -synctex=1" + " " + ["\"", b, "\""].join("");
   var cmd = "cmd /c " + cd + " && " + pdflatex;
 
   var ok = confirm(cmd);
   if (ok) {
     document.Save();
     new ActiveXObject("WScript.Shell").Run(cmd, 1, true);
   }
 }
 
 main();
----

:ショートカット|Shift+Alt+H

**LuaLaTeX.js [#zfcfa91e]

----
 function main()
 {
   var fso = new ActiveXObject("Scripting.FileSystemObject");
   var c = document.Path;
   var b = fso.GetBaseName(document.Name);
   var cd = "cd /d " + ["\"", c, "\""].join("");
   var lualatex = "lualatex -synctex=1" + " " + ["\"", b, "\""].join("");
   var cmd = "cmd /c " + cd + " && " + lualatex;
 
   var ok = confirm(cmd);
   if (ok) {
     document.Save();
     new ActiveXObject("WScript.Shell").Run(cmd, 1, true);
   }
 }
 
 main();
----

:ショートカット|Shift+Alt+Y

**LuaJITLaTeX.js [#f63f5aa7]

----
 function main()
 {
   var fso = new ActiveXObject("Scripting.FileSystemObject");
   var c = document.Path;
   var b = fso.GetBaseName(document.Name);
   var cd = "cd /d " + ["\"", c, "\""].join("");
   var luajitlatex = "luajitlatex -synctex=1" + " " + ["\"", b, "\""].join("");
   var cmd = "cmd /c " + cd + " && " + luajitlatex;
 
   var ok = confirm(cmd);
   if (ok) {
     document.Save();
     new ActiveXObject("WScript.Shell").Run(cmd, 1, true);
   }
 }
 
 main();
----

:ショートカット|Shift+Alt+U

**XeLaTeX.js [#n5d84d27]

----
 function main()
 {
   var fso = new ActiveXObject("Scripting.FileSystemObject");
   var c = document.Path;
   var b = fso.GetBaseName(document.Name);
   var cd = "cd /d " + ["\"", c, "\""].join("");
   var xelatex = "xelatex -synctex=1" + " " + ["\"", b, "\""].join("");
   var cmd = "cmd /c " + cd + " && " + xelatex;
 
   var ok = confirm(cmd);
   if (ok) {
     document.Save();
     new ActiveXObject("WScript.Shell").Run(cmd, 1, true);
   }
 }
 
 main();
----

:ショートカット|Shift+Alt+I

**pBibTeX.js [#oabf20f6]

----
 function main()
 {
   var fso = new ActiveXObject("Scripting.FileSystemObject");
   var c = document.Path;
   var b = fso.GetBaseName(document.Name);
   var cd = "cd /d " + ["\"", c, "\""].join("");
   var bibtex = "pbibtex -kanji=utf8 -sjis-terminal";
   bibtex += " " + ["\"", b, "\""].join("");
   var cmd = "cmd /c " + cd + " && " + bibtex;
 
   var ok = confirm(cmd);
   if (ok) {
     document.Save();
     new ActiveXObject("WScript.Shell").Run(cmd, 1, true);
   }
 }
 
 main();
----

:ショートカット|Ctrl+Alt+N

**upBibTeX.js [#w302791d]

----
 function main()
 {
   var fso = new ActiveXObject("Scripting.FileSystemObject");
   var c = document.Path;
   var b = fso.GetBaseName(document.Name);
   var cd = "cd /d " + ["\"", c, "\""].join("");
   var bibtex = "upbibtex" + " " + ["\"", b, "\""].join("");
   var cmd = "cmd /c " + cd + " && " + bibtex;
 
   var ok = confirm(cmd);
   if (ok) {
     document.Save();
     new ActiveXObject("WScript.Shell").Run(cmd, 1, true);
   }
 }
 
 main();
----

:ショートカット|Shift+Alt+N

**Mendex.js [#pa08cf71]

----
 function main()
 {
   var fso = new ActiveXObject("Scripting.FileSystemObject");
   var c = document.Path;
   var b = fso.GetBaseName(document.Name);
   var cd = "cd /d " + ["\"", c, "\""].join("");
   var makeindex = "mendex -U -T";
   makeindex += " " + ["\"", b, "\""].join("");
   var cmd = "cmd /c " + cd + " && " + makeindex;
 
   var ok = window.Confirm(cmd);
   if (ok) {
     document.Save();
     new ActiveXObject("WScript.Shell").Run(cmd, 1, true);
   }
 }
 
 main();
----

:ショートカット|Ctrl+Alt+M

**TeXworks.js [#eed78d60]

[[TeXworks#組み込みの PDF ビューアに日本語を表示させる>TeXworks#t5313ebc]] を参照してフォントの埋め込みの設定を行います.

----
 function main()
 {
   var fso = new ActiveXObject("Scripting.FileSystemObject");
   var currentTeXFile = document.FullName;
   var pdfFile = currentTeXFile.replace(new RegExp(/\.[^.]*$/), ".pdf");
   var texworks = "texworks";
 
   if (!fso.FileExists(pdfFile)) {
     var mainTeXFile = prompt("Input the path to main TeX file.", pdfFile.replace(new RegExp(/\.[^.]*$/), ".tex"));
     if (mainTeXFile != "") {
       pdfFile = mainTeXFile.replace(new RegExp(/\.[^.]*$/), ".pdf");
     }
   }
 
   var mainTeXDir = fso.GetParentFolderName(pdfFile);
   var cd = "cd /d " + ["\"", mainTeXDir, "\""].join("");
   pdfFile = ["\"", pdfFile, "\""].join("");
 
   var args = texworks + " " + pdfFile;
   var cmd = "cmd /c " + cd + " && echo " + args + " | cmd";
   new ActiveXObject("WScript.Shell").Run(cmd, 1, true);
 }
 
 main();
----

:ショートカット|Ctrl+Alt+O

*SumatraPDF との連携 [#vb348fe8]

**forward and inverse search (SumatraPDF を前面に表示したい場合) [#l2061012]

***SumatraPDF.js [#vcd32599]
----
 function main()
 {
   var fso = new ActiveXObject("Scripting.FileSystemObject");
   var gpad = editor.FullName;
   var currentTeXFile = document.FullName;
   var pdfFile = currentTeXFile.replace(new RegExp(/\.[^.]*$/), ".pdf");
   var line = document.selection.GetActivePointY(ePosLogical);
   var sumatraPDF = "C:/Program Files/SumatraPDF/SumatraPDF.exe";
   var mainTeXDir;
   var cd;
   var cmd;
   var args;
 
   if (!fso.FileExists(sumatraPDF)) {
     sumatraPDF = "C:/Program Files (x86)/SumatraPDF/SumatraPDF.exe";
     if (!fso.FileExists(sumatraPDF)) {
       sumatraPDF = prompt("Input the path to SumatraPDF.exe.", "SumatraPDF.exe");
       if (!fso.FileExists(sumatraPDF)) {
         sumatraPDF = "SumatraPDF.exe";
       }
     }
   }
 
   sumatraPDF = ["\"", sumatraPDF, "\""].join("");
 
   if (!fso.FileExists(pdfFile)) {
     var mainTeXFile = prompt("Input the path to main TeX file.", pdfFile.replace(new RegExp(/\.[^.]*$/), ".tex"));
     if (mainTeXFile != "") {
       pdfFile = mainTeXFile.replace(new RegExp(/\.[^.]*$/), ".pdf");
     }
   }
 
   mainTeXDir = fso.GetParentFolderName(pdfFile);
   cd = "cd /d " + ["\"", mainTeXDir, "\""].join("");
   currentTeXFile = ["\"", currentTeXFile, "\""].join("");
   pdfFile = ["\"", pdfFile, "\""].join("");
 
   args = sumatraPDF + " -reuse-instance " + pdfFile + " -inverse-search \"\\\"" + gpad + "\\\" -Y=%l \\\"%f\\\"\"" + " -forward-search " + currentTeXFile + " " + line;
   cmd = "cmd /c " + cd + " && echo " + args + " | cmd";
   new ActiveXObject("WScript.Shell").Run(cmd, 1, true);
 }
 
 main();
----

**forward search (SumatraPDF を前面に表示したくない場合) [#q6af99da]

[[SumatraPDF#fwdsumatrapdf.exe>SumatraPDF#n8da77e2]] の fwdsumatrapdf.exe を使用します.~

***fwdsumatrapdf.js [#c541770c]
----
 function main()
 {
   var fso = new ActiveXObject("Scripting.FileSystemObject");
   var currentTeXFile = document.FullName;
   var pdfFile = currentTeXFile.replace(new RegExp(/\.[^.]*$/), ".pdf");
   var line = document.selection.GetActivePointY(ePosLogical);
   var fwdsumatrapdf = "C:/w32tex/NDde/Binary/fwdsumatrapdf.exe";
   var mainTeXDir;
   var cd;
   var cmd;
   var args;

   if (!fso.FileExists(fwdsumatrapdf)) {
     fwdsumatrapdf = prompt("Input the path to fwdsumatrapdf.exe.", "fwdsumatrapdf.exe");
     if (!fso.FileExists(fwdsumatrapdf)) {
       fwdsumatrapdf = "fwdsumatrapdf.exe";
     }
   }
 
   fwdsumatrapdf = ["\"", fwdsumatrapdf, "\""].join("");
 
   if (!fso.FileExists(pdfFile)) {
     var mainTeXFile = prompt("Input the path to main TeX file.", pdfFile.replace(new RegExp(/\.[^.]*$/), ".tex"));
     if (mainTeXFile != "") {
       pdfFile = mainTeXFile.replace(new RegExp(/\.[^.]*$/), ".pdf");
     }
   }
 
   mainTeXDir = fso.GetParentFolderName(pdfFile);
   cd = "cd /d " + ["\"", mainTeXDir, "\""].join("");
   currentTeXFile = ["\"", currentTeXFile, "\""].join("");
   pdfFile = ["\"", pdfFile, "\""].join("");
 
   args = fwdsumatrapdf + " " + pdfFile + " " + currentTeXFile + " " + line;
   cmd = "cmd /c " + cd + " && " + args;
   new ActiveXObject("WScript.Shell").Run(cmd, 1, true);
 }
 
 main();
----
**inverse search [#dae36579]

 C:\gPad\gPad.exe -Y=%l "%f"

*Adobe Reader との連携 [#k7e32b43]

**pdfpLaTeXA.js [#w9c8fc43]

----
 function main()
 {
   var fso = new ActiveXObject("Scripting.FileSystemObject");
   var c = document.Path;
   var b = fso.GetBaseName(document.Name);
   var cd = "cd /d " + ["\"", c, "\""].join("");
   var latex = "platex -guess-input-enc -sjis-terminal";
   latex += " " + "-jobname=" + ["\"", b, "\""].join("") + " " + ["\"", b, "\""].join("");
   var dvipdfm = "dvipdfmx" + " " + ["\"", b, "\""].join("");
   var pdf = ["\"", b, ".pdf", "\""].join("");
   var pdfopen = "powershell -Command \"& {$pdf = \"\"" + pdf + "\"\"; $pages = (pdfinfo $pdf | Select-String \"^Pages:\"); $page = (-split $pages)[1]; pdfopen --rxi --file $pdf --page $page}\"";
   var pdfclose = "tasklist /fi \"IMAGENAME eq AcroRd32.exe\" /nh | findstr \"AcroRd32.exe\" > nul && pdfopen --rxi --file " + pdf + " && pdfclose --rxi --file " + pdf;
   var cmd = "cmd /c " + cd + " && " + pdfclose + " & " + latex + " && " + dvipdfm + " && " + pdfopen;
 
   var ok = confirm(cmd);
   if (ok) {
     document.Save();
     new ActiveXObject("WScript.Shell").Run(cmd, 1, true);
   }
 }
 
 main();
----

**pdfpLaTeX2A.js [#f3490b53]

----
 function main()
 {
   var fso = new ActiveXObject("Scripting.FileSystemObject");
   var c = document.Path;
   var b = fso.GetBaseName(document.Name);
   var cd = "cd /d " + ["\"", c, "\""].join("");
   var latex = "platex -guess-input-enc -sjis-terminal";
   latex += " " + "-jobname=" + ["\"", b, "\""].join("") + " " + ["\"", b, "\""].join("");
   var dvips = "dvips -Ppdf -z -f" + " " + ["\"", b, ".dvi", "\""].join("") + " | convbkmk -g > " + ["\"", b, ".ps", "\""].join("");
   var ps2pdf = "ps2pdf.bat" + " " + ["\"", b, ".ps", "\""].join("");
   var pdf = ["\"", b, ".pdf", "\""].join("");
   var pdfopen = "powershell -Command \"& {$pdf = \"\"" + pdf + "\"\"; $pages = (pdfinfo $pdf | Select-String \"^Pages:\"); $page = (-split $pages)[1]; pdfopen --rxi --file $pdf --page $page}\"";
   var pdfclose = "tasklist /fi \"IMAGENAME eq AcroRd32.exe\" /nh | findstr \"AcroRd32.exe\" > nul && pdfopen --rxi --file " + pdf + " && pdfclose --rxi --file " + pdf;
   var cmd = "cmd /c " + cd + " && " + pdfclose + " & " + latex + " && " + dvips + " && " + ps2pdf + " && " + pdfopen;
 
   var ok = confirm(cmd);
   if (ok) {
     document.Save();
     new ActiveXObject("WScript.Shell").Run(cmd, 1, true);
   }
 }
 
 main();
----

**pdfupLaTeXA.js [#rf2dcd15]

----
 function main()
 {
   var fso = new ActiveXObject("Scripting.FileSystemObject");
   var c = document.Path;
   var b = fso.GetBaseName(document.Name);
   var cd = "cd /d " + ["\"", c, "\""].join("");
   var latex = "uplatex -no-guess-input-enc -kanji=utf8" + " " + ["\"", b, "\""].join("");
   var dvipdfm = "dvipdfmx" + " " + ["\"", b, "\""].join("");
   var pdf = ["\"", b, ".pdf", "\""].join("");
   var pdfopen = "powershell -Command \"& {$pdf = \"\"" + pdf + "\"\"; $pages = (pdfinfo $pdf | Select-String \"^Pages:\"); $page = (-split $pages)[1]; pdfopen --rxi --file $pdf --page $page}\"";
   var pdfclose = "tasklist /fi \"IMAGENAME eq AcroRd32.exe\" /nh | findstr \"AcroRd32.exe\" > nul && pdfopen --rxi --file " + pdf + " && pdfclose --rxi --file " + pdf;
   var cmd = "cmd /c " + cd + " && " + pdfclose + " & " + latex + " && " + dvipdfm + " && " + pdfopen;
 
   var ok = confirm(cmd);
   if (ok) {
     document.Save();
     new ActiveXObject("WScript.Shell").Run(cmd, 1, true);
   }
 }
 
 main();
----

**pdfupLaTeX2A.js [#r2783faf]

----
 function main()
 {
   var fso = new ActiveXObject("Scripting.FileSystemObject");
   var c = document.Path;
   var b = fso.GetBaseName(document.Name);
   var cd = "cd /d " + ["\"", c, "\""].join("");
   var latex = "uplatex -no-guess-input-enc -kanji=utf8" + " " + ["\"", b, "\""].join("");
   var dvips = "dvips -Ppdf -z -f" + " " + ["\"", b, ".dvi", "\""].join("") + " | convbkmk -u > " + ["\"", b, ".ps", "\""].join("");
   var ps2pdf = "ps2pdf.bat" + " " + ["\"", b, ".ps", "\""].join("");
   var pdf = ["\"", b, ".pdf", "\""].join("");
   var pdfopen = "powershell -Command \"& {$pdf = \"\"" + pdf + "\"\"; $pages = (pdfinfo $pdf | Select-String \"^Pages:\"); $page = (-split $pages)[1]; pdfopen --rxi --file $pdf --page $page}\"";
   var pdfclose = "tasklist /fi \"IMAGENAME eq AcroRd32.exe\" /nh | findstr \"AcroRd32.exe\" > nul && pdfopen --rxi --file " + pdf + " && pdfclose --rxi --file " + pdf;
   var cmd = "cmd /c " + cd + " && " + pdfclose + " & " + latex + " && " + dvips + " && " + ps2pdf + " && " + pdfopen;
 
   var ok = confirm(cmd);
   if (ok) {
     document.Save();
     new ActiveXObject("WScript.Shell").Run(cmd, 1, true);
   }
 }
 
 main();
----

**pdfLaTeXA.js [#z77a2cf6]

----
 function main()
 {
   var fso = new ActiveXObject("Scripting.FileSystemObject");
   var c = document.Path;
   var b = fso.GetBaseName(document.Name);
   var cd = "cd /d " + ["\"", c, "\""].join("");
   var pdflatex = "pdflatex" + " " + ["\"", b, "\""].join("");
   var pdf = ["\"", b, ".pdf", "\""].join("");
   var pdfopen = "powershell -Command \"& {$pdf = \"\"" + pdf + "\"\"; $pages = (pdfinfo $pdf | Select-String \"^Pages:\"); $page = (-split $pages)[1]; pdfopen --rxi --file $pdf --page $page}\"";
   var pdfclose = "tasklist /fi \"IMAGENAME eq AcroRd32.exe\" /nh | findstr \"AcroRd32.exe\" > nul && pdfopen --rxi --file " + pdf + " && pdfclose --rxi --file " + pdf;
   var cmd = "cmd /c " + cd + " && " + pdfclose + " & " + pdflatex + " && " + pdfopen;
 
   var ok = confirm(cmd);
   if (ok) {
     document.Save();
     new ActiveXObject("WScript.Shell").Run(cmd, 1, true);
   }
 }
 
 main();
----

**LuaLaTeXA.js [#ia6cdb6b]

----
 function main()
 {
   var fso = new ActiveXObject("Scripting.FileSystemObject");
   var c = document.Path;
   var b = fso.GetBaseName(document.Name);
   var cd = "cd /d " + ["\"", c, "\""].join("");
   var lualatex = "lualatex" + " " + ["\"", b, "\""].join("");
   var pdf = ["\"", b, ".pdf", "\""].join("");
   var pdfopen = "powershell -Command \"& {$pdf = \"\"" + pdf + "\"\"; $pages = (pdfinfo $pdf | Select-String \"^Pages:\"); $page = (-split $pages)[1]; pdfopen --rxi --file $pdf --page $page}\"";
   var pdfclose = "tasklist /fi \"IMAGENAME eq AcroRd32.exe\" /nh | findstr \"AcroRd32.exe\" > nul && pdfopen --rxi --file " + pdf + " && pdfclose --rxi --file " + pdf;
   var cmd = "cmd /c " + cd + " && " + pdfclose + " & " + lualatex + " && " + pdfopen;
 
   var ok = confirm(cmd);
   if (ok) {
     document.Save();
     new ActiveXObject("WScript.Shell").Run(cmd, 1, true);
   }
 }
 
 main();
----

**LuaJITLaTeXA.js [#x4fb0b25]

----
 function main()
 {
   var fso = new ActiveXObject("Scripting.FileSystemObject");
   var c = document.Path;
   var b = fso.GetBaseName(document.Name);
   var cd = "cd /d " + ["\"", c, "\""].join("");
   var luajitlatex = "luajitlatex" + " " + ["\"", b, "\""].join("");
   var pdf = ["\"", b, ".pdf", "\""].join("");
   var pdfopen = "powershell -Command \"& {$pdf = \"\"" + pdf + "\"\"; $pages = (pdfinfo $pdf | Select-String \"^Pages:\"); $page = (-split $pages)[1]; pdfopen --rxi --file $pdf --page $page}\"";
   var pdfclose = "tasklist /fi \"IMAGENAME eq AcroRd32.exe\" /nh | findstr \"AcroRd32.exe\" > nul && pdfopen --rxi --file " + pdf + " && pdfclose --rxi --file " + pdf;
   var cmd = "cmd /c " + cd + " && " + pdfclose + " & " + luajitlatex + " && " + pdfopen;
 
   var ok = confirm(cmd);
   if (ok) {
     document.Save();
     new ActiveXObject("WScript.Shell").Run(cmd, 1, true);
   }
 }
 
 main();
----

**XeLaTeXA.js [#u5a50eee]

----
 function main()
 {
   var fso = new ActiveXObject("Scripting.FileSystemObject");
   var c = document.Path;
   var b = fso.GetBaseName(document.Name);
   var cd = "cd /d " + ["\"", c, "\""].join("");
   var xelatex = "xelatex" + " " + ["\"", b, "\""].join("");
   var pdf = ["\"", b, ".pdf", "\""].join("");
   var pdfopen = "powershell -Command \"& {$pdf = \"\"" + pdf + "\"\"; $pages = (pdfinfo $pdf | Select-String \"^Pages:\"); $page = (-split $pages)[1]; pdfopen --rxi --file $pdf --page $page}\"";
   var pdfclose = "tasklist /fi \"IMAGENAME eq AcroRd32.exe\" /nh | findstr \"AcroRd32.exe\" > nul && pdfopen --rxi --file " + pdf + " && pdfclose --rxi --file " + pdf;
   var cmd = "cmd /c " + cd + " && " + pdfclose + " & " + xelatex + " && " + pdfopen;
 
   var ok = confirm(cmd);
   if (ok) {
     document.Save();
     new ActiveXObject("WScript.Shell").Run(cmd, 1, true);
   }
 }
 
 main();
----