I want to dynamically change the way latex-suite determines the MainFile. The main file is usually the latex header file which includes other tex files (like chapters and so on). Using the MainFile it is possible to hit compile on some chapter-file so that latex-suite automatically compiles the header file instead.
This should be possible with g:Tex_MainFileExpression: http://vim-latex.sourceforge.net/documentation/latex-suite/latex-master-file.html
However, the expression is not documented at all and even the example (which imo should reflect the default behavior) does not work.
let g:Tex_MainFileExpression = 'MainFile(modifier)'
function! MainFile(fmod)
if glob('*.latexmain') != ''
return fnamemodify(glob('*.latexmain'), a:fmod)
else
return ''
endif
endif
Can somebody please shortly point out to me how this is supposed to be used? What return expression is expected? Why does the example not work?
Background: I have a latexmain file in the project root. I also have a figure subdirectory. For this subdirectory the root latex main should not be ignored, so that the current file itself is compiled.
I just ran into the problem of not knowing how to set
g:Tex_MainFileExpressionas well. The documentation and the example were not clear to me either. Turns out, the source code defines a functionTex_GetMainFileName, which sets the variablemodifierfrom its arguments before executingg:Tex_MainFileExpression(see source code here). Therefore,g:Tex_MainFileExpressionneeds to be a function that has the argumentmodifier(not called differently!). The vim-latex documentation says, that modifier is a filetype-modifier, therefore your function needs to returnfnamemodify(filename, modifier). So it has to look like this:Example
I used this in a project where I have a two main latex files, one for the main document and one for supplementary material. The project structure looks like this:
I load a
.local-vimrcfile (using the plugin MarcWeber/vim-addon-local-vimrc), where I setg:Tex_MainFileExpressionsuch that<leader>llcompilesmain.texif the file in the current buffer is located in the foldermain-sourceand compilessup.texif it is in the foldersup-source. Below is my.local-vimrcfile. I have very little experience with vimscript, so this is probably a littly hacky, but it might help to get an idea on how to useg:Tex_MainFileExpression. Also, I have modified it to be less messy and not tested the following code explicitly.