diff --git a/autoload/vimtex/syntax/p/unicode_math.vim b/autoload/vimtex/syntax/p/unicode_math.vim new file mode 100644 index 0000000000..de1f291737 --- /dev/null +++ b/autoload/vimtex/syntax/p/unicode_math.vim @@ -0,0 +1,58 @@ +" VimTeX - LaTeX plugin for Vim +" +" Maintainer: Karl Yngve LervÄg +" Email: karl.yngve@gmail.com +" + +function! vimtex#syntax#p#unicode_math#load(cfg) abort " {{{1 + syntax match texMathCmdStyle contained "\\symbb\>" + syntax match texMathCmdStyle contained "\\symbf\>" + syntax match texMathCmdStyle contained "\\symcal\>" + syntax match texMathCmdStyle contained "\\symfrak\>" + syntax match texMathCmdStyle contained "\\symit\>" + syntax match texMathCmdStyle contained "\\symbfit\>" + syntax match texMathCmdStyle contained "\\symnormal\>" + syntax match texMathCmdStyle contained "\\symrm\>" + syntax match texMathCmdStyle contained "\\symsf\>" + syntax match texMathCmdStyle contained "\\symtt\>" + syntax match texMathCmdStyle contained "\\symscr\>" + + let [l:conceal, l:concealends] = + \ (g:vimtex_syntax_conceal.styles ? ['conceal', 'concealends'] : ['', '']) + + let l:map = { + \ 'texMathCmdStyleBold': 'texMathStyleBold', + \ 'texMathCmdStyleItal': 'texMathStyleItal', + \ 'texMathCmdStyleBoth': 'texMathStyleBoth', + \} + + for [l:group, l:pattern] in [ + \ ['texMathCmdStyleBold', 'symbf'], + \ ['texMathCmdStyleItal', 'symit'], + \ ['texMathCmdStyleBoth', 'symbfit'], + \] + execute 'syntax match' l:group '"\\' . l:pattern . '\>"' + \ 'contained skipwhite nextgroup=' . l:map[l:group] + \ l:conceal + endfor + + if g:vimtex_syntax_conceal.styles + syntax match texMathCmdStyle "\v\\sym%(rm|tt|normal|sf)>" + \ contained conceal skipwhite nextgroup=texMathStyleConcArg + endif + + if g:vimtex_syntax_conceal.math_symbols + for [l:cmd, l:alphabet_map] in [ + \ ['sym\%(bb\%(b\|m\%(ss\|tt\)\?\)\?\|ds\)', 'double'], + \ ['symfrak', 'fraktur'], + \ ['sym\%(scr\|cal\)', 'script'], + \ ['symbffrak', 'fraktur_bold'], + \ ['symbf\%(scr\|cal\)', 'script_bold'], + \] + let l:pairs = vimtex#syntax#core#get_alphabet_map(l:alphabet_map) + call vimtex#syntax#core#conceal_cmd_pairs(l:cmd, l:pairs) + endfor + endif +endfunction + +" }}}1 diff --git a/test/test-syntax/test-unicode-math.tex b/test/test-syntax/test-unicode-math.tex new file mode 100644 index 0000000000..e320368466 --- /dev/null +++ b/test/test-syntax/test-unicode-math.tex @@ -0,0 +1,27 @@ +\documentclass{minimal} +\usepackage{unicode-math} + +\begin{document} + +\begin{equation} + \symbb{P} + \symbf{test} + \symcal{a} + \symcal{A} + \symbfcal{a} + \symbfcal{A} + \symcal{aA} + \symfrak{b} + \symfrak{B} + \symbffrak{b} + \symbffrak{B} + \symit{italized} + \symbfit{bold itals} + \symnormal{Re} + \symrm{Re} + \symsf{aA} + \symtt{aA} + \symscr{aA} +\end{equation} + +\end{document} diff --git a/test/test-syntax/test-unicode-math.vim b/test/test-syntax/test-unicode-math.vim new file mode 100644 index 0000000000..5652ead326 --- /dev/null +++ b/test/test-syntax/test-unicode-math.vim @@ -0,0 +1,7 @@ +source common.vim + +EditConcealed test-unicode-math.tex + +if empty($INMAKE) | finish | endif + +call vimtex#test#finished()