我在 minted 包中有一部分代码:
\begin{minted}[
frame=single,
numbersep = 1pt,
breaklines=true,
framesep=1mm,
baselinestretch=1,
bgcolor=LightGray,
fontsize=\footnotesize,
linenos
]{java}
package test.multiple_interactions;
public class MainActivity extends Activity
{static{System.loadLibrary("threadLeak"); //"libthreadLeak.so"}
public static native void send(String data);
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TelephonyManager tel = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
String imei = tel.getDeviceId();//source
String[] arr = new String[10];
arr[1] = imei;
send(arr);}}
\end{minted}
答案1
根据您的(不完整)示例,主要发生以下变化:
- 选项
escapeinside=||
已添加到minted
环境中 - 代码片段
|\setcounter{FancyVerbLine}{1}|
附加在 Java 代码行之后protected void onCreate(Bundle savedInstanceState){
。这FancyVerbLine
是行号中使用的计数器。
注意:这可能会破坏其他行号minted
选项。
\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage{minted}
\begin{document}
\begin{minted}[
frame=single,
numbersep = 1pt,
breaklines=true,
framesep=1mm,
baselinestretch=1,
bgcolor=LightGray,
fontsize=\footnotesize,
linenos,
escapeinside=||
]{java}
package test.multiple_interactions;
public class MainActivity extends Activity
{static{System.loadLibrary("threadLeak"); //"libthreadLeak.so"}
public static native void send(String data);
protected void onCreate(Bundle savedInstanceState){|\setcounter{FancyVerbLine}{1}|
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TelephonyManager tel = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
String imei = tel.getDeviceId();//source
String[] arr = new String[10];
arr[1] = imei;
send(arr);}}
\end{minted}
\end{document}