Am Dienstag, 18. Juli 2017, 04:04:51 CEST schrieb Aditya Mahajan:
On Mon, 17 Jul 2017, Gerion Entrup wrote:
Hi,
I have two questions with the vim module.
1. I want to use the math mode inside the code. I've seen the escape option, e.g. here [1], but this seems to work only with comments. Is there a possibility to use it directly in the code, too?
Short answer. No.
Long answer. t-vim relies on vim to syntax highlight the code. Since the code is not valid python, the default python syntax highlighting will not work. In principle, it is possible to write a vim syntax highlighting script for a derivative of python where math terms are allowed, but that requires a lot of work for each language. The whole point of t-vim module was that I am lazy and don't want to write the parser for each language :-)
I've invested some time and rewrote parts of the vimscript file of t-vim. Now one or more escapechars can be defined, that helps vim to not interpret the text: ``` \usemodule[vim] \definevimtyping[python][syntax=python] \definevimtyping[cpp][syntax=cpp] \starttext \startpython # Returns range(°\m{\sum_{i=1}^{n}i \in F \int_i f}° def sum_upto(°\m{n \in \mathbb{N} \sum_{i=1}}°) r = range(1, °\m{n}° + °\m{\sum_{i=1} 1}°) return sum(r) \stoppython \startcpp foobar(°\m{q_0}°); \stopcpp \stoptext ``` I'm not familiar enough with TeX or ConTeXt to get the TeX part to work, so the escapechar '°' is hardcoded at the moment. If you like the patch, this has to be fixed. Another problem, as you see in the above example, is, that vim interprets the second ')' in the startcpp section as color code "Error", so the whole part is colorized. This can be circumventented with the escapechars '°"', but I have no idea how to teach tex/lua to not interpret the '"'. Simply writing -c "let escapechar='°\"'" % etc. in the t-vim.tex does not work. Another point I saw is, that highlight together with TeX-code is not really usable: ``` \usemodule[vim] \definevimtyping[python][syntax=python, escape=on] \starttext \startpython[highlight=1] # Returns \m{\sum_{i=1}^{n}i \in F \int_i f} \stoppython \stoptext ```
Minimal example: ``` \usemodule[vim] \definevimtyping[python][syntax=python, escape=on]
\starttext \startpython # Returns \m{\sum_{i=1}^{n}i} def sum_upto(\m{n \in \mathbb{N}}) r = range(1, \m{n} + 1) return sum(r) \stoppython \stoptext ```
Another option will be to use the algorithmic module: https://bitbucket.org/wolfs/algorithmic/src/
2. It would be cool, if I can define some background color for the code. Unfortunately I'm very new to context and haven't seen a direct option. I assume this is possible with some kind of extra environment around the code?
You can add
\setupbackground[background=color, backgroundcolor=gray]
\setupvimtyping[python] [ before={\startbackground}, after={\stopbackground}, ]
or, instead of modifying the default background, define a new background and use that. OK, thank you.
Gerion