Color lines in source code that is embedded in LaTeX

I am looking for a way to mark some lines in a source code sample that will be integrated into my LaTeX code.

I already found solutions to embed source code and have syntax highlighting like this solution: Including XML file into LaTeX But this is not exactly what I need. Imagine a source code file I include (XML, if this may be important in any way) and I only want to highlight lines 14, 15 and a part of line 16. I already thought about putting my code in word or open office writer and mark it there and include a screenshot instread of the code-file but there must be a better solution than this.

Anyone can help?

• possible duplicate of highlight lines in listings Oct 20 '13 at 0:48
• Thanks! This is almost what I was looking for but I need to color the text of the code line, not the background of the code line :( Oct 20 '13 at 1:04
• Welcome to TeX.SX! Usually, we don't put a greeting or a “thank you” in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say “thank you” to users who helped you. Oct 20 '13 at 20:53

You could try something like:

\documentclass{article}
\usepackage{listings,xcolor}

\lstdefinestyle{XML}{
language={XML},
moredelim=**[is][\color{orange}]{@}{@},
}

\begin{document}
\begin{lstlisting}[style=XML]
<Line1>
<Line2>
<Line3>
<Line4>
<Line5>
<Line6>
<Line7>
<Line8>
<Line9>
<Line10>
<Line11>
<Line12>
<Line13>
@<Line14>
<Line15>
<Line16>@
</line17>
\end{lstlisting}
\end{document}


Solution pulled from Highlight text in code listing while also keeping syntax highlighting.

• If you directly copy and paste the url of a question/answer, it automatically appears the title. Oct 20 '13 at 11:40
• One downside of this approach is that it forces you to place delimiters in the listing. That's particularly undesirable when \lstinputlisting is used. Oct 20 '13 at 11:47