Skip to content

Commit

Permalink
feat(syntax): add initial support for unicode-math
Browse files Browse the repository at this point in the history
refer: #3004
  • Loading branch information
lervag committed Oct 3, 2024
1 parent 454082a commit fcbaf66
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
58 changes: 58 additions & 0 deletions autoload/vimtex/syntax/p/unicode_math.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
" VimTeX - LaTeX plugin for Vim
"
" Maintainer: Karl Yngve Lervåg
" Email: [email protected]
"

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
27 changes: 27 additions & 0 deletions test/test-syntax/test-unicode-math.tex
Original file line number Diff line number Diff line change
@@ -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}
7 changes: 7 additions & 0 deletions test/test-syntax/test-unicode-math.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source common.vim

EditConcealed test-unicode-math.tex

if empty($INMAKE) | finish | endif

call vimtex#test#finished()

0 comments on commit fcbaf66

Please sign in to comment.