adityam / filter

ConTeXt module to process contents of a start-stop environment through an external program
45 stars 10 forks source link

Escaping with /BTEX ... /ETEX #23

Closed hmenke closed 4 years ago

hmenke commented 7 years ago

It would be cool if one could escape to ConTeXt within /BTEX ... /ETEX like for regular typing. This is extremely useful for annotating code. Currently only automatic escaping in comments works.

\usemodule[vim]

\definevimtyping
  [python]
  [syntax=python,
   escape=on]

\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, /BTEX\m{n}/ETEX + 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
adityam commented 7 years ago

This was also asked on the context mailing list, so I'll copy-paste my reply from there:

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 :-)

hmenke commented 4 years ago

https://adityam.github.io/context-blog/post/vim-btex-etex-escape/

Thank you for taking the time to implement this! Maybe you should mark this as fixed now.

adityam commented 4 years ago

I am embarrassed to say that I forgot that you had raised this issue. As I said in my previous message (and also repeat in my blog post), I always thought that the implementation will be ugly. So, all thanks to Cristoph who wrote a clean implementation of this feature.

adityam commented 4 years ago

Fixed by ada5d0b