ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Aditya Mahajan <adityam@umich.edu>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: t-vim module: math in "normal" code and background color
Date: Wed, 19 Jul 2017 20:06:27 -0400 (EDT)	[thread overview]
Message-ID: <alpine.LNX.2.20.1707191959010.1695@ybpnyubfg.ybpnyqbznva> (raw)
In-Reply-To: <2444358.QlyyuRk0i6@gump>

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
___________________________________________________________________________________

  reply	other threads:[~2017-07-20  0:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-17 19:13 Gerion Entrup
2017-07-17 21:17 ` Henri Menke
2017-07-18  2:04 ` Aditya Mahajan
2017-07-18 22:30   ` Gerion Entrup
2017-07-19 19:07     ` Aditya Mahajan
2017-07-19 19:45       ` Gerion Entrup
2017-07-20  0:06         ` Aditya Mahajan [this message]
2017-07-19 20:39       ` Henri Menke
2017-07-19 23:56         ` Aditya Mahajan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LNX.2.20.1707191959010.1695@ybpnyubfg.ybpnyqbznva \
    --to=adityam@umich.edu \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).