我也遇到了不知道如何设置g:Tex_MainFileExpression 的问题。我也不清楚文档和示例。结果是,源代码定义了一个函数Tex_GetMainFileName,它在执行g:Tex_MainFileExpression 之前从其参数中设置变量modifier(参见source code here)。因此,g:Tex_MainFileExpression 需要是一个具有参数modifier 的函数(没有不同的调用方式!)。 vim-latex 文档说,该修饰符是filetype-modifier,因此您的函数需要返回fnamemodify(filename, modifier)。所以它必须看起来像这样:
let g:Tex_MainFileExpression = 'MainFile(modifier)'
function! MainFile(fmod)
" Determine the full path to your main latex file that you want to compile.
" Store it e.g. in the variable `path`:
" let path = some/path/to/main.tex
" Apply `modifier` to your `path` variable
return fnamemodify(path, a:fmod)
endif
示例
我在一个项目中使用了它,我有两个主要的乳胶文件,一个用于主文档,一个用于补充材料。项目结构如下:
project/
main.tex
sup.tex
.local-vimrc
main-source/
input1.tex
input2.tex
sup-source/
input1.tex
input2.tex
我加载了一个.local-vimrc 文件(使用插件MarcWeber/vim-addon-local-vimrc),我在其中设置g:Tex_MainFileExpression 使得<leader>ll 编译main.tex 如果当前缓冲区中的文件位于文件夹main-source 中并且如果 sup.tex 在文件夹 sup-source 中,则编译它。下面是我的.local-vimrc 文件。我对 vimscript 的经验很少,所以这可能有点 hacky,但它可能有助于了解如何使用 g:Tex_MainFileExpression。另外,我已经对其进行了修改,使其不那么混乱,并且没有明确测试以下代码。
let g:Tex_MainFileExpression = 'g:My_MainTexFile(modifier)'
function! g:My_MainTexFile(fmod)
" Get absolute (link resolved) paths to this script and the open buffer
let l:path_to_script = fnamemodify(resolve(expand('<sfile>:p')), ':h')
let l:path_to_buffer = fnamemodify(resolve(expand('%:p')), ':h')
" Check if the buffer file is a subdirectory of `main-source` or `sup-source`
" stridx(a, b) returns -1 only if b is not substring of a
if stridx(l:path_to_buffer, 'main-source') != -1
let l:name = 'main.tex'
elseif stridx(l:path_to_buffer, 'sup-source') != -1
let l:name = 'sup.tex'
else
echom "Don't know what's the root tex file. '".@%."' is not in 'main-source/' or 'sup-source/' directory."
return ''
endif
" Concatenate this script path with main latex file name
" NOTE: this assumes that this script is located in the same folder as the
" main latex files 'main.tex' and 'sup.tex'
let l:path = l:path_to_script.'/'.l:name
return fnamemodify(l:abs_path_main, a:fmod)
endfunction