From 5e6c36a86d4bca486465e216ffd216bfd57a106f Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Wed, 12 Jan 2022 21:22:19 +0000
Subject: l3 (12jan22)

git-svn-id: svn://tug.org/texlive/trunk@61588 c570f23f-e606-0410-a88d-b1316a301751
---
 .../texmf-dist/tex/latex/l3kernel/expl3-code.tex   | 826 +++++++++++++++------
 1 file changed, 590 insertions(+), 236 deletions(-)

(limited to 'Master/texmf-dist/tex/latex/l3kernel/expl3-code.tex')

diff --git a/Master/texmf-dist/tex/latex/l3kernel/expl3-code.tex b/Master/texmf-dist/tex/latex/l3kernel/expl3-code.tex
index 9bbbaa1dc45..9978b7ca997 100644
--- a/Master/texmf-dist/tex/latex/l3kernel/expl3-code.tex
+++ b/Master/texmf-dist/tex/latex/l3kernel/expl3-code.tex
@@ -55,9 +55,9 @@
 %% l3text-purify.dtx  (with options: `package')
 %% l3candidates.dtx  (with options: `package')
 %% l3legacy.dtx  (with options: `package')
-%% l3deprecation.dtx  (with options: `package,kernel')
+%% l3deprecation.dtx  (with options: `package')
 %% 
-%% Copyright (C) 1990-2021 The LaTeX Project
+%% Copyright (C) 1990-2022 The LaTeX Project
 %% 
 %% It may be distributed and/or modified under the conditions of
 %% the LaTeX Project Public License (LPPL), either version 1.3c of
@@ -70,7 +70,7 @@
 %% and all files in that bundle must be distributed together.
 %% 
 %% File: expl3.dtx
-\def\ExplFileDate{2021-11-22}%
+\def\ExplFileDate{2022-01-12}%
 \begingroup
   \def\next{\endgroup}%
   \expandafter\ifx\csname PackageError\endcsname\relax
@@ -7526,19 +7526,12 @@
       }
   }
 \bool_new:N \g__sys_debug_bool
-\bool_new:N \g__sys_deprecation_bool
 \cs_new_protected:Npn \sys_load_debug:
   {
     \bool_if:NF \g__sys_debug_bool
       { \__kernel_sys_configuration_load:n { l3debug } }
     \bool_gset_true:N \g__sys_debug_bool
   }
-\cs_new_protected:Npn \sys_load_deprecation:
-  {
-    \bool_if:NF \g__sys_deprecation_bool
-      { \__kernel_sys_configuration_load:n { l3deprecation } }
-    \bool_gset_true:N \g__sys_deprecation_bool
-  }
 \tl_new:N \l__sys_internal_tl
 \tl_const:Nx \c__sys_marker_tl { : \token_to_str:N : }
 \cs_new_protected:Npn \sys_get_shell:nnN #1#2#3
@@ -8082,8 +8075,8 @@
 \cs_new:Npn \__clist_remove_all:
   { \exp_after:wN \__clist_remove_all:w \__clist_tmp:w , }
 \cs_new:Npn \__clist_remove_all:w #1 , \s__clist_mark , #2 , { \exp_not:n {#1} }
-\cs_generate_variant:Nn \clist_remove_all:Nn  { c }
-\cs_generate_variant:Nn \clist_gremove_all:Nn { c }
+\cs_generate_variant:Nn \clist_remove_all:Nn  { c , NV , cV }
+\cs_generate_variant:Nn \clist_gremove_all:Nn { c , NV , cV }
 \cs_new_protected:Npn \clist_reverse:N #1
   { \__kernel_tl_set:Nx #1 { \exp_args:No \clist_reverse:n {#1} } }
 \cs_new_protected:Npn \clist_greverse:N #1
@@ -9287,6 +9280,44 @@
       \exp_after:wN \__peek_false:w
     \fi:
   }
+\cs_new_protected:Npn \peek_remove_filler:n #1
+  {
+    \cs_set:Npn \__peek_true_aux:w { \__peek_remove_filler:w }
+    \cs_set:Npx \__peek_false:w
+      {
+        \exp_not:N \group_align_safe_end:
+        \exp_not:n {#1}
+      }
+    \group_align_safe_begin:
+    \__peek_remove_filler:w
+  }
+\cs_new_protected:Npn \__peek_remove_filler:w
+  {
+    \exp_after:wN \peek_after:Nw \exp_after:wN \__peek_remove_filler:
+    \exp:w \exp_end_continue_f:w
+  }
+\cs_new_protected:Npn \__peek_remove_filler:
+  {
+    \if_catcode:w \exp_not:N \l_peek_token \c_space_token
+      \exp_after:wN \__peek_true_remove:w
+    \else:
+      \if_meaning:w \l_peek_token \scan_stop:
+        \exp_after:wN \exp_after:wN \exp_after:wN
+          \__peek_true_remove:w
+      \else:
+        \exp_after:wN \exp_after:wN \exp_after:wN
+          \__peek_remove_filler_expand:w
+      \fi:
+    \fi:
+  }
+\cs_new_protected:Npn \__peek_remove_filler_expand:w
+  {
+    \exp_after:wN \if_meaning:w \exp_not:N \l_peek_token \l_peek_token
+      \exp_after:wN \__peek_false:w
+    \else:
+      \exp_after:wN \__peek_remove_filler:w
+    \fi:
+  }
 \cs_new_protected:Npn \__peek_token_generic_aux:NNNTF #1#2#3#4#5
   {
     \group_align_safe_begin:
@@ -9372,29 +9403,6 @@
           }
       }
   }
-\tl_map_inline:nn
-  {
-    { catcode } { catcode_remove }
-    { charcode } { charcode_remove }
-    { meaning } { meaning_remove }
-  }
-  {
-    \cs_new_protected:cpx { peek_#1_ignore_spaces:NTF } ##1##2##3
-      {
-        \peek_remove_spaces:n
-          { \exp_not:c { peek_#1:NTF } ##1 {##2} {##3} }
-      }
-    \cs_new_protected:cpx { peek_#1_ignore_spaces:NT } ##1##2
-      {
-        \peek_remove_spaces:n
-          { \exp_not:c { peek_#1:NT } ##1 {##2} }
-      }
-    \cs_new_protected:cpx { peek_#1_ignore_spaces:NF } ##1##2
-      {
-        \peek_remove_spaces:n
-          { \exp_not:c { peek_#1:NF } ##1 {##2} }
-      }
-  }
 \group_begin:
   \cs_set_protected:Npn \__peek_tmp:w #1 \s__peek_stop
     {
@@ -9612,6 +9620,42 @@
   }
 \cs_new:Npn \__prop_count:nn #1#2 { + 1 }
 \cs_generate_variant:Nn \prop_count:N { c }
+\cs_if_exist:NTF \tex_expanded:D
+  {
+    \cs_new:Npn \prop_to_keyval:N #1
+      {
+        \__kernel_exp_not:w
+          \prop_if_empty:NTF #1
+            { {} }
+            {
+              \exp_after:wN \exp_after:wN \exp_after:wN
+              {
+                \tex_expanded:D
+                  {
+                    \__kernel_exp_not:w { \use_none:n }
+                    \prop_map_function:NN #1 \__prop_to_keyval:nn
+                  }
+              }
+            }
+      }
+    \cs_new:Npn \__prop_to_keyval:nn #1#2
+      { , ~ {#1} =~ { \__kernel_exp_not:w {#2} } }
+  }
+  {
+    \cs_new:Npn \prop_to_keyval:N #1
+      {
+        \__kernel_exp_not:w
+          \prop_if_empty:NTF #1
+            { {} }
+            {
+              \prop_map_function:NN #1 \__prop_to_keyval:nnw
+              \__prop_to_keyval_exp_after:wN { \use_none:n }
+            }
+      }
+    \cs_new_eq:NN \__prop_to_keyval_exp_after:wN \exp_after:wN
+    \cs_new:Npn \__prop_to_keyval:nnw #1#2#3 \__prop_to_keyval_exp_after:wN #4
+      { #3 \__prop_to_keyval_exp_after:wN { #4 , ~ {#1} =~ {#2} } }
+  }
 \prg_new_protected_conditional:Npnn \prop_pop:NnN #1#2#3 { T , F , TF }
   {
     \__prop_split:NnTF #1 {#2}
@@ -12965,11 +13009,11 @@
   \__keyval_tmp:w { ~ }
 \group_end:
 \str_const:Nn \c__keys_code_root_str     { key~code~>~ }
+\str_const:Nn \c__keys_check_root_str    { key~check~>~ }
 \str_const:Nn \c__keys_default_root_str  { key~default~>~ }
 \str_const:Nn \c__keys_groups_root_str   { key~groups~>~ }
 \str_const:Nn \c__keys_inherit_root_str  { key~inherit~>~ }
 \str_const:Nn \c__keys_type_root_str     { key~type~>~ }
-\str_const:Nn \c__keys_validate_root_str { key~validate~>~ }
 \str_const:Nn \c__keys_props_root_str { key~prop~>~ }
 \int_new:N \l_keys_choice_int
 \tl_new:N \l_keys_choice_tl
@@ -12993,6 +13037,8 @@
 \bool_new:N \l__keys_tmp_bool
 \tl_new:N \l__keys_tmpa_tl
 \tl_new:N \l__keys_tmpb_tl
+\prop_new:N \l_keys_usage_load_prop
+\prop_new:N \l_keys_usage_preamble_prop
 \scan_new:N \s__keys_nil
 \scan_new:N \s__keys_mark
 \scan_new:N \s__keys_stop
@@ -13259,7 +13305,7 @@
 \cs_new_protected:Npn \__keys_undefine:
   {
     \clist_map_inline:nn
-      { code , default , groups , inherit , type , validate }
+      { code , default , groups , inherit , type , check }
       {
         \cs_set_eq:cN
           { \tl_use:c { c__keys_ ##1 _root_str } \l_keys_path_str }
@@ -13273,17 +13319,17 @@
         { true }
           {
             \cs_set_eq:cc
-              { \c__keys_validate_root_str \l_keys_path_str }
-              { __keys_validate_ #1 : }
+              { \c__keys_check_root_str \l_keys_path_str }
+              { __keys_check_ #1 : }
           }
         { false }
           {
             \cs_if_eq:ccT
-              { \c__keys_validate_root_str \l_keys_path_str }
-              { __keys_validate_ #1 : }
+              { \c__keys_check_root_str \l_keys_path_str }
+              { __keys_check_ #1 : }
               {
                 \cs_set_eq:cN
-                  { \c__keys_validate_root_str \l_keys_path_str }
+                  { \c__keys_check_root_str \l_keys_path_str }
                   \tex_undefined:D
               }
           }
@@ -13294,7 +13340,7 @@
           { .value_ #1 :n }
       }
   }
-\cs_new_protected:Npn \__keys_validate_forbidden:
+\cs_new_protected:Npn \__keys_check_forbidden:
   {
     \bool_if:NF \l__keys_no_value_bool
       {
@@ -13303,7 +13349,7 @@
         \use_none:nnn
       }
   }
-\cs_new_protected:Npn \__keys_validate_required:
+\cs_new_protected:Npn \__keys_check_required:
   {
     \bool_if:NT \l__keys_no_value_bool
       {
@@ -13312,6 +13358,52 @@
         \use_none:nnn
       }
   }
+\cs_new_protected:Npn \__keys_usage:n #1
+  {
+    \str_case:nnF {#1}
+      {
+        { general }
+          {
+            \__keys_usage:NN \l_keys_usage_load_prop
+              \c_false_bool
+            \__keys_usage:NN \l_keys_usage_preamble_prop
+              \c_false_bool
+          }
+        { load }
+          {
+            \__keys_usage:NN \l_keys_usage_load_prop
+              \c_true_bool
+            \__keys_usage:NN \l_keys_usage_preamble_prop
+              \c_false_bool
+          }
+        { preamble }
+          {
+            \__keys_usage:NN \l_keys_usage_load_prop
+              \c_false_bool
+            \__keys_usage:NN \l_keys_usage_preamble_prop
+              \c_true_bool
+          }
+      }
+      {
+        \msg_error:nnnn { keys }
+          { choice-unknown }
+          { .usage:n }
+          {#1}
+      }
+  }
+\cs_new_protected:Npn \__keys_usage:NN #1#2
+  {
+    \prop_get:NVNF #1 \l__keys_module_str \l__keys_tmpa_tl
+      { \tl_clear:N \l__keys_tmpa_tl }
+    \tl_set:Nx \l__keys_tmpb_tl
+      { \exp_after:wN \__keys_usage:w \l_keys_path_str \s__keys_stop }
+    \bool_if:NTF #2
+      { \clist_put_right:NV \l__keys_tmpa_tl \l__keys_tmpb_tl }
+      { \clist_remove_all:NV \l__keys_tmpa_tl \l__keys_tmpb_tl }
+    \prop_put:NVV #1 \l__keys_module_str
+      \l__keys_tmpa_tl
+  }
+\cs_new:Npn \__keys_usage:w #1 / #2 \s__keys_stop {#2}
 \cs_new_protected:Npn \__keys_variable_set:NnnN #1#2#3#4
   {
     \use:c { #2_if_exist:NF } #1 { \use:c { #2 _new:N } #1 }
@@ -13505,10 +13597,28 @@
   { \__keys_variable_set:cnnN {#1} { tl } { g } x }
 \cs_new_protected:cpn { \c__keys_props_root_str .undefine: }
   { \__keys_undefine: }
+\cs_new_protected:cpn { \c__keys_props_root_str .usage:n } #1
+  { \__keys_usage:n {#1} }
 \cs_new_protected:cpn { \c__keys_props_root_str .value_forbidden:n } #1
   { \__keys_value_requirement:nn { forbidden } {#1} }
 \cs_new_protected:cpn { \c__keys_props_root_str .value_required:n } #1
   { \__keys_value_requirement:nn { required } {#1} }
+\group_begin:
+  \cs_set_protected:Npn \__keys_tmp:nn #1#2
+    {
+      \quark_if_recursion_tail_stop:n {#1}
+      \cs_new_eq:cc
+        { \c__keys_props_root_str . #2 }
+        { \c__keys_props_root_str . #1 }
+      \__keys_tmp:nn
+    }
+  \__keys_tmp:nn
+    { legacy_if:n } { if }
+    { tl_set:N }    { store }
+    { usage:n }     { usage }
+    { \q_recursion_tail } { }
+    \q_recursion_stop
+\group_end:
 \cs_new_protected:Npn \keys_set:nn #1#2
   {
     \use:x
@@ -13784,7 +13894,7 @@
   {
     \cs_if_exist:cTF { \c__keys_code_root_str \l_keys_path_str }
       {
-        \cs_if_exist_use:c { \c__keys_validate_root_str \l_keys_path_str }
+        \cs_if_exist_use:c { \c__keys_check_root_str \l_keys_path_str }
         \__keys_execute:no \l_keys_path_str \l_keys_value_tl
       }
       {
@@ -13803,7 +13913,7 @@
           { \c__keys_code_root_str ##1 / \l_keys_key_str }
           {
             \str_set:Nn \l__keys_inherit_str {##1}
-            \cs_if_exist_use:c { \c__keys_validate_root_str ##1 / \l_keys_key_str }
+            \cs_if_exist_use:c { \c__keys_check_root_str ##1 / \l_keys_key_str }
             \__keys_execute:no { ##1 / \l_keys_key_str } \l_keys_value_tl
             \clist_map_break:n \use_none:n
           }
@@ -13968,6 +14078,7 @@
       { \prg_return_true: }
       { \prg_return_false: }
   }
+\prg_generate_conditional_variant:Nnn \keys_if_exist:nn { ne } { T , F , TF }
 \prg_new_conditional:Npnn \keys_if_choice_exist:nnn #1#2#3
   { p , T , F , TF }
   {
@@ -23588,6 +23699,18 @@
   }
 \cs_new:Npn \__regex_maplike_break:
   { \prg_map_break:Nn \__regex_maplike_break: { } }
+\cs_new:Npn \__regex_tl_odd_items:n #1 { \__regex_tl_even_items:n { ? #1 } }
+\cs_new:Npn \__regex_tl_even_items:n #1
+  {
+    \__regex_tl_even_items_loop:nn #1 \q__regex_nil \q__regex_nil
+    \prg_break_point:
+  }
+\cs_new:Npn \__regex_tl_even_items_loop:nn #1#2
+  {
+    \__regex_use_none_delimit_by_q_nil:w #2 \prg_break: \q__regex_nil
+    { \exp_not:n {#2} }
+    \__regex_tl_even_items_loop:nn
+  }
 \cs_new:Npn \__regex_tmp:w { }
 \tl_new:N   \l__regex_internal_a_tl
 \tl_new:N   \l__regex_internal_b_tl
@@ -23609,11 +23732,12 @@
 \int_const:Nn \c__regex_ascii_max_int { 127 }
 \int_const:Nn \c__regex_ascii_lower_int { `a - `A }
 \quark_new:N \q__regex_recursion_stop
+\quark_new:N \q__regex_nil
 \cs_new:Npn \__regex_use_none_delimit_by_q_recursion_stop:w
   #1 \q__regex_recursion_stop { }
 \cs_new:Npn \__regex_use_i_delimit_by_q_recursion_stop:nw
   #1 #2 \q__regex_recursion_stop {#1}
-\quark_new:N \q__regex_nil
+\cs_new:Npn \__regex_use_none_delimit_by_q_nil:w #1 \q__regex_nil { }
 \__kernel_quark_new_conditional:Nn \__regex_quark_if_nil:N { F }
 \cs_new_protected:Npn \__regex_break_true:w
    #1 \__regex_break_point:TF #2 #3 {#2}
@@ -24215,6 +24339,20 @@
         }
     \__regex_compile_end:
   }
+\cs_new_protected:Npn \__regex_compile_use:n #1
+  {
+    \tl_if_single_token:nT {#1}
+      {
+        \exp_after:wN \__regex_compile_use_aux:w
+        \token_to_meaning:N #1 ~ \q__regex_nil
+      }
+    \__regex_compile:n {#1} \l__regex_internal_regex
+  }
+\cs_new_protected:Npn \__regex_compile_use_aux:w #1 ~ #2 \q__regex_nil
+  {
+    \str_if_eq:nnT { #1 ~ } { macro:->\__regex_branch:n }
+      { \use_ii:nnn }
+  }
 \cs_new_protected:Npn \__regex_compile_special:N #1
   {
     \cs_if_exist_use:cF { __regex_compile_#1: }
@@ -25382,6 +25520,60 @@
     \__regex_toks_put_right:Nn \l__regex_right_state_int
       { \__regex_action_success: }
   }
+\int_new:N \g__regex_case_int
+\int_new:N \l__regex_case_max_group_int
+\cs_new_protected:Npn \__regex_case_build:n #1
+  {
+    \__regex_case_build_aux:Nn \c_true_bool {#1}
+    \int_gzero:N \g__regex_case_int
+  }
+\cs_generate_variant:Nn \__regex_case_build:n { x }
+\cs_new_protected:Npn \__regex_case_build_aux:Nn #1#2
+  {
+    \__regex_standard_escapechar:
+    \int_set_eq:NN \l__regex_max_state_int \l__regex_min_state_int
+    \__regex_build_new_state:
+    \__regex_build_new_state:
+    \__regex_toks_put_right:Nn \l__regex_left_state_int
+      { \__regex_action_start_wildcard:N #1 }
+    %
+    \__regex_build_new_state:
+    \__regex_toks_put_left:Nx \l__regex_left_state_int
+      { \__regex_action_submatch:nN { 0 } < }
+    \__regex_push_lr_states:
+    \int_zero:N \l__regex_case_max_group_int
+    \int_gzero:N \g__regex_case_int
+    \tl_map_inline:nn {#2}
+      {
+        \int_gincr:N \g__regex_case_int
+        \__regex_case_build_loop:n {##1}
+      }
+    \int_set_eq:NN \l__regex_capturing_group_int \l__regex_case_max_group_int
+    \__regex_pop_lr_states:
+  }
+\cs_new_protected:Npn \__regex_case_build_loop:n #1
+  {
+    \int_set:Nn \l__regex_capturing_group_int { 1 }
+    \__regex_compile_use:n {#1}
+    \int_set:Nn \l__regex_case_max_group_int
+      {
+        \int_max:nn { \l__regex_case_max_group_int }
+          { \l__regex_capturing_group_int }
+      }
+    \seq_pop:NN \l__regex_right_state_seq \l__regex_internal_a_tl
+    \int_set:Nn \l__regex_right_state_int \l__regex_internal_a_tl
+    \__regex_toks_put_left:Nx \l__regex_right_state_int
+      {
+        \__regex_action_submatch:nN { 0 } >
+        \int_gset:Nn \g__regex_case_int
+          { \int_use:N \g__regex_case_int }
+        \__regex_action_success:
+      }
+    \__regex_toks_clear:N \l__regex_max_state_int
+    \seq_push:No \l__regex_right_state_seq
+      { \int_use:N \l__regex_max_state_int }
+    \int_incr:N \l__regex_max_state_int
+  }
 \cs_new_protected:Npn \__regex_build_for_cs:n #1
   {
     \int_set_eq:NN \l__regex_min_state_int \l__regex_max_state_int
@@ -25993,7 +26185,7 @@
 \int_new:N \l__regex_replacement_csnames_int
 \tl_new:N \l__regex_replacement_category_tl
 \seq_new:N \l__regex_replacement_category_seq
-\tl_new:N \l__regex_balance_tl
+\tl_new:N \g__regex_balance_tl
 \cs_new:Npn \__regex_replacement_balance_one_match:n #1
   { - \__regex_submatch_balance:n {#1} }
 \cs_new:Npn \__regex_replacement_do_one_match:n #1
@@ -26046,12 +26238,14 @@
           { 0 }
       }
   }
-\cs_new_protected:Npn \__regex_replacement:n #1
+\cs_new_protected:Npn \__regex_replacement:n
+  { \__regex_replacement_apply:Nn \__regex_replacement_set:n }
+\cs_new_protected:Npn \__regex_replacement_apply:Nn #1#2
   {
     \group_begin:
       \tl_build_begin:N \l__regex_build_tl
       \int_zero:N \l__regex_balance_int
-      \tl_clear:N \l__regex_balance_tl
+      \tl_gclear:N \g__regex_balance_tl
       \__regex_escape_use:nnnn
         {
           \if_charcode:w \c_right_brace_str ##1
@@ -26067,7 +26261,7 @@
         }
         { \__regex_replacement_escaped:N ##1 }
         { \__regex_replacement_normal:n ##1 }
-        {#1}
+        {#2}
       \prg_do_nothing: \prg_do_nothing:
       \if_int_compare:w \l__regex_replacement_csnames_int > \c_zero_int
         \msg_error:nnx { regex } { replacement-missing-rbrace }
@@ -26081,18 +26275,15 @@
             { \seq_count:N \l__regex_replacement_category_seq }
           \seq_clear:N \l__regex_replacement_category_seq
         }
-      \cs_gset:Npx \__regex_replacement_balance_one_match:n ##1
-        {
-          + \int_use:N \l__regex_balance_int
-          \l__regex_balance_tl
-          - \__regex_submatch_balance:n {##1}
-        }
+      \tl_gput_right:Nx \g__regex_balance_tl
+        { + \int_use:N \l__regex_balance_int }
       \tl_build_end:N \l__regex_build_tl
       \exp_args:NNo
     \group_end:
-    \__regex_replacement_aux:n \l__regex_build_tl
+    #1 \l__regex_build_tl
   }
-\cs_new_protected:Npn \__regex_replacement_aux:n #1
+\cs_generate_variant:Nn \__regex_replacement:n { x }
+\cs_new_protected:Npn \__regex_replacement_set:n #1
   {
     \cs_set:Npn \__regex_replacement_do_one_match:n ##1
       {
@@ -26107,6 +26298,37 @@
           }
         #1
       }
+    \exp_args:Nno \use:n
+      { \cs_gset:Npn \__regex_replacement_balance_one_match:n ##1 }
+      {
+        \g__regex_balance_tl
+        - \__regex_submatch_balance:n {##1}
+      }
+  }
+\tl_new:N \g__regex_case_replacement_tl
+\tl_new:N \g__regex_case_balance_tl
+\cs_new_protected:Npn \__regex_case_replacement:n #1
+  {
+    \tl_gset:Nn \g__regex_case_balance_tl
+      {
+        \if_case:w
+          \__kernel_intarray_item:Nn
+            \g__regex_submatch_case_intarray {##1}
+      }
+    \tl_gset_eq:NN \g__regex_case_replacement_tl \g__regex_case_balance_tl
+    \tl_map_tokens:nn {#1}
+      { \__regex_replacement_apply:Nn \__regex_case_replacement_aux:n }
+    \tl_gset:No \g__regex_balance_tl
+      { \g__regex_case_balance_tl \fi: }
+    \exp_args:No \__regex_replacement_set:n
+      { \g__regex_case_replacement_tl \fi: }
+  }
+\cs_generate_variant:Nn \__regex_case_replacement:n { x }
+\cs_new_protected:Npn \__regex_case_replacement_aux:n #1
+  {
+    \tl_gput_right:Nn \g__regex_case_replacement_tl { \or: #1 }
+    \tl_gput_right:No \g__regex_case_balance_tl
+      { \exp_after:wN \or: \g__regex_balance_tl }
   }
 \cs_new_protected:Npn \__regex_replacement_put:n
   { \tl_build_put_right:Nn \l__regex_build_tl }
@@ -26181,11 +26403,8 @@
     \tl_build_put_right:Nn \l__regex_build_tl
       { \__regex_query_submatch:n { \int_eval:n { #1 + ##1 } } }
     \if_int_compare:w \l__regex_replacement_csnames_int = \c_zero_int
-      \tl_put_right:Nn \l__regex_balance_tl
-        {
-          + \__regex_submatch_balance:n
-            { \exp_not:N \int_eval:n { #1 + ##1 } }
-        }
+      \tl_gput_right:Nn \g__regex_balance_tl
+        { + \__regex_submatch_balance:n { \int_eval:n { #1 + ##1 } } }
     \fi:
   }
 \cs_new_protected:Npn \__regex_replacement_g:w #1#2
@@ -26431,6 +26650,20 @@
   { \__regex_count:nnN { \__regex_build:n {#1} } }
 \cs_new_protected:Npn \regex_count:NnN #1
   { \__regex_count:nnN { \__regex_build:N #1 } }
+\cs_new_protected:Npn \regex_match_case:nnTF #1#2#3
+  {
+    \__regex_match_case:nnTF {#1} {#2}
+      {
+        \tl_item:nn {#1} { 2 * \g__regex_case_int }
+        #3
+      }
+  }
+\cs_new_protected:Npn \regex_match_case:nn #1#2
+  { \regex_match_case:nnTF {#1} {#2} { } { } }
+\cs_new_protected:Npn \regex_match_case:nnT #1#2#3
+  { \regex_match_case:nnTF {#1} {#2} {#3} { } }
+\cs_new_protected:Npn \regex_match_case:nnF #1#2
+  { \regex_match_case:nnTF {#1} {#2} { } }
 \cs_set_protected:Npn \__regex_tmp:w #1#2#3
   {
     \cs_new_protected:Npn #2 ##1 { #1 { \__regex_build:n {##1} } }
@@ -26449,6 +26682,52 @@
 \__regex_tmp:w \__regex_replace_all:nnN
   \regex_replace_all:nnN \regex_replace_all:NnN
 \__regex_tmp:w \__regex_split:nnN \regex_split:nnN \regex_split:NnN
+\cs_new_protected:Npn \regex_replace_case_once:nNTF #1#2
+  {
+    \int_if_odd:nTF { \tl_count:n {#1} }
+      {
+        \msg_error:nnxxxx { regex } { case-odd }
+          { \token_to_str:N \regex_replace_case_once:nN(TF) } { code }
+          { \tl_count:n {#1} } { \tl_to_str:n {#1} }
+        \use_ii:nn
+      }
+      {
+        \__regex_replace_once_aux:nnN
+          { \__regex_case_build:x { \__regex_tl_odd_items:n {#1} } }
+          { \__regex_replacement:x { \tl_item:nn {#1} { 2 * \g__regex_case_int } } }
+          #2
+        \bool_if:NTF \g__regex_success_bool
+      }
+  }
+\cs_new_protected:Npn \regex_replace_case_once:nN #1#2
+  { \regex_replace_case_once:nNTF {#1} {#2} { } { } }
+\cs_new_protected:Npn \regex_replace_case_once:nNT #1#2#3
+  { \regex_replace_case_once:nNTF {#1} {#2} {#3} { } }
+\cs_new_protected:Npn \regex_replace_case_once:nNF #1#2
+  { \regex_replace_case_once:nNTF {#1} {#2} { } }
+\cs_new_protected:Npn \regex_replace_case_all:nNTF #1#2
+  {
+    \int_if_odd:nTF { \tl_count:n {#1} }
+      {
+        \msg_error:nnxxxx { regex } { case-odd }
+          { \token_to_str:N \regex_replace_case_all:nN(TF) } { code }
+          { \tl_count:n {#1} } { \tl_to_str:n {#1} }
+        \use_ii:nn
+      }
+      {
+        \__regex_replace_all_aux:nnN
+          { \__regex_case_build:x { \__regex_tl_odd_items:n {#1} } }
+          { \__regex_case_replacement:x { \__regex_tl_even_items:n {#1} } }
+          #2
+        \bool_if:NTF \g__regex_success_bool
+      }
+  }
+\cs_new_protected:Npn \regex_replace_case_all:nN #1#2
+  { \regex_replace_case_all:nNTF {#1} {#2} { } { } }
+\cs_new_protected:Npn \regex_replace_case_all:nNT #1#2#3
+  { \regex_replace_case_all:nNTF {#1} {#2} {#3} { } }
+\cs_new_protected:Npn \regex_replace_case_all:nNF #1#2
+  { \regex_replace_case_all:nNTF {#1} {#2} { } }
 \int_new:N \l__regex_match_count_int
 \flag_new:n { __regex_begin }
 \flag_new:n { __regex_end }
@@ -26458,6 +26737,7 @@
 \intarray_new:Nn \g__regex_submatch_prev_intarray { 65536 }
 \intarray_new:Nn \g__regex_submatch_begin_intarray { 65536 }
 \intarray_new:Nn \g__regex_submatch_end_intarray { 65536 }
+\intarray_new:Nn \g__regex_submatch_case_intarray { 65536 }
 \intarray_new:Nn \g__regex_balance_intarray { 65536 }
 \int_new:N \l__regex_added_begin_int
 \int_new:N \l__regex_added_end_int
@@ -26499,6 +26779,23 @@
       \__regex_match:n {#2}
     \group_end:
   }
+\cs_new_protected:Npn \__regex_match_case:nnTF #1#2
+  {
+    \int_if_odd:nTF { \tl_count:n {#1} }
+      {
+        \msg_error:nnxxxx { regex } { case-odd }
+          { \token_to_str:N \regex_match_case:nn(TF) } { code }
+          { \tl_count:n {#1} } { \tl_to_str:n {#1} }
+        \use_ii:nn
+      }
+      {
+        \__regex_if_match:nn
+          { \__regex_case_build:x { \__regex_tl_odd_items:n {#1} } }
+          {#2}
+        \bool_if:NTF \g__regex_success_bool
+      }
+  }
+\cs_new:Npn \__regex_match_case_aux:nn #1#2 { \exp_not:n { {#1} } }
 \cs_new_protected:Npn \__regex_count:nnN #1#2#3
   {
     \group_begin:
@@ -26682,10 +26979,14 @@
         {
           \__kernel_intarray_gset:Nnn \g__regex_submatch_prev_intarray
             { \l__regex_submatch_int } { 0 }
+          \__kernel_intarray_gset:Nnn \g__regex_submatch_case_intarray
+            { \l__regex_submatch_int } { 0 }
           \int_incr:N \l__regex_submatch_int
         }
       \__kernel_intarray_gset:Nnn \g__regex_submatch_prev_intarray
         { \l__regex_zeroth_submatch_int } { \l__regex_start_pos_int }
+      \__kernel_intarray_gset:Nnn \g__regex_submatch_case_intarray
+        { \l__regex_zeroth_submatch_int } { \g__regex_case_int }
       \int_zero:N \l__regex_internal_a_int
       \exp_after:wN \__regex_extract_aux:w \l__regex_success_submatches_tl
         \prg_break_point: \__regex_use_none_delimit_by_q_recursion_stop:w ,
@@ -26705,18 +27006,19 @@
     \int_incr:N \l__regex_internal_a_int
     \__regex_extract_aux:w
   }
-\cs_new_protected:Npn \__regex_replace_once:nnN #1#2#3
+\cs_new_protected:Npn \__regex_replace_once:nnN #1#2
+  { \__regex_replace_once_aux:nnN {#1} { \__regex_replacement:n {#2} } }
+\cs_new_protected:Npn \__regex_replace_once_aux:nnN #1#2#3
   {
     \group_begin:
       \__regex_single_match:
       #1
       \exp_args:No \__regex_match:n {#3}
-      \if_meaning:w \c_false_bool \g__regex_success_bool
-        \group_end:
-      \else:
+    \bool_if:NTF \g__regex_success_bool
+      {
         \__regex_extract:
         \exp_args:No \__regex_query_set:n {#3}
-        \__regex_replacement:n {#2}
+        #2
         \int_set:Nn \l__regex_balance_int
           {
             \__regex_replacement_balance_one_match:n
@@ -26734,16 +27036,19 @@
               { \l__regex_max_pos_int }
           }
         \__regex_group_end_replace:N #3
-      \fi:
+      }
+      { \group_end: }
   }
-\cs_new_protected:Npn \__regex_replace_all:nnN #1#2#3
+\cs_new_protected:Npn \__regex_replace_all:nnN #1#2
+  { \__regex_replace_all_aux:nnN {#1} { \__regex_replacement:n {#2} } }
+\cs_new_protected:Npn \__regex_replace_all_aux:nnN #1#2#3
   {
     \group_begin:
       \__regex_multi_match:n { \__regex_extract: }
       #1
       \exp_args:No \__regex_match:n {#3}
       \exp_args:No \__regex_query_set:n {#3}
-      \__regex_replacement:n {#2}
+      #2
       \int_set:Nn \l__regex_balance_int
         {
           0
@@ -27271,6 +27576,13 @@
 \msg_new:nnnn { regex } { backwards-quantifier }
   { Quantifer~"{#1,#2}"~is~backwards. }
   { The~values~given~in~a~quantifier~must~be~in~order. }
+\msg_new:nnnn { regex } { case-odd }
+  { #1~with~odd~number~of~items }
+  {
+    There~must~be~a~#2~part~for~each~regex:~
+    found~odd~number~of~items~(#3)~in\\
+    \iow_indent:n {#4}
+  }
 \msg_new:nnn { regex } { show }
   {
     >~Compiled~regex~
@@ -28009,7 +28321,10 @@
 \cs_new_protected:Npn \__color_select:N #1
   { \exp_after:wN \__color_select:nn #1 }
 \cs_new_protected:Npn \__color_select:nn #1#2
-  { \use:c { __color_backend_select_ #1 :n } {#2} }
+  {
+    \use:c { __color_backend_select_ #1 :n } {#2}
+    \group_insert_after:N \__color_backend_reset:
+  }
 \tl_new:N \l__color_current_tl
 \tl_set:Nn \l__color_current_tl { { gray } { 0 } }
 
@@ -28033,22 +28348,50 @@
 \cs_new_protected:Npn \__color_convert:nnN #1#2#3
   { \__color_convert:nnVN {#1} {#2} #3 #3 }
 \cs_generate_variant:Nn \__color_convert:nnN { VV }
+\cs_generate_variant:Nn \exp_last_unbraced:Nf { c }
 \cs_new_protected:Npn \__color_convert:nnnN #1#2#3#4
   {
     \tl_set:Nx #4
       {
-        \cs_if_exist:cTF { __color_convert_ #1 _ #2 :w }
-          { \use:c { __color_convert_ #1 _ #2 :w } #3 \s__color_stop }
-          { \use:c { c__color_fallback_ #2 _tl } }
+        \cs_if_exist_use:cTF { __color_convert_ #1 _ #2 :w }
+          { #3 \s__color_stop }
+          {
+            \cs_if_exist:cTF { __color_convert_ \use:c { c__color_fallback_ #1 _tl } _ #2 :w }
+              {
+                \exp_last_unbraced:cf
+                  { __color_convert_ \use:c { c__color_fallback_ #1 _tl } _ #2 :w }
+                  { \use:c { __color_convert_ #1 _ \use:c { c__color_fallback_ #1 _tl } :w } #3 \s__color_stop }
+                  \s__color_stop
+              }
+              {
+                \exp_last_unbraced:cf
+                  { __color_convert_ \use:c { c__color_fallback_ #2 _tl } _ #2 :w }
+                  {
+                    \cs_if_exist_use:cTF { __color_convert_ #1 _ \use:c { c__color_fallback_ #2 _tl } :w }
+                      { #3 \s__color_stop }
+                      {
+                        \exp_last_unbraced:cf
+                          { __color_convert_ \use:c { c__color_fallback_ #1 _tl } _ \use:c { c__color_fallback_ #2 _tl } :w }
+                          { \use:c { __color_convert_ #1 _ \use:c { c__color_fallback_ #1 _tl } :w } #3 \s__color_stop }
+                          \s__color_stop
+                      }
+                  }
+                  \s__color_stop
+              }
+          }
       }
   }
 \cs_generate_variant:Nn \__color_convert:nnnN { nV , nnV }
+\cs_new:Npn \__color_convert_gray_gray:w #1 \s__color_stop
+  { #1 }
 \cs_new:Npn \__color_convert_gray_rgb:w #1 \s__color_stop
   { #1 ~ #1 ~ #1 }
 \cs_new:Npn \__color_convert_gray_cmyk:w #1 \s__color_stop
   { 0 ~ 0 ~ 0 ~ \fp_eval:n { 1 - #1 } }
 \cs_new:Npn \__color_convert_rgb_gray:w #1 ~ #2 ~ #3 \s__color_stop
   { \fp_eval:n { 0.3 * #1 + 0.59 * #2 + 0.11 * #3 } }
+\cs_new:Npn \__color_convert_rgb_rgb:w #1 \s__color_stop
+  { #1 }
 \cs_new:Npn \__color_convert_rgb_cmyk:w #1 ~ #2 ~ #3 \s__color_stop
   {
     \exp_args:Nf \__color_convert_rgb_cmyk:nnnn
@@ -28069,6 +28412,8 @@
     \fp_eval:n { 1 - min ( 1 , #2 + #4 ) } \c_space_tl
     \fp_eval:n { 1 - min ( 1 , #3 + #4 ) }
   }
+\cs_new:Npn \__color_convert_cmyk_cmyk:w #1 \s__color_stop
+  { #1 }
 \tl_new:N \l__color_model_tl
 \tl_new:N \l__color_value_tl
 \tl_new:N \l__color_next_model_tl
@@ -28421,7 +28766,7 @@
     \tl_set:Nn \l__color_model_tl {#1}
     \tl_set:Nn \l__color_value_tl {#2}
   }
-\cs_new_protected:Npx \__color_select:
+\cs_new_protected:Npx \__color_finalise_current:
   {
     \tl_set:Nx \exp_not:c { l__color_named_ . _tl }
       { \exp_not:N \__color_model:N \exp_not:N \l__color_current_tl }
@@ -28429,18 +28774,19 @@
     \prop_put:NVx \exp_not:c { l__color_named_ . _prop }
       \exp_not:c { l__color_named_ . _tl }
       { \exp_not:N \__color_values:N \exp_not:N \l__color_current_tl }
-    \__color_select:N \exp_not:N \l__color_current_tl
   }
 \cs_new_protected:Npn \color_select:n #1
   {
     \__color_parse:nN {#1} \l__color_current_tl
-    \__color_select:
+    \__color_finalise_current:
+    \__color_select:N \l__color_current_tl
   }
 \cs_new_protected:Npn \color_select:nn #1#2
   {
     \__color_select_main:Nw \l__color_current_tl
       #1 / / \s__color_mark #2 / / \s__color_stop
-    \__color_select:
+    \__color_finalise_current:
+    \__color_select:N \l__color_current_tl
   }
 \cs_new_protected:Npn \__color_select_main:Nw
   #1 #2 / #3 / #4 \s__color_mark #5 / #6 / #7 \s__color_stop
@@ -28710,9 +29056,9 @@
   { \tl_set:Nn #1 {#2} }
 \prop_new:N \l__color_internal_prop
 \int_new:N \g__color_model_int
-\tl_const:Nn \c__color_fallback_cmyk_tl { 0 ~ 0 ~ 0 ~ 1 }
-\tl_const:Nn \c__color_fallback_gray_tl { 1 }
-\tl_const:Nn \c__color_fallback_rgb_tl { 1 ~ 1 ~ 1 }
+\tl_const:Nn \c__color_fallback_cmyk_tl { cmyk }
+\tl_const:Nn \c__color_fallback_gray_tl { gray }
+\tl_const:Nn \c__color_fallback_rgb_tl { rgb }
 \prop_new:N \g__color_colorants_prop
 \prop_gput:Nnn \g__color_colorants_prop { black }   { Black }
 \prop_gput:Nnn \g__color_colorants_prop { blue }    { Blue }
@@ -28766,10 +29112,9 @@
           }
       }
   }
-\cs_new_protected:Npn \__color_model_init:nnnnn #1#2#3#4#5
+\cs_new_protected:Npn \__color_model_init:nnnn #1#2#3#4
   {
     \int_gincr:N \g__color_model_int
-    \tl_const:cn { c__color_fallback_ #1 _tl } { #4 }
     \clist_map_inline:nn { fill , stroke , select }
       {
         \cs_new_protected:cpx { __color_backend_ ##1 _ #1 :n } ####1
@@ -28781,23 +29126,13 @@
     \cs_new_protected:cpx { __color_model_ #1 _white: }
       {
         \prop_put:Nnn \exp_not:N \l__color_named_white_prop {#1}
-        { \exp_not:n {#5} }
+        { \exp_not:n {#4} }
         \exp_not:N \int_compare:nNnF { \tex_currentgrouplevel:D } = 0
           { \group_insert_after:N \exp_not:c { __color_model_ #1 _ white: } }
       }
     \use:c { __color_model_ #1 _white: }
   }
-\cs_generate_variant:Nn \__color_model_init:nnnnn { nnnxx }
-\cs_new_protected:Npn \__color_model_init:nnn #1#2#3
-  {
-    \__color_model_init:nnnxx { #1 } { #2 } { #3 }
-      {
-        1 \prg_replicate:nn { #2 - 1 } { ~ 1 }
-      }
-      {
-        0 \prg_replicate:nn { #2 - 1 } { ~ 0 }
-      }
-  }
+\cs_generate_variant:Nn \__color_model_init:nnnn { nnnx }
 \cs_new_protected:Npn \__color_model_separation:n #1
   {
     \prop_get:NnNTF \l__color_internal_prop { name }
@@ -28847,7 +29182,7 @@
 \cs_new_protected:Npn \__color_model_separation:w
   #1 , #2 , #3 , #4 , #5 \s__color_stop #6#7#8
   {
-    \__color_model_init:nnn {#6} { 1 } { separation }
+    \__color_model_init:nnnn {#6} { 1 } { separation } { 0 }
     \cs_new_eq:cN { __color_parse_mix_ #6 :nw } \__color_parse_mix_gray:nw
     \cs_new:cpn { __color_parse_model_ #6 :w } ##1 , ##2 \s__color_stop
       { {#6} { \__color_parse_number:n {##1} } }
@@ -28859,6 +29194,7 @@
   }
 \cs_new_protected:Npn \__color_model_separation_cmyk:nnnnnn #1#2#3#4#5#6
   {
+    \tl_const:cn { c__color_fallback_ #1 _tl } { cmyk }
     \cs_new:cpn { __color_convert_ #1 _cmyk:w } ##1 \s__color_stop
       {
          \fp_eval:n {##1 * #3} ~
@@ -28866,43 +29202,31 @@
          \fp_eval:n {##1 * #5} ~
          \fp_eval:n {##1 * #6}
       }
-    \__color_model_convert:nnn {#1} { cmyk } { rgb }
-    \__color_model_convert:nnn {#1} { cmyk } { gray }
+    \cs_new:cpn { __color_convert_cmyk_ #1 :w } ##1 \s__color_stop { 1 }
     \prop_gput:Nnn \g__color_alternative_values_prop {#1} { #3 , #4 , #5 , #6 }
     \__color_backend_separation_init:nnnnn {#2} { /DeviceCMYK } { }
       { 0 ~ 0 ~ 0 ~ 0 } { #3 ~ #4 ~ #5 ~ #6 }
   }
 \cs_new_protected:Npn \__color_model_separation_rgb:nnnnnn #1#2#3#4#5#6
   {
+    \tl_const:cn { c__color_fallback_ #1 _tl } { rgb }
     \cs_new:cpn { __color_convert_ #1 _rgb:w } ##1 \s__color_stop
       {
          \fp_eval:n {##1 * #3} ~
          \fp_eval:n {##1 * #4} ~
          \fp_eval:n {##1 * #5}
       }
-    \__color_model_convert:nnn {#1} { rgb } { cmyk }
-    \__color_model_convert:nnn {#1} { rgb } { gray }
+    \cs_new:cpn { __color_convert_rgb_ #1 :w } ##1 \s__color_stop { 1 }
     \prop_gput:Nnn \g__color_alternative_values_prop {#1} { #3 , #4 , #5 }
     \__color_backend_separation_init:nnnnn {#2} { /DeviceRGB } { }
       { 0 ~ 0 ~ 0 } { #3 ~ #4 ~ #5 }
   }
 \cs_new_protected:Npn \__color_model_separation_gray:nnnnnn #1#2#3#4#5#6
   {
-    \cs_new:cpn { __color_convert_ #1 _cmyk:w } ##1 \s__color_stop
-      {
-        \fp_eval:n {##1 * #3} ~
-        \fp_eval:n {##1 * #3} ~
-        \fp_eval:n {##1 * #3} ~
-        \fp_eval:n {##1 * #3}
-      }
+    \tl_const:cn { c__color_fallback_ #1 _tl } { gray }
     \cs_new:cpn { __color_convert_ #1 _gray:w } ##1 \s__color_stop
       { \fp_eval:n {##1 * #3} }
-    \cs_new:cpn { __color_convert_ #1 _rgb:w } ##1 \s__color_stop
-      {
-        \fp_eval:n {##1 * #3} ~
-        \fp_eval:n {##1 * #3} ~
-        \fp_eval:n {##1 * #3}
-      }
+    \cs_new:cpn { __color_convert_gray_ #1 :w } ##1 \s__color_stop { 1 }
     \prop_gput:Nnn \g__color_alternative_values_prop {#1} {#3}
     \__color_backend_separation_init:nnnnn {#2} { /DeviceGray } { } { 0 } {#3}
   }
@@ -28933,11 +29257,10 @@
     \tl_if_exist:cTF { c__color_model_whitepoint_CIELAB_ #1 _tl }
       {
         \__color_backend_separation_init_CIELAB:nnn {#1} {#3} { #4 ~ #5 ~ #6 }
-        \cs_new:cpn { __color_convert_ #2 _cmyk:w } ##1 \s__color_stop
-          { 0 ~ 0 ~ 0 ~ 1 }
-        \cs_new:cpn { __color_convert_ #2 _rgb:w } ##1 \s__color_stop
-          { 1 ~ 1 ~ 1 }
+        \tl_const:cn { c__color_fallback_ #2 _tl } { gray }
         \cs_new:cpn { __color_convert_ #2 _gray:w } ##1 \s__color_stop
+          { 0 }
+        \cs_new:cpn { __color_convert_gray_ #2 :w } ##1 \s__color_stop
           { 1 }
       }
       {
@@ -29001,12 +29324,18 @@
   }
 \cs_new_protected:Npn \__color_model_devicen:nnnn #1#2#3#4
   {
-    \__color_model_init:nnn {#4} {#1} { devicen }
+    \__color_model_init:nnnx {#4} {#1} { devicen }
+      {
+        0 \prg_replicate:nn { #1 - 1 } { ~ 0 }
+      }
     \cs_if_exist_use:cF { __color_model_devicen_parse_ #1 :nn }
       { \__color_model_devicen_parse_generic:nn }
         {#4} {#1}
     \__color_model_devicen_init:nnn {#1} {#2} {#3}
-    \__color_model_devicen_convert:nnn {#4} {#2} {#3}
+    \__color_model_devicen_convert:nnnx {#4} {#2} {#3}
+      {
+        1 \prg_replicate:nn { #1 - 1 } { ~ 1 }
+      }
   }
 \cs_new_protected:cpn { __color_model_devicen_parse_1:nn } #1#2
   {
@@ -29177,30 +29506,29 @@
   {
     / \prop_item:Nn \g__color_colorants_prop {#1} ~
   }
-\cs_new_protected:Npn \__color_model_devicen_convert:nnn #1#2#3
+\cs_new_protected:Npn \__color_model_devicen_convert:nnnn #1#2#3
   {
-    \use:c { __color_model_devicen_convert_ #2 :nn } {#1} {#3}
+    \use:c { __color_model_devicen_convert_ #2 :nnn } {#1} {#3}
   }
-\cs_new_protected:Npn \__color_model_devicen_convert_cmyk:nn #1#2
+\cs_generate_variant:Nn \__color_model_devicen_convert:nnnn { nnnx }
+\cs_new_protected:Npn \__color_model_devicen_convert_cmyk:nnn #1#2
   {
-    \__color_model_convert:nnn {#1} { cmyk } { gray }
-    \__color_model_convert:nnn {#1} { cmyk } { rgb }
-    \__color_model_devicen_convert:nnnn {#1} { cmyk } { 4 } {#2}
+    \tl_const:cn { c__color_fallback_ #1 _tl } { cmyk }
+    \__color_model_devicen_convert:nnnnn {#1} { cmyk } { 4 } {#2}
   }
-\cs_new_protected:Npn \__color_model_devicen_convert_gray:nn #1#2
+\cs_new_protected:Npn \__color_model_devicen_convert_gray:nnn #1#2
   {
-    \__color_model_convert:nnn {#1} { gray } { cmyk }
-    \__color_model_convert:nnn {#1} { gray } { rgb }
-    \__color_model_devicen_convert:nnnn {#1} { gray } { 1 } {#2}
+    \tl_const:cn { c__color_fallback_ #1 _tl } { gray }
+    \__color_model_devicen_convert:nnnnn {#1} { gray } { 1 } {#2}
   }
-\cs_new_protected:Npn \__color_model_devicen_convert_rgb:nn #1#2
+\cs_new_protected:Npn \__color_model_devicen_convert_rgb:nnn #1#2
   {
-    \__color_model_convert:nnn {#1} { rgb } { cmyk }
-    \__color_model_convert:nnn {#1} { rgb } { gray }
-    \__color_model_devicen_convert:nnnn {#1} { rgb } { 3 } {#2}
+    \tl_const:cn { c__color_fallback_ #1 _tl } { rgb }
+    \__color_model_devicen_convert:nnnnn {#1} { rgb } { 3 } {#2}
   }
-\cs_new_protected:Npn \__color_model_devicen_convert:nnnn #1#2#3#4
+\cs_new_protected:Npn \__color_model_devicen_convert:nnnnn #1#2#3#4#5
   {
+    \cs_new:cpn { __color_convert_ #2 _ #1 :w } ##1 \s__color_stop {#5}
     \cs_new:cpx { __color_convert_ #1 _ #2 :w } ##1 \s__color_stop
       {
         \exp_not:c { __color_convert_devicen_ #2 : \prg_replicate:nn {#3} { n } w }
@@ -29351,7 +29679,10 @@
   }
 \cs_new_protected:Npn \__color_model_iccbased_aux:nnnnnn #1#2#3#4#5#6
   {
-    \__color_model_init:nnnnn {#5} {#1} { iccbased } {#2} {#3}
+    \__color_model_init:nnnn {#5} {#1} { iccbased } {#3}
+    \tl_const:cn { c__color_fallback_ #5 _tl } { gray }
+    \cs_new:cpn { __color_convert_ #5 _gray:w } ##1 \s__color_stop { 0 }
+    \cs_new:cpn { __color_convert_gray_ #5 :w } ##1 \s__color_stop { #2 }
     \use:c { __color_model_devicen_parse_ #1 :nn } {#5} {#1}
     \exp_args:Nx \__color_backend_iccbased_init:nnn
       { \file_full_name:n {#6} } {#1} {#4}
@@ -34457,47 +34788,6 @@
     {#1}
   }
 %% File: l3deprecation.dtx
-\bool_new:N \l__deprecation_grace_period_bool
-\scan_new:N \s__deprecation_mark
-\scan_new:N \s__deprecation_stop
-\cs_new:Npn \__deprecation_date_compare:nNnTF #1#2#3
-  { \__deprecation_date_compare_aux:w #1 -0-0- \s__deprecation_mark #2 #3 -0-0- \s__deprecation_stop }
-\cs_new:Npn \__deprecation_date_compare_aux:w
-  #1 - #2 - #3 - #4 \s__deprecation_mark #5 #6 - #7 - #8 - #9 \s__deprecation_stop
-  {
-    \int_compare:nNnTF {#1} = {#6}
-      {
-        \int_compare:nNnTF {#2} = {#7}
-          { \int_compare:nNnTF {#3} #5 {#8} }
-          { \int_compare:nNnTF {#2} #5 {#7} }
-      }
-      { \int_compare:nNnTF {#1} #5 {#6} }
-  }
-\bool_new:N \g__kernel_deprecation_undo_recent_bool
-\cs_new_protected:Npn \__deprecation_not_yet_deprecated:nTF #1
-  {
-    \bool_set_false:N \l__deprecation_grace_period_bool
-    \exp_args:No \__deprecation_date_compare:nNnTF { \ExplLoaderFileDate } < {#1}
-      { \use_i:nn }
-      {
-        \exp_args:Nf \__deprecation_date_compare:nNnTF
-          {
-            \exp_after:wN \__deprecation_minus_six_months:w
-            \ExplLoaderFileDate -0-0- \s__deprecation_stop
-          } < {#1}
-          {
-            \bool_set_true:N \l__deprecation_grace_period_bool
-            \bool_if:NTF \g__kernel_deprecation_undo_recent_bool
-          }
-          { \use_ii:nn }
-      }
-  }
-\cs_new:Npn \__deprecation_minus_six_months:w #1 - #2 - #3 - #4 \s__deprecation_stop
-  {
-    \int_compare:nNnTF {#2} > 6
-      { #1 - \int_eval:n { #2 - 6 } - #3 }
-      { \int_eval:n { #1 - 1 } - \int_eval:n { #2 + 6 } - #3 }
-  }
 \cs_new_protected:Npn \__kernel_patch_deprecation:nnNNpn #1#2#3#4#5#
   { \__deprecation_patch_aux:nnNNnn {#1} {#2} #3 #4 {#5} }
 \cs_new_protected:Npn \__deprecation_patch_aux:nnNNnn #1#2#3#4#5#6
@@ -34508,18 +34798,9 @@
         \__kernel_deprecation_error:Nnn #4 {#2} {#1}
       }
       { \tex_let:D #4 \scan_stop: }
-    \__deprecation_not_yet_deprecated:nTF {#1}
-      {
-        \bool_if:nTF
-          {
-            \cs_if_eq_p:NN #3 \cs_gset_protected:Npn &&
-            \__kernel_if_debug:TF
-              { \c_true_bool } { \g__kernel_deprecation_undo_recent_bool }
-          }
-          { \__deprecation_warn_once:nnNnn {#1} {#2} #4 {#5} {#6} }
-          { \__deprecation_patch_aux:Nn #3 { #4 #5 {#6} } }
-      }
-      { \__deprecation_just_error:nnNN {#1} {#2} #3 #4 }
+     \cs_if_eq:NNTF #3 \cs_gset_protected:Npn
+        { \__deprecation_warn_once:nnNnn {#1} {#2} #4 {#5} {#6} }
+        { \__deprecation_patch_aux:Nn #3 { #4 #5 {#6} } }
   }
 \cs_new_protected:Npn \__deprecation_warn_once:nnNnn #1#2#3#4#5
   {
@@ -34547,23 +34828,6 @@
       { \__kernel_deprecation_code:nn { } { \cs_set_protected:Npn #2 } }
       { \__kernel_deprecation_code:nn { } { \cs_set:Npn #2 } }
   }
-\cs_new_protected:Npn \__deprecation_just_error:nnNN #1#2#3#4
-  {
-    \exp_args:NNx \__deprecation_patch_aux:Nn #3
-      {
-        \exp_not:N #4
-        {
-          \cs_if_eq:NNTF #3 \cs_gset_protected:Npn
-            { \exp_not:N \msg_error:nnnnnn }
-            { \exp_not:N \msg_expandable_error:nnnnnn }
-            { deprecation } { deprecated-command }
-            {#1}
-            { \token_to_str:N #4 }
-            { \tl_to_str:n {#2} }
-            { \bool_if:NT \l__deprecation_grace_period_bool { grace } }
-        }
-      }
-  }
 \cs_new_protected:Npn \__kernel_deprecation_error:Nnn #1#2#3
   {
     \tex_protected:D \tex_outer:D \tex_edef:D #1
@@ -34580,13 +34844,6 @@
   {
     \tl_if_blank:nF {#3} { Use~ \tl_trim_spaces:n {#3} ~not~ }
     #2~deprecated~on~#1.
-    \str_if_eq:nnT {#4} { grace }
-      {
-        \c_space_tl
-        For~6~months~after~that~date~one~can~restore~a~deprecated~
-        command~by~loading~the~expl3~package~with~the~option~
-        'undo-recent-deprecations'.
-      }
   }
 \cs_new_protected:Npn \__deprecation_old_protected:Nnn #1#2#3
   {
@@ -34598,9 +34855,13 @@
     \__kernel_patch_deprecation:nnNNpn {#3} {#2}
     \cs_gset:Npn #1 { }
   }
-\__deprecation_old:Nnn \box_resize:Nnn
+\__deprecation_old_protected:Nnn \box_gset_eq_clear:NN
+  { \box_gset_eq_drop:NN } { 2021-07-01 }
+\__deprecation_old_protected:Nnn \box_set_eq_clear:NN
+  { \box_set_eq_drop:NN } { 2021-07-01 }
+\__deprecation_old_protected:Nnn \box_resize:Nnn
   { \box_resize_to_wd_and_ht_plus_dp:Nnn } { 2019-01-01 }
-\__deprecation_old:Nnn \box_use_clear:N
+\__deprecation_old_protected:Nnn \box_use_clear:N
   { \box_use_drop:N } { 2019-01-01 }
 \__deprecation_old:Nnn \c_job_name_tl
   { \c_sys_jobname_str } { 2017-01-01 }
@@ -34652,22 +34913,26 @@
   { 1000 } { 2020-01-01 }
 \__deprecation_old:Nnn \c_ten_thousand
   { 10000 } { 2020-01-01 }
+\__deprecation_old:Nnn \c_term_ior
+  { -1 } { 2021-07-01 }
 \__deprecation_old:Nnn \dim_case:nnn
   { \dim_case:nnF } { 2015-07-14 }
-\__deprecation_old:Nnn \file_add_path:nN
+\__deprecation_old_protected:Nnn \file_add_path:nN
   { \file_get_full_name:nN } { 2019-01-01 }
 \__deprecation_old_protected:Nnn \file_if_exist_input:nT
   { \file_if_exist:nT and~ \file_input:n } { 2018-03-05 }
 \__deprecation_old_protected:Nnn \file_if_exist_input:nTF
   { \file_if_exist:nT and~ \file_input:n } { 2018-03-05 }
-\__deprecation_old:Nnn \file_list:
+\__deprecation_old_protected:Nnn \file_list:
   { \file_log_list: } { 2019-01-01 }
 \__deprecation_old:Nnn \file_path_include:n
   { \seq_put_right:Nn \l_file_search_path_seq } { 2019-01-01 }
-\__deprecation_old:Nnn \file_path_remove:n
+\__deprecation_old_protected:Nnn \file_path_remove:n
   { \seq_remove_all:Nn \l_file_search_path_seq } { 2019-01-01 }
 \__deprecation_old:Nnn \g_file_current_name_tl
   { \g_file_curr_name_str } { 2019-01-01 }
+\__deprecation_old_protected:Nnn \hbox_unpack_clear:N
+  { \hbox_unpack_drop:N  } { 2021-07-01 }
 \__deprecation_old:Nnn \int_case:nnn
   { \int_case:nnF } { 2015-07-14 }
 \__deprecation_old:Nnn \int_from_binary:n
@@ -34684,13 +34949,13 @@
   { \int_to_oct:n } { 2016-01-05 }
 \__deprecation_old_protected:Nnn \ior_get_str:NN
   { \ior_str_get:NN } { 2018-03-05 }
-\__deprecation_old:Nnn \ior_list_streams:
+\__deprecation_old_protected:Nnn \ior_list_streams:
   { \ior_show_list: } { 2019-01-01 }
-\__deprecation_old:Nnn \ior_log_streams:
+\__deprecation_old_protected:Nnn \ior_log_streams:
   { \ior_log_list: } { 2019-01-01 }
-\__deprecation_old:Nnn \iow_list_streams:
+\__deprecation_old_protected:Nnn \iow_list_streams:
   { \iow_show_list: } { 2019-01-01 }
-\__deprecation_old:Nnn \iow_log_streams:
+\__deprecation_old_protected:Nnn \iow_log_streams:
   { \iow_log_list: } { 2019-01-01 }
 \__deprecation_old:Nnn \lua_escape_x:n
   { \lua_escape:e } { 2020-01-01 }
@@ -34764,12 +35029,28 @@
   { \tl_case:cnF } { 2015-07-14 }
 \__deprecation_old:Nnn \tl_case:Nnn
   { \tl_case:NnF } { 2015-07-14 }
+\__deprecation_old_protected:Nnn \tl_gset_from_file:Nnn
+  { \file_get:nnN } { 2021-07-01 }
+\__deprecation_old_protected:Nnn \tl_gset_from_file_x:Nnn
+  { \file_get:nnN } { 2021-07-01 }
+\__deprecation_old_protected:Nnn \tl_set_from_file:Nnn
+  { \file_get:nnN } { 2021-07-01 }
+\__deprecation_old_protected:Nnn \tl_set_from_file_x:Nnn
+  { \file_get:nnN } { 2021-07-01 }
 \__deprecation_old_protected:Nnn \tl_to_lowercase:n
   { \tex_lowercase:D } { 2018-03-05 }
 \__deprecation_old_protected:Nnn \tl_to_uppercase:n
   { \tex_uppercase:D } { 2018-03-05 }
-\__deprecation_old:Nnn \token_new:Nn
+\__deprecation_old:Nnn \token_get_arg_spec:N
+  { \cs_argument_spec:N } { 2021-07-01 }
+\__deprecation_old:Nnn \token_get_prefix_spec:N
+  { \cs_prefix_spec:N } { 2021-07-01 }
+\__deprecation_old:Nnn \token_get_replacement_spec:N
+  { \cs_replacement_spec:N } { 2021-07-01 }
+\__deprecation_old_protected:Nnn \token_new:Nn
   { \cs_new_eq:NN } { 2019-01-01 }
+\__deprecation_old_protected:Nnn \vbox_unpack_clear:N
+  { \vbox_unpack_drop:N  } { 2021-07-01 }
 \__deprecation_old:Nnn \xetex_if_engine_p:
   { \sys_if_engine_xetex_p: } { 2017-01-01 }
 \__deprecation_old:Nnn \xetex_if_engine:F
@@ -34778,22 +35059,95 @@
   { \sys_if_engine_xetex:T } { 2017-01-01 }
 \__deprecation_old:Nnn \xetex_if_engine:TF
   { \sys_if_engine_xetex:TF } { 2017-01-01 }
-\group_begin:
-\cs_set_protected:Npn \ProvidesExplFile
+\__kernel_patch_deprecation:nnNNpn { 2020-01-03 } { \str_lowercase:n }
+\cs_gset:Npn \str_lower_case:n { \str_lowercase:n }
+\__kernel_patch_deprecation:nnNNpn { 2020-01-03 } { \str_lowercase:f }
+\cs_gset:Npn \str_lower_case:f { \str_lowercase:f }
+\__kernel_patch_deprecation:nnNNpn { 2020-01-03 } { \str_uppercase:n }
+\cs_gset:Npn \str_upper_case:n { \str_uppercase:n }
+\__kernel_patch_deprecation:nnNNpn { 2020-01-03 } { \str_uppercase:f }
+\cs_gset:Npn \str_upper_case:f { \str_uppercase:f }
+\__kernel_patch_deprecation:nnNNpn { 2020-01-03 } { \str_foldcase:n }
+\cs_gset:Npn \str_fold_case:n { \str_foldcase:n }
+\__kernel_patch_deprecation:nnNNpn { 2020-01-03 } { \str_foldcase:V }
+\cs_gset:Npn \str_fold_case:V { \str_foldcase:V }
+\__kernel_patch_deprecation:nnNNpn { 2020-08-20 } { }
+\cs_gset_protected:Npn \str_declare_eight_bit_encoding:nnn #1
+  { \__str_declare_eight_bit_encoding:nnnn {#1} { 1114112 } }
+\__kernel_patch_deprecation:nnNNpn { 2020-06-18 } { \seq_map_indexed_inline:Nn }
+\cs_gset_protected:Npn \seq_indexed_map_inline:Nn { \seq_map_indexed_inline:Nn }
+\__kernel_patch_deprecation:nnNNpn { 2020-06-18 } { \seq_map_indexed_function:NN }
+\cs_gset:Npn \seq_indexed_map_function:NN { \seq_map_indexed_function:NN }
+\__kernel_patch_deprecation:nnNNpn { 2021-01-11 } { (no~longer~required) }
+\cs_gset_protected:Npn \sys_load_deprecation:
+  {
+    \bool_if:NF \g__str_deprecation_bool
+      { \__kernel_sys_configuration_load:n { l3deprecation } }
+    \bool_gset_true:N \g__str_deprecation_bool
+  }
+\__kernel_patch_deprecation:nnNNpn { 2020-01-03 } { \text_lowercase:n }
+\cs_gset:Npn \tl_lower_case:n #1
+  { \text_lowercase:n {#1} }
+\__kernel_patch_deprecation:nnNNpn { 2020-01-03 } { \text_lowercase:nn }
+\cs_gset:Npn \tl_lower_case:nn #1#2
+  { \text_lowercase:nn {#1} {#2} }
+\__kernel_patch_deprecation:nnNNpn { 2020-01-03 } { \text_uppercase:n }
+\cs_gset:Npn \tl_upper_case:n #1
+  { \text_uppercase:n {#1} }
+\__kernel_patch_deprecation:nnNNpn { 2020-01-03 } { \text_uppercase:nn }
+\cs_gset:Npn \tl_upper_case:nn #1#2
+  { \text_uppercase:nn {#1} {#2} }
+\__kernel_patch_deprecation:nnNNpn { 2020-01-03 } { \text_titlecase:n }
+\cs_gset:Npn \tl_mixed_case:n #1
+  { \text_titlecase:n {#1} }
+\__kernel_patch_deprecation:nnNNpn { 2020-01-03 } { \text_titlecase:nn }
+\cs_gset:Npn \tl_mixed_case:nn #1#2
+  { \text_titlecase:nn {#1} {#2} }
+\__kernel_patch_deprecation:nnNNpn { 2020-01-03 } { \char_lowercase:N }
+\cs_gset:Npn \char_lower_case:N { \char_lowercase:N }
+\__kernel_patch_deprecation:nnNNpn { 2020-01-03 } { \char_uppercase:N }
+\cs_gset:Npn \char_upper_case:N { \char_uppercase:N }
+\__kernel_patch_deprecation:nnNNpn { 2020-01-03 } { \char_titlecase:N }
+\cs_gset:Npn \char_mixed_case:N { \char_titlecase:N }
+\__kernel_patch_deprecation:nnNNpn { 2020-01-03 } { \char_foldcase:N }
+\cs_gset:Npn \char_fold_case:N { \char_foldcase:N }
+\__kernel_patch_deprecation:nnNNpn { 2020-01-03 } { \char_str_lowercase:N }
+\cs_gset:Npn \char_str_lower_case:N { \char_str_lowercase:N }
+\__kernel_patch_deprecation:nnNNpn { 2020-01-03 } { \char_str_uppercase:N }
+\cs_gset:Npn \char_str_upper_case:N { \char_str_uppercase:N }
+\__kernel_patch_deprecation:nnNNpn { 2020-01-03 } { \char_str_titlecase:N }
+\cs_gset:Npn \char_str_mixed_case:N { \char_str_titlecase:N }
+\__kernel_patch_deprecation:nnNNpn { 2020-01-03 } { \char_str_foldcase:N }
+\cs_gset:Npn \char_str_fold_case:N { \char_str_foldcase:N }
+\tl_map_inline:nn
   {
-    \char_set_catcode_space:n { `\  }
-    \ProvidesExplFileAux
+    { catcode } { catcode_remove }
+    { charcode } { charcode_remove }
+    { meaning } { meaning_remove }
   }
-\cs_set_protected:Npx \ProvidesExplFileAux #1#2#3#4
   {
-    \group_end:
-    \cs_if_exist:NTF \ProvidesFile
-      { \exp_not:N \ProvidesFile {#1} [ #2~v#3~#4 ] }
-      { \iow_log:x { File:~#1~#2~v#3~#4 } }
+    \use:x
+      {
+        \__kernel_patch_deprecation:nnNNpn { 2022-01-11 } { \peek_remove_spaces:n }
+        \cs_gset_protected:Npn \exp_not:c { peek_ #1 _ignore_spaces:NTF } ####1####2####3
+          {
+            \peek_remove_spaces:n
+              { \exp_not:c { peek_ #1 :NTF } ####1 {####2} {####3} }
+          }
+        \__kernel_patch_deprecation:nnNNpn { 2022-01-11 } { \peek_remove_spaces:n }
+        \cs_gset_protected:Npn \exp_not:c { peek_ #1 _ignore_spaces:NT } ####1####2
+          {
+            \peek_remove_spaces:n
+              { \exp_not:c { peek_ #1 :NT } ####1 {####2} }
+          }
+        \__kernel_patch_deprecation:nnNNpn { 2022-01-11 } { \peek_remove_spaces:n }
+        \cs_gset_protected:Npn \exp_not:c { peek_ #1 _ignore_spaces:NF } ####1####2
+          {
+            \peek_remove_spaces:n
+              { \exp_not:c { peek_ #1 :NF } ####1 {####2} }
+          }
+      }
   }
-\cs_gset_protected:Npn \__kernel_sys_configuration_load:n #1
-  { \file_input:n { #1 .def } }
-\__kernel_sys_configuration_load:n { l3deprecation }
 %% 
 %%
 %% End of file `expl3-code.tex'.
-- 
cgit v1.2.3

