最近接觸latex,一開始在mac上用texpad,感覺體驗不錯。后來,由于試用期過了,必須購買才能使用。因此,準備再試試vim。這里要用的latex插件是vim-latex。
0、環(huán)境
操作系統(tǒng):OS X EI Caption版本10.11.6
Vim版本:MacVim Custom Version 7.4 (104)
已經(jīng)安裝了mactex-20161009.pkg。
1、安裝
按照官方文檔,一步一步走就行:
下載
到SourceForge Files for vim-latex,下載安裝文件。這里下的是vim-latex-1.9.0.tar.gz (289.3 kB)。安裝
將壓縮包解壓到.vim目錄下。注意,是要將壓縮包中的各個子文件夾和文件等內(nèi)容解壓到.vim目錄下。-
安裝help文檔
安裝包正確解壓之后,.vim/doc目錄下就是vim-latex的文檔。啟動vim,用如下命令可以進行安裝::helptags ~/.vim/doc(for *nix users) -
配置
在vimrc文件中,確保vimrc中包含了如下配置:" REQUIRED. This makes vim invoke Latex-Suite when you open a tex file. filetype plugin on " IMPORTANT: win32 users will need to have 'shellslash' set so that latex " can be called correctly. " set shellslash " IMPORTANT: grep will sometimes skip displaying the file name if you " search in a singe file. This will confuse Latex-Suite. Set your grep " program to always generate a file-name. set grepprg=grep\ -nH\ $* " OPTIONAL: This enables automatic indentation as you type. filetype indent on " OPTIONAL: Starting with Vim 7, the filetype of empty .tex files defaults to " 'plaintex' instead of 'tex', which results in vim-latex not being loaded. " The following changes the default filetype back to 'tex': let g:tex_flavor='latex' " this is mostly a matter of taste. but LaTeX looks good with just a bit " of indentation. set sw=2 " TIP: if you write your \label's as \label{fig:something}, then if you " type in \ref{fig: and press you will automatically cycle through " all the figure labels. Very useful! set iskeyword+=:
這里的配置是從官方安裝說明中拷貝的,其中不需要的可以自行注釋掉。由于這里用的不是windows,所以上面我的配置中就注掉了set shellslash。
5.完成
到這里,就完成了vim的安裝。可以在vim中查看其幫助文檔:
:help latex-suite.txt
:help latexhelp.txt
2、試錯和使用
2.1報錯解決
安裝完成之后,就可以使用了。打開一份latex文檔,在normal模式下,按下:
\ll
順利的話就可以編譯成功,latex生成的pdf。不過,這里我還是遇到了報錯:
I can't find file `latex_notes.tex`. latex_notes.tex
Emergency stop. latex_notes.tex
網(wǎng)上查了下,好像是由于latex源文件所在的路徑中有中文字符導(dǎo)致的。這里遷就下,將其放到一個全是英文的路徑中,然后重新編譯,應(yīng)該就可以了(參考鏈接)。
如果latex文件中有中文字符,這時編譯得到的pdf文檔里面中文字符的位置,可能全是空白。這里需要設(shè)置下latex的編譯引擎,將其設(shè)置為xelatex。vim-latex配置文件(.vim/ftplugin/latex-suite/texrc)
110 TexLet g:Tex_CompileRule_pdf = 'xelatex -interaction=nonstopmode $*'
這樣,應(yīng)該就可以編譯成功了。(參考鏈接)
2.2使用
下面是幾個操作命令:
- \ll編譯
- \lv預(yù)覽pdf
先寫這些,后續(xù)再補充。