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

Color series using method last never cycle #9

Open
muzimuzhi opened this issue Nov 8, 2021 · 4 comments
Open

Color series using method last never cycle #9

muzimuzhi opened this issue Nov 8, 2021 · 4 comments

Comments

@muzimuzhi
Copy link

The name of \colorseriescycle and the phrase vector \emph{last} used in the doc for color series may make users misunderstand that such a series cycle.

In the following example, user may expect foo!![4] == base == {.3,.3,.3}, but actually it's {.6,.6,.6}

\documentclass{article}
\usepackage{xcolor}

\begin{document}
\definecolorseries{foo}{rgb}{last}[rgb]{.3,.3,.3}[rgb]{.5,.5,.5}
\resetcolorseries[2]{foo} % step = .1,.1,.1

\ttfamily
\begin{testcolors}[rgb]
  \testcolor{foo!![0]}
  \testcolor{foo!![1]}
  \testcolor{foo!![2]}
  \testcolor{foo!![3]}
\end{testcolors}
\end{document}

image

The relevant doc indicates this is the expected behavior, not a bug.

xcolor/xcolor.dtx

Lines 1267 to 1281 in 1924d5a

% This is the general scheme:
% \begin{gather}
% \emph{color}_1 := \emph{base},\qquad
% \emph{color}_{n+1} := U\bigl(\emph{color}_{n} + \emph{step}\bigr)
% \end{gather}
% for $n=1,2,\dots$, where $U$ maps arbitrary real $m$-vectors into the unit $m$-cube:
% \begin{gather}
% U(x_1,\dots,x_m) = (u(x_1),\dots,u(x_m)),\qquad
% u(x) =
% \begin{cases}
% 1 & \text{if $x=1$}\\
% x-[x]& \text{if $x\neq1$}\\
% \end{cases}\label{eq.U}
% \end{gather}
% Thus, every step of the algorithm yields a valid color with parameters from the interval $[0,1]$.

Perhaps xcolor could add some words to the doc?

@muzimuzhi
Copy link
Author

The relevant doc indicates this is the expected behavior, not a bug.

That's why tabu did a manual cycling for its \taburowcolors.

@u-fischer
Copy link
Member

It does cycle. But it leaves out the base color:

\documentclass{article}
\usepackage{xcolor}

\begin{document}
\definecolorseries{foo}{rgb}{last}{blue}{red}
\resetcolorseries[4]{foo}

\ttfamily

\begin{testcolors}[rgb]
  \testcolor{foo!!+}
  \testcolor{foo!!+}
  \testcolor{foo!!+}
  \testcolor{foo!!+}
  \testcolor{foo!!+}
  \testcolor{foo!!+}
  \testcolor{foo!!+}
  \testcolor{foo!!+}
  \testcolor{foo!!+}
  \testcolor{foo!!+}
  \testcolor{foo!!+}
  \testcolor{foo!!+}
  \testcolor{foo!!+}
  \testcolor{foo!!+}
  \testcolor{foo!!+}
  
\end{testcolors}
\end{document}

image

The same happens with absolute index numbers. This looks like a bug to me.

@zauguin
Copy link
Member

zauguin commented Nov 8, 2021

It's not a bug, it's working as documented. Every component individually wraps around, so after 1 0 0 we get to 1.25 0 -0.25 which gets remapped to allowed color values by the documented U function from the manual to 0.25 0 0.75. This just happens to repeat the second value since the base and last values in your example only contain 0 and 1 and therefore are exactly at the points where it gets wrapped.

@u-fischer
Copy link
Member

@zauguin yes, I just saw it too. We should document this better.

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

3 participants