1

do you have any idea how to change code snippet's background color? I'm using vim-t (\definevimtyping..) and context. In vim documentation I found only how to change background color of highlighted lines, but I'd love to have whole code snippet with background.

I tried using /framed but it just broke code formatting. (I'm newbie)

Thanks!

Edit 1:

definition:

\definevimtyping [JAVA]  [
        syntax=java,
        lines=split,
        option=hyphenated,
        align=hyphenated,
        style={\switchtobodyfont[small,tt]}
]

used:

\startJAVA[numbering=yes]

public class LocationCoordinate2D {
    private Double longitude; // zemepisná dĺžka
    private Double latitude; // zemepisná šírka

    public LocationCoordinate2D(double longitude, double latitude) {
        this.longitude = longitude;
        this.latitude = latitude;
    }
    public LocationCoordinate2D getNewLocation(double bearing, double distance) {
        double brng = Math.toRadians(bearing); // smer v radiánoch
        final int R = 6371; // polomer Zeme v kilometroch
        double lat1 = Math.toRadians(latitude);
        double lon1 = Math.toRadians(longitude);
        double lat2 = Math.asin(Math.sin(lat1) * Math.cos(distance/R) + Math.cos(lat1) * Math.sin(distance/R) * Math.cos(brng));
        double lon2 = lon1 + Math.atan2(Math.sin(brng) * Math.sin(distance/R)*Math.cos(lat1), Math.cos(distance/R)-Math.sin(lat1)*Math.sin(lat2));

        return new LocationCoordinate2D(Math.toDegrees(lon2), Math.toDegrees(lat2));
    }
}

\stopJAVA
3

You can use the textbackground environment to add a colored background behind the code block.

Before you can use the mechanism you have create a new instance with the \definetextbackground command where you set location=paragraph to enclose the complete code block in the frame.

The new textbackground instance is than applied to the code block with the before and after keys of the \definevimtyping or \setupvimtyping commands.

\usemodule[vim]

\definetextbackground
  [VerbatimBackground]
  [location=paragraph,
   frame=off,
   backgroundcolor=lightgray,
   topoffset=.25ex,
   bottomoffset=.25ex,
   leftoffset=.5ex]

\definevimtyping
  [JAVA]
  [syntax=java,
   lines=split,
   option=hyphenated,
   align=hyphenated,
   style=smalltype,
   before=\startVerbatimBackground,
   after=\stopVerbatimBackground]

\starttext

\startJAVA[numbering=yes]
public class LocationCoordinate2D {
    private Double longitude; // zemepisná dĺžka
    private Double latitude; // zemepisná šírka

    public LocationCoordinate2D(double longitude, double latitude) {
        this.longitude = longitude;
        this.latitude = latitude;
    }
    public LocationCoordinate2D getNewLocation(double bearing, double distance) {
        double brng = Math.toRadians(bearing); // smer v radiánoch
        final int R = 6371; // polomer Zeme v kilometroch
        double lat1 = Math.toRadians(latitude);
        double lon1 = Math.toRadians(longitude);
        double lat2 = Math.asin(Math.sin(lat1) * Math.cos(distance/R) + Math.cos(lat1) * Math.sin(distance/R) * Math.cos(brng));
        double lon2 = lon1 + Math.atan2(Math.sin(brng) * Math.sin(distance/R) * Math.cos(lat1), Math.cos(distance/R) - Math.sin(lat1) * Math.sin(lat2));

        return new LocationCoordinate2D(Math.toDegrees(lon2), Math.toDegrees(lat2));
    }
}
\stopJAVA

\stoptext

Produces:

Typing environment output

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.