I have the following code in my vimrc to compile my latex documents with <F5>
:
map <F5> :write <Bar> :if expand("%") == "body.tex" <bar>
:exe ':!arara -v "main.tex"' <cr>
:endif <cr> <bar> :!arara -v % <cr> :endif <cr>
(Line breaks added purley for legibility, no linebreaks in my original code.)
I sometimes separate my latex documents in one containing the preamble, called "main.tex", and one containing the text, called "body.tex". If that's the case I want arara to run on the file called "main.tex", otherwise I want it to run on the file I'm writing on itself. None of this matters to the question I'm asking, I just wanted to explain what I'm doing here.
Oddly enough, this code is working, and it only works as intended if I keep it this way. A plausible assumption would have been that the following code would have been sufficient:
map <F5> :write <Bar> :if expand("%") == "body.tex" <bar>
:exe ':!arara -v "main.tex"' <bar>
:else <bar> :!arara -v % <bar> :endif <cr>
Here, vim complains about :else
outside of :if
if I'm in a file not called "body.tex", and if I'm within body.tex, I have to press enter to run arara, and have to close the if
manually by entering :endif
.
You'd also expect vim to complain about the two occurrences of endif
in a single if
command in the first code, and for the first one to be utterly redundant.
Can anybody shed some light on the exact syntax that I'm dealing with here? Vim help hasn't been a lot of actual help on this.