一直在用Sublime Text + ctex集成環境編寫Latex文檔,最近發現ctex套件內嵌的MiKTeX包管理器功能太弱了,遂將目標轉向了功能更加強大的Tex Live環境。
首先安裝Tex Live環境,可以選擇在線安裝或者下載iso文件安裝。可以參考官方網站的安裝教程http://www.tug.org/texlive/,也可以參考這篇博文http://exciton.eo.yzu.edu.tw/~lab/latex/install_latex_cjk_ms_windows.html。
安裝完成后,將Tex Live安裝目錄中的可執行文件目錄添加進系統PATH路徑,目錄一般是這種形式的D:\texlive\2014\bin\win32。
Sublime Text中安裝LaTeXTools插件,然后依次點擊:Preferences -->> Package Settings -->> LaTeXTools --> Reconfigure LaTeXTools and migrate settings,插件會在User目錄下生成LaTeXTools的配置文件。如果系統安裝的是MiKTeX集成環境的話,配置文件不需要修改直接ctrl+b就可以編譯Latex文件。現在我們想要LaTeXTools調用Tex Live編譯Latex文件,只需要修改配置文件中的Platform settings部分。
"windows": { // Path used when invoking tex & friends; "" is fine for MiKTeX // For TeXlive 2011 (or other years) use // "texpath" : "C:\\texlive\\2011\\bin\\win32;$PATH", "texpath" : "", // TeX distro: "miktex" or "texlive" "distro" : "texlive" },
將"distro"屬性修改成"texlive",LaTeXTools插件就可以默然調用Tex Live編譯Latex文件了。在這種情況下,如果Build engine settings里設置成"traditional",那么ctrl+b編譯的時候,實際上調用的是Tex Live中的latexmk命令。
// ------------------------------------------------------------------ // Build engine settings // ------------------------------------------------------------------ // OPTION: "builder" // Specifies a build engine // Possible values: // // "default" or "" the default built-in build engine; currently // this is the same as "traditional" // // "simple" invokes pdflatex 1x or 2x as needed, then // bibtex and pdflatex again if needed; // intended mainly as a simple example for // peoeple writing their own build engines. // // "traditional" replicates the 'old' system based on // latexmk (TeXLive) / texify (MiKTeX) // // "script" external script: just invokes the script // specified in "builder_settings" // // custom name you can also use third-party build engines; // if so, set the "builder_path" option below // // NOTE: custom builders CANNOT have the same name as an existing // built-in build engine (including "default") "builder": "traditional",
插一句題外話,latexmk命令還有一個強大的功能,它可以通過讀取Latex文件首行的Tex引擎設置參數來調用不同編譯引擎編譯文件。其Tex引擎設置命令格式為:%!TEX program = <program>。在這里program可以是pdflatex(默認),luaoatex或xelatex。如果首行沒有Tex引擎選擇指令,latexmk將默認調用pdflatex引擎。例如,在Latex文件的第一行的內容是:
%!TEX program = xelatex。那么在用latexmk命令編譯文件的時候,實際上調用的是xelatex編譯引擎。這個功能使得我們可以在不修改編譯命令的情況下,修改編譯引擎,只需要在Latex文件的首行加一條配置命令即可實現編譯引擎的選擇,可以大大方提高Latex文件編譯的靈活度。目前,MiKTeX的texify並不支持。