function! GetMainDoc() let l:maindoc = search('\\begin{document}', "cnw") if l:maindoc > 0 return '%' else " Find the main document file " Must be in the same folder of the current file let l:maindocs = split(system("grep -lE '\\\\begin{document}' " . expand('%:h') . "/*.tex"), '\n') if len(l:maindocs) > 0 " Use the first document containing `begin{document}` return l:maindocs[0] else return "" endif endif endfunction function! CompileMainDoc() let l:latexcmd ='autocmd BufWritePost ! \ latexrun --latex-args="-synctex=1 -interaction=nonstopmode" ' execute(l:latexcmd . GetMainDoc()) endfunction function! Synctex() " remove 'silent' for debugging let l:doc = GetMainDoc() execute "silent !mv -u latex.out/" . substitute(l:doc, '\.tex', '') . ".synctex.gz ." execute "silent !zathura --synctex-forward " . line('.') . ":" . col('.') . ":" . bufname('%') . " " . expand('%:t:r') . ".pdf" redraw! endfunction imap FTT \texttt{}i imap FBF \textbf{}i imap FIT \textit{}i imap FSC \textsc{}i imap MTT \mathtt{}i imap MBF \mathbf{}i imap MIT \mathit{}i imap MSC \mathsc{}i imap MCC \mathcal{}<++>T{i inoremap /<++>cf> noremap /<++>cf> vnoremap `it `>a}` vnoremap `bf `>a}` vnoremap `tt `>a}` vnoremap `mi `>a}` vnoremap `mb `>a}` vnoremap `mt `>a}` " put \begin{} \end{} tags tags around the current word vnoremap YpkI\begin{A}jI\end{A}kA nmap :call Synctex() "setlocal spell spelllang=en_US call CompileMainDoc() " autocmd BufRead *.tex imap /\ \land " autocmd BufRead *.tex imap \/ \lor " autocmd BufRead *.tex imap -> \rightarrow " autocmd BufRead *.tex imap ~~ \neg