On Thu, 20 Jul 2017, Henri Menke wrote:
On Wed, 2017-07-19 at 15:07 -0400, Aditya Mahajan wrote:
On Wed, 19 Jul 2017, Gerion Entrup wrote:
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:
I'll look at this later....
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 ```
By default, the highlighting is done using the bars mechanism. It works for simple cases but fails with math mode (the spaces are not covered). One option is to highlight using the textbackground mechanism:
\definetextbackground[texthighlight] [ background=color, backgroundcolor=gray, frame=off, ]
\define[1]\texthighlight{\starttexthighlight#1\stoptexthighlight}
\usemodule[vim] \definevimtyping[python][syntax=python, escape=on, highlightcommand=\texthighlight]
\starttext
\startpython[highlight=3] for x in 1:n print(x) # Returns \m{\sum_{i=1}^{n}i \in F \int_i f} for x in 1:n print(x) \stoppython \stoptext
The spacing in math mode is bad. What is happening is the following. To make sure that spaces are obeyed in the code listing, I set (a modified version of) \activatespacehandler{on}, so the output that you get is the following:
{\obeyspaces \def\obeyedspace{\hskip\interwordspace\relax} \m{\sum_{i=1}^{n}i \in F \int_i f}}
The simplest way to fix this is to define a new command:
\define[1]\MATH{\bgroup\activatespacehandler{off}\m{\rescan{#1}}\egroup}
Why not just this?
\def\obeyedspace{\ifmmode\else\hskip\interwordspace\relax\fi}
That's a good suggestion and will be easier to incorporate in t-vim. Thanks, Aditya