【问题标题】:vim latex-suite Understand MainFileExpressionvim latex-suite 理解 MainFileExpression
【发布时间】:2015-04-18 11:34:23
【问题描述】:

我想动态改变 latex-suite 确定 MainFile 的方式。 主文件通常是包含其他 tex 文件(如章节等)的 latex 头文件。使用 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 文件。我也有一个图形子目录。对于此子目录,不应忽略根 latex main,以便编译当前文件本身。

【问题讨论】:

  • 为什么不在项目中打开问题?毕竟,您遇到过不存在或不清楚的文档。
  • 老实说,我认为我的理解问题只是由于我对 vim 的脚本系统和 latex-suite 配置完全缺乏经验。更有经验的用户可能会很快弄清楚如何正确使用它。

标签: vim latex-suite


【解决方案1】:

我也遇到了不知道如何设置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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多