Don't format lines inside math envs (#436)

This commit is contained in:
Karl Yngve Lervåg 2016-07-24 21:57:29 +02:00
parent 0db96d9d97
commit e66c07ff8f
2 changed files with 45 additions and 0 deletions

View File

@ -14,7 +14,9 @@ function! vimtex#format#init_script() " {{{1
\ '\\item', \ '\\item',
\ '\\begin', \ '\\begin',
\ '\\end', \ '\\end',
\ '%(\\\[|\$\$)\s*$',
\], '|') . ')' \], '|') . ')'
let s:border_end = '\v[^\\]\%' let s:border_end = '\v[^\\]\%'
\ . '|\\%(' . join([ \ . '|\\%(' . join([
\ '\\\*?', \ '\\\*?',
@ -24,6 +26,7 @@ function! vimtex#format#init_script() " {{{1
\ 'pagebreak', \ 'pagebreak',
\ '%(begin|end)\{[^}]*\}', \ '%(begin|end)\{[^}]*\}',
\ ], '|') . ')\s*$' \ ], '|') . ')\s*$'
\ . '|^\s*%(\\\]|\$\$)\s*$'
endfunction endfunction
" }}}1 " }}}1
@ -52,6 +55,12 @@ function! vimtex#format#formatexpr() " {{{1
for l:current in range(l:bottom, l:top, -1) for l:current in range(l:bottom, l:top, -1)
let l:line = getline(l:current) let l:line = getline(l:current)
if vimtex#util#in_mathzone(l:current, 1)
\ && vimtex#util#in_mathzone(l:current, col([l:current, '$']))
let l:mark = l:current - 1
continue
endif
if l:line =~# s:border_end if l:line =~# s:border_end
if l:current < l:mark if l:current < l:mark
execute 'normal!' (l:current+1) . 'Ggw' . l:mark . 'G' execute 'normal!' (l:current+1) . 'Ggw' . l:mark . 'G'

View File

@ -96,3 +96,39 @@ Expect tex (Verify):
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Given tex (Format: With math):
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed
diam nonumy eirmod tempor invidunt asd asdj klkut \( g(x)
= 4\) labore et dolore magna aliquyam erat, sed diam volu.
$f(x) = 3$ vero eos et accusam et justo duo dolores et ea
\begin{align}
f(x) &= 1 \\
g(x) &= 2
\end{align}
rebum. Stet clita kasd gubergren, no sea takimata sanctus
est Lorem ipsum dolor sit amet.
\[
e^{2\pi i} = 1
\]
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed
diam nonumy eirmod tempor invidunt asd asdj klkut labore et
Do (Format text):
gqG
Expect tex (Verify):
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt asd asdj klkut \( g(x) = 4\) labore et dolore magna aliquyam
erat, sed diam volu. $f(x) = 3$ vero eos et accusam et justo duo dolores et ea
\begin{align}
f(x) &= 1 \\
g(x) &= 2
\end{align}
rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor
sit amet.
\[
e^{2\pi i} = 1
\]
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt asd asdj klkut labore et