" LaTeX filetype plugin " Language: LaTeX (ft=tex) " Maintainer: Srinath Avadhanula " URL: http://vim.sourceforge.net/scripts/script.php?script_id=93 " Last Change: Thu Mar 21 06:00 AM 2002 PST " " Help: " NOTE: the macros which were previously placed in this file have been moved " to the plugin imaps.vim (get it from http://vim.sf.net). " " Changes: {{{ " Mar 17 2002: 1. added errorformat and makeprg options for latex. " 2001 Dec 9: 1. took some stuff from auctex.vim " such as smart quotes and dollar, etc. " 2001 Dec 7: 1. changed things so that most mappings emulate the operator " pending mode. this greatly facilitates typing by not " requiring the LHS to be typed quickly. one can infact type " the LHS (without the ), roam around in the file, come " back to the end of the file, press and still have the " LHS expand properly! " 2. planning a second release for this. " }}} " $Id: tex.vim,v 1.28 2006/08/10 09:25:13 rajo Exp $ set fileencoding=latin2 if exists("b:didLocalTex") finish end let b:didLocalTex = 1 let s:save_cpo = &cpo set cpo&vim setlocal isk+=: setlocal sw=4 setlocal ts=4 setlocal textwidth=72 setlocal formatoptions=croqt setlocal iskeyword=@,161-255,\\ " disable IMAP() function in math environments let b:disabled_imap_syntax_items = "texMathZone\\|texStatement" if &encoding == 'utf-8' let b:input_method = &encoding else let b:input_method = "tex-iso8859-2" endif call UseDiacritics() " These lines come from $VIMRUNTIME/ftplugin/tex.vim (modified by Lubomir Host) {{{ " Thanks to Benji Fisher, Ph.D. let s:save_cpo = &cpo set cpo&vim " Set 'comments' to format dashed lists in comments setlocal comments=sO:%\ -,mO:%\ \ ,eO:%%,:% " Allow "[d" to be used to find a macro definition: " Recognize plain TeX \def as well as LaTeX \newcommand and \renewcommand . setlocal define=\\\\def\\\\|\\\\\\(re\\)\\=newcommand{ " Tell Vim how to recognize LaTeX \include{foo} and plain \input bar : setlocal include=\\\\input\\\\|\\\\include{ setlocal includeexpr=s:TexIncludeExpr() if !exists("*s:TexIncludeExpr") fun! s:TexIncludeExpr() " On some file systems, "}" is inluded in 'isfname'. In case the " TeX file has \include{fname} (LaTeX only), strip the "}" and " any other trailing characters. let fname = substitute(v:fname, '}.*', '', '') " Now, add ".tex" if there is no other file extension. if fname !~ '\.' let fname = fname . '.tex' endif return fname endfun endif " The following lines enable the macros/matchit.vim plugin for " extended matching with the % key. if exists("loaded_matchit") let b:match_ignorecase = 0 \ | let b:match_skip = 'r:\\\@', '\ge', "tex") call IMAP ('`,', '\nonumber', "tex") " call IMAP ('`~', '\tilde{ää}«»', "tex") call IMAP ('`~', '\tilde{ää}', "tex") " call IMAP ('`;', '\dot{ää}«»', "tex") call IMAP ('`;', '\dot{ää}', "tex") " call IMAP ('`:', '\ddot{ää}«»', "tex") call IMAP ('`:', '\ddot{ää}', "tex") " call IMAP ('`2', '\sqrt{ää}«»', "tex") call IMAP ('`2', '\sqrt{ää}', "tex") call IMAP ('`|', '\Big|', "tex") " call IMAP ('`I', "\\int_{ää}^{«»}«»", 'tex') call IMAP ('`I', "\\int_{ää}^{}", 'tex') " }}} " latex environments (my style) originally in imaps.vim {{{ call IMAP ("bar".s:ml, "\\leftää\\\begin{array}{«dimension»}\«elements»\\\end{array}\\\right«»", "tex") call IMAP ("ben".s:ml, "\\begin{enumerate}\\\item ää\\\end{enumerate}«»", "tex") call IMAP ("bit".s:ml, "\\begin{itemize}\\\item ää\\\end{itemize}«»", "tex") call IMAP ("beq".s:ml, "\\begin{equation}\\\label{ää}\\\end{equation}«»", "tex") call IMAP ("bqn".s:ml, "\\begin{eqnarray}\ää\\\end{eqnarray}«»", "tex") call IMAP ("bfg".s:ml, "\\begin{figure}[h]\\\centerline{\\psfig{figure=«eps file»}}\\\caption{«caption text»}\\\label{fig:«label»}\\\end{figure}«»", "tex") call IMAP ("bfe".s:ml, "\\begin{figure}\\\vspace{ää}\\\caption{«caption text»}\\\end{figure}«»", "tex") call IMAP ("btb".s:ml, "\\begin{tabular}{ää}\\\\end{tabular}«»", "tex") call IMAP ("bta".s:ml, "\\begin{table}\\\centering\\\caption{tab:ää}\\\begin{tabular}{«dimensions»}\\\\end{tabular}\\\label{tab:«label»}\\\end{table}«»", "tex") call IMAP ("pic".s:ml, "\\begin{picture}(4,4)\\\put(0.5,0){\\framebox(4,4){ää}}\\\end{picture}«»", "tex") call IMAP ("mat".s:ml, "\\left[\\\begin{array}{ää}\«»\\\end{array}\\\right]«»", "tex") call IMAP ("verb".s:ml, "\\begin{verbatim}\\ää\\end{verbatim}«»", "tex") call IMAP ("minip".s:ml, "\\begin{minipage}[t]{ääcm}\\\end{minipage}«»", "tex") " end my style latex environments }}} " latex environments from Mikolaj Machowski {{{ function! TeX_imap_env(shortcut,env) " exe 'call IMAP ("'.a:shortcut.'", "\\begin{'.a:env.'}\ää\\\end{'.a:env.'}«»", "tex")' exe 'call IMAP ("'.a:shortcut.'", "\\begin{'.a:env.'}\ää\\\end{'.a:env.'}", "tex")' endfunction call TeX_imap_env("EAB","abstract") call TeX_imap_env("EAP","appendix") call TeX_imap_env("EAR","array") call TeX_imap_env("ECE","center") call TeX_imap_env("EDE","description") call TeX_imap_env("EDI","displaymath") call TeX_imap_env("EDO","document") call TeX_imap_env("EEN","enumerate") call TeX_imap_env("EEA","eqnarray") call TeX_imap_env("EEQ","equation") call TeX_imap_env("EFI","figure") call TeX_imap_env("EFC","filecontents") call TeX_imap_env("EFL","flushleft") call TeX_imap_env("EFR","flushright") call TeX_imap_env("EIT","itemize") call TeX_imap_env("ELE","letter") call TeX_imap_env("ELI","list") call TeX_imap_env("ELR","lrbox") call TeX_imap_env("EMA","math") call TeX_imap_env("EMI","minipage") call TeX_imap_env("ENO","note") call TeX_imap_env("EOV","overlay") call TeX_imap_env("EPI","picture") call TeX_imap_env("EQN","quotation") call TeX_imap_env("EQE","quote") call TeX_imap_env("ESL","slide") call TeX_imap_env("ESB","sloppybar") call TeX_imap_env("ETA","tabbing") call TeX_imap_env("ETE","table") call TeX_imap_env("ETR","tabular") call TeX_imap_env("ETB","thebibliography") call TeX_imap_env("ETI","theindex") call TeX_imap_env("ETH","theorem") call TeX_imap_env("ETP","titlepage") call TeX_imap_env("ETL","trivlist") call TeX_imap_env("EVB","verbatim") call TeX_imap_env("EVS","verse") " }}} " other miscellaneous stuff taken from imaps.vim. {{{ call IMAP ("vb".s:ml, "\\verb|ää|«»", "tex") call IMAP ("bf".s:ml, "{\\bf ää}«»", "tex") call IMAP ("em".s:ml, "{\\em ää}«»", "tex") call IMAP ("it".s:ml, "{\\it ää}«»", "tex") call IMAP ("mb".s:ml, "\\mbox{ää}«»", "tex") call IMAP ("frac".s:ml, "\\frac{ää}{«»}«»", "tex") call IMAP ("sq".s:ml, "\\sqrt{ää}«»", "tex") call IMAP ("eps".s:ml, "\\psfig{figure=ää.eps}«»", "tex") call IMAP ("sec".s:ml, "\\section{ää}«»", "tex") call IMAP ("ssec".s:ml, "\\subsection{ää}«»", "tex") call IMAP ("sssec".s:ml, "\\subsubsection{ää}«»", "tex") call IMAP ("sec2".s:ml, "\\subsection{ää}«»", "tex") call IMAP ("sec3".s:ml, "\\subsubsection{ää}«»", "tex") call IMAP ("sum".s:ml, "\\sum{ää}{«»}«»", "tex") call IMAP ("suml".s:ml, "\\sum\\limits_{ää}^{«»}«»", "tex") call IMAP ("int".s:ml, "\\int_{ää}^{«»}«»", "tex") call IMAP ("intl".s:ml, "\\int\\limits_{ää}^{«»}«»", "tex") call IMAP ("bbr".s:ml, "\\left( ää \\right)«»", "tex") call IMAP ("bbc".s:ml, "\\left\\{ ää \\right\\}«»", "tex") call IMAP ("bbs".s:ml, "\\left[ ää \\right]«»", "tex") call IMAP ("rr".s:ml, "\\right", "tex") call IMAP ("ll".s:ml, "\\left", "tex") call IMAP ("part".s:ml, "\\partial", "tex") call IMAP ("dot".s:ml, "\\dot{ää}«»", "tex") call IMAP ("ddot".s:ml, "\\ddot{ää}«»", "tex") " }}} " Greek letters imaps.vim style {{{ call IMAP('`a', "\\alpha", "tex") call IMAP('`b', "\\beta", "tex") call IMAP('`c', "\\chi", "tex") call IMAP('`d', "\\delta", "tex") call IMAP('`e', "\\varepsilon", 'tex') call IMAP('`f', "\\varphi", 'tex') call IMAP('`g', "\\gamma", "tex") call IMAP('`h', "\\eta", "tex") call IMAP('`k', "\\kappa", "tex") call IMAP('`l', "\\lambda", "tex") call IMAP('`m', "\\mu", "tex") call IMAP('`n', "\\nu", "tex") call IMAP('`p', "\\pi", "tex") call IMAP('`q', "\\theta", "tex") call IMAP('`r', "\\rho", "tex") call IMAP('`s', "\\sigma", "tex") call IMAP('`t', "\\tau", "tex") call IMAP('`u', "\\upsilon", "tex") call IMAP('`v', "\\varsigma", "tex") call IMAP('`w', "\\omega", "tex") " call IMAP('`w', "\\wedge", 'tex') " AUCTEX style call IMAP('`x', "\\xi", "tex") call IMAP('`y', "\\psi", "tex") call IMAP('`z', "\\zeta", "tex") call IMAP('`A', "\\Alpha", "tex") call IMAP('`B', "\\Beta", "tex") call IMAP('`C', "\\Chi", "tex") call IMAP('`D', "\\Delta", "tex") call IMAP('`E', "\\Epsilon", "tex") call IMAP('`F', "\\Phi", "tex") call IMAP('`G', "\\Gamma", "tex") call IMAP('`H', "\\Eta", "tex") call IMAP('`K', "\\Kappa", "tex") call IMAP('`L', "\\Lambda", "tex") call IMAP('`M', "\\Mu", "tex") call IMAP('`N', "\\Nu", "tex") call IMAP('`P', "\\Pi", "tex") call IMAP('`Q', "\\Theta", "tex") call IMAP('`R', "\\Rho", "tex") call IMAP('`S', "\\Sigma", "tex") call IMAP('`T', "\\Tau", "tex") call IMAP('`U', "\\Upsilon", "tex") call IMAP('`V', "\\Varsigma", "tex") call IMAP('`W', "\\Omega", "tex") call IMAP('`X', "\\Xi", "tex") call IMAP('`Y', "\\Psi", "tex") call IMAP('`Z', "\\Zeta", "tex") " }}} " vmaps: enclose selected region in brackts, environments {{{ vnoremap ( "rxi\left(\right)k"rP vnoremap [ "rxi\left[\right]k"rP vnoremap { "rxi\left\{\right\}k"rP vnoremap v "rxi\begin{verbatim}\end{verbatim}k"rP vnoremap c "rxi\begin{center}\end{center}k"rP " }}} end " }}} " RunLaTeX: compilation function {{{ " this function runs the latex command on the currently open file. often times " the file being currently edited is only a fragment being \input'ed into some " master tex file. in this case, make a file called mainfile.latexmain in the " directory containig the file. in other words, if the current file is " ~/thesis/chapter.tex " so that doing "latex chapter.tex" doesnt make sense, then make a file called " main.tex.latexmain " in the ~/thesis directory. this will then run "latex main.tex" when " RunLaTeX() is called. function! RunLaTeX() if &ft != 'tex' echo "calling RunLaTeX from a non-tex file" return end let dir = expand("%:p:h").'/' let curd = getcwd() exec 'cd '.expand("%:p:h") if glob(dir.'*.latexmain') != '' let lheadfile = glob(dir.'*.latexmain') let mainfname = fnamemodify(lheadfile, ":t:r") exec 'make '.mainfname else make % endif cwindow exec 'cd '.curd endfunction if !hasmapto('RunLaTeX') if has("gui") nnoremap ll :silent! call RunLaTeX() else nnoremap ll :call RunLaTeX() end end " }}} " set up the latex compiler {{{ if filereadable(expand(':p:h:h').'/compiler/tex.vim') exe "source ".expand(':p:h:h')."/compiler/tex.vim" else runtime! compiler/tex.vim end " }}} " ----------------------------------------------------------------------------- " Smart functions " ----------------------------------------------------------------------------- " TexQuotes: inserts `` or '' instead of " {{{ " the functions in this section taken from auctex.vim " Smart quotes. Thanks to Ron Aaron . " typing " after whitespace results in `` otherwise '' function! s:TexQuotes() let s:insert = "''" let s:left = getline(line("."))[col(".")-2] if s:left == ' ' || s:left == '' || s:left == ' ' " Tab let s:insert = '``' elseif s:left == '\' let s:insert = '"' endif return s:insert endfunction " disabled: "imap " =TexQuotes() " }}} " SmartBS: smart backspacing {{{ " set regular expresion for Smart backspacing let g:smartBS_tex = '\(' . \ "\\\\[\"^'=v]{\\S}" . '\|' . \ "\\\\[\"^'=]\\S" . '\|' . \ '\\v \S' . '\|' . \ "\\\\[\"^'=v]{\\\\[iI]}" . '\|' . \ '\\v \\[iI]' . '\|' . \ '\\q \S' . '\|' . \ '\\-' . \ '\)' . "$" " map to function SmartBS() inoremap =SmartBS() " }}} " MakeTexFolds: see ../plugin/syntaxFolds.vim for documentation {{{ function! MakeTexFolds(force) " the order in which these calls are made decides the nestedness. in " latex, a table environment will always be embedded in either an item or " a section etc. not the other way around. so we first fold up all the " tables. and then proceed with the other regions. let b:startPat_1 = '^\s*\\begin{table}' let b:endPat_1 = '^\s*\\end{table}' let b:startOff_1 = 0 let b:endOff_1 = 0 let b:startPat_2 = '^\s*\\begin{figure}' let b:endPat_2 = '^\s*\\end{figure}' let b:startOff_2 = 0 let b:endOff_2 = 0 let b:startPat_3 = '^\s*\\begin{eq' let b:endPat_3 = '^\s*\\end{eq' let b:startOff_3 = 0 let b:endOff_3 = 0 " both versions for taking care of nestedness of the itemize environments " work, but the lower one is more general and results in greater " recursion. let b:startPat_4 = '^\s*\\item' let b:endPat_4 = '^\s*\\item\|^\s*\\end{\(enumerate\|itemize\|description\)}' let b:startOff_4 = 0 let b:endOff_4 = -1 let b:skipStartPat_4 = '^\s*\\begin{\(enumerate\|itemize\)}' " let b:skipStartPat_4 = '^\s*\\begin' let b:skipEndPat_4 = '^\s*\\end' let b:startPat_5 = '^\s*\\subsubsection' let b:endPat_5 = '^\s*\\section\|^\s*\\subsection\|^\s*\\subsubsection' let b:startOff_5 = 0 let b:endOff_5 = -1 let b:startPat_6 = '^\s*\\subsection' let b:endPat_6 = '^\s*\\section\|^\s*\\subsection' let b:startOff_6 = 0 let b:endOff_6 = -1 let b:startPat_7 = '^\s*\\section' let b:endPat_7 = '^\s*\\section' let b:startOff_7 = 0 let b:endOff_7 = -1 let b:startPat_8 = '^\s*\\chapter' let b:endPat_8 = '^\s*\\section' let b:startOff_8 = 0 let b:endOff_8 = -1 call MakeSyntaxFolds(a:force) endfunction " }}} " TexFoldTextFunction: see ../plugin/syntaxFolds.vim for documentation {{{ function! TexFoldTextFunction() if getline(v:foldstart) =~ '^\s*\\begin{' let header = matchstr(getline(v:foldstart), '^\s*\\begin{\zs[^}]*\ze}') let caption = '' let label = '' let i = v:foldstart while i <= v:foldend if getline(i) =~ '^\s*\\caption' let caption = matchstr(getline(i), '\\caption{\zs.*\ze}') elseif getline(i) =~ '\\label' let label = matchstr(getline(i), '\\label{\zs.*\ze}') end let i = i + 1 endwhile let ftxto = foldtext() let retText = matchstr(ftxto, '^[^:]*').': '.header.' ('.label.') : '.caption return retText else return foldtext() end endfunction " }}} " source other related files. exe "so ".expand(':p:h').'/miktexmenus.vim' " TEX_ShowVariableValue: debugging help {{{ " provides a way to examine script local variables from outside the script. " very handy for debugging. function! TEX_ShowVariableValue(...) let i = 1 while i <= a:0 exe 'let arg = a:'.i if exists('s:'.arg) || \ exists('*s:'.arg) exe 'let val = s:'.arg echomsg 's:'.arg.' = '.val end let i = i + 1 endwhile endfunction " }}} augroup TeXFolds au! au FileType tex :set foldtext=TexFoldTextFunction() au FileType tex :call MakeTexFolds(0) au FileType tex :if mapcheck('') == "" \ | exe ':nnoremap :call MakeTexFolds(1)' \ | endif au FileType tex :nnoremap rf :call MakeTexFolds(1) augroup END augroup VIMFolds au! au FileType vim :if mapcheck('') == "" \ | exe ':nnoremap :call MakeVimFolds(1)' \ | endif augroup END " Modeline {{{ " vim:set ts=4: " vim600:fdm=marker fdl=0 fdc=3 nowrap: " }}}