我这样编写 Java 代码:
\begin{minted}[breaklines, breakanywhere, escapeinside=||]{java}
private byte[] doEncryption(String data, SecretKey key){
|\colorbox{green}{Logger logger = Logger.getLogger("MyLog"); }|
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
logger.info("plaintext is: "+data);
cipher.init|(Cipher.ENCRYPT_MODE, Key);
byte[] cipherText=cipher.doFinal(data);
logger.info("ciphertext is: "+cipherText);
return cipherText;
}
\end{minted}
它出什么问题了?
答案1
该问题是由"
颜色框内部引起的,解决方法是:
\documentclass{article}
\usepackage{minted}
\newcommand{\foo}[1]{"#1"}
\begin{document}
\begin{minted}[breaklines, breakanywhere, escapeinside=||]{java}
private byte[] doEncryption(String data, SecretKey key){
|\colorbox{green}{Logger logger = Logger.getLogger(\foo{MyLog}); }|
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
logger.info("plaintext is: "+data);
cipher.init(Cipher.ENCRYPT_MODE, Key);
byte[] cipherText=cipher.doFinal(data);
logger.info("ciphertext is: "+cipherText);
return cipherText;
}
\end{minted}
\end{document}