[Tex/LaTex] Emphasise a particular keyword in minted

minted

In minted, how do I highlight a particular set of keywords by making them bold. Say for example consider the MWE,

\documentclass[a4paper , 12pt]{article}
\usepackage{minted}
\usemintedstyle{manni}
\begin{document}
\begin{minted}{java}
class Test
{
    public static void main(String args[])
    {
        System.out.println("Hello World");
    }
}
\end{minted}
\end{document} 

The above generates this:
enter image description here
Now, whenever I use the keyword class, it should be in bold. How do I do that?

Best Answer

AFAIK, there is no such option with minted. But with listings it is easy. you can use

escapechar=!,   %% use any character as you wish

or

moredelim=[is][\bfseries\color{magenta}]{`}{`},   %% same as above

Or

escapeinside={*@}{@*}     %% Use as *@ \bfseries class @*

etc.

Here is some sample:

\documentclass[a4paper,11pt]{article}
\usepackage{xcolor}
\usepackage{courier}
\usepackage{listings} % for code snippets

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}

\lstset{frame=single,
  framerule=0pt,
  backgroundcolor=\color{olive!10},
  language=Java,
  aboveskip=3mm,
  belowskip=3mm,
  showstringspaces=false,
  columns=fullflexible,
  basicstyle={\footnotesize\ttfamily},
  numbers=left,
  numbersep=10pt,
  numberstyle=\scriptsize\color{gray},
  keywordstyle=\color{blue},
  commentstyle=\color{dkgreen},
  stringstyle=\color{mauve},
  escapechar=!,
  moredelim=[is][\bfseries\color{magenta}]{`}{`},
  breaklines=true,
  breakatwhitespace=true,
  tabsize=2
}

\begin{document}
\begin{lstlisting}[escapechar=!,]
!\bfseries\color{blue} class! Test
{
    public static void main(String args[])
    {
        System.out.println("Hello World");
    }
}
`class`
\end{lstlisting}
\end{document}

enter image description here