fvextra
fvextra copied to clipboard
demo of new feature: alternate line color
The purpose of this feature is to let odd- and even lines have different highlight colors. I have committed a demo implementation to my forked repo. Only sty file is changed in that commit.
Some Explanations
- Now
highlightcolor
can be used ashighlightcolor = SingleColor | {<OddLineColor>, <EvenLineColor>}
. - New option
highlightlinenumbercolor
changes the highlight color of line number, and this option can be used the same ashighlightcolor
. - Since calculating the max width of actual line number (
\arabic{FancyVerbLine}
) is hard, a new optionlinenumberwidth=<dimen>
is defined. - If
breaklines=true
, the total heigh of a line is not determined until\FV@SaveLineBox
. Therefore\FV@LeftListNumber
(with its background) is typeset after\FancyVerbFormatLine
.
Shortcut:
-
\def\FV@LineNumberBackground{}
is a compromise since\def\FV@LineNumberBackground\@empty
and\def\FV@LineNumberBackground\relax
both raise error. I guess it is a problem of order of macro expanding. - The
\pickTwo
macro may have nicer implementation.
I am not fully understood about packages fancyvrb
and fvextra
, so any suggestions are helpful. And, more test is needed of course.
Here are some simple examples:
\documentclass{article}
\usepackage{fvextra}
\usepackage[x11names]{xcolor}
\fvset{
highlightcolor={LightBlue1!50, LightBlue1!30},
highlightlinenumbercolor={yellow!50, yellow!30},
numbersep=5pt
}
\begin{document}
\begin{Verbatim}[linenos, numbers=right, breaklines=true]
\def\FV@HighlightLine#1{%
\@tempcnta=\c@FancyVerbLine
\@tempcntb=\c@FancyVerbLine
\ifcsname FV@HighlightLine:\number\@tempcnta\endcsname %\@tempcnta\endcsname
\advance\@tempcntb\m@ne % some some some some some some some comments
\ifcsname FV@HighlightLine:\number\@tempcntb\endcsname
\advance\@tempcntb\tw@
\end{Verbatim}
\bigskip
\begin{Verbatim}[linenos, numbers=left, breaklines=false]
\def\FV@HighlightLine#1{%
\@tempcnta=\c@FancyVerbLine
\@tempcntb=\c@FancyVerbLine
\ifcsname FV@HighlightLine:\number\@tempcnta\endcsname
\advance\@tempcntb\m@ne
\ifcsname FV@HighlightLine:\number\@tempcntb\endcsname
\advance\@tempcntb\tw@
\end{Verbatim}
\bigskip
\begin{Verbatim}[linenos, numbers=both, breaklines=false, frame=single]
\def\FV@HighlightLine#1{%
\@tempcnta=\c@FancyVerbLine
\@tempcntb=\c@FancyVerbLine
\ifcsname FV@HighlightLine:\number\@tempcnta\endcsname
\advance\@tempcntb\m@ne
\ifcsname FV@HighlightLine:\number\@tempcntb\endcsname
\advance\@tempcntb\tw@
\end{Verbatim}
\end{document}
This looks like a very nice feature and I'll be happy to include it. I will need to think a little about the best way to do some things. Your \FancyVerbHighlightLineBase
is definitely going in the right direction in terms of sharing core line configuration. I'll need to think more about exactly how it relates to \FancyVerbHighlightLineFirst
, \FancyVerbHighlightLineMiddle
, \FancyVerbHighlightLineLast
, etc. Unfortunately, I have a lot of other projects going at the moment, so it may be a while before I can get back to this.
Thanks so much for your response.
Before you getting back, if I get new ideas related to this feature, I will post them here as well.