4

I saw the example of minted: enter image description here

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

However, I only get enter image description here

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
2

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

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.