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

Support HSL color model #25

Open
lvjr opened this issue Nov 1, 2022 · 4 comments
Open

Support HSL color model #25

lvjr opened this issue Nov 1, 2022 · 4 comments

Comments

@lvjr
Copy link

lvjr commented Nov 1, 2022

At present, xcolor supports HSB color model. It would be nice if it also supports HSL color model. In HSL color model, when L goes from 0 to 1, the color goes from black to white. Therefore it is much easier to control color contrast.

@u-fischer
Copy link
Member

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}

@lvjr
Copy link
Author

lvjr commented Nov 5, 2022

HTML uses HSL but not HSB. For HTML output, it is more natural to use HSL colors.

@lvjr
Copy link
Author

lvjr commented Jan 28, 2023

In HSL color model, when L goes from 0 to 1, 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.

@mgkurtz
Copy link

mgkurtz commented Nov 26, 2023

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.

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