更改 vim-t 背景颜色

更改 vim-t 背景颜色

您知道如何更改代码片段的背景颜色吗?我使用 vim-t (\definevimtyping..) 和上下文。在 vim 文档中,我只找到了如何更改突出显示行的背景颜色,但我希望整个代码片段都有背景。

我尝试使用 /framed,但它破坏了代码格式。(我是新手)

谢谢!

编辑1:

定义:

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

用过的:

\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

答案1

您可以使用textbackground环境在代码块后面添加彩色背景。

在使用该机制之前,您必须使用命令创建一个新实例,并\definetextbackground在其中设置location=paragraph将完整的代码块封闭在框架中。

然后使用或命令的和键将新textbackground实例应用于代码块。beforeafter\definevimtyping\setupvimtyping

\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

生成:

打字环境输出

相关内容