Open u-fischer opened 1 year ago
One side question: currently l3color
only supports !
operator in color expression, which is far less than those provided by xcolor
. Will l3color
gradually add more operators?
I'm not sure, that's something for @josephwright. Personally I think that xcolor is overdoing a bit. I certainly never used anything else than !
. Do you have real use cases for the other operators?
Do you have real use cases for the other operators?
Just did a rough test and it seems at least the pgfmanual doesn't use operators other than !
, see branch test/l3color
.
But I can recall some use cases: <name>!!+
for color series used in tabulars, extended color expression like rgb,255:red,231;green,84;blue,121
used in some TeX-SX Q&A[^1], and -<name>
used for complement color.
[^1]: for example https://tex.stackexchange.com/a/343680
I've filed latex3/latex3#1181 so discussions here won't be too off-topic.
I would be grateful if you could look if pgf could switch here to "official" interfaces. I'm also interested to know if some interfaces are missing in the color packages.
@u-fischer It seems pgf
could stick to \extractcolorspec
and \extractcolorspecs
. Quick versions of these two commands that only take a color name, rather than a color expression are welcome. I'll look into this.
I could add a test if that the color exist. That should make them quite fast:
\documentclass{article}
\usepackage{xcolor,l3benchmark}
\makeatletter %\let\XR@useURL\XR@URL
\def\XC@extractcolorspec#1#2#3#4%
{\XC@sdef\@@mod{#3}\edef\@@clr{#4}\edef\@@tmp{{\@@mod}{#4}}}%
\def\extractcolorspec#1#2%
{%
\ifcsname \@backslashchar color@#1\endcsname
\begingroup
\let\xcolor@\XC@extractcolorspec
\@nameuse{\@backslashchar color@#1}%
\aftergroupdef#2\@@tmp
\else
\XC@split{#1}\edef\@@tmp{{\@@mod}{\@@clr}}\aftergroupdef#2\@@tmp
\fi
}
\begin{document}
\extractcolorspec{red}\mycolor \show\mycolor
\extractcolorspec{red!50!blue}\mycolor \show\mycolor
\ExplSyntaxOn
\benchmark:n {\extractcolorspec{red}\mycolor}
\benchmark:n {\extractcolorspec{red!50!blue}\mycolor}
\ExplSyntaxOff
abc
\end{document}
More findings, still incomplete
\string\color@
\pgfutil@doifcolorelse{<color>}{<true>}{<false>}
, used to test if a color is defined, so tikz can distinguish \draw[red]
(color expression as unknown key) from \draw[-Stealth]
(arrow specification as unknown key).
Thus a new interface is needed, which tests whether a color is defined.
https://github.com/pgf-tikz/pgf/blob/ca303609e828dd2824b9e2b9dbfcc9241b546988/tex/generic/pgf/utilities/pgfutil-latex.def#L51-L58color@#2
in csname
\pgfutil@colorlet{<name>}{<color>}
, used to test if a defined color is an ordinary or a named color, so \pgfutil@colorlet
can be used to let internal names to arbitrary defined colors.
Thus a new interface is needed, which tests whether a defined color is ordinary or named.
https://github.com/pgf-tikz/pgf/blob/ca303609e828dd2824b9e2b9dbfcc9241b546988/tex/generic/pgf/utilities/pgfutil-latex.def#L31-L40\set@color
and \reset@color
dvisvgm
driver pgfsys-dvisvgm.def
, used to prepend code that write dvisvgm:raw
specials. The corresponding graphics
driver dvisvgm.def
defines these commands the same as those in dvips.def
.
Need to check if this patching is really needed.
https://github.com/pgf-tikz/pgf/blob/ca303609e828dd2824b9e2b9dbfcc9241b546988/tex/generic/pgf/systemlayer/pgfsys-dvisvgm.def#L144-L149
- found in \pgfutil@doifcolorelse{
}{ }{ }, used to test if a color is defined, so tikz can distinguish \draw[red] (color expression as unknown key)
We should provide a counterpart to \color_if_exist:nTF
in l3color. The main question is the name. Perhaps \IfColorExistTF
? But I wonder a bit about the pgf code, this handles only defined color names, like red
, but tikz actually also can handle color expressions, e.g. \draw[red!50!white]
, obviously in the unknown key handler. Why doesn't handle red
there too?
- found in
\pgfutil@colorlet{<name>}{<color>}
Imho the xcolor documentation is confusing here. It uses named
both for the special named color model useful only with postscript and for the general concept of a color name like red or Goldenrod. Imho pgf wants here to force a color conversion into a target model (in case this has been set with \selectcolormodel
). Using [named]
for this works but is imho conceptuelly wrong. The correct things would be imho \colorlet{#1}[\XC@tgt@mod{}]{#2}
. (\XC@tgt@mod{}
expands either to empty or to a color model). Imho we should here provide a command which expands to the target model, similar to \l_color_fixed_model_tl
in l3color. Any suggestion about a good name.
- redefinition of \set@color and \reset@color
It could be that this is related to the missing support of fill and stroke colors in xcolor and could be resolved by switching to l3color as underlying color system. But that requires first to get rid of the use of \string\color@XXX
@josephwright any comments on the names for the public interfaces?
I'm trying to improve the use of spot colors in LaTeX (for some background see https://www.tug.org/TUGboat/tb43-2/tb134fischer-spotcolor.pdf) and also to unify the color packages.
A good solution for this problem requires the switch to the color commands provided the l3color module. This is complicated as various packages use "internal" commands of the color and xcolor package and would break if these internal commands change. (This is not meant as a reproach, due to the long history of these packages I'm quite aware that the border between internal and public interfaces are quite blurry and that some uses of internal commands simply reflect the fact that some interfaces were or still are missing.)
Problematic uses of internal color commands in pgf are from my point of view for example
\string\color...
especially if they rely on the internal structure of the command\set@color
and\reset@color
\current@color
assignments to the dot color
.
as this changes the reserved color name.
I would be grateful if you could look if pgf could switch here to "official" interfaces. I'm also interested to know if some interfaces are missing in the color packages.