0

Is it possible to highlight Java annotations in lstlisting? desired output

I could not find any similar questions in tex.stackexchange. I'm searching for some yellow-like color.

Update: I found another question similar to mine, but it didn't work well. My code is:

    \documentclass{report}
\usepackage{xcolor}
\usepackage{listings}          % for source code snippets.
\definecolor{pblue}{rgb}{0.13,0.13,1}
\definecolor{pgreen}{rgb}{0,0.5,0}
\definecolor{pred}{rgb}{0.9,0,0}
\definecolor{pgrey}{rgb}{0.46,0.45,0.48}
\lstdefinestyle{Javastyle}{  
    showspaces=false,
    showtabs=false,
    breaklines=true,
    showstringspaces=false,
    breakatwhitespace=true,
    commentstyle=\color{pgreen},
    keywordstyle=\color{pblue},
    stringstyle=\color{pred},
    basicstyle=\ttfamily\singlespacing,
    moredelim=[il][\textcolor{pgrey}]{\$\$},
    moredelim=[is][\textcolor{pgrey}]{\%\%}{\%\%},
    rulecolor= \color{black} 
}

\begin{document}

%\lstset{style=Javastyle}
\begin{lstlisting}[language=Java]
@NonNull
public static byte[] longToBytes(long x) {
buffer.clear();
buffer.putLong(0, x);
return buffer.array();
}
\end{lstlisting}
\end{document}

When I remove the % before \lstset{}, I get an error message: Undefined control sequence. \begin{lstlisting}[language=Java]

  • 1
    Could you provide a Minimal Working Example of what you have achieved so far, and describe what exactly you want to change in the output of it? – Tiuri Jun 01 '17 at 16:55
  • I tried the answer of link, but it is not working. – Sweidán Omár Jun 01 '17 at 17:24
  • 1
    Could you a bit elaborate on what you try to do? Best, post a code example (complete from \documentclass down to \end{document}) and explain what it does and what feature you are missing. You can, of course, take the code of the linked answer and describe here errors you get or features you are missing. – Tiuri Jun 01 '17 at 17:35

0 Answers0