我想动态改变latex-suite确定MainFile的方式。主文件通常是latex头文件,其中包括其他tex文件(如章节等)。使用MainFile,可以在某些章节文件上点击编译,这样latex-suite就会自动编译头文件。
使用g:Tex_MainFileExpression:http://vim-latex.sourceforge.net/documentation/latex-suite/latex-master-file.html应该可以做到这一点
但是,表达式根本没有文档记录,甚至示例( imo应该反映默认行为)也不起作用。
let g:Tex_MainFileExpression = 'MainFile(modifier)'
function! MainFile(fmod)
if glob('*.latexmain') != ''
return fnamemodify(glob('*.latexmain'), a:fmod)
else
return ''
endif
endif有人能简短地告诉我这应该是如何使用的吗?预期的返回表达式是什么?为什么这个例子不起作用?
背景:我在项目根目录中有一个latexmain文件。我还有一个figure子目录。对于该子目录,不应忽略根latex main,以便编译当前文件本身。
发布于 2020-03-26 02:06:44
原来,源代码定义了一个函数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,以便如果当前缓冲区中的文件位于文件夹main-source中,则<leader>ll编译main.tex,如果它位于文件夹sup-source中,则编译sup.tex。下面是我的.local-vimrc文件。我几乎没有使用g:Tex_MainFileExpression的经验,所以这可能有点老生常谈,但它可能有助于了解如何使用vimscript。
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)
endfunctionhttps://stackoverflow.com/questions/28567148
复制相似问题