Code Hilighting in ConTeXt

学完 ConTeXt 的基础知识之后,第一件事就是想找一个类似于 LaTeX 下面 listings 宏包这样的工具,来实现代码的自动语法高亮。经百般 Google 竟然未果。然而我死活不相信 ConTeXt 连这个功能都没有,于是发扬愚公移山的精神,埋头在 TeXLive 的 doc 里面一阵乱翻,居然就被我翻到了(幸亏 ConTeXt 的模块并不多),原来 ConTeXt 是用一个叫做 t-vim 的模块来干这事情的。这个名字起得实在太隐蔽了,根本看不出来跟语法高亮有任何的关系。再仔细看文档,原来这个模块是直接调用 vim 来生成语法高亮配置的。

然后照着文档随便写了一个代码。然后 ConTeXt 报错

VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Mar 8 2010 22:56:09)
Garbage after option argument: "-u NONE -e -C -n -c "set tabstop=8" -c "syntax on" -c "set syntax=sh" -c "let contextstartline=1" -c "let contextstopline=0" -c "source /opt/context-minimals/texmf-context/tex/context/third/vim/2context.vim" -c "wqa" "4-vimsyntax.tmp" "

传给 vim 的参数竟然有错,我大囧。研究了半天,似乎跟最后面那个空格有关系。于是看 t-vim.tex 源文件,修改了一下

@@ -329,7 +329,7 @@
 \def\runvimsyntax#1
    {\executesystemcommand
       {mtxrun --verbose --noquote bin:vim
-          "-u NONE  % No need to read unnessary configurations
+           -u NONE  % No need to read unnessary configurations
            -e       % run in ex mode
            -C       % Set compatibile
            -n       % No swap
@@ -341,7 +341,7 @@
            -c \shellescapedquote let contextstopline=\@@vsstop\shellescapedquote  \space
            -c \shellescapedquote source kpse:2context.vim\shellescapedquote\space
            -c \shellescapedquote wqa\shellescapedquote\space    
-            \shellescapedquote#1\shellescapedquote\space "}}
+            \shellescapedquote#1}}
 
 
 %D \macros{definetypevimfile}

就可以正常使用了

This entry was posted on Wednesday, April 7th, 2010 at 5:16 pm and is filed under 技术相关. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply