Re: [NTG-context] t-vim module: math in "normal" code and background color

2017-07-19 Thread Aditya Mahajan

On Wed, 19 Jul 2017, Gerion Entrup wrote:


Am Mittwoch, 19. Juli 2017, 21:07:09 CEST schrieb Aditya Mahajan:

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

Thank you, this works much better (critic on high level: the sum symbol is
higher than the highlight box, relevant on fractions).


Another option (slightly better visually, but increases the interline 
distance)


\defineframed[texthighlight]
[
  background=color,
  backgroundcolor=gray,
  frame=off,
  location=middle,
]

\usemodule[vim]
\definevimtyping[python][syntax=python, escape=on,
highlightcommand=\dontleavehmode\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

Aditya
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] t-vim module: math in "normal" code and background color

2017-07-19 Thread Aditya Mahajan

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___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] t-vim module: math in "normal" code and background color

2017-07-19 Thread Henri Menke
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}

> 
> and use \MATH{} instead of \m{}.
> 
> I'll test this is a bit, and if the solution is robust, then I will map 
> \m{...} to something equivalent to the above in the t-vim environments.
> 
> 
> Aditya
> ___
> If your question is of interest to others as well, please add an entry to the 
> Wiki!
> 
> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki : http://contextgarden.net
> ___
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] t-vim module: math in "normal" code and background color

2017-07-19 Thread Gerion Entrup
Am Mittwoch, 19. Juli 2017, 21:07:09 CEST schrieb Aditya Mahajan:
> 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
Thank you, this works much better (critic on high level: the sum symbol is
higher than the highlight box, relevant on fractions).

 
> 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}
> 
> and use \MATH{} instead of \m{}.
> 
> I'll test this is a bit, and if the solution is robust, then I will map 
> \m{...} to something equivalent to the above in the t-vim environments.
I saw the strange spacing. Thank you very much to provide a solution.

Gerion

___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] t-vim module: math in "normal" code and background color

2017-07-19 Thread Aditya Mahajan

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}

and use \MATH{} instead of \m{}.

I'll test this is a bit, and if the solution is robust, then I will map 
\m{...} to something equivalent to the above in the t-vim environments.



Aditya
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] t-vim module: math in "normal" code and background color

2017-07-18 Thread Gerion Entrup
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

From 994de513a23210f1f4d50d24270f8f988abdd21c Mon Sep 17 00:00:00 2001
From: Gerion Entrup 
Date: Wed, 19 Jul 2017 00:13:52 +0200
Subject: [PATCH] t-vim: extended escape mode

With this change it is possible to define one or more escapechars, that
are used by vim to recognize parts that should not be interpreted.
---
 2context.vim | 50 +-
 t-vim.tex| 12 ++--
 2 files changed, 35 insertions(+), 27 deletions(-)

diff --git a/2context.vim b/2context.vim
index 9c72ba1..b208e65 100644
--- a/2context.vim
+++ b/2context.vim
@@ -8,6 +8,11 @@
 " output buffer. The script parses content line-by-line from the first buffer
 " and pastes the modified result on the second buffer.
 
+" Compare a char of  at  with some Unicode 
+function UnicodeCompare(string, bytepos, ochar)
+return strpart(a:string, a:bytepos, max([strlen(a:ochar), 1])) ==# a:ochar
+endfunction
+
 " Split screen and go to the second buffer, ensure modifiable is set, and the
 " buffer is empty.
 sblast 
@@ -38,9 +43,9 @@ if !exists("highlight")
   let highlight=[]
 endif
 
-" Set escapecomments
-if !exists("escapecomments")
-  let escapecomments=0
+" Set escapechar
+if !exists("escapechar")
+  let escapechar=''
 endif
 
 let s:strip = strlen( matchstr( getline(s:lstart), '^\s*' ) )
@@ -71,37 +76,48 @@ let s:lines = []
 let s:buffer_lnum = 1
 let s:lnum = s:lstart
 
+let s:lenesc = strlen(escapechar)
+
 while s:lnum <= s:lstop
 " Get the current line
   let s:line = getline(s:lnum)
   let s:len  = strlen(s:line)
-  let s:new  = '' 
+  let s:new  = ''
 
 " Loop over each character in the line
-  let s:col = s:strip + 1
-  while s:col <= s:len
+  let s:col = s:strip
+  while s:col < s:len
 let s:startcol = s:col " The start column for processing text
-let s:id   

Re: [NTG-context] t-vim module: math in "normal" code and background color

2017-07-17 Thread 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 
:-)



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.


Aditya
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

Re: [NTG-context] t-vim module: math in "normal" code and background color

2017-07-17 Thread Henri Menke
On Mon, 2017-07-17 at 21:13 +0200, 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?
> 
> 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
> ```
> 
> 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?

Background is no problem, escape in code is not implemented in t-vim.  I filed 
a feature request for
/BTEX ... /ETEX escaping as in regular typing on Aditya's GitHub: 
https://github.com/adityam/filter/
issues/23


\definetextbackground
  [verbatim]
  [location=paragraph]

\usemodule[vim]

\definevimtyping
  [python]
  [syntax=python,
   escape=on,
   before={\starttextbackground[verbatim]},
   after={\stoptextbackground}]

\setuptyping
  [before={\starttextbackground[verbatim]},
   after={\stoptextbackground}]

\starttext

\starttyping[escape=yes]
# Returns /BTEX\m{\sum_{i=1}^{n}i}/ETEX
def sum_upto(/BTEX\m{n \in \mathbb{N}}/ETEX)
r = range(1, \m{n} + 1)
return sum(r)
\stoptyping

\startpython
# Returns \m{\sum_{i=1}^{n}i}
def sum_upto(\m{n \in \mathbb{N}}w)
r = range(1, \m{n} + 1)
return sum(r)
\stoppython

\stoptext


> (I've subscribed the list, so you don't have to CC me.)
> 
> Thank you in advance,
> Gerion
> 
> ___
> If your question is of interest to others as well, please add an entry to the 
> Wiki!
> 
> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki : http://contextgarden.net
> ___
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___

[NTG-context] t-vim module: math in "normal" code and background color

2017-07-17 Thread Gerion Entrup
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?

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
```

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?

(I've subscribed the list, so you don't have to CC me.)

Thank you in advance,
Gerion

___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___