I am using Vim + LaTeX-Suite plugin to write LaTeX source file. I noticed that LaTeX-Suite would automatically italicize characters in \textit
.
Is there a way to enable this behavior for \emph
as well?
Note that, unlike \textit
, \emph
acts as a switch to indicate emphasis. So when used in regular text \emph
is by default defined as italics, but within already emphasized text \emph
switches back to upright. Therefore it is not fully semantically correct to highlight \emph
as italics in the editor.
However, it can be done without too much trouble. The highlighting comes from Vim itself, not from Latex-Suite. The syntax highlighting definitions are stored in a directory similar to /usr/share/vim/vim80/syntax
(the exact location can be different depending on your installation method and version). In the file tex.vim
the highlighting for LaTeX is defined. Vim can read additional highlighting definitions from files placed in ~/.vim/after/syntax
. So you can copy the relevant definitions for \textit
from the original tex.vim
files, substitute \emph
and save this as an additional file in the /after/syntax
directory.
In the following file the first two blocks are copied from the original tex.vim
to define the variables tex_fast
and tex_conceal
, the third block contains the actual definitions for \emph
. Note that I did not implement bold+emphasized combinations.
~/.vim/after/syntax/tex.vim
:
" by default, enable all region-based highlighting
let s:tex_fast= "bcmMprsSvV"
if exists("g:tex_fast")
if type(g:tex_fast) != 1
" g:tex_fast exists and is not a string, so
" turn off all optional region-based highighting
let s:tex_fast= ""
else
let s:tex_fast= g:tex_fast
endif
endif
" let user determine which classes of concealment will be supported
" a=accents/ligatures d=delimiters m=math symbols g=Greek s=superscripts/subscripts
if !exists("g:tex_conceal")
let s:tex_conceal= 'abdmgsS'
else
let s:tex_conceal= g:tex_conceal
endif
" particular support for emph {{{1
if s:tex_fast =~# 'b'
if s:tex_conceal =~# 'b'
if !exists("g:tex_nospell") || !g:tex_nospell
syn region texItalStyle matchgroup=texTypeStyle start="\\emph\s*{" matchgroup=texTypeStyle end="}" concealends contains=@texItalGroup,@Spell
else
syn region texItalStyle matchgroup=texTypeStyle start="\\emph\s*{" matchgroup=texTypeStyle end="}" concealends contains=@texItalGroup
endif
endif
endif
Screenshot from Vim: