[latex3-commits] [git/LaTeX3-latex3-latex3] main: Allow for expressions inside RGB/HSB colors (b254573fd)

Joseph Wright joseph.wright at morningstar2.co.uk
Fri Jan 27 14:49:41 CET 2023


Repository : https://github.com/latex3/latex3
On branch  : main
Link       : https://github.com/latex3/latex3/commit/b254573fdec0bc9421e1172da85988acbb48375f

>---------------------------------------------------------------

commit b254573fdec0bc9421e1172da85988acbb48375f
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Fri Jan 27 13:49:36 2023 +0000

    Allow for expressions inside RGB/HSB colors


>---------------------------------------------------------------

b254573fdec0bc9421e1172da85988acbb48375f
 l3experimental/CHANGELOG.md       |  3 +++
 l3kernel/l3color.dtx              | 14 +++++++-------
 l3kernel/testfiles/m3color002.lvt |  8 ++++++++
 l3kernel/testfiles/m3color002.tlg | 30 ++++++++++++++++++++++--------
 4 files changed, 40 insertions(+), 15 deletions(-)

diff --git a/l3experimental/CHANGELOG.md b/l3experimental/CHANGELOG.md
index d147f91b3..dff0330c3 100644
--- a/l3experimental/CHANGELOG.md
+++ b/l3experimental/CHANGELOG.md
@@ -7,6 +7,9 @@ this project uses date-based 'snapshot' version identifiers.
 
 ## [Unreleased]
 
+### Fixed
+- Allow for expressions within color `RGB`/`HSB` input
+
 ## [2023-01-24]
 
 ### Changed
diff --git a/l3kernel/l3color.dtx b/l3kernel/l3color.dtx
index 6cda94918..c4c101012 100644
--- a/l3kernel/l3color.dtx
+++ b/l3kernel/l3color.dtx
@@ -1150,7 +1150,7 @@
     { rgb }
     {
       \exp_args:Ne \@@_parse_model_hsb_aux:nnn
-        { \fp_eval:n { 6 * #1 } } {#2} {#3}
+        { \fp_eval:n { 6 * (#1) } } {#2} {#3}
     }
   }
 \cs_new:Npn \@@_parse_model_hsb_aux:nnn #1#2#3
@@ -1183,9 +1183,9 @@
 \cs_new:Npn \@@_parse_model_HSB:w #1 , #2 , #3 , #4 \s_@@_stop
   {
     \exp_args:Neee \@@_parse_model_hsb:nnn
-      { \fp_eval:n {#1 / 240} }
-      { \fp_eval:n {#2 / 240} }
-      { \fp_eval:n {#3 / 240} }
+      { \fp_eval:n { round((#1) / 240,5) } }
+      { \fp_eval:n { round((#2) / 240,5) } }
+      { \fp_eval:n { round((#3) / 240,5) } }
   }
 \cs_new:Npn \@@_parse_model_HTML:w #1 , #2 \s_@@_stop
   { \@@_parse_model_HTML_aux:w #1 0 0 0 0 0 0 \s_@@_stop }
@@ -1202,9 +1202,9 @@
   {
     { rgb }
     {
-      \fp_eval:n { round(#1 / 255,5) } ~
-      \fp_eval:n { round(#2 / 255,5) } ~
-      \fp_eval:n { round(#3 / 255,5) }
+      \fp_eval:n { round((#1) / 255,5) } ~
+      \fp_eval:n { round((#2) / 255,5) } ~
+      \fp_eval:n { round((#3) / 255,5) }
     }
   }
 %    \end{macrocode}
diff --git a/l3kernel/testfiles/m3color002.lvt b/l3kernel/testfiles/m3color002.lvt
index b4cdad349..4d91abe76 100644
--- a/l3kernel/testfiles/m3color002.lvt
+++ b/l3kernel/testfiles/m3color002.lvt
@@ -78,6 +78,14 @@
     \color_show:n { foo2 }
   }
 
+\TEST { Expressions~in~converted~models }
+  {
+    \color_set:nnn { foo1 } { HSB } { 20 + 10 ,  { 20 / 2 } , 11 - 1 }
+    \color_show:n { foo1 }
+    \color_set:nnn { foo1 } { RGB } { 5 + 5 + 10 , 4 * 10 , { 120 / 2 } }
+    \color_show:n { foo1 }
+  }
+
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 \TEST { cmy~model }
diff --git a/l3kernel/testfiles/m3color002.tlg b/l3kernel/testfiles/m3color002.tlg
index d4fcdd9e2..22d61d8e3 100644
--- a/l3kernel/testfiles/m3color002.tlg
+++ b/l3kernel/testfiles/m3color002.tlg
@@ -170,7 +170,7 @@ TEST 5: Integer/integer-like models
 ============================================================
 The color foo1 has the properties:
 >  model  =>  rgb
->  rgb  =>  0.04166666666666667 0.04123 0.03993.
+>  rgb  =>  0.04167 0.04124 0.03993.
 <recently read> }
 l. ...  }
 The color foo1 has the properties:
@@ -187,7 +187,21 @@ The color foo2 has the properties:
 l. ...  }
 ============================================================
 ============================================================
-TEST 6: cmy model
+TEST 6: Expressions in converted models
+============================================================
+The color foo1 has the properties:
+>  model  =>  rgb
+>  rgb  =>  0.04167 0.04124 0.03993.
+<recently read> }
+l. ...  }
+The color foo1 has the properties:
+>  model  =>  rgb
+>  rgb  =>  0.07843 0.15686 0.23529.
+<recently read> }
+l. ...  }
+============================================================
+============================================================
+TEST 7: cmy model
 ============================================================
 The color foo1 has the properties:
 >  model  =>  cmyk
@@ -196,7 +210,7 @@ The color foo1 has the properties:
 l. ...  }
 ============================================================
 ============================================================
-TEST 7: tHsb model
+TEST 8: tHsb model
 ============================================================
 The color foo1 has the properties:
 >  model  =>  rgb
@@ -224,7 +238,7 @@ The color foo4 has the properties:
 l. ...  }
 ============================================================
 ============================================================
-TEST 8: &spot model
+TEST 9: &spot model
 ============================================================
 The color foo1 has the properties:
 >  model  =>  gray
@@ -233,7 +247,7 @@ The color foo1 has the properties:
 l. ...  }
 ============================================================
 ============================================================
-TEST 9: Exporting colors
+TEST 10: Exporting colors
 ============================================================
 > \l_tmpa_tl={rgb}{0.0 0.0 1.0}.
 <recently read> }
@@ -285,7 +299,7 @@ l. ...  }
 l. ...  }
 ============================================================
 ============================================================
-TEST 10: Exporting color: errors
+TEST 11: Exporting color: errors
 ============================================================
 ! LaTeX Error: Unknown export format 'mumble'.
 For immediate help type H <return>.
@@ -295,7 +309,7 @@ LaTeX has been asked to export a color in format 'mumble', but this has never
 been defined.
 ============================================================
 ============================================================
-TEST 11: Exporting complex models
+TEST 12: Exporting complex models
 ============================================================
 > \l_tmpa_tl={BarToneCMYK}{0.6}.
 <recently read> }
@@ -335,7 +349,7 @@ l. ...  }
 l. ...  }
 ============================================================
 ============================================================
-TEST 12: Multiple models
+TEST 13: Multiple models
 ============================================================
 The color foo3 has the properties:
 >  model  =>  rgb





More information about the latex3-commits mailing list.