Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions autoload/vimtex/syntax/p/tabularx.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,27 @@

function! vimtex#syntax#p#tabularx#load(cfg) abort " {{{1
call vimtex#syntax#packages#load('array')

" The format is \begin{tabularx}{WIDTH}[POS]{PREAMBLE}
syntax match texCmdTabularx "\\begin{tabularx}"
\ skipwhite skipnl
\ nextgroup=texTabularxWidth
\ contains=texCmdEnv
call vimtex#syntax#core#new_arg('texTabularxWidth', {
\ 'next': 'texTabularxPreamble,texTabularxOpt,',
\ 'contains': 'texLength',
\})
call vimtex#syntax#core#new_opt('texTabularxOpt', {
\ 'next': 'texTabularxPreamble',
\ 'contains': 'texComment,@NoSpell',
\})
call vimtex#syntax#core#new_arg('texTabularxPreamble', {
\ 'contains': '@texClusterTabular'
\})

highlight def link texTabularxPreamble texOpt
highlight def link texTabularxWidth texLength
highlight def link texTabularxOpt texEnvOpt
endfunction

" }}}1
13 changes: 13 additions & 0 deletions test/test-syntax/test-tabularx.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
\documentclass{article}

\usepackage{tabularx}

\begin{document}
\begin{tabularx}{\linewidth}{llXX}
1 & 2 & 3 & 4 \\
\end{tabularx}

\begin{tabularx}{\linewidth}[pos]{llXX}
1 & 2 & 3 & 4 \\
\end{tabularx}
\end{document}
17 changes: 17 additions & 0 deletions test/test-syntax/test-tabularx.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
source common.vim

silent edit test-tabularx.tex

set spell

if empty($INMAKE) | finish | endif

call assert_true(vimtex#syntax#in('texCmdTabularx', 6, 2))
call assert_true(vimtex#syntax#in('texTabularxWidth', 6, 20))
call assert_true(vimtex#syntax#in('texTabularxPreamble', 6, 32))

call assert_true(vimtex#syntax#in('texCmdTabularx', 10, 2))
call assert_true(vimtex#syntax#in('texTabularxWidth', 10, 20))
call assert_true(vimtex#syntax#in('texTabularxOpt', 10, 32))
call assert_true(vimtex#syntax#in('texTabularxPreamble', 10, 37))
call vimtex#test#finished()