@@ -34,7 +34,8 @@ function! vimtex#state#class#new(opts) abort " {{{1
3434 \ ? vimtex#parser#preamble (l: new .tex, {' root' : l: new .root})
3535 \ : []
3636
37- let l: new .documentclass = s: parse_documentclass (l: preamble )
37+ let [l: new .documentclass, l: new .documentclass_options] =
38+ \ s: parse_documentclass (l: preamble )
3839 let l: new .packages = s: parse_packages (l: preamble )
3940 let l: new .graphicspath = s: parse_graphicspath (l: preamble , l: new .root)
4041 let l: new .glossaries = s: parse_glossaries (
@@ -74,6 +75,16 @@ function! s:vimtex.__pprint() abort dict " {{{1
7475 call add (l: items , [' document class' , self .documentclass])
7576 endif
7677
78+ if exists (' self.documentclass_options' )
79+ let l: string = join (map (sort (keys (self .documentclass_options)),
80+ \ {_, key - > key .." =" ..
81+ \ (self .documentclass_options[key ]== v: true ? ' true' :
82+ \ self .documentclass_options[key ] == v: false ? ' false' :
83+ \ self .documentclass_options[key ])
84+ \ }))
85+ call add (l: items , [' document class options' , l: string ])
86+ endif
87+
7788 if ! empty (self .packages)
7889 call add (l: items , [' packages' , join (sort (keys (self .packages)))])
7990 endif
@@ -194,9 +205,37 @@ endfunction
194205
195206
196207function ! s: parse_documentclass (preamble) abort " {{{1
197- let l: preamble_lines = filter (copy (a: preamble ), {_, x - > x !~# ' ^\s*%' })
198- return matchstr (join (l: preamble_lines , ' ' ),
199- \ ' \\documentclass[^{]*{\zs[^}]\+\ze}' )
208+ " Remove EOL comments and then join
209+ let l: preamble_joined = join (map (copy (a: preamble ),
210+ \ {_, x - > split (x ..' ' , ' %' )[0 ]}), ' ' )
211+
212+ let l: docclass = matchstr (l: preamble_joined , ' \\documentclass[^{]*{\zs[^}]\+\ze}' )
213+
214+ let l: docclass_options = {}
215+ let l: unparsed = matchstr (l: preamble_joined , ' \\documentclass[^\[]*\[\zs[^\]]\+\ze\]' )
216+ for l: el in map (split (l: unparsed , ' ,' ), {_, x - > trim (x )})
217+ if l: el == ' '
218+ " Empty option
219+ continue
220+ elseif l: el = ~ ' ='
221+ " Key-value option
222+ let [l: key , l: value ] = map (split (l: el , ' =' ), {_, x - > trim (x )} )
223+
224+ if l: value == ? ' true'
225+ let l: docclass_options [l: key ] = v: true
226+ elseif l: value == ? ' false'
227+ let l: docclass_options [l: key ] = v: false
228+ else
229+ let l: docclass_options [l: key ] = l: value
230+ endif
231+
232+ else
233+ " Key-only option
234+ let l: docclass_options [l: el ] = v: true
235+ endif
236+ endfor
237+
238+ return [l: docclass , l: docclass_options ]
200239endfunction
201240
202241" }}}1
0 commit comments