Reputation: 2647
I would like to exploit vim's syntax highlighting capabilities to highlight code (any language) in latex (using the xcolor package). Therefore I wonder if it is possible to have a vim-script export the vim internal information about the highlighted text in the buffer. Obviously it would be sufficient to know start, end and color of each highlighted entity. The generation of the latex code or other languages such as html would then be obvious.
Upvotes: 0
Views: 970
Reputation: 53654
You can use my formatvim plugin: it can export to latex-xcolor format with
Format format latex-xcolor
. If you are not fine with the result (it is completely untested and I almost never used this option) feel free to send patches, dictionary with format specification can be seen here, everything what you need to create your own format is in documentation.
Note: if you need to export to any other language all you need is to write a specification for it in terms of my plugin. Here is a code that will add latex-xcolor-clone
format to my plugin:
scriptencoding utf-8
execute frawor#Setup('0.0', {'plugin/format': '3.0'})
let s:texescape=
\'substitute('.
\ 'substitute(@@@, ''\v[\\\[\]{}&$_\^%#]'', '.
\ '''\=''''\char''''.char2nr(submatch(0))."{}"'', '.
\ '"g"),'.
\'" ", ''\\enskip{}'', "g")'
let s:texstylestart=
\'((@inverse@)?'.
\ '(''\colorbox[HTML]{''.'.
\ '((@fgcolor@!=#"")?'.
\ '(toupper(@fgcolor@[1:])):'.
\ '(toupper(@_fgcolor@[1:])))."}{".'.
\ '''\textcolor[HTML]{''.'.
\ '((@bgcolor@!=#"")?'.
\ '(toupper(@bgcolor@[1:])):'.
\ '(toupper(@_bgcolor@[1:])))."}{"):'.
\ '(((@bgcolor@!=#"")?'.
\ '(''\colorbox[HTML]{''.toupper(@bgcolor@[1:])."}{"):'.
\ '("")).'.
\ '''\textcolor[HTML]{''.'.
\ '((@fgcolor@!=#"")?'.
\ '(toupper(@fgcolor@[1:])):'.
\ '(toupper(@_fgcolor@[1:])))."}{"))'
let s:texstyleend=
\'repeat("}", '.
\ '((@inverse@)?'.
\ '(2):'.
\ '((@bgcolor@!=#"")+1)))'
let s:format={
\'begin': '\documentclass[a4paper,12pt]{article}'.
\ '\usepackage[utf8]{inputenc}'.
\ '\usepackage[HTML]{xcolor}'.
\ '\pagecolor[HTML]{%''toupper(@_bgcolor@[1:])''%}'.
\ '\color[HTML]{%''toupper(@_fgcolor@[1:])''%}'.
\ '\begin{document}{\ttfamily\noindent',
\'line': '%>'.s:texstylestart.".".
\ s:texescape.".".
\ s:texstyleend,
\'lineend': '\\',
\'end': '}\end{document}',
\'strescape': s:texescape,
\}
call s:_f.format.add('latex-xcolor-clone', s:format)
Upvotes: 3
Reputation: 196789
The :TOhtml
command is built in Vim. It, rather obviously, generates HTML, not Latex, though.
Upvotes: 0