lvjr / tabularray

Typeset tabulars and arrays with LaTeX3
https://ctan.org/pkg/tabularray
258 stars 22 forks source link

Colour models inside tabularray #106

Open JDMCreator opened 3 years ago

JDMCreator commented 3 years ago

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}
u-fischer commented 3 years ago

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: https://github.com/latex3/latex3/issues/907

lvjr commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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