首先, 编辑器可选, 可用texpad、sublime、vim等.
其次, mactex是必装环境.
一、安装MacTex
在如下地址下载MacTex, 月3G以上, 双击安装.
http://www.tug.org/mactex/mactex-download.html
说明:MacTex自带的编辑器Texshop简单实用
二、安装Vim-latex
Vim-latex 插件
Vim-latex 插件是一个强大的Latex插件, 它的安装方法是:
1. 将下面代码放在~/.vimrc 中:
Plugin 'vim-latex/vim-latex'
" 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
" 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'
然后在vim中运行:
:source %
:PluginInstall
2. In addition, the following settings could go in your ~/.vim/ftplugin/tex.vim file:
" 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 <C-n> you will automatically cycle through
" all the figure labels. Very useful!
set iskeyword+=:
3. In the unlikely case that Latex-Suite is installed, but you do not want to use it (e.g., if it is installed system-wide and you use some other package to deal with tex files), you can suppress the loading of Latex-Suite by setting
let b:suppress_latex_suite = 1
in your ~/.vim/ftplugin/tex.vim.
4. 到这里,就完成了vim的安装。可以在vim中查看其帮助文档:
:help latex-suite.txt
:help latexhelp.txt
试错和使用
1.报错解决
安装完成之后,就可以使用了。打开一份latex文档,在normal模式下,按下:
\ll
顺利的话就可以编译成功,latex生成的pdf。不过,这里我还是遇到了报错:
I can't find file `latex_notes.tex`. latex_notes.tex
Emergency stop. latex_notes.tex
网上查了下,好像是由于latex源文件所在的路径中有中文字符导致的。这里迁就下,将其放到一个全是英文的路径中,然后重新编译,应该就可以了(参考链接)。
如果latex文件中有中文字符,这时编译得到的pdf文档里面中文字符的位置,可能全是空白。这里需要设置下latex的编译引擎,将其设置为xelatex。vim-latex配置文件(.vim/ftplugin/latex-suite/texrc)
110 TexLet g:Tex_CompileRule_pdf = 'xelatex -interaction=nonstopmode $*'
这样,应该就可以编译成功了。(参考链接)
2.使用
下面是几个操作命令:
\ll编译
\lv预览pdf
先写这些,后续再补充。