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

Colour models inside tabularray #106

Closed
JDMCreator opened this issue Sep 14, 2021 · 13 comments
Closed

Colour models inside tabularray #106

JDMCreator opened this issue Sep 14, 2021 · 13 comments
Labels
feature request New feature or request
Milestone

Comments

@JDMCreator
Copy link

It would be great to be able to use colours inside a table without having to declare the colours before:

\begin{tblr}{llll}
\hline[1pt]
 Alpha   & \SetCell{bg={gray/0.6},fg={HTML/#FFFFFF}} Beta & Gamma \\
\hline
 Epsilon & Zeta & \SetCell{r,font=\scshape} Eta \\
\hline
 Iota    & Kappa & Lambda \\
\hline[1pt]
\end{tblr}
@lvjr lvjr added the feature request New feature or request label Sep 14, 2021
@u-fischer
Copy link

I would suggest not to use slashes but a syntax like bg=[gray]{0.6} and fg=[rgb]{1,1,0} as this is the syntax that is also used by the color command \color[rgb]{1,0.5,1}, and by hyperref \hypersetup{urlcolor=[rgb]{1,1,0}} . I have also an open feature request to add a key val handler for this syntax: latex3/latex3#907

@lvjr
Copy link
Owner

lvjr commented Sep 15, 2021

In tabularray, \SetCell[arg1]{arg2} is the same as cell{i}{j} = {arg1}{arg2}, and \SetHline[arg1]{arg2}{arg3} is the same as hline{i} = {arg1}{arg2}{arg3}. So I think it is better to follow existing rules: using bg={gray}{0.6} and fg={rgb}{1,1,0}.

@JDMCreator
Copy link
Author

Of course, I think it would be better to follow LaTeX3 rules on this matter. If [model]{definition} becomes the standard for color keys, I think it would be better for users to follow the standard.

@u-fischer
Copy link

This aren't "LaTeX3" rules and we aren't setting a standard here. It is more what is already there, e.g. in hyperref, colortbl, nicematrix.
One advantage is that it is quite easy to parse and so to distinguish [rgb]{1,0,0} and {red}: you only have to check if there is a [ at the begin.

@JDMCreator
Copy link
Author

I understand there are no "rules" per say. However, if each package uses their own standards, it will become very confusing for users and website like StackOverflow will be overwhelmed with confused users.

@lvjr
Copy link
Owner

lvjr commented Sep 16, 2021

The disadvantage of [arg] is that it can not contain commas if it is in the key-val lists. (unless we write an extra pairs of curly braces). But in tabularray we obviously need commas, such as in cell{1}{2} = {r=2,c=3}{c}. That is why tabularray chose to use {arg} and why I am not going to change it.

@FrankMittelbach
Copy link

So you trading the advantage of being able to support optional arguments. I can understand that in places where optional arguments make little sense but I think it is counterproductive when the optionals are the norm and expected and used in this way everywhere else (as, for example, with color specifications).

@u-fischer
Copy link

The disadvantage of [arg] is that it can not contain commas if it is in the key-val lists.

but color models don't contain commas. And we don't speak here about arguments of commands, but how to provide a value.
A color can currently take as value a name like pink or an expression like pink!50!blue, and [rgb]{1,0,1} is in this context only another, already established syntax for a color value. You could even provide both syntax if you want and allow {rgb}{1,0,1} too.

@lvjr
Copy link
Owner

lvjr commented Sep 21, 2021

First, maybe it was due to some historical reasons, in my opinion \color[model]{spec} was a bad design. Most of the optional arguments in LaTeX world are really optional: removing them gives slightly different but valid results. But obviously \color{1,0,1} gives an error. In fact, since both model and spec are mandatory, maybe it was better to use another command name such as \colorm{model}{spec}.

Second, bg key may not strictly correspond to \color command. It is much easier to extend the syntax with curly braces. We may allow keyval inside curly braces or add the third pairs of braces in the future if we want to make some fancy backgrounds.

Third, I care more about the consistency of interfaces inside this package than others. It looks weird if most of the interfaces use curly braces but several interfaces use square brackets.

@lvjr
Copy link
Owner

lvjr commented Sep 21, 2021

As far as I know, pgf/tikz doesn't provide this funtionality; beamer doesn't provide this funtionality; tcolorbox doesn't provide this funtionality, either. I think maybe it is not neccessary to provide this funtionality in this smaller package.

@lvjr
Copy link
Owner

lvjr commented Sep 28, 2021

In issue #111, I am planning to add bg+ key for mixing with current color. For example, with the following code

\begin{tblr}{row{2}={red7},column{2}={bg+=green7}}
 Alpha   & Beta  & Gamma  \\
 Epsilon & Zeta  & Eta    \\
 Iota    & Kappa & Lambda \\
\end{tblr}

we get cell{2}{2}={red7!50!green7}. It is easy to mix two named colors. But it is a little complicated to mix two unnamed colors.

@JDMCreator
Copy link
Author

NiceMatrix provide this funtionality (see p.5 of their manual). On mixing unnamed colors, it could be possible to provide them temp names internally.

@lvjr
Copy link
Owner

lvjr commented Nov 11, 2024

With latest tabularray and functional packages (not yet released) (#270), this problem has a solution:

\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{functional}
\begin{document}

\begin{tblr}{
  hlines,
  row{2} = {bg=\funColor{rgb}{0,1,1}},
}
  Alpha   & Beta  & Gamma  \\
  Epsilon & Zeta  & Eta    \\
  Iota    & Kappa & Lambda \\
\end{tblr}

\begin{tblr}{
  hlines,
  row{2} = {bg=\funColor{RGB}{100,255,100}},
}
  Alpha   & Beta  & Gamma  \\
  Epsilon & Zeta  & Eta    \\
  Iota    & Kappa & Lambda \\
\end{tblr}

\begin{tblr}{
  hlines,
  row{2} = {bg=\funColor{HTML}{FF0077}},
}
  Alpha   & Beta  & Gamma  \\
  Epsilon & Zeta  & Eta    \\
  Iota    & Kappa & Lambda \\
\end{tblr}

\begin{tblr}[evaluate=all]{hlines}
  Alpha   & Beta  & Gamma  \\
  \SetRow{bg=\funColor{cmyk}{0,0.5,1,0}}
  Epsilon & Zeta  & Eta    \\
  Iota    & Kappa & Lambda \\
\end{tblr}

\end{document}
image

@lvjr lvjr added this to the 2025A milestone Nov 12, 2024
@lvjr lvjr closed this as completed Nov 12, 2024
lvjr added a commit that referenced this issue Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants