Open lvjr opened 2 years ago
well https://en.wikipedia.org/wiki/HSL_and_HSV doesn't think much of these color models. And they don't have much use in PDF. I doubt that we will add them. But the formula to convert HSL to HSB looks rather simple, so you could simply use \fpeval to do it:
\documentclass{article}
\usepackage{xcolor}
\ExplSyntaxOn
\cs_new:Npn\lvjr_convert_Hsl:nnn #1#2#3
{
#1,
\fpeval{#3 + #2*min(#3,1-#3)},
\fpeval
{
(#3 + #2*min(#3,1-#3))=0?
0:
round(2*(1-#3/(#3 + #2*min(#3,1-#3))),5)
}
}
\fp_trap:nn{invalid_operation}{none}% avoid error from 0/0
\definecolor{test}{Hsb}{\lvjr_convert_Hsl:nnn{180}{0.5}{0.5}}
\definecolor{testb}{Hsb}{\lvjr_convert_Hsl:nnn{0}{1}{0.5}}
\fp_trap:nn{invalid_operation}{error}%
\ExplSyntaxOff
\begin{document}
\color{test} ccccc
\color{testb} bbbb
\end{document}
HTML
uses HSL
but not HSB
. For HTML
output, it is more natural to use HSL
colors.
In
HSL
color model, whenL
goes from0
to1
, the color goes from black to white. Therefore it is much easier to control color contrast.
WCAG
color contrast is used in PDF/UA
standard. But RGB
, CMY
and HSB
don't have this feature. So IMHO it may be a good idea to encourage users to choose colors with HSL
color model.
In case anyone wants to do add an other color model to xcolor, it could be worth wile to go with Oklch instead, which was recently added to CSS Color Module Level 4 on the strength of both matching human color perception rather well and being comparatively simple to compute. You can try an online color picker here or there.
At present,
xcolor
supportsHSB
color model. It would be nice if it also supportsHSL
color model. InHSL
color model, whenL
goes from0
to1
, the color goes from black to white. Therefore it is much easier to control color contrast.