# Latex, how to highlight code with different background colors

I saw the example of minted:

I write my java code like that:

\begin{minted}[breaklines, breakanywhere, escapeinside=||]{java}
private byte[] doEncryption(String data, SecretKey key){
|\colorbox{green}{Logger logger = Logger.getLogger("MyLog"); }|
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}


However, I only get

What's wrong with it?

• Please use a complete MWE that contains the \documentclass, all the \usepackages (and libraries if you use tikz or something like that), as well as the \begin{document} and \end{document}. Please refer to this and to this – Vinccool96 Apr 9 at 15:04
• What do you want it to look like? What's wrong with the result? – Vinccool96 Apr 9 at 15:05
• Very good question! That's indeed a surprising output! – user185220 Apr 9 at 19:23
• The problem are the " signs, without them the box works – user185220 Apr 9 at 19:37

The problem is caused by the " inside the colorbox, for a workaround:

\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}); }|