4

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?

1 Answers1

2

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}

Example

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

aqua
  • 136
  • If you directly copy and paste the url of a question/answer, it automatically appears the title. – Claudio Fiandrino 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. – jub0bs Oct 20 '13 at 11:47