最近CTF的writeup要求使用LaTeX來寫,之前的一次使用了集成的C-TeX,雖然某種程度上講比較不錯,但是缺點也很明顯,太過臃腫而且有一些缺少的包安裝起來比較麻煩,界面美化,字體,高亮都不是很舒服,所以看了一些其他人的配置之后,打算用sublime+MikTeX+SumatraPDF這一套。
sublime就不用說了,編輯器中的神器。MikTeX和TeXLive則都是LaTeX的編譯引擎,個人理解兩者最主要的區別就是,TeXLive幾乎集成了LaTeX所有的包,而MikTex只有最基本的一些包,但是在使用過程中如果需要的話可以自動下載。SumatraPDF則可以稱得上是最輕量級的PDF閱讀器。
使用這套配置的主要原因一個是sublime對於代碼字體以及高亮的處理,再有就是這套配置基本是能找到的最輕量級的配置了,因為使用並不是很頻繁,所以以上配置足夠我進行日常的文檔編排了。選擇MikTex是因為在安裝TeXlive時的安裝速度實在是不敢恭維,一個小時才安裝了10%,可能是我安裝的方法不對,總之最后還是選擇換成了MikTeX。
軟件版本:我使用的是sublime 2,MikTex當前最新,Sumatra無所謂。
首先需要先在sublime中安裝LaTeX Tools,在這之前又要安裝Package Control,在官網之間下載插件,放在C:\Users\username\AppData\Roaming\Sublime Text 2\Installed Packages 目錄下,重啟sublime即可。安裝完成后ctrl+shift+p,選擇package control:install package,再搜索LaTeXtools,點擊即可安裝。
以上是sublime為了鏈接LaTeX引擎,需要安裝的一個插件,關於此插件的配置則需要在安裝完TeX引擎后再進行。
第二步是安裝MikTeX,這個就不多說了,直接google下載就好。
第三步則是配置LaTeXtools,因為LaTeXtools默認的LaTeX引擎就是MikTeX,所以本身不需要太多的配置,但是在生成xelatex文件時,則需要有一些小小的改動。打開sublime,選擇Preferences->Package Settings->LaTeX Tools->Settings(-user),這個文件就是LaTeX Tools的配置文件了,首先需要修改的地方是:
"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" : "miktex", // Command to invoke Sumatra. If blank, "SumatraPDF.exe" is used (it has to be on your PATH) "sumatra": ""
將其中的texpath的值改為$PATH。
第二處要修改的地方是:
"builder": "traditional", // OPTION: "builder_path" // If non-empty, specifies a path to a custom builder, relative to the // Sublime Text Packages directory. // For instance, "User/builders" (on Windows: "User\builders") is a good // choice if you roll your own. // (Note: if you choose "User", you may get a Python import error in the // console, but things will still work). // Leave empty ("") for a built-in builder. "builder_path": "", // OPTION: "builder_settings" // Specify builder-dependent settings and preferences // Possible values: see README or documentation provided with // third-party build engine. // Builder setting can be general or OS-dependent "builder_settings" : { // General settings: // See README or third-party documentation // (built-ins): true shows the log of each command in the output panel "display_log" : false, "options" : ["--shell-escape"], // Platform-specific settings: "osx" : { // See README or third-party documentation }, "windows" : { // See README or third-party documentation }, "linux" : { // See README or third-party documentation } },
其中的關鍵是builder_settings中的options,初始的setting中是沒有這個配置選項的,我們在這里需要加入:
"options" : ["--shell-escape"],
就相當於在編譯的命令行命令前添加了這樣一句。
第三步是安裝及配置SumatraPDF,完成Sumatra的下載安裝后,將SumatraPDF.exe的目錄添加到環境變量中的Path即可(是添加不是覆蓋)。然后打開SuamtraPDF->設置->選項,在最下方的“設置反向搜索命令行”處添加以下內容:
"E:\Program Files\Sublime Text 2\sublime_text.exe" "%f:%l"
其中前半部分的內容是你的sublime安裝目錄。
上面的全部配置完成后就可以順利的使用sublime進行LaTeX文檔的書寫以及編譯了,記得編譯之前把BuildSystem修改為LaTeX,然后Ctrl + B就ok了,在pdf文檔中點擊任意位置時,也可以反向到LaTex代碼中了。
感謝團長在配置過程中提供的幫助,同時本文部分內容參照了http://www.360doc.com/content/14/0517/19/9206388_378573988.shtml。
以上。