Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

demo of new feature: alternate line color #8

Open
muzimuzhi opened this issue Aug 9, 2018 · 3 comments
Open

demo of new feature: alternate line color #8

muzimuzhi opened this issue Aug 9, 2018 · 3 comments

Comments

@muzimuzhi
Copy link

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

  1. Now highlightcolor can be used as highlightcolor = SingleColor | {<OddLineColor>, <EvenLineColor>}.
  2. New option highlightlinenumbercolor changes the highlight color of line number, and this option can be used the same as highlightcolor.
  3. Since calculating the max width of actual line number (\arabic{FancyVerbLine}) is hard, a new option linenumberwidth=<dimen> is defined.
  4. 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:

  1. \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.
  2. 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.

@muzimuzhi
Copy link
Author

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}

image

@gpoore
Copy link
Owner

gpoore commented Aug 12, 2018

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.

@muzimuzhi
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants