" ============================================================================== " Author: Carl Mueller " (incorporated into latex-suite by Srinath Avadhanula) " Last Change: Tue Dec 31 11:00 AM 2002 PST " Description: " This ftplugin provides the following maps: " . encloses the previous character in \mathbf{} " . is polymorphic as follows: " Insert mode: " 1. If the previous character is a letter or number, then capitalize it and " enclose it in \mathcal{} " 2. otherwise insert \cite{} " Visual Mode: " 1. Enclose selection in \mathcal{} " . is also polymorphic as follows: " If the character before typing is one of '([{| \left(\right " similarly for [, | " { \left\{\right\} " 2. < \langle\rangle " 3. q \lefteqn{} " otherwise insert \label{} " " These functions make it extremeley easy to do all the \left \right stuff in " latex. " " NOTE: The insert mode maps are created only if maps are no maps already to " the relevant functions Tex_MathBF, Tex_MathCal and Tex_LeftRight. This is to " enable people who might need the alt keys for typing to use some other " keypress to trigger the same behavior. In order to use some other key, (say " ) to use Tex_MathCal(), do the following " " inoremap =Tex_MathCal() " " ============================================================================== " Avoid reinclusion. if exists('b:did_brackets') finish endif let b:did_brackets = 1 " ============================================================================== " Insert mode mappings " All the insert mode mappings check to see if the function they are creating " the map for already exists in the rhs of some map. " ============================================================================== " {{{ " Provide 'd mapping for easy user customization. " inoremap Tex_MathBF =Tex_MathBF() inoremap Tex_MathCal =Tex_MathCal() inoremap Tex_LeftRight =Tex_LeftRight() " Provide mappings only if the user hasn't provided a map already or if the " target lhs doesn't have a mapping. " TODO: These will be removed in future revisions. Alt mappings are a headache " for European users... if !hasmapto('Tex_MathBF', 'i') && mapcheck('', 'i') == '' imap Tex_MathBF endif if !hasmapto('Tex_MathCal', 'i') && mapcheck('', 'i') == '' imap Tex_MathCal endif if !hasmapto('Tex_LeftRight', 'i') && mapcheck('', 'i') == '' imap Tex_LeftRight endif " }}} " ============================================================================== " Visual/Normal Mode mappings. " ============================================================================== " {{{ vnoremap `>a}` vnoremap `>a}` nnoremap :call PutLeftRight() " }}} " ============================================================================== " Function definitions " ============================================================================== " define the funtions only once. if exists('*Tex_MathBF') finish endif " Tex_MathBF: encloses te previous letter/number in \mathbf{} {{{ " Description: function! Tex_MathBF() return "\\\mathbf{\}\hvUla" endfunction " }}} " Tex_MathCal: enclose the previous letter/number in \mathcal {{{ " Description: " if the last character is not a letter/number, then insert \cite{} function! Tex_MathCal() let line = getline(line(".")) let char = line[col(".")-2] if char =~ '[a-zA-Z0-9]' return "\".'\mathcal{'.toupper(char).'}' else return IMAP_PutTextWithMovement('\cite{<++>}<++>') endif endfunction " }}} " Tex_LeftRight: maps in insert mode. {{{ " Description: " This is a polymorphic function, which maps the behaviour of in the " following way: " If the character before typing is one of '([{| \left(<++>\right<++> " similarly for [, | " { \left\{<++>\right\}<++> " 2. < \langle<++>\rangle<++> " 3. q \lefteqn{<++>}<++> " otherwise insert \label{<++>}<++> function! Tex_LeftRight() let line = getline(line(".")) let char = line[col(".")-2] let previous = line[col(".")-3] let matchedbrackets = '()[]{}||' if char =~ '(\|\[\|{\||' let add = '' if char =~ '{' let add = "\\" endif let rhs = matchstr(matchedbrackets, char.'\zs.\ze') return "\".IMAP_PutTextWithMovement('\left'.add.char.'<++>\right'.add.rhs.'<++>') elseif char == '<' return "\".IMAP_PutTextWithMovement('langle<++>\rangle<++>') elseif char == 'q' return "\".IMAP_PutTextWithMovement('\lefteqn{<++>}<++>') else return IMAP_PutTextWithMovement('\label{<++>}<++>') endif endfunction " }}} " Tex_PutLeftRight: maps in normal mode {{{ " Description: " Put \left...\right in front of the matched brackets. function! Tex_PutLeftRight() let previous = getline(line("."))[col(".") - 2] let char = getline(line("."))[col(".") - 1] if previous == '\' if char == '{' exe "normal ileft\\\l%iright\\\l%" elseif char == '}' exe "normal iright\\\l%ileft\\\l%" endif elseif char =~ '\[\|(' exe "normal i\\left\l%i\\right\l%" elseif char =~ '\]\|)' exe "normal i\\right\l%i\\left\l%" endif endfunction " }}} " vim:fdm=marker