Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Emphasized lines with listings

0 views
Skip to first unread message

LuCa

unread,
Nov 11, 2009, 12:08:27 PM11/11/09
to
Hi to all!
I use listings and I'm looking for a particular behaviour.

Two examples first:
One
-----
\documentclass[a4paper]{article}
\usepackage{listings}
\begin{document}
\lstinputlisting[linerange=1-7]{data.dat}
\end{document}
-----
In this way I will print only lines from 1 to 7 of "data.dat".

Two
-----
\documentclass[a4paper]{article}
\usepackage{listings}
\usepackage{xcolor}
\begin{document}
\lstinputlisting[emph={keyword},emphstyle=\color{red}]{data.dat}
\end{document}
-----
In this way I will print in red only the word "keyword", every time it
occurres.

My question: is there a simple way to combine the two behaviors and
obtain a defined range of lines emphasized in a chosen way?
Obviously I don't want to change the file "data.dat" neither it has
useful characters in it that can be used with "morestring" or
"morecomment".

Thanks
LuCa

Ulrike Fischer

unread,
Nov 12, 2009, 4:19:32 AM11/12/09
to
Am Wed, 11 Nov 2009 09:08:27 -0800 (PST) schrieb LuCa:

> Hi to all!
> I use listings and I'm looking for a particular behaviour.
>
> Two examples first:

> In this way I will print only lines from 1 to 7 of "data.dat".

> In this way I will print in red only the word "keyword", every time it


> occurres.

> My question: is there a simple way to combine the two behaviors and
> obtain a defined range of lines emphasized in a chosen way?
> Obviously I don't want to change the file "data.dat" neither it has
> useful characters in it that can be used with "morestring" or
> "morecomment".

Well you could do something like this:

\documentclass[a4paper]{article}
\usepackage{listings}
\usepackage{xcolor}
\begin{document}

\lstinputlisting[basicstyle=\color{red},linerange=1-2,belowskip=0pt]{data.dat}
\lstinputlisting[linerange=3-4,aboveskip=0pt]{data.dat}
\end{document}

--
Ulrike Fischer

LuCa

unread,
Nov 12, 2009, 4:45:59 AM11/12/09
to

Thank, this is a nice workaround!
Non that general but it works!
;)

LuCa

0 new messages