![更改 vim-t 背景颜色](https://linux22.com/image/411134/%E6%9B%B4%E6%94%B9%20vim-t%20%E8%83%8C%E6%99%AF%E9%A2%9C%E8%89%B2.png)
您知道如何更改代码片段的背景颜色吗?我使用 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
实例应用于代码块。before
after
\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
生成: