I'm writing a report for a class project and I need to highlight several lines within some of the algorithms in the report. I managed to do so, but I don't like the solution I got. Here is a picture (see code of MWE below).
To get this, I used \color{red}, then put the text I wanted to highlight, followed by \color{black}. I wonder if I can highlight in red the same lines of the algorithm but not the line numbers and also not the comment a miracle in polynomial time. What solutions are there for this? This answer proposes redefining commands of the package but they are not using the same package as I am, and I wonder whether it can be made more simply or not.
If I could be given advice on how to do this, while sticking to the package algorithm2e, as far as it is possible, that would be great.
Code:
\documentclass[12pt]{article}
\pdfoutput=1
\usepackage[linesnumbered,titlenumbered,ruled,vlined,resetcount,algosection]{algorithm2e}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{color}
\begin{document}
\title{MWE}
\maketitle
\section{Algorithm}
\begin{algorithm}
\caption{3-SAT in polynomial time}
\label{alg:hs}
\DontPrintSemicolon
\KwIn{List of clauses}
\KwOut{The clauses are satisfiable}
\SetKwProg{Fn}{Function}{ is}{end}
\Fn{\textsc{IsSatisfiable}($C$)} {
\color{red} %<- my best attempt
$k\gets 0$ \;
\For {$i = 1$ \bf{to} $|C|$}
{
$c_i \gets $ $i$-th clause \;
$L \gets$ list of literals of $c_i$ \;
$k\gets f(k, L)$ \tcp{a miracle in polynomial time}
}
\color{black} %<- go back to color black
\If {$k$ is even} {
\Return true
}
\Else {
\Return false
}
}
\end{algorithm}
\end{document}

