Emphasize line in minted code

As Konrad Rudolph pointed out you can't expand pygmentize with the option \hl_lines.

Pygmentize doesn’t support the hl_lines option for the LaTeX formatter, and by extension, neither does minted, sorry.

I have another suggestion. You can use tikz to emphasize special lines.

Here the code:

\documentclass[letterpaper, 10pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{minted}
\usepackage{tikz}
\usepackage{hyperref}
\def\theFancyVerbLine{%
  \rmfamily\tiny\arabic{FancyVerbLine}%
  {\tikz[remember picture,overlay]\node(minted-\arabic{FancyVerbLine}){};}%
}

\begin{document}

\begin{minted}[linenos]{bash}
#!/bin/bash
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd -P "$( dirname "$SOURCE" )" && pwd )"
java -jar "$DIR/arara.jar" $*
\end{minted}

\tikz[remember picture,overlay]\draw[fill=yellow,opacity=0.2] ([yshift=-0.05cm,xshift=0.3cm]minted-2) rectangle ([yshift=0.35cm,xshift=5.5cm]minted-2);

\end{document}

enter image description here

Tags:

Minted