我只是遇到了不知道如何设置的问题g:Tex_MainFileExpression
。我也不清楚文档和示例。事实证明,源代码定义了一个函数,它在执行之前从它的参数Tex_GetMainFileName
中设置变量(参见这里的源代码)。因此,需要是一个具有参数的函数(没有不同的调用方式!)。vim-latex 文档说,该修饰符是filetype-modifier,因此您的函数需要 return 。所以它必须看起来像这样:modifier
g:Tex_MainFileExpression
g:Tex_MainFileExpression
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
编译,如果它位于文件夹中则编译。下面是我的文件。我对 vimscript 的经验很少,所以这可能有点 hacky,但它可能有助于了解如何使用. 此外,我已将其修改为不那么混乱,并且没有明确测试以下代码。main.tex
main-source
sup.tex
sup-source
.local-vimrc
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