Home > Archive > Tex > June 2007 > Using lineno package to color lines of a document
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Using lineno package to color lines of a document
|
|
| yasirniazkhan 2007-06-26, 7:21 pm |
| I am trying to use lineno package to alternatively (red, blue, red,
blue,...) color all the text in a TEX document. Although lineno
provides customization to put anything around rendered text lines, i
cannot insert color tags on them. It either gives a lot of errors or
doesn't color the lines. The command (among many others) i tried is:
\documentclass[12pt]{book}
\usepackage[usenames]{color}
\usepackage{lineno}
\linenumbers
\renewcommand\makeLineNumber{\hss$\color
{red}{$\ \rlap{\hskip\textwidth
\ $}$}}
\begin{document}
Please take a look at the important information in this header.
We encourage you to keep this file on your own disk, keeping an
electronic path open for the next readers. Do not remove this.
\end{document}
| |
| Lars Madsen 2007-06-26, 7:21 pm |
| yasirniazkhan wrote:
> I am trying to use lineno package to alternatively (red, blue, red,
> blue,...) color all the text in a TEX document. Although lineno
> provides customization to put anything around rendered text lines, i
> cannot insert color tags on them. It either gives a lot of errors or
> doesn't color the lines. The command (among many others) i tried is:
>
> \documentclass[12pt]{book}
> \usepackage[usenames]{color}
> \usepackage{lineno}
> \linenumbers
> \renewcommand\makeLineNumber{\hss$\color
{red}{$\ \rlap{\hskip\textwidth
> \ $}$}}
> \begin{document}
> Please take a look at the important information in this header.
> We encourage you to keep this file on your own disk, keeping an
> electronic path open for the next readers. Do not remove this.
> \end{document}
>
your {}'s aren't nested very good
This works fine on my system
\documentclass[12pt]{book}
\usepackage[usenames]{color}
\usepackage{lineno}
\linenumbers
\renewcommand\makeLineNumber{%
\llap{$\color{red}($\ }\rlap{\kern\textwidth\ $\color{red})$}}
\begin{document}
Please take a look at the important information in this header.
We encourage you to keep this file on your own disk, keeping an
electronic path open for the next readers. Do not remove this.
\end{document}
--
/daleif (remove RTFSIGNATURE from email address)
LaTeX FAQ: http://www.tex.ac.uk/faq
LaTeX book: http://www.imf.au.dk/system/latex/bog/ (in Danish)
Remember to post minimal examples, see URL below
http://www.tex.ac.uk/cgi-bin/texfaq2html?label=minxampl
http://www.minimalbeispiel.de/mini-en.html
| |
| Stephan Boettcher 2007-06-26, 7:21 pm |
|
yasirniazkhan <yasir.niaz@gmail.com> writes:
> I am trying to use lineno package to alternatively (red, blue, red,
> blue,...) color all the text in a TEX document. Although lineno
> provides customization to put anything around rendered text lines, i
> cannot insert color tags on them. It either gives a lot of errors or
> doesn't color the lines. The command (among many others) i tried is:
>
> \documentclass[12pt]{book}
> \usepackage[usenames]{color}
> \usepackage{lineno}
> \linenumbers
> \renewcommand\makeLineNumber{\hss$\color
{red}{$\ \rlap{\hskip\textwidth
> \ $}$}}
> \begin{document}
> Please take a look at the important information in this header.
> We encourage you to keep this file on your own disk, keeping an
> electronic path open for the next readers. Do not remove this.
> \end{document}
You need to go one level further up, and redefine \MakeLineNo to grab
the last line and wrap it in a colored box.
I am not sure if lineno is the right tool for this job, but it might
be.
This works with lineno.sty v3.14. Uwe may have made changes to v4
that breaks it:
\documentclass[12pt]{book}
\usepackage[usenames]{color}
\usepackage{lineno}
\linenumbers
\makeatletter
\def\MakeLineNo{%
\boxmaxdepth\maxdimen\setbox\z@\vbox{\un
vbox\@cclv}%
\@tempdima\dp\z@ \unvbox\z@
\setbox\z@\lastbox
\ifodd \c@linenumber
\sbox\@tempboxa{\color{red}\box\z@}%
\else
\sbox\@tempboxa{\color{blue}\box\z@}%
\fi
\stepcounter{linenumber}%
\dp\@tempboxa=\@tempdima
\box\@tempboxa
\ifnum\outputpenalty=-\linenopenaltypar\else
\@tempcnta\outputpenalty
\advance\@tempcnta -\linenopenalty
\penalty\@tempcnta
\fi
}
\makeatother
\begin{document}
Please take a look at the important information in this header.
We encourage you to keep this file on your own disk, keeping an
electronic path open for the next readers. Do not remove this.
\end{document}
--
Stephan
| |
|
|
|
|
|