From b95d7e12e4b85cb577f3efc950cf50413dfea72b Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Fri, 7 May 2021 20:16:16 +0000
Subject: l3 (7may21)

git-svn-id: svn://tug.org/texlive/trunk@59118 c570f23f-e606-0410-a88d-b1316a301751
---
 .../texmf-dist/tex/latex/l3kernel/expl3-code.tex   | 1734 +++++++++++++-------
 1 file changed, 1144 insertions(+), 590 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 52982c3fe50..be777b6ab07 100644
--- a/Master/texmf-dist/tex/latex/l3kernel/expl3-code.tex
+++ b/Master/texmf-dist/tex/latex/l3kernel/expl3-code.tex
@@ -70,7 +70,7 @@
 %% and all files in that bundle must be distributed together.
 %% 
 %% File: expl3.dtx
-\def\ExplFileDate{2021-02-18}%
+\def\ExplFileDate{2021-05-07}%
 \begingroup
   \def\next{\endgroup}%
   \expandafter\ifx\csname PackageError\endcsname\relax
@@ -1303,6 +1303,7 @@
   \__kernel_primitive:NN \omathchardef          \tex_omathchardef:D
   \__kernel_primitive:NN \omathcode             \tex_omathcode:D
   \__kernel_primitive:NN \oradical              \tex_oradical:D
+  \__kernel_primitive:NN \tracingstacklevels    \tex_tracingstacklevels:D
 \tex_endgroup:D
 \tex_ifdefined:D \@@end
   \tex_let:D \tex_end:D                  \@@end
@@ -1617,12 +1618,12 @@
 \cs_set_protected:Npn \__kernel_if_debug:TF #1#2 {#2}
 \cs_set_protected:Npn \debug_on:n #1
   {
-    \__kernel_msg_error:nnx { kernel } { enable-debug }
+    \__kernel_msg_error:nnx { debug } { enable-debug }
       { \tl_to_str:n { \debug_on:n {#1} } }
   }
 \cs_set_protected:Npn \debug_off:n #1
   {
-    \__kernel_msg_error:nnx { kernel } { enable-debug }
+    \__kernel_msg_error:nnx { debug } { enable-debug }
        { \tl_to_str:n { \debug_off:n {#1} } }
   }
 \cs_set_protected:Npn \debug_suspend: { }
@@ -1754,7 +1755,7 @@
     #8
       { \exp_args:Nc #2 { #4 : #5 T } #6 }
       { { #7 \exp_end: \use:n \use_none:n } }
-      { #7 \exp_after:wN \use_ii:nn \fi: \use_none:n }
+      { #7 \__prg_T_true:w \fi: \use_none:n }
   }
 \cs_set_protected:Npn \__prg_generate_F_form:wNNnnnnN
     #1 \s__prg_stop #2#3#4#5#6#7#8
@@ -1762,7 +1763,7 @@
     #8
       { \exp_args:Nc #2 { #4 : #5 F } #6 }
       { { #7 \exp_end: { } } }
-      { #7 \exp_after:wN \use_none:nn \fi: \use:n }
+      { #7 \__prg_F_true:w \fi: \use:n }
   }
 \cs_set_protected:Npn \__prg_generate_TF_form:wNNnnnnN
     #1 \s__prg_stop #2#3#4#5#6#7#8
@@ -1770,9 +1771,12 @@
     #8
       { \exp_args:Nc #2 { #4 : #5 TF } #6 }
       { { #7 \exp_end: } }
-      { #7 \exp_after:wN \use_ii:nnn \fi: \use_ii:nn }
+      { #7 \__prg_TF_true:w \fi: \use_ii:nn }
   }
-\cs_set:Npn \__prg_p_true:w \fi: \c_false_bool { \fi: \c_true_bool }
+\cs_set:Npn \__prg_p_true:w  \fi: \c_false_bool { \fi: \c_true_bool }
+\cs_set:Npn \__prg_T_true:w  \fi: \use_none:n   { \fi: \use:n }
+\cs_set:Npn \__prg_F_true:w  \fi: \use:n        { \fi: \use_none:n }
+\cs_set:Npn \__prg_TF_true:w \fi: \use_ii:nn    { \fi: \use_i:nn }
 \cs_set_protected:Npn \prg_set_eq_conditional:NNn
   { \__prg_set_eq_conditional:NNNn \cs_set_eq:cc }
 \cs_set_protected:Npn \prg_new_eq_conditional:NNn
@@ -3438,7 +3442,7 @@
 \cs_new_protected:Npn \__quark_new_test_aux:Nn #1 #2
   {
     \if_meaning:w \q_nil #2 \q_nil
-      \__kernel_msg_error:nnx { kernel } { invalid-quark-function }
+      \__kernel_msg_error:nnx { quark } { invalid-function }
         { \token_to_str:N #1 }
     \else:
       \__quark_new_test:Nccn #1
@@ -3462,11 +3466,11 @@
 \cs_new_protected:Npn \__quark_new_conditional:Nnnn #1#2#3#4
   {
     \if_meaning:w \q_nil #2 \q_nil
-      \__kernel_msg_error:nnx { kernel } { invalid-quark-function }
+      \__kernel_msg_error:nnx { quark } { invalid-function }
         { \token_to_str:N #1 }
     \else:
       \if_meaning:w \q_nil #3 \q_nil
-        \__kernel_msg_error:nnx { kernel } { invalid-quark-function }
+        \__kernel_msg_error:nnx { quark } { invalid-function }
           { \token_to_str:N #1 }
       \else:
         \exp_last_unbraced:Nf \__quark_new_test_aux:nnNNnnnn
@@ -3481,7 +3485,7 @@
   {
     \cs_if_exist_use:cTF { __quark_new_#5_#2:Nnnn } { #4 }
       {
-        \__kernel_msg_error:nnxx { kernel } { invalid-quark-function }
+        \__kernel_msg_error:nnxx { quark } { invalid-function }
           { \token_to_str:N #4 } {#2}
         \use_none:nnn
       }
@@ -3610,7 +3614,7 @@
   {
     \tl_if_in:NnTF \g__scan_marks_tl { #1 }
       {
-        \__kernel_msg_error:nnx { kernel } { scanmark-already-defined }
+        \__kernel_msg_error:nnx { scanmark } { already-defined }
           { \token_to_str:N #1 }
       }
       {
@@ -4731,8 +4735,16 @@
   {
     \__kernel_chk_defined:NT #2
       {
-        \exp_args:Ne #1
-          { \token_to_str:N #2 = \__kernel_exp_not:w \exp_after:wN {#2} }
+        \exp_args:Nf \tl_if_empty:nTF
+          { \cs_prefix_spec:N #2 \cs_argument_spec:N #2 }
+          {
+            \exp_args:Ne #1
+              { \token_to_str:N #2 = \__kernel_exp_not:w \exp_after:wN {#2} }
+          }
+          {
+            \__kernel_msg_error:nnxxx { kernel } { bad-type }
+              { \token_to_str:N #2 } { \token_to_meaning:N #2 } { tl }
+          }
       }
   }
 \cs_new_protected:Npn \tl_show:n #1
@@ -4752,6 +4764,28 @@
 \cs_new:Npn \__tl_show:w #1 > #2 . \s__tl_stop {#2}
 \cs_new_protected:Npn \tl_log:n #1
   { \iow_wrap:nnnN { > ~ \tl_to_str:n {#1} . } { } { } \iow_log:n }
+\cs_new_protected:Npn \__kernel_chk_tl_type:NnnT #1#2#3#4
+  {
+    \__kernel_chk_defined:NT #1
+      {
+        \exp_args:Nf \tl_if_empty:nTF
+          { \cs_prefix_spec:N #1 \cs_argument_spec:N #1 }
+          {
+            \tl_set:Nx \l__tl_internal_a_tl {#3}
+            \tl_if_eq:NNTF #1 \l__tl_internal_a_tl
+              {#4}
+              {
+                \__kernel_msg_error:nnxxxx { kernel } { bad-type }
+                  { \token_to_str:N #1 } { \tl_to_str:N #1 }
+                  {#2} { \tl_to_str:N \l__tl_internal_a_tl }
+              }
+          }
+          {
+            \__kernel_msg_error:nnxxx { kernel } { bad-type }
+              { \token_to_str:N #1 } { \token_to_meaning:N #1 } {#2}
+          }
+      }
+  }
 \scan_new:N \s__tl_nil
 \scan_new:N \s__tl_mark
 \scan_new:N \s__tl_stop
@@ -4981,7 +5015,7 @@
 \cs_new:Npn \str_map_function:nN #1#2
   {
     \exp_after:wN \__str_map_function:w
-    \exp_after:wN \__str_map_function:Nn \exp_after:wN #2
+    \exp_after:wN \__str_map_function:nn \exp_after:wN #2
       \__kernel_tl_to_str:w {#1}
       \q__str_recursion_tail ? ~
     \prg_break_point:Nn \str_map_break: { }
@@ -4990,12 +5024,12 @@
   { \exp_args:No \str_map_function:nN }
 \cs_new:Npn \__str_map_function:w #1 ~
   { #1 { ~ { ~ } \__str_map_function:w } }
-\cs_new:Npn \__str_map_function:Nn #1#2
+\cs_new:Npn \__str_map_function:nn #1#2
   {
     \if_meaning:w \q__str_recursion_tail #2
       \exp_after:wN \str_map_break:
     \fi:
-    #1 #2 \__str_map_function:Nn #1
+    #1 #2 \__str_map_function:nn {#1}
   }
 \cs_generate_variant:Nn \str_map_function:NN { c }
 \cs_new_protected:Npn \str_map_inline:nn #1#2
@@ -5046,6 +5080,16 @@
   { \prg_map_break:Nn \str_map_break: { } }
 \cs_new:Npn \str_map_break:n
   { \prg_map_break:Nn \str_map_break: }
+\cs_new:Npn \str_map_tokens:nn #1#2
+  {
+    \exp_args:Nno \use:nn
+      { \__str_map_function:w \__str_map_function:nn {#2} }
+      { \__kernel_tl_to_str:w {#1} }
+      \q__str_recursion_tail ? ~
+    \prg_break_point:Nn \str_map_break: { }
+  }
+\cs_new:Npn \str_map_tokens:Nn { \exp_args:No \str_map_tokens:nn }
+\cs_generate_variant:Nn \str_map_tokens:Nn { c }
 \cs_new:Npn \__kernel_str_to_other:n #1
   {
     \exp_after:wN \__str_to_other_loop:w
@@ -5377,10 +5421,18 @@
 \str_new:N \g_tmpa_str
 \str_new:N \g_tmpb_str
 \cs_new_eq:NN \str_show:n \tl_show:n
-\cs_new_eq:NN \str_show:N \tl_show:N
+\cs_new_protected:Npn \str_show:N #1
+  {
+    \__kernel_chk_tl_type:NnnT #1 { str } { \tl_to_str:N #1 }
+      { \tl_show:N #1 }
+  }
 \cs_generate_variant:Nn \str_show:N { c }
 \cs_new_eq:NN \str_log:n \tl_log:n
-\cs_new_eq:NN \str_log:N \tl_log:N
+\cs_new_protected:Npn \str_log:N #1
+  {
+    \__kernel_chk_tl_type:NnnT #1 { str } { \tl_to_str:N #1 }
+      { \tl_log:N #1 }
+  }
 \cs_generate_variant:Nn \str_log:N { c }
 %% File: l3seq.dtx
 \scan_new:N \s__seq
@@ -5388,7 +5440,7 @@
 \scan_new:N \s__seq_stop
 \cs_new:Npn \__seq_item:n
   {
-    \__kernel_msg_expandable_error:nn { kernel } { misused-sequence }
+    \__kernel_msg_expandable_error:nn { seq } { misused }
     \use_none:n
   }
 \tl_new:N \l__seq_internal_a_tl
@@ -5454,42 +5506,48 @@
   }
 \cs_generate_variant:Nn \seq_const_from_clist:Nn { c }
 \cs_new_protected:Npn \seq_set_split:Nnn
-  { \__seq_set_split:NNnn \__kernel_tl_set:Nx }
+  { \__seq_set_split:NNNnn \__kernel_tl_set:Nx \tl_trim_spaces:n }
 \cs_new_protected:Npn \seq_gset_split:Nnn
-  { \__seq_set_split:NNnn \__kernel_tl_gset:Nx }
-\cs_new_protected:Npn \__seq_set_split:NNnn #1#2#3#4
+  { \__seq_set_split:NNNnn \__kernel_tl_gset:Nx \tl_trim_spaces:n }
+\cs_new_protected:Npn \seq_set_split_keep_spaces:Nnn
+  { \__seq_set_split:NNNnn \__kernel_tl_set:Nx \exp_not:n }
+\cs_new_protected:Npn \seq_gset_split_keep_spaces:Nnn
+  { \__seq_set_split:NNNnn \__kernel_tl_gset:Nx \exp_not:n }
+\cs_new_protected:Npn \__seq_set_split:NNNnn #1#2#3#4#5
   {
-    \tl_if_empty:nTF {#3}
+    \tl_if_empty:nTF {#4}
       {
         \tl_set:Nn \l__seq_internal_a_tl
-          { \tl_map_function:nN {#4} \__seq_wrap_item:n }
+          { \tl_map_function:nN {#5} \__seq_wrap_item:n }
       }
       {
         \tl_set:Nn \l__seq_internal_a_tl
           {
-            \__seq_set_split_auxi:w \prg_do_nothing:
-            #4
+            \__seq_set_split:Nw #2 \prg_do_nothing:
+            #5
             \__seq_set_split_end:
           }
-        \tl_replace_all:Nnn \l__seq_internal_a_tl { #3 }
+        \tl_replace_all:Nnn \l__seq_internal_a_tl {#4}
           {
             \__seq_set_split_end:
-            \__seq_set_split_auxi:w \prg_do_nothing:
+            \__seq_set_split:Nw #2 \prg_do_nothing:
           }
         \__kernel_tl_set:Nx \l__seq_internal_a_tl { \l__seq_internal_a_tl }
       }
-    #1 #2 { \s__seq \l__seq_internal_a_tl }
+    #1 #3 { \s__seq \l__seq_internal_a_tl }
   }
-\cs_new:Npn \__seq_set_split_auxi:w #1 \__seq_set_split_end:
+\cs_new:Npn \__seq_set_split:Nw #1#2 \__seq_set_split_end:
   {
-    \exp_not:N \__seq_set_split_auxii:w
-    \exp_args:No \tl_trim_spaces:n {#1}
+    \exp_not:N \__seq_set_split:w
+    \exp_args:No #1 {#2}
     \exp_not:N \__seq_set_split_end:
   }
-\cs_new:Npn \__seq_set_split_auxii:w #1 \__seq_set_split_end:
+\cs_new:Npn \__seq_set_split:w #1 \__seq_set_split_end:
   { \__seq_wrap_item:n {#1} }
 \cs_generate_variant:Nn \seq_set_split:Nnn  { NnV }
 \cs_generate_variant:Nn \seq_gset_split:Nnn { NnV }
+\cs_generate_variant:Nn \seq_set_split_keep_spaces:Nnn  { NnV }
+\cs_generate_variant:Nn \seq_gset_split_keep_spaces:Nnn { NnV }
 \cs_new_protected:Npn \seq_concat:NNN #1#2#3
   { \tl_set:Nf #1 { \exp_after:wN \use_i:nn \exp_after:wN #2 #3 } }
 \cs_new_protected:Npn \seq_gconcat:NNN #1#2#3
@@ -5610,7 +5668,7 @@
       {
         \int_compare:nNnTF { \seq_count:N #2 } > \c_max_register_int
           {
-            \__kernel_msg_error:nnx { kernel } { shuffle-too-large }
+            \__kernel_msg_error:nnx { seq } { shuffle-too-large }
               { \token_to_str:N #2 }
           }
           {
@@ -6036,20 +6094,31 @@
 \prg_new_eq_conditional:NNn \seq_pop:cN  \seq_pop_left:cN  { T , F , TF }
 \prg_new_eq_conditional:NNn \seq_gpop:NN \seq_gpop_left:NN { T , F , TF }
 \prg_new_eq_conditional:NNn \seq_gpop:cN \seq_gpop_left:cN { T , F , TF }
-\cs_new_protected:Npn \seq_show:N { \__seq_show:NN \msg_show:nnxxxx }
+\cs_new_protected:Npn \seq_show:N { \__seq_show:NN \__kernel_msg_show:nnxxxx }
 \cs_generate_variant:Nn \seq_show:N { c }
-\cs_new_protected:Npn \seq_log:N { \__seq_show:NN \msg_log:nnxxxx }
+\cs_new_protected:Npn \seq_log:N { \__seq_show:NN \__kernel_msg_log:nnxxxx }
 \cs_generate_variant:Nn \seq_log:N { c }
 \cs_new_protected:Npn \__seq_show:NN #1#2
   {
-    \__kernel_chk_defined:NT #2
+    \__kernel_chk_tl_type:NnnT #2 { seq }
       {
-        #1 { LaTeX/kernel } { show-seq }
+        \s__seq
+        \exp_after:wN \use_i:nn \exp_after:wN \__seq_show_validate:nn #2
+        \q_recursion_tail \q_recursion_tail \q_recursion_stop
+      }
+      {
+        #1 { seq } { show }
           { \token_to_str:N #2 }
           { \seq_map_function:NN #2 \msg_show_item:n }
           { } { }
       }
   }
+\cs_new:Npn \__seq_show_validate:nn #1#2
+  {
+    \quark_if_recursion_tail_stop:n {#2}
+    \__seq_wrap_item:n {#2}
+    \__seq_show_validate:nn
+  }
 \seq_new:N \l_tmpa_seq
 \seq_new:N \l_tmpb_seq
 \seq_new:N \g_tmpa_seq
@@ -6162,24 +6231,26 @@
   }
 \cs_generate_variant:Nn \int_new:N { c }
 \cs_new_protected:Npn \int_const:Nn #1#2
+  { \exp_args:Ne \__int_const:nN { \int_eval:n {#2} } #1 }
+\cs_new_protected:Npn \__int_const:nN #1#2
   {
-    \int_compare:nNnTF {#2} < \c_zero_int
+    \int_compare:nNnTF {#1} < \c_zero_int
       {
-        \int_new:N #1
+        \int_new:N #2
         \tex_global:D
       }
       {
-        \int_compare:nNnTF {#2} > \c__int_max_constdef_int
+        \int_compare:nNnTF {#1} > \c__int_max_constdef_int
           {
-            \int_new:N #1
+            \int_new:N #2
             \tex_global:D
           }
           {
-            \__kernel_chk_if_free_cs:N #1
+            \__kernel_chk_if_free_cs:N #2
             \tex_global:D \__int_constdef:Nw
           }
       }
-    #1 = \__int_eval:w #2 \__int_eval_end:
+    #2 = \__int_eval:w #1 \__int_eval_end:
   }
 \cs_generate_variant:Nn \int_const:Nn { c }
 \if_int_odd:w 0
@@ -6998,7 +7069,17 @@
 \cs_new_protected:Npn \__bool_show:NN #1#2
   {
     \__kernel_chk_defined:NT #2
-      { \exp_args:Nx #1 { \token_to_str:N #2 = \__bool_to_str:n {#2} } }
+      {
+        \token_case_meaning:NnF #2
+          {
+            \c_true_bool { \exp_args:Nx #1 { \token_to_str:N #2 = true } }
+            \c_false_bool { \exp_args:Nx #1 { \token_to_str:N #2 = false } }
+          }
+          {
+            \__kernel_msg_error:nnxxx { kernel } { bad-type }
+              { \token_to_str:N #2 } { \token_to_meaning:N #2 } { bool }
+          }
+      }
   }
 \bool_new:N \l_tmpa_bool
 \bool_new:N \l_tmpb_bool
@@ -7201,7 +7282,7 @@
 \cs_new:cpn { __prg_replicate_first_-:n } #1
   {
     \exp_end:
-    \__kernel_msg_expandable_error:nn { kernel } { negative-replication }
+    \__kernel_msg_expandable_error:nn { prg } { negative-replication }
   }
 \cs_new:cpn { __prg_replicate_first_0:n } #1 { \exp_end: }
 \cs_new:cpn { __prg_replicate_first_1:n } #1 { \exp_end: #1 }
@@ -7992,16 +8073,16 @@
   {
     \clist_if_empty:NF #1
       {
-        \exp_last_unbraced:NNo \__clist_map_function:Nw #2 #1
+        \exp_last_unbraced:NNo \__clist_map_function:nw #2 #1
           , \q__clist_recursion_tail ,
         \prg_break_point:Nn \clist_map_break: { }
       }
   }
-\cs_new:Npn \__clist_map_function:Nw #1#2 ,
+\cs_new:Npn \__clist_map_function:nw #1#2 ,
   {
     \__clist_if_recursion_tail_break:nN {#2} \clist_map_break:
     #1 {#2}
-    \__clist_map_function:Nw #1
+    \__clist_map_function:nw {#1}
   }
 \cs_generate_variant:Nn \clist_map_function:NN { c }
 \cs_new:Npn \clist_map_function:nN #1#2
@@ -8013,11 +8094,11 @@
 \cs_new:Npn \__clist_map_function_n:Nn #1 #2
   {
     \__clist_if_recursion_tail_break:nN {#2} \clist_map_break:
-    \__clist_map_unbrace:Nw #1 #2,
+    \__clist_map_unbrace:wn #2 , #1
     \exp_after:wN \__clist_map_function_n:Nn \exp_after:wN #1
     \exp:w \__clist_trim_next:w \prg_do_nothing:
   }
-\cs_new:Npn \__clist_map_unbrace:Nw #1 #2, { #1 {#2} }
+\cs_new:Npn \__clist_map_unbrace:wn #1, #2 { #2 {#1} }
 \cs_new_protected:Npn \clist_map_inline:Nn #1#2
   {
     \clist_if_empty:NF #1
@@ -8025,7 +8106,7 @@
         \int_gincr:N \g__kernel_prg_map_int
         \cs_gset_protected:cpn
           { __clist_map_ \int_use:N \g__kernel_prg_map_int :w } ##1 {#2}
-        \exp_last_unbraced:Nco \__clist_map_function:Nw
+        \exp_last_unbraced:Nco \__clist_map_function:nw
           { __clist_map_ \int_use:N \g__kernel_prg_map_int :w }
           #1 , \q__clist_recursion_tail ,
         \prg_break_point:Nn \clist_map_break:
@@ -8062,6 +8143,33 @@
     \__clist_map_variable:Nnw #1 {#2}
   }
 \cs_generate_variant:Nn \clist_map_variable:NNn { c }
+\cs_new:Npn \clist_map_tokens:Nn #1#2
+  {
+    \clist_if_empty:NF #1
+      {
+        \exp_last_unbraced:Nno \__clist_map_function:nw {#2} #1
+          , \q__clist_recursion_tail ,
+        \prg_break_point:Nn \clist_map_break: { }
+      }
+  }
+\cs_generate_variant:Nn \clist_map_tokens:Nn { c }
+\cs_new:Npn \clist_map_tokens:nn #1#2
+  {
+    \__clist_map_tokens_n:nw {#2}
+    \prg_do_nothing: #1 , \q__clist_recursion_tail ,
+    \prg_break_point:Nn \clist_map_break: { }
+  }
+\cs_new:Npn \__clist_map_tokens_n:nw #1#2 ,
+  {
+    \tl_if_empty:oF { \use_none:nn #2 ? }
+      {
+        \exp_args:No \__clist_if_recursion_tail_break:nN {#2} \clist_map_break:
+        \tl_trim_spaces_apply:oN {#2} \__clist_use_ii_i:nn
+        \__clist_map_unbrace:wn , {#1}
+      }
+    \__clist_map_tokens_n:nw {#1} \prg_do_nothing:
+  }
+\cs_new:Npn \__clist_use_ii_i:nn #1#2 { #2 #1 }
 \cs_new:Npn \clist_map_break:
   { \prg_map_break:Nn \clist_map_break: { } }
 \cs_new:Npn \clist_map_break:n
@@ -8196,25 +8304,33 @@
       { \clist_item:Nn #1 { \int_rand:nn { 1 } { \clist_count:N #1 } } }
   }
 \cs_generate_variant:Nn \clist_rand_item:N { c }
-\cs_new_protected:Npn \clist_show:N { \__clist_show:NN \msg_show:nnxxxx }
+\cs_new_protected:Npn \clist_show:N { \__clist_show:NN \__kernel_msg_show:nnxxxx }
 \cs_generate_variant:Nn \clist_show:N { c }
-\cs_new_protected:Npn \clist_log:N { \__clist_show:NN \msg_log:nnxxxx }
+\cs_new_protected:Npn \clist_log:N { \__clist_show:NN \__kernel_msg_log:nnxxxx }
 \cs_generate_variant:Nn \clist_log:N { c }
 \cs_new_protected:Npn \__clist_show:NN #1#2
   {
-    \__kernel_chk_defined:NT #2
+    \__kernel_chk_tl_type:NnnT #2 { clist } { \exp_not:o #2 }
       {
-        #1 { LaTeX/kernel } { show-clist }
-          { \token_to_str:N #2 }
-          { \clist_map_function:NN #2 \msg_show_item:n }
-          { } { }
+        \int_compare:nNnTF { \clist_count:N #2 }
+          = { \exp_args:No \clist_count:n #2 }
+          {
+            #1 { clist } { show }
+              { \token_to_str:N #2 }
+              { \clist_map_function:NN #2 \msg_show_item:n }
+              { } { }
+          }
+          {
+            \__kernel_msg_error:nnxx { kernel } { non-clist }
+              { \token_to_str:N #2 } { \tl_to_str:N #2 }
+          }
       }
   }
-\cs_new_protected:Npn \clist_show:n { \__clist_show:Nn \msg_show:nnxxxx }
-\cs_new_protected:Npn \clist_log:n { \__clist_show:Nn \msg_log:nnxxxx }
+\cs_new_protected:Npn \clist_show:n { \__clist_show:Nn \__kernel_msg_show:nnxxxx }
+\cs_new_protected:Npn \clist_log:n { \__clist_show:Nn \__kernel_msg_log:nnxxxx }
 \cs_new_protected:Npn \__clist_show:Nn #1#2
   {
-    #1 { LaTeX/kernel } { show-clist }
+    #1 { clist } { show }
       { } { \clist_map_function:nN {#2} \msg_show_item:n } { } { }
   }
 \clist_new:N \l_tmpa_clist
@@ -8356,9 +8472,9 @@
   {
     \if_int_compare:w #2 = 10 \exp_stop_f:
       \if_int_compare:w #1 =  0 \exp_stop_f:
-        \__kernel_msg_expandable_error:nn { kernel } { char-null-space }
+        \__kernel_msg_expandable_error:nn { char } { null-space }
       \else:
-        \__kernel_msg_expandable_error:nn { kernel } { char-space }
+        \__kernel_msg_expandable_error:nn { char } { space }
       \fi:
     \else:
       \if_int_odd:w 0
@@ -8366,14 +8482,14 @@
           \if_int_compare:w #2 = 5  \exp_stop_f: 1 \fi:
           \if_int_compare:w #2 = 9  \exp_stop_f: 1 \fi:
           \if_int_compare:w #2 > 13 \exp_stop_f: 1 \fi: \exp_stop_f:
-        \__kernel_msg_expandable_error:nn { kernel }
-          { char-invalid-catcode }
+        \__kernel_msg_expandable_error:nn { char }
+          { invalid-catcode }
       \else:
         \if_int_odd:w 0
           \if_int_compare:w #1 < 0 \exp_stop_f: 1 \fi:
           \if_int_compare:w #1 > \c_max_char_int 1 \fi: \exp_stop_f:
-          \__kernel_msg_expandable_error:nn { kernel }
-            { char-out-of-range }
+          \__kernel_msg_expandable_error:nn { char }
+            { out-of-range }
         \else:
           \__char_generate_aux:nnw {#1} {#2}
         \fi:
@@ -8402,7 +8518,7 @@
             {
               #3
               \if_int_compare:w #2 = 13 \exp_stop_f:
-                \__kernel_msg_expandable_error:nn { kernel } { char-active }
+                \__kernel_msg_expandable_error:nn { char } { active }
               \else:
                 \__char_generate_auxii:nnw {#1} {#2}
               \fi:
@@ -9187,7 +9303,7 @@
 %% File: l3prop.dtx
 \scan_new:N \s__prop
 \cs_new:Npn \__prop_pair:wn #1 \s__prop #2
-  { \__kernel_msg_expandable_error:nn { kernel } { misused-prop } }
+  { \__kernel_msg_expandable_error:nn { prop } { misused } }
 \tl_new:N \l__prop_internal_tl
 \tl_const:Nn \c_empty_prop { \s__prop }
 \scan_new:N \s__prop_mark
@@ -9281,7 +9397,7 @@
         \str_if_eq:nnTF {#2} { = }
           { \prop_put:Nnn \l__prop_internal_prop {#3} {#1} }
           {
-            \__kernel_msg_error:nnx { kernel } { prop-keyval }
+            \__kernel_msg_error:nnx { prop } { prop-keyval }
               { \exp_not:o {#4} }
           }
       }
@@ -9521,20 +9637,31 @@
   { \prg_map_break:Nn \prop_map_break: { } }
 \cs_new:Npn \prop_map_break:n
   { \prg_map_break:Nn \prop_map_break: }
-\cs_new_protected:Npn \prop_show:N { \__prop_show:NN \msg_show:nnxxxx }
+\cs_new_protected:Npn \prop_show:N { \__prop_show:NN \__kernel_msg_show:nnxxxx }
 \cs_generate_variant:Nn \prop_show:N { c }
-\cs_new_protected:Npn \prop_log:N { \__prop_show:NN \msg_log:nnxxxx }
+\cs_new_protected:Npn \prop_log:N { \__prop_show:NN \__kernel_msg_log:nnxxxx }
 \cs_generate_variant:Nn \prop_log:N { c }
 \cs_new_protected:Npn \__prop_show:NN #1#2
   {
-    \__kernel_chk_defined:NT #2
+    \__kernel_chk_tl_type:NnnT #2 { prop }
+      {
+        \s__prop
+        \exp_after:wN \use_i:nn \exp_after:wN \__prop_show_validate:w #2
+        \__prop_pair:wn \q_recursion_tail \s__prop { } \q_recursion_stop
+      }
       {
-        #1 { LaTeX/kernel } { show-prop }
+        #1 { prop } { show }
           { \token_to_str:N #2 }
           { \prop_map_function:NN #2 \msg_show_item:nn }
           { } { }
       }
   }
+\cs_new:Npn \__prop_show_validate:w #1 \__prop_pair:wn #2 \s__prop #3
+  {
+    \quark_if_recursion_tail_stop:n {#2}
+    \exp_not:N \__prop_pair:wn \tl_to_str:n {#2} \s__prop \exp_not:n { {#3} }
+    \__prop_show_validate:w
+  }
 %% File: l3msg.dtx
 \tl_new:N \l__msg_internal_tl
 \str_new:N \l__msg_name_str
@@ -9553,7 +9680,7 @@
   {
     \msg_if_exist:nnT {#1} {#2}
       {
-        \__kernel_msg_error:nnxx { kernel } { message-already-defined }
+        \__kernel_msg_error:nnxx { msg } { already-defined }
           {#1} {#2}
       }
   }
@@ -9921,7 +10048,7 @@
 \cs_new:Npn \__msg_class_chk_exist:nT #1
   {
     \cs_if_free:cTF { __msg_ #1 _code:nnnnnn }
-      { \__kernel_msg_error:nnx { kernel } { message-class-unknown } {#1} }
+      { \__kernel_msg_error:nnx { msg } { class-unknown } {#1} }
   }
 \tl_new:N \l__msg_class_tl
 \tl_new:N \l__msg_current_class_tl
@@ -9947,7 +10074,7 @@
             \__msg_use_redirect_name:n { #2 / #3 }
           }
       }
-      { \__kernel_msg_error:nnxx { kernel } { message-unknown } {#2} {#3} }
+      { \__kernel_msg_error:nnxx { msg } { unknown } {#2} {#3} }
     \cs_if_exist_use:N \conditionally@traceon
   }
 \cs_new_protected:Npn \__msg_use_code: { }
@@ -10036,7 +10163,7 @@
               {
                 \prop_put:cnn { l__msg_redirect_ #2 _prop } {#3} {#2}
                 \__kernel_msg_warning:nnxxxx
-                  { kernel } { message-redirect-loop }
+                  { msg } { redirect-loop }
                   { \seq_item:Nn \l__msg_class_loop_seq { 1 } }
                   { \seq_item:Nn \l__msg_class_loop_seq { 2 } }
                   {#3}
@@ -10106,8 +10233,14 @@
   \__msg_kernel_class_new:nN { error } \__msg_error_code:nnnnnn
   \__msg_kernel_class_new:nN { warning } \msg_warning:nnxxxx
   \__msg_kernel_class_new:nN { info } \msg_info:nnxxxx
+\cs_new_protected:Npn \__kernel_msg_log:nnnnnn #1
+  { \msg_log:nnnnnn { LaTeX / #1 } }
+\cs_generate_variant:Nn \__kernel_msg_log:nnnnnn { nnxxxx }
+\cs_new_protected:Npn \__kernel_msg_show:nnnnnn #1
+  { \msg_show:nnnnnn { LaTeX / #1 } }
+\cs_generate_variant:Nn \__kernel_msg_show:nnnnnn { nnxxxx }
 \group_end:
-\__kernel_msg_new:nnnn { kernel } { message-already-defined }
+\__kernel_msg_new:nnnn { msg } { already-defined }
   { Message~'#2'~for~module~'#1'~already~defined. }
   {
     \c__msg_coding_error_text_tl
@@ -10115,7 +10248,7 @@
     by~the~module~'#1':~this~message~already~exists.
     \c__msg_return_text_tl
   }
-\__kernel_msg_new:nnnn { kernel } { message-unknown }
+\__kernel_msg_new:nnnn { msg } { unknown }
   { Unknown~message~'#2'~for~module~'#1'. }
   {
     \c__msg_coding_error_text_tl
@@ -10123,14 +10256,14 @@
     by~the~module~'#1':~this~message~does~not~exist.
     \c__msg_return_text_tl
   }
-\__kernel_msg_new:nnnn { kernel } { message-class-unknown }
+\__kernel_msg_new:nnnn { msg } { class-unknown }
   { Unknown~message~class~'#1'. }
   {
     LaTeX~has~been~asked~to~redirect~messages~to~a~class~'#1':\\
     this~was~never~defined.
     \c__msg_return_text_tl
   }
-\__kernel_msg_new:nnnn { kernel } { message-redirect-loop }
+\__kernel_msg_new:nnnn { msg } { redirect-loop }
   {
     Message~redirection~loop~caused~by~ {#1} ~=>~ {#2}
     \tl_if_empty:nF {#3} { ~for~module~' \use_none:n #3 ' } .
@@ -10149,16 +10282,6 @@
     #2~arguments.~
     TeX~allows~between~0~and~9~arguments~for~a~single~function.
   }
-\__kernel_msg_new:nnn { kernel } { char-active }
-  { Cannot~generate~active~chars. }
-\__kernel_msg_new:nnn { kernel } { char-invalid-catcode }
-  { Invalid~catcode~for~char~generation. }
-\__kernel_msg_new:nnn { kernel } { char-null-space }
-  { Cannot~generate~null~char~as~a~space. }
-\__kernel_msg_new:nnn { kernel } { char-out-of-range }
-  { Charcode~requested~out~of~engine~range. }
-\__kernel_msg_new:nnn { kernel } { char-space }
-  { Cannot~generate~space~chars. }
 \__kernel_msg_new:nnnn { kernel } { command-already-defined }
   { Control~sequence~#1~already~defined. }
   {
@@ -10236,7 +10359,55 @@
     LaTeX~has~been~asked~to~define~the~conditional~form~'#1'~of~
     the~function~'#2',~but~only~'TF',~'T',~'F',~and~'p'~forms~exist.
   }
-\__kernel_msg_new:nnnn { kernel } { key-no-property }
+\__kernel_msg_new:nnnn { kernel } { variant-too-long }
+  { Variant~form~'#1'~longer~than~base~signature~of~'#2'. }
+  {
+    \c__msg_coding_error_text_tl
+    LaTeX~has~been~asked~to~create~a~variant~of~the~function~'#2'~
+    with~a~signature~starting~with~'#1',~but~that~is~longer~than~
+    the~signature~(part~after~the~colon)~of~'#2'.
+  }
+\__kernel_msg_new:nnnn { kernel } { invalid-variant }
+  { Variant~form~'#1'~invalid~for~base~form~'#2'. }
+  {
+    \c__msg_coding_error_text_tl
+    LaTeX~has~been~asked~to~create~a~variant~of~the~function~'#2'~
+    with~a~signature~starting~with~'#1',~but~cannot~change~an~argument~
+    from~type~'#3'~to~type~'#4'.
+  }
+\__kernel_msg_new:nnnn { kernel } { invalid-exp-args }
+  { Invalid~variant~specifier~'#1'~in~'#2'. }
+  {
+    \c__msg_coding_error_text_tl
+    LaTeX~has~been~asked~to~create~an~\iow_char:N\\exp_args:N...~
+    function~with~signature~'N#2'~but~'#1'~is~not~a~valid~argument~
+    specifier.
+  }
+\__kernel_msg_new:nnn { kernel } { deprecated-variant }
+  {
+    Variant~form~'#1'~deprecated~for~base~form~'#2'.~
+    One~should~not~change~an~argument~from~type~'#3'~to~type~'#4'
+    \str_case:nnF {#3}
+      {
+        { n } { :~use~a~'\token_if_eq_charcode:NNTF #4 c v V'~variant? }
+        { N } { :~base~form~only~accepts~a~single~token~argument. }
+        {#4} { :~base~form~is~already~a~variant. }
+      } { . }
+  }
+\__kernel_msg_new:nnn { char } { active }
+  { Cannot~generate~active~chars. }
+\__kernel_msg_new:nnn { char } { invalid-catcode }
+  { Invalid~catcode~for~char~generation. }
+\__kernel_msg_new:nnn { char } { null-space }
+  { Cannot~generate~null~char~as~a~space. }
+\__kernel_msg_new:nnn { char } { out-of-range }
+  { Charcode~requested~out~of~engine~range. }
+\__kernel_msg_new:nnn { char } { space }
+  { Cannot~generate~space~chars. }
+\__kernel_msg_new:nnnn { ior } { quote-in-shell }
+  { Quotes~in~shell~command~'#1'. }
+  { Shell~commands~cannot~contain~quotes~("). }
+\__kernel_msg_new:nnnn { keys } { no-property }
   { No~property~given~in~definition~of~key~'#1'. }
   {
     \c__msg_coding_error_text_tl
@@ -10245,30 +10416,27 @@
     \iow_indent:n { #1 .<property> } \\ \\
     LaTeX~did~not~find~a~'.'~to~indicate~the~start~of~a~property.
   }
-\__kernel_msg_new:nnnn { kernel } { key-property-boolean-values-only }
+\__kernel_msg_new:nnnn { keys } { property-boolean-values-only }
   { The~property~'#1'~accepts~boolean~values~only. }
   {
     \c__msg_coding_error_text_tl
     The~property~'#1'~only~accepts~the~values~'true'~and~'false'.
   }
-\__kernel_msg_new:nnnn { kernel } { key-property-requires-value }
+\__kernel_msg_new:nnnn { keys } { property-requires-value }
   { The~property~'#1'~requires~a~value. }
   {
     \c__msg_coding_error_text_tl
     LaTeX~was~asked~to~set~property~'#1'~for~key~'#2'.\\
     No~value~was~given~for~the~property,~and~one~is~required.
   }
-\__kernel_msg_new:nnnn { kernel } { key-property-unknown }
+\__kernel_msg_new:nnnn { keys } { property-unknown }
   { The~key~property~'#1'~is~unknown. }
   {
     \c__msg_coding_error_text_tl
     LaTeX~has~been~asked~to~set~the~property~'#1'~for~key~'#2':~
     this~property~is~not~defined.
   }
-\__kernel_msg_new:nnnn { kernel } { quote-in-shell }
-  { Quotes~in~shell~command~'#1'. }
-  { Shell~commands~cannot~contain~quotes~("). }
-\__kernel_msg_new:nnnn { kernel } { invalid-quark-function }
+\__kernel_msg_new:nnnn { quark } { invalid-function }
   { Quark~test~function~'#1'~is~invalid. }
   {
     \c__msg_coding_error_text_tl
@@ -10278,16 +10446,16 @@
       { with~signature~'#2',~but~that~signature~ }
     is~not~valid.
   }
-\__kernel_msg_new:nnn { kernel } { invalid-quark }
+\__kernel_msg_new:nnn { quark } { invalid }
   { Invalid~quark~variable~'#1'. }
-\__kernel_msg_new:nnnn { kernel } { scanmark-already-defined }
+\__kernel_msg_new:nnnn { scanmark } { already-defined }
   { Scan~mark~#1~already~defined. }
   {
     \c__msg_coding_error_text_tl
     LaTeX~has~been~asked~to~create~a~new~scan~mark~'#1'~
     but~this~name~has~already~been~used~for~a~scan~mark.
   }
-\__kernel_msg_new:nnnn { kernel } { shuffle-too-large }
+\__kernel_msg_new:nnnn { seq } { shuffle-too-large }
   { The~sequence~#1~is~too~long~to~be~shuffled~by~TeX. }
   {
     TeX~has~ \int_eval:n { \c_max_register_int + 1 } ~
@@ -10302,42 +10470,32 @@
     LaTeX~has~been~asked~to~show~a~variable~#1,~but~this~has~not~
     been~defined~yet.
   }
-\__kernel_msg_new:nnnn { kernel } { variant-too-long }
-  { Variant~form~'#1'~longer~than~base~signature~of~'#2'. }
-  {
-    \c__msg_coding_error_text_tl
-    LaTeX~has~been~asked~to~create~a~variant~of~the~function~'#2'~
-    with~a~signature~starting~with~'#1',~but~that~is~longer~than~
-    the~signature~(part~after~the~colon)~of~'#2'.
-  }
-\__kernel_msg_new:nnnn { kernel } { invalid-variant }
-  { Variant~form~'#1'~invalid~for~base~form~'#2'. }
+\__kernel_msg_new:nnnn { kernel } { bad-type }
+  { Variable~'#1'~is~not~a~valid~#3. }
   {
     \c__msg_coding_error_text_tl
-    LaTeX~has~been~asked~to~create~a~variant~of~the~function~'#2'~
-    with~a~signature~starting~with~'#1',~but~cannot~change~an~argument~
-    from~type~'#3'~to~type~'#4'.
+    The~variable~'#1'~with~\tl_if_empty:nTF {#4} {meaning} {value}\\\\
+    \iow_indent:n {#2}\\\\
+    should~be~a~#3~variable,~but~
+    \tl_if_empty:nTF {#4}
+      { it~is~not \str_if_eq:nnF {#3} { bool } { ~a~short~macro } . }
+      {
+        it~does~not~have~the~correct~
+        \str_if_eq:nnTF {#2} {#4}
+          { category~codes. }
+          { internal~structure:\\\\\iow_indent:n {#4} }
+      }
   }
-\__kernel_msg_new:nnnn { kernel } { invalid-exp-args }
-  { Invalid~variant~specifier~'#1'~in~'#2'. }
+\__kernel_msg_new:nnnn { kernel } { non-clist }
+  { Variable~'#1'~is~not~a~valid~clist. }
   {
     \c__msg_coding_error_text_tl
-    LaTeX~has~been~asked~to~create~an~\iow_char:N\\exp_args:N...~
-    function~with~signature~'N#2'~but~'#1'~is~not~a~valid~argument~
-    specifier.
-  }
-\__kernel_msg_new:nnn { kernel } { deprecated-variant }
-  {
-    Variant~form~'#1'~deprecated~for~base~form~'#2'.~
-    One~should~not~change~an~argument~from~type~'#3'~to~type~'#4'
-    \str_case:nnF {#3}
-      {
-        { n } { :~use~a~'\token_if_eq_charcode:NNTF #4 c v V'~variant? }
-        { N } { :~base~form~only~accepts~a~single~token~argument. }
-        {#4} { :~base~form~is~already~a~variant. }
-      } { . }
+    The~variable~'#1'~with~value\\\\
+    \iow_indent:n {#2}\\\\
+    should~be~a~clist~variable,~but~it~includes~empty~or~blank~items~
+    without~braces.
   }
-\__kernel_msg_new:nnnn { kernel } { enable-debug }
+\__kernel_msg_new:nnnn { debug } { enable-debug }
   { To~use~'#1'~set~the~'enable-debug'~option. }
   {
     The~function~'#1'~will~be~ignored~because~it~can~only~work~if~
@@ -10350,13 +10508,13 @@
   { Misused~\exp_end_continue_f:w or~:nw }
 \__kernel_msg_new:nnn { kernel } { bad-variable }
   { Erroneous~variable~#1 used! }
-\__kernel_msg_new:nnn { kernel } { misused-sequence }
+\__kernel_msg_new:nnn { seq } { misused }
   { A~sequence~was~misused. }
-\__kernel_msg_new:nnn { kernel } { misused-prop }
+\__kernel_msg_new:nnn { prop } { misused }
   { A~property~list~was~misused. }
-\__kernel_msg_new:nnn { kernel } { negative-replication }
+\__kernel_msg_new:nnn { prg } { negative-replication }
   { Negative~argument~for~\iow_char:N\\prg_replicate:nn. }
-\__kernel_msg_new:nnn { kernel } { prop-keyval }
+\__kernel_msg_new:nnn { prop } { prop-keyval }
   { Missing/extra~'='~in~'#1'~(in~'..._keyval:Nn') }
 \__kernel_msg_new:nnn { kernel } { unknown-comparison }
   { Relation~'#1'~unknown:~use~=,~<,~>,~==,~!=,~<=,~>=. }
@@ -10367,23 +10525,23 @@
     \__kernel_msg_new:nnn { kernel } { e-type }
       { #1 ~ in~e-type~argument }
   }
-\__kernel_msg_new:nnn { kernel } { show-clist }
+\__kernel_msg_new:nnn { clist } { show }
   {
     The~comma~list~ \tl_if_empty:nF {#1} { #1 ~ }
     \tl_if_empty:nTF {#2}
       { is~empty \\>~ . }
       { contains~the~items~(without~outer~braces): #2 . }
   }
-\__kernel_msg_new:nnn { kernel } { show-intarray }
+\__kernel_msg_new:nnn { intarray } { show }
   { The~integer~array~#1~contains~#2~items: \\ #3 . }
-\__kernel_msg_new:nnn { kernel } { show-prop }
+\__kernel_msg_new:nnn { prop } { show }
   {
     The~property~list~#1~
     \tl_if_empty:nTF {#2}
       { is~empty \\>~ . }
       { contains~the~pairs~(without~outer~braces): #2 . }
   }
-\__kernel_msg_new:nnn { kernel } { show-seq }
+\__kernel_msg_new:nnn { seq } { show }
   {
     The~sequence~#1~
     \tl_if_empty:nTF {#2}
@@ -10579,11 +10737,11 @@
       }
   }
 \cs_generate_variant:Nn \ior_close:N { c }
-\cs_new_protected:Npn \ior_show_list: { \__ior_list:N \msg_show:nnxxxx }
-\cs_new_protected:Npn \ior_log_list: { \__ior_list:N \msg_log:nnxxxx }
+\cs_new_protected:Npn \ior_show_list: { \__ior_list:N \__kernel_msg_show:nnxxxx }
+\cs_new_protected:Npn \ior_log_list: { \__ior_list:N \__kernel_msg_log:nnxxxx }
 \cs_new_protected:Npn \__ior_list:N #1
   {
-    #1 { LaTeX / kernel } { show-streams }
+    #1 { kernel } { show-streams }
       { ior }
       {
         \prop_map_function:NN \g__ior_streams_prop
@@ -10594,19 +10752,19 @@
 \cs_new_eq:NN \if_eof:w \tex_ifeof:D
 \prg_new_conditional:Npnn \ior_if_eof:N #1 { p , T , F , TF }
   {
-    \cs_if_exist:NTF #1
-      {
-        \int_compare:nTF { -1 < #1 < \c__ior_term_ior }
-          {
-            \if_eof:w #1
-              \prg_return_true:
-            \else:
-              \prg_return_false:
-            \fi:
-          }
-          { \prg_return_true: }
-      }
-      { \prg_return_true: }
+    \if_int_compare:w -1 < #1
+      \if_int_compare:w #1 < \c__ior_term_ior
+        \if_eof:w #1
+          \prg_return_true:
+        \else:
+          \prg_return_false:
+        \fi:
+      \else:
+        \prg_return_true:
+      \fi:
+    \else:
+      \prg_return_true:
+    \fi:
   }
 \cs_new_protected:Npn \ior_get:NN #1#2
   { \ior_get:NNF #1 #2 { \tl_set:Nn #2 { \q_no_value } } }
@@ -10775,11 +10933,11 @@
       }
   }
 \cs_generate_variant:Nn \iow_close:N { c }
-\cs_new_protected:Npn \iow_show_list: { \__iow_list:N \msg_show:nnxxxx }
-\cs_new_protected:Npn \iow_log_list: { \__iow_list:N \msg_log:nnxxxx }
+\cs_new_protected:Npn \iow_show_list: { \__iow_list:N \__kernel_msg_show:nnxxxx }
+\cs_new_protected:Npn \iow_log_list: { \__iow_list:N \__kernel_msg_log:nnxxxx }
 \cs_new_protected:Npn \__iow_list:N #1
   {
-    #1 { LaTeX / kernel } { show-streams }
+    #1 { kernel } { show-streams }
       { iow }
       {
         \prop_map_function:NN \g__iow_streams_prop
@@ -11188,98 +11346,81 @@
 \__kernel_quark_new_test:N \__file_if_recursion_tail_stop_do:nn
 \cs_new:Npn \__kernel_file_name_sanitize:n #1
   {
-    \exp_args:Ne \__kernel_file_name_trim_spaces:n
+    \exp_args:Ne \__file_name_trim_spaces:n
       {
-        \exp_args:Ne \__kernel_file_name_strip_quotes:n
-          {
-            \__kernel_file_name_expand_loop:w #1
-              \q__file_recursion_tail \q__file_recursion_stop
-          }
+        \exp_args:Ne \__file_name_strip_quotes:n
+          { \__file_name_expand:n {#1} }
       }
   }
-\cs_new:Npn \__kernel_file_name_expand_loop:w #1 \q__file_recursion_stop
+\cs_new:Npn \__file_name_expand:n #1
   {
-    \tl_if_head_is_N_type:nTF {#1}
-      { \__kernel_file_name_expand_N_type:Nw }
-      {
-        \tl_if_head_is_group:nTF {#1}
-          { \__kernel_file_name_expand_group:nw }
-          { \__kernel_file_name_expand_space:w }
-      }
-    #1 \q__file_recursion_stop
+    \exp_after:wN \__file_name_expand_cleanup:Nw
+      \cs:w __file_name = #1 \cs_end:
+        \__file_name_expand_end:
   }
-\cs_new:Npn \__kernel_file_name_expand_N_type:Nw #1
+\cs_new:Npn \__file_name_expand_cleanup:Nw #1 #2 \__file_name_expand_end:
   {
-    \__file_if_recursion_tail_stop:N #1
-    \bool_lazy_and:nnTF
-      { \token_if_expandable_p:N #1 }
-      {
-        \bool_not_p:n
-          {
-            \bool_lazy_any_p:n
-              {
-                { \token_if_protected_macro_p:N #1 }
-                { \token_if_protected_long_macro_p:N #1 }
-                { \token_if_active_p:N #1 }
-              }
-          }
-      }
-      { \exp_after:wN \__kernel_file_name_expand_loop:w #1 }
-      {
-        \token_to_str:N #1
-        \__kernel_file_name_expand_loop:w
-      }
+    \tl_if_empty:nF {#2}
+      { \__file_name_expand_error:Nw #2 \__file_name_expand_end: }
+    \exp_after:wN \__file_name_expand_cleanup:w \token_to_str:N #1
   }
-\cs_new:Npx \__kernel_file_name_expand_group:nw #1
+\exp_last_unbraced:NNNNo
+\cs_new:Npn \__file_name_expand_cleanup:w #1 \tl_to_str:n { __file_name = } { }
+\cs_new:Npn \__file_name_expand_end:
   {
-    \c_left_brace_str
-    \exp_not:N \__kernel_file_name_expand_loop:w
-     #1
-     \c_right_brace_str
+    \__kernel_msg_expandable_error:nn
+      { kernel } { filename-missing-endcsname }
+    \cs_end: \__file_name_expand_end:
   }
-\exp_last_unbraced:NNo
-  \cs_new:Npx \__kernel_file_name_expand_space:w \c_space_tl
-    {
-      \c_space_tl
-      \exp_not:N \__kernel_file_name_expand_loop:w
-    }
-\cs_new:Npn \__kernel_file_name_strip_quotes:n #1
+\cs_new:Npn \__file_name_expand_error:Nw #1 #2 \__file_name_expand_end:
+  { \__file_name_expand_error_aux:Nw #1 #2 \cs_end: \__file_name_expand_end: }
+\cs_new:Npn \__file_name_expand_error_aux:Nw #1 #2 \cs_end: #3
+    \__file_name_expand_end:
+  {
+    \__kernel_msg_expandable_error:nnff
+      { kernel } { filename-chars-lost }
+        { \token_to_str:N #1 } { \exp_stop_f: #2 }
+  }
+\cs_new:Npn \__file_name_strip_quotes:n #1
   {
-    \__kernel_file_name_strip_quotes:nnnw {#1} { 0 } { }
-      #1 " \q__file_recursion_tail " \q__file_recursion_stop
+    \__file_name_strip_quotes:nw { 0 }
+      #1 " \q__file_recursion_tail " \q__file_recursion_stop {#1}
   }
-\cs_new:Npn \__kernel_file_name_strip_quotes:nnnw #1#2#3#4 "
+\cs_new:Npn \__file_name_strip_quotes:nw #1#2 "
   {
-    \__file_if_recursion_tail_stop_do:nn {#4}
-      { \__kernel_file_name_strip_quotes:nnn {#1} {#2} {#3} }
-    \__kernel_file_name_strip_quotes:nnnw {#1} { #2 + 1 } { #3#4 }
+    \if_meaning:w \q__file_recursion_tail #2
+      \__file_name_strip_quotes_end:wnwn
+    \fi:
+    #2
+    \__file_name_strip_quotes:nw { #1 + 1 }
   }
-\cs_new:Npn \__kernel_file_name_strip_quotes:nnn #1#2#3
+\cs_new:Npn \__file_name_strip_quotes_end:wnwn \fi: #1
+    \__file_name_strip_quotes:nw #2 \q__file_recursion_stop #3
   {
-    \int_if_even:nT {#2}
+    \fi:
+    \int_if_odd:nT {#2}
       {
         \__kernel_msg_expandable_error:nnn
-          { kernel } { unbalanced-quote-in-filename } {#1}
+          { kernel } { unbalanced-quote-in-filename } {#3}
       }
-    #3
   }
-\cs_new:Npn \__kernel_file_name_trim_spaces:n #1
-  { \__kernel_file_name_trim_spaces:nw {#1} #1 . \q__file_nil . \s__file_stop }
-\cs_new:Npn \__kernel_file_name_trim_spaces:nw #1#2 . #3 . #4 \s__file_stop
+\cs_new:Npn \__file_name_trim_spaces:n #1
+  { \__file_name_trim_spaces:nw {#1} #1 . \q__file_nil . \s__file_stop }
+\cs_new:Npn \__file_name_trim_spaces:nw #1#2 . #3 . #4 \s__file_stop
   {
     \__file_quark_if_nil:nTF {#3}
       {
-        \exp_args:Ne \__kernel_file_name_trim_spaces_aux:n
-          { \tl_trim_spaces:n { #1 \s__file_stop } }
+        \tl_trim_spaces_apply:nN { #1 \s__file_stop }
+          \__file_name_trim_spaces_aux:n
       }
       { \tl_trim_spaces:n {#1} }
   }
-\cs_new:Npn \__kernel_file_name_trim_spaces_aux:n #1
-  { \__kernel_file_name_trim_spaces_aux:w #1 }
-\cs_new:Npn \__kernel_file_name_trim_spaces_aux:w #1 \s__file_stop {#1}
+\cs_new:Npn \__file_name_trim_spaces_aux:n #1
+  { \__file_name_trim_spaces_aux:w #1 }
+\cs_new:Npn \__file_name_trim_spaces_aux:w #1 \s__file_stop {#1}
 \cs_new:Npn \__kernel_file_name_quote:n #1
-  { \__kernel_file_name_quote:nw {#1} #1 ~ \q__file_nil \s__file_stop }
-\cs_new:Npn \__kernel_file_name_quote:nw #1 #2 ~ #3 \s__file_stop
+  { \__file_name_quote:nw {#1} #1 ~ \q__file_nil \s__file_stop }
+\cs_new:Npn \__file_name_quote:nw #1 #2 ~ #3 \s__file_stop
   {
     \__file_quark_if_nil:nTF {#3}
       { #1 }
@@ -11335,65 +11476,71 @@
 \cs_new:Npn \__file_full_name:n #1
   {
     \tl_if_blank:nF {#1}
+      { \exp_args:Nne \__file_full_name_aux:nn {#1} { \__file_size:n {#1} } }
+  }
+\cs_new:Npn \__file_full_name_aux:nn #1 #2
+  {
+    \tl_if_blank:nTF {#2}
       {
-        \tl_if_blank:eTF { \__file_size:n {#1} }
+        \seq_map_tokens:Nn \l_file_search_path_seq
+          { \__file_full_name_aux:Nnn \seq_map_break:n {#1} }
+        \cs_if_exist:NT \input@path
           {
-            \seq_map_tokens:Nn \l_file_search_path_seq
-              { \__file_full_name_aux:Nnn \seq_map_break:n {#1} }
-            \cs_if_exist:NT \input@path
-              {
-                \tl_map_tokens:Nn \input@path
-                  { \__file_full_name_aux:Nnn \tl_map_break:n {#1} }
-              }
-            \__file_name_end:
+            \tl_map_tokens:Nn \input@path
+              { \__file_full_name_aux:Nnn \tl_map_break:n {#1} }
           }
-          { \__file_ext_check:n {#1} }
+        \__file_name_end:
       }
+      { \__file_ext_check:nn {#1} {#2} }
   }
 \cs_new:Npn \__file_full_name_aux:Nnn #1#2#3
   { \exp_args:Ne \__file_full_name_aux:nN { \tl_to_str:n {#3} / #2 } #1 }
-\cs_new:Npn \__file_full_name_aux:nN #1 #2
+\cs_new:Npn \__file_full_name_aux:nN #1
+  { \exp_args:Nne \__file_full_name_aux:nnN {#1} { \__file_size:n {#1} } }
+\cs_new:Npn \__file_full_name_aux:nnN #1 #2 #3
   {
-    \tl_if_blank:eF { \__file_size:n {#1} }
+    \tl_if_blank:nF {#2}
       {
-        #2
+        #3
           {
-            \__file_ext_check:n {#1}
+            \__file_ext_check:nn {#1} {#2}
             \__file_name_cleanup:w
           }
       }
   }
 \cs_new:Npn \__file_name_cleanup:w #1 \__file_name_end: { }
 \cs_new:Npn \__file_name_end: { }
-\cs_new:Npn \__file_ext_check:n #1
-  { \__file_ext_check:nw { / } #1 / \q__file_nil / \s__file_stop }
-\cs_new:Npn \__file_ext_check:nw #1 #2 / #3 / #4 \s__file_stop
+\cs_new:Npn \__file_ext_check:nn #1 #2
+{ \__file_ext_check:nnw {#2} { / } #1 / \q__file_nil / \s__file_stop }
+\cs_new:Npn \__file_ext_check:nnw #1 #2 #3 / #4 / #5 \s__file_stop
   {
-    \__file_quark_if_nil:nTF {#3}
+    \__file_quark_if_nil:nTF {#4}
       {
-        \exp_args:No \__file_ext_check:nnw
-          { \use_none:n #1 } {#2} #2 . \q__file_nil . \s__file_stop
+        \exp_args:No \__file_ext_check:nnnw
+          { \use_none:n #2 } {#1} {#3} #3 . \q__file_nil . \s__file_stop
       }
-      { \__file_ext_check:nw { #1 #2 / } #3 / #4 \s__file_stop }
+      { \__file_ext_check:nnw {#1} { #2 #3 / } #4 / #5 \s__file_stop }
   }
-\cs_new:Npx \__file_ext_check:nnw #1#2#3 . #4 . #5 \s__file_stop
+\cs_new:Npx \__file_ext_check:nnnw #1#2#3#4 . #5 . #6 \s__file_stop
   {
-    \exp_not:N \__file_quark_if_nil:nTF {#4}
+    \exp_not:N \__file_quark_if_nil:nTF {#5}
       {
-        \exp_not:N \__file_ext_check:nn
-          { #1 #2 } { #1 #2 \tl_to_str:n { .tex } }
+        \exp_not:N \__file_ext_check:nnn
+          { #1 #3 \tl_to_str:n { .tex } } { #1 #3 } {#2}
       }
-      { #1 #2 }
+      { #1 #3 }
   }
-\cs_new:Npn \__file_ext_check:nn #1#2
+\cs_new:Npn \__file_ext_check:nnn #1
+  { \exp_args:Nne \__file_ext_check:nnnn {#1} { \__file_size:n {#1} } }
+\cs_new:Npn \__file_ext_check:nnnn #1#2#3#4
   {
-    \tl_if_blank:eTF { \__file_size:n {#2} }
-      {#1}
+    \tl_if_blank:nTF {#2}
+      {#3}
       {
         \int_compare:nNnTF
-          { \__file_size:n {#1} } = { \__file_size:n {#2} }
-          {#2}
+          {#4} = {#2}
           {#1}
+          {#3}
       }
   }
 \cs_if_exist:NF \tex_filesize:D
@@ -11793,8 +11940,8 @@
     \str_set:Nn #6 {#3}
   }
 \cs_generate_variant:Nn \file_parse_full_name:nNNN { V }
-\cs_new_protected:Npn \file_show_list: { \__file_list:N \msg_show:nnxxxx }
-\cs_new_protected:Npn \file_log_list: { \__file_list:N \msg_log:nnxxxx }
+\cs_new_protected:Npn \file_show_list: { \__file_list:N \__kernel_msg_show:nnxxxx }
+\cs_new_protected:Npn \file_log_list: { \__file_list:N \__kernel_msg_log:nnxxxx }
 \cs_new_protected:Npn \__file_list:N #1
   {
     \seq_clear:N \l__file_tmp_seq
@@ -11805,7 +11952,7 @@
       }
     \seq_concat:NNN \l__file_tmp_seq \l__file_tmp_seq \g__file_record_seq
     \seq_remove_duplicates:N \l__file_tmp_seq
-    #1 { LaTeX/kernel } { file-list }
+    #1 { kernel } { file-list }
       { \seq_map_function:NN \l__file_tmp_seq \__file_list_aux:n }
         { } { } { }
   }
@@ -11943,6 +12090,19 @@
     #1 \\
     .............
   }
+\__kernel_msg_new:nnnn { kernel } { filename-chars-lost }
+  { #1~invalid~in~file~name.~Lost:~#2. }
+  {
+    There~was~an~invalid~token~in~the~file~name~that~caused~
+    the~characters~following~it~to~be~lost.
+  }
+\__kernel_msg_new:nnnn { kernel } { filename-missing-endcsname }
+  { Missing~\iow_char:N\\endcsname~inserted~in~filename. }
+  {
+    The~file~name~had~more~\iow_char:N\\csname~commands~than~
+    \iow_char:N\\endcsname~ones.~LaTeX~will~add~the~missing~
+    \iow_char:N\\endcsname~and~try~to~continue~as~best~as~it~can.
+  }
 \__kernel_msg_new:nnnn { kernel } { unbalanced-quote-in-filename }
   { Unbalanced~quotes~in~file~name~'#1'. }
   {
@@ -12582,7 +12742,7 @@
            #2 \s__keyval_mark \__keyval_clean_up_active:w
         {
           \__kernel_msg_expandable_error:nn
-            { kernel } { misplaced-equals-sign }
+            { keyval } { misplaced-equals-sign }
           \__keyval_loop_other:nnw
         }
       \cs_new:Npn \__keyval_misplaced_equal_in_split_error:w
@@ -12590,7 +12750,7 @@
           ##3 \s__keyval_mark ##4 ##5
         {
           \__kernel_msg_expandable_error:nn
-            { kernel } { misplaced-equals-sign }
+            { keyval } { misplaced-equals-sign }
           \__keyval_loop_other:nnw
         }
       \cs_new:Npn \__keyval_end_loop_other:w
@@ -12632,11 +12792,11 @@
 \cs_new:Npn \__keyval_blank_key_error:w \s__keyval_mark \s__keyval_stop \exp_not:n #1
   {
     \__kernel_msg_expandable_error:nn
-      { kernel } { blank-key-name }
+      { keyval } { blank-key-name }
   }
-\__kernel_msg_new:nnn { kernel } { misplaced-equals-sign }
+\__kernel_msg_new:nnn { keyval } { misplaced-equals-sign }
   { Misplaced~equals~sign~in~key-value~input~\msg_line_context: }
-\__kernel_msg_new:nnn { kernel } { blank-key-name }
+\__kernel_msg_new:nnn { keyval } { blank-key-name }
   { Blank~key~name~in~key-value~input~\msg_line_context: }
 \group_begin:
   \cs_set_protected:Npn \__keyval_tmp:n #1
@@ -12740,7 +12900,7 @@
       {
         \str_if_empty:NF \l__keys_property_str
           {
-            \__kernel_msg_error:nnxx { kernel } { key-property-unknown }
+            \__kernel_msg_error:nnxx { keys } { property-unknown }
               \l__keys_property_str \l_keys_path_str
           }
       }
@@ -12783,7 +12943,7 @@
     #1 \s__keys_nil #2 \__keys_property_find_err:w
   {
     \str_clear:N \l__keys_property_str
-    \__kernel_msg_error:nnn { kernel } { key-no-property } {#1}
+    \__kernel_msg_error:nnn { keys } { no-property } {#1}
   }
 \cs_new_protected:Npn \__keys_define_code:n #1
   {
@@ -12793,7 +12953,7 @@
           \l__keys_property_str \s__keys_stop
           { \use:c { \c__keys_props_root_str \l__keys_property_str } }
           {
-            \__kernel_msg_error:nnxx { kernel } { key-property-requires-value }
+            \__kernel_msg_error:nnxx { keys } { property-requires-value }
               \l__keys_property_str \l_keys_path_str
           }
       }
@@ -12812,7 +12972,7 @@
       { \exp_not:c { bool_ #2 set_false:N } \exp_not:N #1 }
     \__keys_cmd_set:nn { \l_keys_path_str / unknown }
       {
-        \__kernel_msg_error:nnx { kernel } { boolean-values-only }
+        \__kernel_msg_error:nnx { keys } { boolean-values-only }
           \l_keys_key_str
       }
     \__keys_default_set:n { true }
@@ -12828,7 +12988,7 @@
       { \exp_not:c { bool_ #2 set_true:N } \exp_not:N #1 }
     \__keys_cmd_set:nn { \l_keys_path_str / unknown }
       {
-        \__kernel_msg_error:nnx { kernel } { boolean-values-only }
+        \__kernel_msg_error:nnx { keys } { boolean-values-only }
           \l_keys_key_str
       }
     \__keys_default_set:n { true }
@@ -12847,7 +13007,7 @@
           { \c__keys_type_root_str \__keys_parent:o \l_keys_path_str }
           { choice }
           {
-            \__kernel_msg_error:nnxx { kernel } { nested-choice-key }
+            \__kernel_msg_error:nnxx { keys } { nested-choice-key }
               \l_keys_path_tl { \__keys_parent:o \l_keys_path_str }
           }
           { \__keys_choice_make_aux:N #1 }
@@ -12861,7 +13021,7 @@
     \__keys_cmd_set:nn \l_keys_path_str { #1 {##1} }
     \__keys_cmd_set:nn { \l_keys_path_str / unknown }
       {
-        \__kernel_msg_error:nnxx { kernel } { key-choice-unknown }
+        \__kernel_msg_error:nnxx { keys } { choice-unknown }
           \l_keys_path_str {##1}
       }
   }
@@ -12996,8 +13156,8 @@
           }
       }
       {
-        \__kernel_msg_error:nnx { kernel }
-          { key-property-boolean-values-only }
+        \__kernel_msg_error:nnx { keys }
+          { property-boolean-values-only }
           { .value_ #1 :n }
       }
   }
@@ -13005,7 +13165,7 @@
   {
     \bool_if:NF \l__keys_no_value_bool
       {
-        \__kernel_msg_error:nnxx { kernel } { value-forbidden }
+        \__kernel_msg_error:nnxx { keys } { value-forbidden }
           \l_keys_path_str \l_keys_value_tl
         \use_none:nnn
       }
@@ -13014,7 +13174,7 @@
   {
     \bool_if:NT \l__keys_no_value_bool
       {
-        \__kernel_msg_error:nnx { kernel } { value-required }
+        \__kernel_msg_error:nnx { keys } { value-required }
           \l_keys_path_str
         \use_none:nnn
       }
@@ -13502,7 +13662,7 @@
           { \c__keys_code_root_str \l__keys_module_str / unknown }
           { \__keys_execute:no { \l__keys_module_str / unknown } \l_keys_value_tl }
           {
-            \__kernel_msg_error:nnxx { kernel } { key-unknown }
+            \__kernel_msg_error:nnxx { keys } { unknown }
               \l_keys_path_str \l__keys_module_str
           }
       }
@@ -13555,7 +13715,7 @@
         {
           \tl_if_blank:nF {##1}
             {
-              \__kernel_msg_error:nnxx { kernel } { bad-relative-key-path }
+              \__kernel_msg_error:nnxx { keys } { bad-relative-key-path }
                 \l_keys_path_str
                 \l__keys_relative_tl
             }
@@ -13660,12 +13820,12 @@
       { \prg_return_false: }
   }
 \cs_new_protected:Npn \keys_show:nn
-  { \__keys_show:Nnn \msg_show:nnxxxx }
+  { \__keys_show:Nnn \__kernel_msg_show:nnxxxx }
 \cs_new_protected:Npn \keys_log:nn
-  { \__keys_show:Nnn \msg_log:nnxxxx }
+  { \__keys_show:Nnn \__kernel_msg_log:nnxxxx }
 \cs_new_protected:Npn \__keys_show:Nnn #1#2#3
   {
-    #1 { LaTeX / kernel } { show-key }
+    #1 { keys } { show-key }
       { \__keys_trim_spaces:n { #2 / #3 } }
       {
         \keys_if_exist:nnT {#2} {#3}
@@ -13682,43 +13842,43 @@
       }
       { } { }
   }
-\__kernel_msg_new:nnnn { kernel } { bad-relative-key-path }
+\__kernel_msg_new:nnnn { keys } { bad-relative-key-path }
   { The~key~'#1'~is~not~inside~the~'#2'~path. }
   { The~key~'#1'~cannot~be~expressed~relative~to~path~'#2'. }
-\__kernel_msg_new:nnnn { kernel } { boolean-values-only }
+\__kernel_msg_new:nnnn { keys } { boolean-values-only }
   { Key~'#1'~accepts~boolean~values~only. }
   { The~key~'#1'~only~accepts~the~values~'true'~and~'false'. }
-\__kernel_msg_new:nnnn { kernel } { key-choice-unknown }
+\__kernel_msg_new:nnnn { keys } { choice-unknown }
   { Key~'#1'~accepts~only~a~fixed~set~of~choices. }
   {
     The~key~'#1'~only~accepts~predefined~values,~
     and~'#2'~is~not~one~of~these.
   }
-\__kernel_msg_new:nnnn { kernel } { key-unknown }
+\__kernel_msg_new:nnnn { keys } { unknown }
   { The~key~'#1'~is~unknown~and~is~being~ignored. }
   {
     The~module~'#2'~does~not~have~a~key~called~'#1'.\\
     Check~that~you~have~spelled~the~key~name~correctly.
   }
-\__kernel_msg_new:nnnn { kernel } { nested-choice-key }
+\__kernel_msg_new:nnnn { keys } { nested-choice-key }
   { Attempt~to~define~'#1'~as~a~nested~choice~key. }
   {
     The~key~'#1'~cannot~be~defined~as~a~choice~as~the~parent~key~'#2'~is~
     itself~a~choice.
   }
-\__kernel_msg_new:nnnn { kernel } { value-forbidden }
+\__kernel_msg_new:nnnn { keys } { value-forbidden }
   { The~key~'#1'~does~not~take~a~value. }
   {
     The~key~'#1'~should~be~given~without~a~value.\\
     The~value~'#2'~was~present:~the~key~will~be~ignored.
   }
-\__kernel_msg_new:nnnn { kernel } { value-required }
+\__kernel_msg_new:nnnn { keys } { value-required }
   { The~key~'#1'~requires~a~value. }
   {
     The~key~'#1'~must~have~a~value.\\
     No~value~was~present:~the~key~will~be~ignored.
   }
-\__kernel_msg_new:nnn { kernel } { show-key }
+\__kernel_msg_new:nnn { keys } { show-key }
   {
     The~key~#1~
     \tl_if_empty:nTF {#2}
@@ -13914,15 +14074,15 @@
     \int_incr:N \l__intarray_loop_int
     \__intarray_gset_range:Nw #1
   }
-\cs_new_protected:Npn \intarray_show:N { \__intarray_show:NN \msg_show:nnxxxx }
+\cs_new_protected:Npn \intarray_show:N { \__intarray_show:NN \__kernel_msg_show:nnxxxx }
 \cs_generate_variant:Nn \intarray_show:N { c }
-\cs_new_protected:Npn \intarray_log:N { \__intarray_show:NN \msg_log:nnxxxx }
+\cs_new_protected:Npn \intarray_log:N { \__intarray_show:NN \__kernel_msg_log:nnxxxx }
 \cs_generate_variant:Nn \intarray_log:N { c }
 \cs_new_protected:Npn \__intarray_show:NN #1#2
   {
     \__kernel_chk_defined:NT #2
       {
-        #1 { LaTeX/kernel } { show-intarray }
+        #1 { intarray } { show }
           { \token_to_str:N #2 }
           { \intarray_count:N #2 }
           { >~ \__intarray_to_clist:Nn #2 { , ~ } }
@@ -14012,7 +14172,7 @@
 \cs_new:Npn \__fp_use_i:ww #1; #2; { #1; }
 \cs_new:Npn \__fp_use_i:www #1; #2; #3; { #1; }
 \cs_new_protected:Npn \__fp_misused:n #1
-  { \__kernel_msg_error:nnx { kernel } { misused-fp } { \fp_to_tl:n {#1} } }
+  { \__kernel_msg_error:nnx { fp } { misused } { \fp_to_tl:n {#1} } }
 \scan_new:N \s__fp
 \cs_new_protected:Npn \__fp_chk:w #1 ;
   { \__fp_misused:n { \s__fp \__fp_chk:w #1 ; } }
@@ -14381,7 +14541,7 @@
   { \cs_new:Npn \__fp_func_to_name_aux:w ##1 #1 ##2 #2 ##3 X {##2} }
 \exp_args:Nff \__fp_tmp:w { \tl_to_str:n { __fp_ } }
   { \tl_to_str:n { _o: } }
-\__kernel_msg_new:nnnn { kernel } { misused-fp }
+\__kernel_msg_new:nnnn { fp } { misused }
   { A~floating~point~with~value~'#1'~was~misused. }
   {
     To~obtain~the~value~of~a~floating~point~variable,~use~
@@ -14402,12 +14562,12 @@
           { invalid_operation , division_by_zero , overflow , underflow }
           {#1}
           {
-            \__kernel_msg_error:nnxx { kernel }
+            \__kernel_msg_error:nnxx { fp }
               { unknown-fpu-trap-type } {#1} {#2}
           }
           {
             \__kernel_msg_error:nnx
-              { kernel } { unknown-fpu-exception } {#1}
+              { fp } { unknown-fpu-exception } {#1}
           }
       }
   }
@@ -14423,7 +14583,7 @@
       { \cs_set:Npn \__fp_invalid_operation:nnw ##1##2##3; }
       {
         #1
-        \__fp_error:nnfn { fp-invalid } {##2} { \fp_to_tl:n { ##3; } } { }
+        \__fp_error:nnfn { invalid } {##2} { \fp_to_tl:n { ##3; } } { }
         \flag_raise_if_clear:n { fp_invalid_operation }
         ##1
       }
@@ -14431,7 +14591,7 @@
       { \cs_set:Npn \__fp_invalid_operation_o:Nww ##1##2; ##3; }
       {
         #1
-        \__fp_error:nffn { fp-invalid-ii }
+        \__fp_error:nffn { invalid-ii }
           { \fp_to_tl:n { ##2; } } { \fp_to_tl:n { ##3; } } {##1}
         \flag_raise_if_clear:n { fp_invalid_operation }
         \exp_after:wN \c_nan_fp
@@ -14440,7 +14600,7 @@
       { \cs_set:Npn \__fp_invalid_operation_tl_o:ff ##1##2 }
       {
         #1
-        \__fp_error:nffn { fp-invalid } {##1} {##2} { }
+        \__fp_error:nffn { invalid } {##1} {##2} { }
         \flag_raise_if_clear:n { fp_invalid_operation }
         \exp_after:wN \c_nan_fp
       }
@@ -14457,7 +14617,7 @@
       { \cs_set:Npn \__fp_division_by_zero_o:Nnw ##1##2##3; }
       {
         #1
-        \__fp_error:nnfn { fp-zero-div } {##2} { \fp_to_tl:n { ##3; } } { }
+        \__fp_error:nnfn { zero-div } {##2} { \fp_to_tl:n { ##3; } } { }
         \flag_raise_if_clear:n { fp_division_by_zero }
         \exp_after:wN ##1
       }
@@ -14465,7 +14625,7 @@
       { \cs_set:Npn \__fp_division_by_zero_o:NNww ##1##2##3; ##4; }
       {
         #1
-        \__fp_error:nffn { fp-zero-div-ii }
+        \__fp_error:nffn { zero-div-ii }
           { \fp_to_tl:n { ##3; } } { \fp_to_tl:n { ##4; } } {##2}
         \flag_raise_if_clear:n { fp_division_by_zero }
         \exp_after:wN ##1
@@ -14494,7 +14654,7 @@
       {
         #1
         \__fp_error:nffn
-          { fp-flow \if_meaning:w 1 ##1 -to \fi: }
+          { flow \if_meaning:w 1 ##1 -to \fi: }
           { \fp_to_tl:n { \s__fp \__fp_chk:w ##1##2##3; } }
           { \token_if_eq_meaning:NNF 0 ##2 { - } #4 }
           {#2}
@@ -14517,9 +14677,9 @@
   { \__fp_invalid_operation:nnw { \exp_after:wN \c_nan_fp } }
 \cs_generate_variant:Nn \__fp_invalid_operation_o:nw { f }
 \cs_new:Npn \__fp_error:nnnn
-  { \__kernel_msg_expandable_error:nnnnn { kernel } }
+  { \__kernel_msg_expandable_error:nnnnn { fp } }
 \cs_generate_variant:Nn \__fp_error:nnnn { nnf, nff , nfff }
-\__kernel_msg_new:nnnn { kernel } { unknown-fpu-exception }
+\__kernel_msg_new:nnnn { fp } { unknown-fpu-exception }
   {
     The~FPU~exception~'#1'~is~not~known:~
     that~trap~will~never~be~triggered.
@@ -14534,7 +14694,7 @@
         * ~ underflow
       }
   }
-\__kernel_msg_new:nnnn { kernel } { unknown-fpu-trap-type }
+\__kernel_msg_new:nnnn { fp } { unknown-fpu-trap-type }
   { The~FPU~trap~type~'#2'~is~not~known. }
   {
     The~trap~type~must~be~one~of \\
@@ -14545,19 +14705,19 @@
         * ~ none
       }
   }
-\__kernel_msg_new:nnn { kernel } { fp-flow }
+\__kernel_msg_new:nnn { fp } { flow }
   { An ~ #3 ~ occurred. }
-\__kernel_msg_new:nnn { kernel } { fp-flow-to }
+\__kernel_msg_new:nnn { fp } { flow-to }
   { #1 ~ #3 ed ~ to ~ #2 . }
-\__kernel_msg_new:nnn { kernel } { fp-zero-div }
+\__kernel_msg_new:nnn { fp } { zero-div }
   { Division~by~zero~in~ #1 (#2) }
-\__kernel_msg_new:nnn { kernel } { fp-zero-div-ii }
+\__kernel_msg_new:nnn { fp } { zero-div-ii }
   { Division~by~zero~in~ (#1) #3 (#2) }
-\__kernel_msg_new:nnn { kernel } { fp-invalid }
+\__kernel_msg_new:nnn { fp } { invalid }
   { Invalid~operation~ #1 (#2) }
-\__kernel_msg_new:nnn { kernel } { fp-invalid-ii }
+\__kernel_msg_new:nnn { fp } { invalid-ii }
   { Invalid~operation~ (#1) #3 (#2) }
-\__kernel_msg_new:nnn { kernel } { fp-unknown-type }
+\__kernel_msg_new:nnn { fp } { unknown-type }
   { Unknown~type~for~'#1' }
 %% File: l3fp-round.dtx
 \cs_new:Npn \__fp_parse_word_trunc:N
@@ -14713,9 +14873,9 @@
 \cs_new:Npn \__fp_round_no_arg_o:Nw #1
   {
     \cs_if_eq:NNTF #1 \__fp_round_to_nearest:NNN
-      { \__fp_error:nnnn { fp-num-args } { round () } { 1 } { 3 } }
+      { \__fp_error:nnnn { num-args } { round () } { 1 } { 3 } }
       {
-        \__fp_error:nffn { fp-num-args }
+        \__fp_error:nffn { num-args }
           { \__fp_round_name_from_cs:N #1 () } { 1 } { 2 }
       }
     \exp_after:wN \c_nan_fp
@@ -14736,12 +14896,12 @@
             #2 ; #3 ;
           }
           {
-            \__fp_error:nnnn { fp-num-args } { round () } { 1 } { 3 }
+            \__fp_error:nnnn { num-args } { round () } { 1 } { 3 }
             \exp_after:wN \c_nan_fp
           }
       }
       {
-        \__fp_error:nffn { fp-num-args }
+        \__fp_error:nffn { num-args }
           { \__fp_round_name_from_cs:N #1 () } { 1 } { 2 }
         \exp_after:wN \c_nan_fp
       }
@@ -14930,7 +15090,7 @@
           }
       }
       {
-        \__kernel_msg_expandable_error:nn { kernel } { fp-early-end }
+        \__kernel_msg_expandable_error:nn { fp } { early-end }
         \exp_after:wN \c_nan_fp \exp:w \exp_end_continue_f:w
       }
     #1
@@ -14952,8 +15112,8 @@
               {
                 \cs_if_eq:NNTF ##2 #1 { \use_i:nn } { \use:n }
                 {
-                  \__kernel_msg_expandable_error:nnn { kernel }
-                    { fp-robust-cmd }
+                  \__kernel_msg_expandable_error:nnn { fp }
+                    { robust-cmd }
                 }
               }
               {
@@ -15024,7 +15184,7 @@
     \str_if_eq:nnTF {#1} {#2}
       {
         \__kernel_msg_expandable_error:nnn
-          { kernel } { fp-infty-pi } {#1}
+          { fp } { infty-pi } {#1}
         \c_nan_fp
       }
       { #4 \__fp_parse_expand:w }
@@ -15081,7 +15241,7 @@
           { __fp_parse_caseless_ \str_foldcase:n {#2} :N }
           {
             \__kernel_msg_expandable_error:nnn
-              { kernel } { unknown-fp-word } {#2}
+              { fp } { unknown-fp-word } {#2}
             \exp_after:wN \c_nan_fp \exp:w \exp_end_continue_f:w
             \__fp_parse_infix:NN
           }
@@ -15120,13 +15280,13 @@
     \cs_if_exist:cTF { __fp_parse_infix_ \token_to_str:N #1 :N }
       {
         \__kernel_msg_expandable_error:nnn
-          { kernel } { fp-missing-number } {#1}
+          { fp } { missing-number } {#1}
         \exp_after:wN \c_nan_fp \exp:w \exp_end_continue_f:w
         \__fp_parse_infix:NN #3 #1
       }
       {
         \__kernel_msg_expandable_error:nnn
-          { kernel } { fp-unknown-symbol } {#1}
+          { fp } { unknown-symbol } {#1}
         \__fp_parse_one:Nw #3
       }
   }
@@ -15464,7 +15624,7 @@
             = 0 \exp_stop_f:
           0
           \__kernel_msg_expandable_error:nnn
-            { kernel } { fp-after-e } { floating~point~ }
+            { fp } { after-e } { floating~point~ }
           \prg_return_true:
         \else:
           0
@@ -15480,14 +15640,14 @@
         \else:
           0
           \__kernel_msg_expandable_error:nnn
-            { kernel } { fp-after-e } { dimension~#1 }
+            { fp } { after-e } { dimension~#1 }
         \fi:
         \prg_return_false:
       \fi:
     \else:
       0
       \__kernel_msg_expandable_error:nnn
-        { kernel } { fp-missing } { exponent }
+        { fp } { missing } { exponent }
       \prg_return_true:
     \fi:
   }
@@ -15515,7 +15675,7 @@
 \cs_new:Npn \__fp_parse_apply_unary_chk:nNNNNw #1#2#3#4#5#6 @
   {
     #2
-    \__fp_error:nffn { fp-#1-arg } { \__fp_func_to_name:N #4 } { } { }
+    \__fp_error:nffn { #1-arg } { \__fp_func_to_name:N #4 } { } { }
     \exp_after:wN #4 \exp_after:wN #5 \c_nan_fp @
   }
 \cs_new:Npn \__fp_parse_apply_unary_type:NNN #1#2#3
@@ -15578,7 +15738,7 @@
       }
       {
         \exp_not:N \__kernel_msg_expandable_error:nnn
-          { kernel } { fp-missing } { ) }
+          { fp } { missing } { ) }
         \exp_not:N \tl_if_empty:nT {#2} \exp_not:N \c__fp_empty_tuple_fp
         #2 @
         \exp_not:N \use_none:n #3
@@ -15592,7 +15752,7 @@
         \exp_after:wN \c__fp_empty_tuple_fp \exp:w
       \else:
         \__kernel_msg_expandable_error:nnn
-          { kernel } { fp-missing-number } { ) }
+          { fp } { missing-number } { ) }
         \exp_after:wN \c_nan_fp \exp:w
       \fi:
       \exp_end_continue_f:w
@@ -15792,7 +15952,7 @@
   {
     \if_meaning:w \scan_stop: #1
       \__kernel_msg_expandable_error:nnn
-        { kernel } { fp-missing } { * }
+        { fp } { missing } { * }
       \exp_after:wN \__fp_parse_infix_mul:N
       \exp_after:wN #2
       \exp_after:wN #3
@@ -15844,7 +16004,7 @@
           \exp_after:wN \use_none:n
           \exp_after:wN #1
         \else:
-          \__kernel_msg_expandable_error:nnn { kernel } { fp-extra } { ) }
+          \__kernel_msg_expandable_error:nnn { fp } { extra } { ) }
           \exp_after:wN \__fp_parse_infix:NN
           \exp_after:wN ##1
           \exp:w \exp_after:wN \__fp_parse_expand:w
@@ -15979,7 +16139,7 @@
   \__fp_ternary_auxii:NwwN \c__fp_prec_colon_int
   {
     \__kernel_msg_expandable_error:nnnn
-      { kernel } { fp-missing } { ? } { ~for~?: }
+      { fp } { missing } { ? } { ~for~?: }
   }
 \cs_new:cpn { __fp_parse_infix_<:N } #1
   { \__fp_parse_compare:NNNNNNN #1 1 0 0 0 0 < }
@@ -16000,7 +16160,7 @@
 \cs_new:Npn \__fp_parse_excl_error:
   {
     \__kernel_msg_expandable_error:nnnn
-      { kernel } { fp-missing } { = } { ~after~!. }
+      { fp } { missing } { = } { ~after~!. }
   }
 \cs_new:Npn \__fp_parse_compare:NNNNNNN #1
   {
@@ -16094,7 +16254,7 @@
     \__fp_array_if_all_fp:nTF {#3}
       { #2 #3 @ }
       {
-        \__fp_error:nffn { fp-bad-args }
+        \__fp_error:nffn { bad-args }
           {#1}
           { \fp_to_tl:n { \s__fp_tuple \__fp_tuple_chk:w {#3} ; } }
           { }
@@ -16109,7 +16269,7 @@
   }
 \cs_new:Npn \__fp_parse_function_one_two_error_o:w #1#2#3#4 @
   {
-    \__fp_error:nffn { fp-bad-args }
+    \__fp_error:nffn { bad-args }
       {#2}
       { \fp_to_tl:n { \s__fp_tuple \__fp_tuple_chk:w {#4} ; } }
       { }
@@ -16176,37 +16336,37 @@
     \exp:w \exp_end_continue_f:w
     \__fp_tuple_mapthread_loop_o:nw {#1} #4 @
   }
-\__kernel_msg_new:nnn { kernel } { fp-deprecated }
+\__kernel_msg_new:nnn { fp } { deprecated }
   { '#1'~deprecated;~use~'#2' }
-\__kernel_msg_new:nnn { kernel } { unknown-fp-word }
+\__kernel_msg_new:nnn { fp } { unknown-fp-word }
   { Unknown~fp~word~#1. }
-\__kernel_msg_new:nnn { kernel } { fp-missing }
+\__kernel_msg_new:nnn { fp } { missing }
   { Missing~#1~inserted #2. }
-\__kernel_msg_new:nnn { kernel } { fp-extra }
+\__kernel_msg_new:nnn { fp } { extra }
   { Extra~#1~ignored. }
-\__kernel_msg_new:nnn { kernel } { fp-early-end }
+\__kernel_msg_new:nnn { fp } { early-end }
   { Premature~end~in~fp~expression. }
-\__kernel_msg_new:nnn { kernel } { fp-after-e }
+\__kernel_msg_new:nnn { fp } { after-e }
   { Cannot~use~#1 after~'e'. }
-\__kernel_msg_new:nnn { kernel } { fp-missing-number }
+\__kernel_msg_new:nnn { fp } { missing-number }
   { Missing~number~before~'#1'. }
-\__kernel_msg_new:nnn { kernel } { fp-unknown-symbol }
+\__kernel_msg_new:nnn { fp } { unknown-symbol }
   { Unknown~symbol~#1~ignored. }
-\__kernel_msg_new:nnn { kernel } { fp-extra-comma }
+\__kernel_msg_new:nnn { fp } { extra-comma }
   { Unexpected~comma~turned~to~nan~result. }
-\__kernel_msg_new:nnn { kernel } { fp-no-arg }
+\__kernel_msg_new:nnn { fp } { no-arg }
   { #1~got~no~argument;~used~nan. }
-\__kernel_msg_new:nnn { kernel } { fp-multi-arg }
+\__kernel_msg_new:nnn { fp } { multi-arg }
   { #1~got~more~than~one~argument;~used~nan. }
-\__kernel_msg_new:nnn { kernel } { fp-num-args }
+\__kernel_msg_new:nnn { fp } { num-args }
   { #1~expects~between~#2~and~#3~arguments. }
-\__kernel_msg_new:nnn { kernel } { fp-bad-args }
+\__kernel_msg_new:nnn { fp } { bad-args }
   { Arguments~in~#1#2~are~invalid. }
-\__kernel_msg_new:nnn { kernel } { fp-infty-pi }
+\__kernel_msg_new:nnn { fp } { infty-pi }
   { Math~command~#1 is~not~an~fp }
 \cs_if_exist:cT { @unexpandable@protect }
   {
-    \__kernel_msg_new:nnn { kernel } { fp-robust-cmd }
+    \__kernel_msg_new:nnn { fp } { robust-cmd }
       { Robust~command~#1 invalid~in~fp~expression! }
   }
 %% File: l3fp-assign.dtx
@@ -16252,9 +16412,23 @@
 \cs_generate_variant:Nn \fp_log:N { c }
 \cs_new_protected:Npn \__fp_show:NN #1#2
   {
-    \__kernel_chk_defined:NT #2
+    \__kernel_chk_tl_type:NnnT #2 { fp }
+      {
+        \str_if_eq:eeTF { \tl_head:N #2 } { \s__fp_tuple } { \exp_not:o #2 }
+          {
+            \exp_after:wN \__fp_show_validate:w #2
+            \s__fp \__fp_chk:w ??? ; \s__fp_stop
+          }
+      }
       { \exp_args:Nx #1 { \token_to_str:N #2 = \fp_to_tl:N #2 } }
   }
+\cs_new:Npn \__fp_show_validate:w
+    #1 \s__fp \__fp_chk:w #2#3#4#5 ; #6 \s__fp_stop
+  {
+    \token_if_eq_meaning:NNTF #2 1
+      { \s__fp \__fp_chk:w #2 #3 {#4} #5 ; }
+      { \s__fp \__fp_chk:w #2 #3 #4 #5 ; }
+  }
 \cs_new_protected:Npn \fp_show:n
   { \msg_show_eval:Nn \fp_to_tl:n }
 \cs_new_protected:Npn \fp_log:n
@@ -16481,7 +16655,7 @@
     \prg_break_point:
     \use:n
       {
-        \__fp_error:nfff { fp-step-tuple } { \fp_to_tl:n { #1#2 ; } }
+        \__fp_error:nfff { step-tuple } { \fp_to_tl:n { #1#2 ; } }
           { \fp_to_tl:n { #3#4 ; } } { \fp_to_tl:n { #5#6 ; } }
       }
   }
@@ -16500,7 +16674,7 @@
               { zero-step } {#6}
           }
           {
-            \__fp_error:nnfn { fp-bad-step } { }
+            \__fp_error:nnfn { bad-step } { }
               { \fp_to_tl:n { \s__fp \__fp_chk:w #2#3#4 ; } } {#6}
           }
         \use_none:nnnnn
@@ -16511,7 +16685,7 @@
   {
     \fp_compare:nNnTF {#2} = {#3}
       {
-        \__fp_error:nffn { fp-tiny-step }
+        \__fp_error:nffn { tiny-step }
           { \fp_to_tl:n {#3} } { \fp_to_tl:n {#4} } {#6}
       }
       {
@@ -16549,11 +16723,11 @@
     \fp_step_function:nnnN {#3} {#4} {#5} #2
     \prg_break_point:Nn \scan_stop: { \int_gdecr:N \g__kernel_prg_map_int }
   }
-\__kernel_msg_new:nnn { kernel } { fp-step-tuple }
+\__kernel_msg_new:nnn { fp } { step-tuple }
   { Tuple~argument~in~fp_step_...~{#1}{#2}{#3}. }
-\__kernel_msg_new:nnn { kernel } { fp-bad-step }
+\__kernel_msg_new:nnn { fp } { bad-step }
   { Invalid~step~size~#2~in~step~function~#3. }
-\__kernel_msg_new:nnn { kernel } { fp-tiny-step }
+\__kernel_msg_new:nnn { fp } { tiny-step }
   { Tiny~step~size~(#1+#2=#1)~in~step~function~#3. }
 \cs_new:Npn \__fp_minmax_o:Nw #1
   {
@@ -16658,7 +16832,7 @@
         \__fp_parse_expand:w
     \else:
       \__kernel_msg_expandable_error:nnnn
-        { kernel } { fp-missing } { : } { ~for~?: }
+        { fp } { missing } { : } { ~for~?: }
       \exp_after:wN \__fp_parse_continue:NwN
       \exp_after:wN #1
       \exp:w \exp_end_continue_f:w
@@ -19610,7 +19784,7 @@
   }
 \cs_new:Npn \__fp_to_scientific_recover:w #1 #2 ;
   {
-    \__fp_error:nffn { fp-unknown-type } { \tl_to_str:n { #2 ; } } { } { }
+    \__fp_error:nffn { unknown-type } { \tl_to_str:n { #2 ; } } { } { }
     nan
   }
 \cs_new:Npn \__fp_tuple_to_scientific:w
@@ -19664,7 +19838,7 @@
   }
 \cs_new:Npn \__fp_to_decimal_recover:w #1 #2 ;
   {
-    \__fp_error:nffn { fp-unknown-type } { \tl_to_str:n { #2 ; } } { } { }
+    \__fp_error:nffn { unknown-type } { \tl_to_str:n { #2 ; } } { } { }
     nan
   }
 \cs_new:Npn \__fp_tuple_to_decimal:w
@@ -19738,7 +19912,7 @@
   { \__fp_change_func_type:NNN #1 \__fp_to_tl:w \__fp_to_tl_recover:w #1 }
 \cs_new:Npn \__fp_to_tl_recover:w #1 #2 ;
   {
-    \__fp_error:nffn { fp-unknown-type } { \tl_to_str:n { #2 ; } } { } { }
+    \__fp_error:nffn { unknown-type } { \tl_to_str:n { #2 ; } } { } { }
     nan
   }
 \cs_new:Npn \__fp_tuple_to_tl:w
@@ -19928,7 +20102,7 @@
           }
           {
             \__kernel_msg_expandable_error:nnnnn
-              { kernel } { fp-num-args } { rand() } { 0 } { 0 }
+              { fp } { num-args } { rand() } { 0 } { 0 }
             \exp_after:wN \c_nan_fp
           }
       }
@@ -20163,7 +20337,6 @@
       }
   }
 %% File: l3fparray.dtx
-
 \int_new:N \g__fp_array_int
 \int_new:N \l__fp_array_loop_int
 \cs_new_protected:Npn \fparray_new:Nn #1#2
@@ -20242,7 +20415,7 @@
   }
 \cs_new_protected:Npn \__fp_array_gset_recover:Nw #1#2 ;
   {
-    \__fp_error:nffn { fp-unknown-type } { \tl_to_str:n { #2 ; } } { } { }
+    \__fp_error:nffn { unknown-type } { \tl_to_str:n { #2 ; } } { } { }
     \exp_after:wN #1 \c_nan_fp
   }
 \cs_new_protected:Npn \__fp_array_gset:w \s__fp \__fp_chk:w #1#2
@@ -20502,7 +20675,7 @@
           { \__cctab_nesting_number:N \l__cctab_internal_a_tl }
         \__cctab_select:N \l__cctab_internal_a_tl
       }
-      { \__kernel_msg_error:nn { kernel } { cctab-extra-end } }
+      { \__kernel_msg_error:nn { cctab } { extra-end } }
   }
 \cs_new_protected:Npn \__cctab_chk_group_begin:n #1
   {
@@ -20520,7 +20693,7 @@
       }
       { \cs_if_exist_p:c { __cctab_group_ #1 _chk: } }
       {
-        \__kernel_msg_error:nnx { kernel } { cctab-group-mismatch }
+        \__kernel_msg_error:nnx { cctab } { group-mismatch }
           {
             \int_sign:n
               { \tex_currentgrouplevel:D - \l__cctab_internal_b_tl }
@@ -20544,10 +20717,10 @@
   }
 \cs_if_exist:NT \hook_gput_code:nnn
   {
-    \hook_gput_code:nnn { enddocument/end } { kernel }
+    \hook_gput_code:nnn { enddocument/end } { cctab }
       {
         \seq_if_empty:NF \g__cctab_stack_seq
-          { \__kernel_msg_error:nn { kernel } { cctab-missing-end } }
+          { \__kernel_msg_error:nn { cctab } { missing-end } }
       }
   }
 \prg_new_eq_conditional:NNn \cctab_if_exist:N \cs_if_exist:N
@@ -20562,7 +20735,7 @@
         \__cctab_chk_if_valid_aux:NTF #1
           { \prg_return_true: }
           {
-            \__kernel_msg_error:nnx { kernel } { invalid-cctab }
+            \__kernel_msg_error:nnx { cctab } { invalid-cctab }
               { \token_to_str:N #1 }
             \prg_return_false:
           }
@@ -20664,32 +20837,32 @@
         \char_set_catcode_active:n         { 126 }
       }
   }
-\__kernel_msg_new:nnnn { kernel } { cctab-stack-full }
+\__kernel_msg_new:nnnn { cctab } { stack-full }
   { The~category~code~table~stack~is~exhausted. }
   {
     LaTeX~has~been~asked~to~switch~to~a~new~category~code~table,~
     but~there~is~no~more~space~to~do~this!
   }
-\__kernel_msg_new:nnnn { kernel } { cctab-extra-end }
+\__kernel_msg_new:nnnn { cctab } { extra-end }
   { Extra~\iow_char:N\\cctab_end:~ignored~\msg_line_context:. }
   {
     LaTeX~came~across~a~\iow_char:N\\cctab_end:~without~a~matching~
     \iow_char:N\\cctab_begin:N.~This~command~will~be~ignored.
   }
-\__kernel_msg_new:nnnn { kernel } { cctab-missing-end }
+\__kernel_msg_new:nnnn { cctab } { missing-end }
   { Missing~\iow_char:N\\cctab_end:~before~end~of~TeX~run. }
   {
     LaTeX~came~across~more~\iow_char:N\\cctab_begin:N~than~
     \iow_char:N\\cctab_end:.
   }
-\__kernel_msg_new:nnnn { kernel } { invalid-cctab }
+\__kernel_msg_new:nnnn { cctab } { invalid-cctab }
   { Invalid~\iow_char:N\\catcode~table. }
   {
     You~can~only~switch~to~a~\iow_char:N\\catcode~table~that~is~
     initialized~using~\iow_char:N\\cctab_new:N~or~
     \iow_char:N\\cctab_const:Nn.
   }
-\__kernel_msg_new:nnnn { kernel } { cctab-group-mismatch }
+\__kernel_msg_new:nnnn { cctab } { group-mismatch }
   {
     \iow_char:N\\cctab_end:~occurred~in~a~
     \int_case:nn {#1}
@@ -20940,14 +21113,14 @@
 \cs_new_protected:Npn \__sort_return_mark:w #1 \s__sort_mark { }
 \cs_new_protected:Npn \__sort_return_none_error:
   {
-    \__kernel_msg_error:nnxx { kernel } { return-none }
+    \__kernel_msg_error:nnxx { sort } { return-none }
       { \tex_the:D \tex_toks:D \l__sort_A_int }
       { \tex_the:D \tex_toks:D \l__sort_C_int }
     \__sort_return_same:w \__sort_return_none_error:
   }
 \cs_new_protected:Npn \__sort_return_two_error:
   {
-    \__kernel_msg_error:nnxx { kernel } { return-two }
+    \__kernel_msg_error:nnxx { sort } { return-two }
       { \tex_the:D \tex_toks:D \l__sort_A_int }
       { \tex_the:D \tex_toks:D \l__sort_C_int }
   }
@@ -21077,12 +21250,12 @@
   { \cs_set_eq:NN \toksdef \__sort_disabled_toksdef:n }
 \cs_new_protected:Npn \__sort_disabled_toksdef:n #1
   {
-    \__kernel_msg_error:nnx { kernel } { toksdef }
+    \__kernel_msg_error:nnx { sort } { toksdef }
       { \token_to_str:N #1 }
     \__sort_error:
     \tex_toksdef:D #1
   }
-\__kernel_msg_new:nnnn { kernel } { toksdef }
+\__kernel_msg_new:nnnn { sort } { toksdef }
   { Allocation~of~\iow_char:N\\toks~registers~impossible~while~sorting. }
   {
     The~comparison~code~used~for~sorting~a~list~has~attempted~to~
@@ -21093,20 +21266,20 @@
 \cs_new_protected:Npn \__sort_too_long_error:NNw #1#2 \fi:
   {
     \fi:
-    \__kernel_msg_error:nnxxx { kernel } { too-large }
+    \__kernel_msg_error:nnxxx { sort } { too-large }
       { \token_to_str:N #2 }
       { \int_eval:n { \l__sort_true_max_int - \l__sort_min_int } }
       { \int_eval:n { \l__sort_top_int - \l__sort_min_int } }
     #1 \__sort_error:
   }
-\__kernel_msg_new:nnnn { kernel } { too-large }
+\__kernel_msg_new:nnnn { sort } { too-large }
   { The~list~#1~is~too~long~to~be~sorted~by~TeX. }
   {
     TeX~has~#2~toks~registers~still~available:~
     this~only~allows~to~sort~with~up~to~#3~
     items.~The~list~will~not~be~sorted.
   }
-\__kernel_msg_new:nnnn { kernel } { return-none }
+\__kernel_msg_new:nnnn { sort } { return-none }
   { The~comparison~code~did~not~return. }
   {
     When~sorting~a~list,~the~code~to~compare~items~#1~and~#2~
@@ -21115,7 +21288,7 @@
     \iow_char:N\\sort_return_swapped: .~
     Exactly~one~of~these~should~be~called.
   }
-\__kernel_msg_new:nnnn { kernel } { return-two }
+\__kernel_msg_new:nnnn { sort } { return-two }
   { The~comparison~code~returned~multiple~times. }
   {
     When~sorting~a~list,~the~code~to~compare~items~#1~and~#2~called~
@@ -22824,7 +22997,7 @@
     \tl_if_exist:NTF #1
       {
         \exp_args:No \__tl_analysis:n {#1}
-        \msg_show:nnxxxx { LaTeX / kernel } { show-tl-analysis }
+        \__kernel_msg_show:nnxxxx { tl } { show-analysis }
           { \token_to_str:N #1 } { \__tl_analysis_show: } { } { }
       }
       { \tl_show:N #1 }
@@ -22832,7 +23005,7 @@
 \cs_new_protected:Npn \tl_analysis_show:n #1
   {
     \__tl_analysis:n {#1}
-    \msg_show:nnxxxx { LaTeX / kernel } { show-tl-analysis }
+    \__kernel_msg_show:nnxxxx { tl } { show-analysis }
       { } { \__tl_analysis_show: } { } { }
   }
 \cs_new:Npn \__tl_analysis_show:
@@ -23118,7 +23291,7 @@
   }
 \tl_const:Nx \c__tl_analysis_show_etc_str % (
   { \token_to_str:N \ETC.) }
-\__kernel_msg_new:nnn { kernel } { show-tl-analysis }
+\__kernel_msg_new:nnn { tl } { show-analysis }
   {
     The~token~list~ \tl_if_empty:nF {#1} { #1 ~ }
     \tl_if_empty:nTF {#2}
@@ -23230,9 +23403,7 @@
     \if_int_compare:w #1 = \l__regex_curr_char_int
       \exp_after:wN \__regex_break_true:w
     \fi:
-    \if_int_compare:w \l__regex_case_changed_char_int = \c_max_int
-      \__regex_compute_case_changed_char:
-    \fi:
+    \__regex_maybe_compute_ccc:
     \if_int_compare:w #1 = \l__regex_case_changed_char_int
       \exp_after:wN \__regex_break_true:w
     \fi:
@@ -23244,9 +23415,7 @@
         \exp_after:wN \exp_after:wN \exp_after:wN \__regex_break_true:w
       \fi:
     \fi:
-    \if_int_compare:w \l__regex_case_changed_char_int = \c_max_int
-      \__regex_compute_case_changed_char:
-    \fi:
+    \__regex_maybe_compute_ccc:
     \reverse_if:N \if_int_compare:w #1 > \l__regex_case_changed_char_int
       \reverse_if:N \if_int_compare:w #2 < \l__regex_case_changed_char_int
         \exp_after:wN \exp_after:wN \exp_after:wN \__regex_break_true:w
@@ -23269,7 +23438,9 @@
           { \c__regex_ascii_lower_int }
       \fi:
     \fi:
+    \cs_set_eq:NN \__regex_maybe_compute_ccc: \prg_do_nothing:
   }
+\cs_new_eq:NN \__regex_maybe_compute_ccc: \__regex_compute_case_changed_char:
 \cs_new_eq:NN \__regex_item_equal:n ?
 \cs_new_eq:NN \__regex_item_range:nn ?
 \cs_new_protected:Npn \__regex_item_catcode:
@@ -23444,7 +23615,7 @@
 \cs_new_eq:NN \__regex_escape_break:w \prg_break:
 \cs_new:cpn { __regex_escape_/break:w }
   {
-    \__kernel_msg_expandable_error:nn { kernel } { trailing-backslash }
+    \__kernel_msg_expandable_error:nn { regex } { trailing-backslash }
     \prg_break:
   }
 \cs_new:cpn { __regex_escape_~:w } { }
@@ -23469,7 +23640,7 @@
   {
     \int_compare:nNnTF {#1} > \c_max_char_int
       {
-        \__kernel_msg_expandable_error:nnff { kernel } { x-overflow }
+        \__kernel_msg_expandable_error:nnff { regex } { x-overflow }
           {#1} { \int_to_Hex:n {#1} }
       }
       {
@@ -23530,7 +23701,7 @@
   }
 \cs_new:Npn \__regex_escape_x_loop_error:n #1
   {
-    \__kernel_msg_expandable_error:nnn { kernel } { x-missing-rbrace } {#1}
+    \__kernel_msg_expandable_error:nnn { regex } { x-missing-rbrace } {#1}
     \__regex_escape_loop:N #1
   }
 \prg_new_conditional:Npnn \__regex_hexadecimal_use:N #1 { TF }
@@ -23705,7 +23876,7 @@
       \if_int_compare:w \l__regex_mode_int = \c__regex_class_mode_int
         \exp_after:wN \exp_after:wN \exp_after:wN \use:n
       \else:
-        \__kernel_msg_error:nn { kernel } { c-bad-mode }
+        \__kernel_msg_error:nn { regex } { c-bad-mode }
         \exp_after:wN \exp_after:wN \exp_after:wN \use_none:n
       \fi:
     \fi:
@@ -23738,13 +23909,13 @@
   {
       \__regex_if_in_class:TF
         {
-          \__kernel_msg_error:nn { kernel } { missing-rbrack }
+          \__kernel_msg_error:nn { regex } { missing-rbrack }
           \use:c { __regex_compile_]: }
           \prg_do_nothing: \prg_do_nothing:
         }
         { }
       \if_int_compare:w \l__regex_group_level_int > 0 \exp_stop_f:
-        \__kernel_msg_error:nnx { kernel } { missing-rparen }
+        \__kernel_msg_error:nnx { regex } { missing-rparen }
           { \int_use:N \l__regex_group_level_int }
         \prg_replicate:nn
           { \l__regex_group_level_int }
@@ -23786,10 +23957,10 @@
       \prg_do_nothing: \prg_do_nothing:
       \prg_do_nothing: \prg_do_nothing:
       \int_compare:nNnT \l__regex_mode_int = \c__regex_catcode_mode_int
-        { \__kernel_msg_error:nn { kernel } { c-trailing } }
+        { \__kernel_msg_error:nn { regex } { c-trailing } }
       \int_compare:nNnT \l__regex_mode_int < \c__regex_outer_mode_int
         {
-          \__kernel_msg_error:nn { kernel } { c-missing-rbrace }
+          \__kernel_msg_error:nn { regex } { c-missing-rbrace }
           \__regex_compile_end_cs:
           \prg_do_nothing: \prg_do_nothing:
           \prg_do_nothing: \prg_do_nothing:
@@ -23836,6 +24007,13 @@
       }
   }
 \cs_generate_variant:Nn \__regex_compile_abort_tokens:n { x }
+\cs_new_protected:Npn \__regex_compile_if_quantifier:TFw #1#2#3#4
+  {
+    \token_if_eq_meaning:NNTF #3 \__regex_compile_special:N
+      { \cs_if_exist:cTF { __regex_compile_quantifier_#4:w } }
+      { \use_ii:nn }
+    {#1} {#2} #3 #4
+  }
 \cs_new_protected:Npn \__regex_compile_quantifier:w #1#2
   {
     \token_if_eq_meaning:NNTF #1 \__regex_compile_special:N
@@ -23853,7 +24031,7 @@
 \cs_new_protected:Npn \__regex_compile_quantifier_abort:xNN #1#2#3
   {
     \__regex_compile_quantifier_none:
-    \__kernel_msg_warning:nnxx { kernel } { invalid-quantifier } {#1} {#3}
+    \__kernel_msg_warning:nnxx { regex } { invalid-quantifier } {#1} {#3}
     \__regex_compile_abort_tokens:x {#1}
     #2 #3
   }
@@ -23923,7 +24101,7 @@
       {
         \if_int_compare:w \l__regex_internal_a_int >
           \l__regex_internal_b_int
-          \__kernel_msg_error:nnxx { kernel } { backwards-quantifier }
+          \__kernel_msg_error:nnxx { regex } { backwards-quantifier }
             { \int_use:N \l__regex_internal_a_int }
             { \int_use:N \l__regex_internal_b_int }
           \int_zero:N \l__regex_internal_b_int
@@ -23946,7 +24124,7 @@
   }
 \cs_new_protected:Npn \__regex_compile_raw_error:N #1
   {
-    \__kernel_msg_error:nnx { kernel } { bad-escape } {#1}
+    \__kernel_msg_error:nnx { regex } { bad-escape } {#1}
     \__regex_compile_raw:N #1
   }
 \cs_new_protected:Npn \__regex_compile_raw:N #1#2#3
@@ -23988,7 +24166,7 @@
     \__regex_if_end_range:NNTF #2 #3
       {
         \if_int_compare:w `#1 > `#3 \exp_stop_f:
-          \__kernel_msg_error:nnxx { kernel } { range-backwards } {#1} {#3}
+          \__kernel_msg_error:nnxx { regex } { range-backwards } {#1} {#3}
         \else:
           \tl_build_put_right:Nx \l__regex_build_tl
             {
@@ -24002,7 +24180,7 @@
         \fi:
       }
       {
-        \__kernel_msg_warning:nnxx { kernel } { range-missing-end }
+        \__kernel_msg_warning:nnxx { regex } { range-missing-end }
           {#1} { \c_backslash_str #3 }
         \tl_build_put_right:Nx \l__regex_build_tl
           {
@@ -24147,11 +24325,11 @@
           {
             : { \__regex_compile_class_posix:NNNNw }
             = {
-                \__kernel_msg_warning:nnx { kernel }
+                \__kernel_msg_warning:nnx { regex }
                   { posix-unsupported } { = }
               }
             . {
-                \__kernel_msg_warning:nnx { kernel }
+                \__kernel_msg_warning:nnx { regex }
                   { posix-unsupported } { . }
               }
           }
@@ -24193,7 +24371,7 @@
               }
           }
           {
-            \__kernel_msg_warning:nnx { kernel } { posix-unknown }
+            \__kernel_msg_warning:nnx { regex } { posix-unknown }
               { \l__regex_internal_a_tl }
             \__regex_compile_abort_tokens:x
               {
@@ -24203,7 +24381,7 @@
           }
       }
       {
-        \__kernel_msg_error:nnxx { kernel } { posix-missing-close }
+        \__kernel_msg_error:nnxx { regex } { posix-missing-close }
           { [: \l__regex_internal_a_tl } { #2 #4 }
         \__regex_compile_abort_tokens:x { [: \l__regex_internal_a_tl }
         #1 #2 #3 #4
@@ -24231,7 +24409,7 @@
       \int_set_eq:NN \l__regex_catcodes_int \l__regex_default_catcodes_int
       \exp_after:wN \__regex_compile_quantifier:w
     \else:
-      \__kernel_msg_warning:nn { kernel } { extra-rparen }
+      \__kernel_msg_warning:nn { regex } { extra-rparen }
       \exp_after:wN \__regex_compile_raw:N \exp_after:wN )
     \fi:
   }
@@ -24241,7 +24419,7 @@
       {
         \if_int_compare:w \l__regex_mode_int =
           \c__regex_catcode_in_class_mode_int
-          \__kernel_msg_error:nn { kernel } { c-lparen-in-class }
+          \__kernel_msg_error:nn { regex } { c-lparen-in-class }
           \exp_after:wN \__regex_compile_raw:N \exp_after:wN (
         \else:
           \exp_after:wN \__regex_compile_lparen:w
@@ -24255,7 +24433,7 @@
         \cs_if_exist_use:cF
           { __regex_compile_special_group_\token_to_str:N #4 :w }
           {
-            \__kernel_msg_warning:nnx { kernel } { special-group-unknown }
+            \__kernel_msg_warning:nnx { regex } { special-group-unknown }
               { (? #4 }
             \__regex_compile_group_begin:N \__regex_group:nnnN
               \__regex_compile_raw:N ? #3 #4
@@ -24293,7 +24471,7 @@
           { \__regex_item_caseless_range:nn }
       }
       {
-        \__kernel_msg_warning:nnx { kernel } { unknown-option } { (?i #2 }
+        \__kernel_msg_warning:nnx { regex } { unknown-option } { (?i #2 }
         \__regex_compile_raw:N (
         \__regex_compile_raw:N ?
         \__regex_compile_raw:N i
@@ -24312,7 +24490,7 @@
           { \__regex_item_caseful_range:nn }
       }
       {
-        \__kernel_msg_warning:nnx { kernel } { unknown-option } { (?-#2#4 }
+        \__kernel_msg_warning:nnx { regex } { unknown-option } { (?-#2#4 }
         \__regex_compile_raw:N (
         \__regex_compile_raw:N ?
         \__regex_compile_raw:N -
@@ -24340,7 +24518,7 @@
       }
       { \cs_if_exist_use:cF { __regex_compile_c_#2:w } }
           {
-            \__kernel_msg_error:nnx { kernel } { c-missing-category } {#2}
+            \__kernel_msg_error:nnx { regex } { c-missing-category } {#2}
             #1 #2
           }
   }
@@ -24353,7 +24531,7 @@
           { \token_if_eq_charcode:NNF #2 ( } % )
       }
       { \use:n }
-    { \__kernel_msg_error:nnn { kernel } { c-C-invalid } {#2} }
+    { \__kernel_msg_error:nnn { regex } { c-C-invalid } {#2} }
     #1 #2
   }
 \cs_new_protected:cpn { __regex_compile_c_[:w } #1#2
@@ -24392,7 +24570,7 @@
           { \__regex_compile_c_lbrack_end: }
       }
           {
-            \__kernel_msg_error:nnx { kernel } { c-missing-rbrack } {#2}
+            \__kernel_msg_error:nnx { regex } { c-missing-rbrack } {#2}
             \__regex_compile_c_lbrack_end:
             #1 #2
           }
@@ -24422,6 +24600,12 @@
             \c__regex_cs_in_class_mode_int
           \fi:
   }
+\cs_new_protected:cpn { __regex_compile_ \c_left_brace_str : }
+  {
+    \__regex_if_in_cs:TF
+      { \__kernel_msg_error:nnn { regex } { cu-lbrace } { c } }
+      { \exp_after:wN \__regex_compile_raw:N \c_left_brace_str }
+  }
 \flag_new:n { __regex_cs }
 \cs_new_protected:cpn { __regex_compile_ \c_right_brace_str : }
   {
@@ -24492,15 +24676,25 @@
     \__regex_if_in_class_or_catcode:TF
       { \__regex_compile_raw_error:N u #1 #2 }
       {
-        \__regex_two_if_eq:NNNNTF #1 #2 \__regex_compile_special:N \c_left_brace_str
-          {
-            \__kernel_tl_set:Nx \l__regex_internal_a_tl { \if_false: } \fi:
-            \__regex_compile_u_loop:NN
-          }
-          {
-            \__kernel_msg_error:nn { kernel } { u-missing-lbrace }
-            \__regex_compile_raw:N u #1 #2
-          }
+        \__regex_two_if_eq:NNNNTF #1 #2 \__regex_compile_raw:N r
+          { \__regex_compile_u_brace:NNN \__regex_compile_ur_end: }
+          { \__regex_compile_u_brace:NNN \__regex_compile_u_end: #1 #2 }
+      }
+  }
+\cs_new:Npn \__regex_compile_u_brace:NNN #1#2#3
+  {
+    \__regex_two_if_eq:NNNNTF #2 #3 \__regex_compile_special:N \c_left_brace_str
+      {
+        \tl_set:Nn \l__regex_internal_b_tl {#1}
+        \__kernel_tl_set:Nx \l__regex_internal_a_tl { \if_false: } \fi:
+        \__regex_compile_u_loop:NN
+      }
+      {
+        \__kernel_msg_error:nn { regex } { u-missing-lbrace }
+        \token_if_eq_meaning:NNTF #1 \__regex_compile_ur_end:
+          { \__regex_compile_raw:N u \__regex_compile_raw:N r }
+          { \__regex_compile_raw:N u }
+        #2 #3
       }
   }
 \cs_new:Npn \__regex_compile_u_loop:NN #1#2
@@ -24511,18 +24705,62 @@
         \token_if_eq_meaning:NNTF #1 \__regex_compile_special:N
           {
             \exp_after:wN \token_if_eq_charcode:NNTF \c_right_brace_str #2
-              { \if_false: { \fi: } \__regex_compile_u_end: }
-              { #2 \__regex_compile_u_loop:NN }
+              { \if_false: { \fi: } \l__regex_internal_b_tl }
+              {
+                \if_charcode:w \c_left_brace_str #2
+                  \__kernel_msg_expandable_error:nnn { regex } { cu-lbrace } { u }
+                \else:
+                  #2
+                \fi:
+                \__regex_compile_u_loop:NN
+              }
           }
           {
             \if_false: { \fi: }
-            \__kernel_msg_error:nnx { kernel } { u-missing-rbrace } {#2}
-            \__regex_compile_u_end:
+            \__kernel_msg_error:nnx { regex } { u-missing-rbrace } {#2}
+            \l__regex_internal_b_tl
             #1 #2
           }
       }
   }
+\cs_new_protected:Npn \__regex_compile_ur_end:
+  {
+    \group_begin:
+      \cs_set:Npn \__regex_group:nnnN { \__regex_group_no_capture:nnnN }
+      \cs_set:Npn \__regex_group_resetting:nnnN { \__regex_group_no_capture:nnnN }
+      \exp_args:NNx
+    \group_end:
+    \__regex_compile_ur:n { \use:c { \l__regex_internal_a_tl } }
+  }
+\cs_new_protected:Npn \__regex_compile_ur:n #1
+  {
+    \tl_if_empty:oTF { \__regex_compile_ur_aux:w #1 {} ? ? \q__regex_nil }
+      { \__regex_compile_if_quantifier:TFw }
+      { \use_i:nn }
+          {
+            \tl_build_put_right:Nn \l__regex_build_tl
+              { \__regex_group_no_capture:nnnN { \if_false: } \fi: #1 }
+            \__regex_compile_quantifier:w
+          }
+          { \tl_build_put_right:Nn \l__regex_build_tl { \use_ii:nn #1 } }
+  }
+\cs_new:Npn \__regex_compile_ur_aux:w \__regex_branch:n #1#2#3 \q__regex_nil {#2}
 \cs_new_protected:Npn \__regex_compile_u_end:
+  {
+    \__regex_compile_if_quantifier:TFw
+      {
+        \tl_build_put_right:Nn \l__regex_build_tl
+          {
+            \__regex_group_no_capture:nnnN { \if_false: } \fi:
+            \__regex_branch:n { \if_false: } \fi:
+          }
+        \__regex_compile_u_payload:
+        \tl_build_put_right:Nn \l__regex_build_tl { \if_false: { \fi: } }
+        \__regex_compile_quantifier:w
+      }
+      { \__regex_compile_u_payload: }
+  }
+\cs_new_protected:Npn \__regex_compile_u_payload:
   {
     \tl_set:Nv \l__regex_internal_a_tl { \l__regex_internal_a_tl }
     \if_int_compare:w \l__regex_mode_int = \c__regex_outer_mode_int
@@ -24575,6 +24813,139 @@
       { \tl_build_put_right:Nn \l__regex_build_tl { \__regex_command_K: } }
       { \__regex_compile_raw_error:N K }
   }
+\cs_new:Npn \__regex_clean_bool:n #1
+  {
+    \tl_if_single:nTF {#1}
+      { \bool_if:NTF #1 \c_true_bool \c_false_bool }
+      { \c_true_bool }
+  }
+\cs_new:Npn \__regex_clean_int:n #1
+  {
+    \tl_if_head_eq_meaning:nNTF {#1} -
+      { - \exp_args:No \__regex_clean_int:n { \use_none:n #1 } }
+      { \int_eval:n { 0 \str_map_function:nN {#1} \__regex_clean_int_aux:N } }
+  }
+\cs_new:Npn \__regex_clean_int_aux:N #1
+  {
+    \if_int_compare:w 1 < 1 #1 ~
+      #1
+    \else:
+      \exp_after:wN \str_map_break:
+    \fi:
+  }
+\cs_new:Npn \__regex_clean_regex:n #1
+  {
+    \__regex_clean_regex_loop:w #1
+    \__regex_branch:n { \q_recursion_tail } \q_recursion_stop
+  }
+\cs_new:Npn \__regex_clean_regex_loop:w #1 \__regex_branch:n #2
+  {
+    \quark_if_recursion_tail_stop:n {#2}
+    \__regex_branch:n { \__regex_clean_branch:n {#2} }
+    \__regex_clean_regex_loop:w
+  }
+\cs_new:Npn \__regex_clean_branch:n #1
+  {
+    \__regex_clean_branch_loop:n #1
+    ? ? ? ? ? ? \prg_break_point:
+  }
+\cs_new:Npn \__regex_clean_branch_loop:n #1
+  {
+    \tl_if_single:nF {#1} { \prg_break: }
+    \token_case_meaning:NnF #1
+      {
+        \__regex_command_K: { #1 \__regex_clean_branch_loop:n }
+        \__regex_assertion:Nn { #1 \__regex_clean_assertion:Nn }
+        \__regex_class:NnnnN { #1 \__regex_clean_class:NnnnN }
+        \__regex_group:nnnN { #1 \__regex_clean_group:nnnN }
+        \__regex_group_no_capture:nnnN { #1 \__regex_clean_group:nnnN }
+        \__regex_group_resetting:nnnN { #1 \__regex_clean_group:nnnN }
+      }
+      { \prg_break: }
+  }
+\cs_new:Npn \__regex_clean_assertion:Nn #1#2
+  {
+    \__regex_clean_bool:n {#1}
+    \tl_if_single:nF {#2} { { \__regex_A_test: } \prg_break: }
+    \token_case_meaning:NnTF #2
+      {
+        \__regex_A_test: { }
+        \__regex_G_test: { }
+        \__regex_Z_test: { }
+        \__regex_b_test: { }
+      }
+      { {#2} }
+      { { \__regex_A_test: } \prg_break: }
+    \__regex_clean_branch_loop:n
+  }
+\cs_new:Npn \__regex_clean_class:NnnnN #1#2#3#4#5
+  {
+    \__regex_clean_bool:n {#1}
+    { \__regex_clean_class:n {#2} }
+    { \int_max:nn { 0 } { \__regex_clean_int:n {#3} } }
+    { \int_max:nn { -1 } { \__regex_clean_int:n {#4} } }
+    \__regex_clean_bool:n {#5}
+    \__regex_clean_branch_loop:n
+  }
+\cs_new:Npn \__regex_clean_group:nnnN #1#2#3#4
+  {
+    { \__regex_clean_regex:n {#1} }
+    { \int_max:nn { 0 } { \__regex_clean_int:n {#2} } }
+    { \int_max:nn { -1 } { \__regex_clean_int:n {#3} } }
+    \__regex_clean_bool:n {#4}
+    \__regex_clean_branch_loop:n
+  }
+\cs_new:Npn \__regex_clean_class:n #1
+  { \__regex_clean_class_loop:nnn #1 ????? \prg_break_point: }
+\cs_new:Npn \__regex_clean_class_loop:nnn #1#2#3
+  {
+    \tl_if_single:nF {#1} { \prg_break: }
+    \token_case_meaning:NnTF #1
+      {
+        \__regex_item_cs:n { #1 { \__regex_clean_regex:n {#2} } }
+        \__regex_item_exact_cs:n { #1 { \__regex_clean_exact_cs:n {#2} } }
+        \__regex_item_caseful_equal:n { #1 { \__regex_clean_int:n {#2} } }
+        \__regex_item_caseless_equal:n { #1 { \__regex_clean_int:n {#2} } }
+        \__regex_item_reverse:n { #1 { \__regex_clean_class:n {#2} } }
+      }
+      { \__regex_clean_class_loop:nnn {#3} }
+      {
+        \token_case_meaning:NnTF #1
+          {
+            \__regex_item_caseful_range:nn { }
+            \__regex_item_caseless_range:nn { }
+            \__regex_item_exact:nn { }
+          }
+          { #1 { \__regex_clean_int:n {#2} } { \__regex_clean_int:n {#3} } }
+          {
+            \token_case_meaning:NnTF #1
+              {
+                \__regex_item_catcode:nT { }
+                \__regex_item_catcode_reverse:nT { }
+              }
+              {
+                #1 { \__regex_clean_int:n {#2} } { \__regex_clean_class:n {#3} }
+                \__regex_clean_class_loop:nnn
+              }
+              { \prg_break: }
+          }
+      }
+  }
+\cs_new:Npn \__regex_clean_exact_cs:n #1
+  {
+    \exp_last_unbraced:Nf \use_none:n
+      {
+        \__regex_clean_exact_cs:w #1
+        \scan_stop: \q_recursion_tail \scan_stop:
+        \q_recursion_stop
+      }
+  }
+\cs_new:Npn \__regex_clean_exact_cs:w #1 \scan_stop:
+  {
+    \quark_if_recursion_tail_stop:n {#1}
+    \scan_stop: \tl_to_str:n {#1}
+    \__regex_clean_exact_cs:w
+  }
 \cs_new_protected:Npn \__regex_show:N #1
   {
     \group_begin:
@@ -24607,18 +24978,18 @@
       \cs_set:Npn \__regex_A_test: { anchor~at~start~(\iow_char:N\\A) }
       \cs_set:Npn \__regex_G_test: { anchor~at~start~of~match~(\iow_char:N\\G) }
       \cs_set_protected:Npn \__regex_item_caseful_equal:n ##1
-        { \__regex_show_one:n { char~code~\int_eval:n{##1} } }
+        { \__regex_show_one:n { char~code~\__regex_show_char:n{##1} } }
       \cs_set_protected:Npn \__regex_item_caseful_range:nn ##1##2
         {
           \__regex_show_one:n
-            { range~[\int_eval:n{##1}, \int_eval:n{##2}] }
+            { range~[\__regex_show_char:n{##1}, \__regex_show_char:n{##2}] }
         }
       \cs_set_protected:Npn \__regex_item_caseless_equal:n ##1
-        { \__regex_show_one:n { char~code~\int_eval:n{##1}~(caseless) } }
+        { \__regex_show_one:n { char~code~\__regex_show_char:n{##1}~(caseless) } }
       \cs_set_protected:Npn \__regex_item_caseless_range:nn ##1##2
         {
           \__regex_show_one:n
-            { Range~[\int_eval:n{##1}, \int_eval:n{##2}]~(caseless) }
+            { Range~[\__regex_show_char:n{##1}, \__regex_show_char:n{##2}]~(caseless) }
         }
       \cs_set_protected:Npn \__regex_item_catcode:nT
         { \__regex_show_item_catcode:NnT \c_true_bool }
@@ -24627,7 +24998,7 @@
       \cs_set_protected:Npn \__regex_item_reverse:n
         { \__regex_show_scope:nn { Reversed~match } }
       \cs_set_protected:Npn \__regex_item_exact:nn ##1##2
-        { \__regex_show_one:n { char~##2,~catcode~##1 } }
+        { \__regex_show_one:n { char~\__regex_show_char:n{##2},~catcode~##1 } }
       \cs_set_eq:NN \__regex_item_exact_cs:n \__regex_show_item_exact_cs:n
       \cs_set_protected:Npn \__regex_item_cs:n
         { \__regex_show_scope:nn { control~sequence } }
@@ -24640,6 +25011,12 @@
     \group_end:
     \tl_set:Nn \l__regex_internal_a_tl { \l__regex_build_tl }
   }
+\cs_new:Npn \__regex_show_char:n #1
+  {
+    \int_eval:n {#1}
+    \int_compare:nT { 32 <= #1 <= 126 }
+      { ~ ( \char_generate:nn {#1} {12} ) }
+  }
 \cs_new_protected:Npn \__regex_show_one:n #1
   {
     \int_incr:N \l__regex_show_lines_int
@@ -25217,7 +25594,7 @@
     \int_add:Nn \l__regex_step_int { 2 }
     \int_incr:N \l__regex_curr_pos_int
     \int_set_eq:NN \l__regex_last_char_int \l__regex_curr_char_int
-    \int_set_eq:NN \l__regex_case_changed_char_int \c_max_int
+    \cs_set_eq:NN \__regex_maybe_compute_ccc: \__regex_compute_case_changed_char:
     \tl_set:Nn \l__regex_curr_token_tl {#1}
     \int_set:Nn \l__regex_curr_char_int {#2}
     \int_set:Nn \l__regex_curr_catcode_int { "#3 }
@@ -25432,7 +25809,11 @@
           \if_charcode:w \c_right_brace_str ##1
             \__regex_replacement_rbrace:N
           \else:
-            \__regex_replacement_normal:n
+            \if_charcode:w \c_left_brace_str ##1
+              \__regex_replacement_lbrace:N
+            \else:
+              \__regex_replacement_normal:n
+            \fi:
           \fi:
           ##1
         }
@@ -25441,14 +25822,14 @@
         {#1}
       \prg_do_nothing: \prg_do_nothing:
       \if_int_compare:w \l__regex_replacement_csnames_int > 0 \exp_stop_f:
-        \__kernel_msg_error:nnx { kernel } { replacement-missing-rbrace }
+        \__kernel_msg_error:nnx { regex } { replacement-missing-rbrace }
           { \int_use:N \l__regex_replacement_csnames_int }
         \tl_build_put_right:Nx \l__regex_build_tl
           { \prg_replicate:nn \l__regex_replacement_csnames_int \cs_end: }
       \fi:
       \seq_if_empty:NF \l__regex_replacement_category_seq
         {
-          \__kernel_msg_error:nnx { kernel } { replacement-missing-rparen }
+          \__kernel_msg_error:nnx { regex } { replacement-missing-rparen }
             { \seq_count:N \l__regex_replacement_category_seq }
           \seq_clear:N \l__regex_replacement_category_seq
         }
@@ -25484,7 +25865,7 @@
 \cs_new_protected:Npn \__regex_replacement_normal:n #1
   {
     \tl_if_empty:NTF \l__regex_replacement_category_tl
-      { \__regex_replacement_put:n {#1} }
+      { \__regex_replacement_normal_aux:N #1 }
       { % (
         \token_if_eq_charcode:NNTF #1 )
           {
@@ -25492,15 +25873,37 @@
               \l__regex_replacement_category_tl
           }
           {
-            \use:c
-              {
-                __regex_replacement_c_
-                \l__regex_replacement_category_tl :w
-              }
-              \__regex_replacement_normal:n {#1}
+            \use:c { __regex_replacement_c_ \l__regex_replacement_category_tl :w }
+            ? #1
           }
       }
   }
+\cs_new_protected:Npn \__regex_replacement_normal_aux:N #1
+  {
+    \token_if_eq_charcode:NNTF #1 \c_space_token
+      { \__regex_replacement_c_S:w }
+      {
+        \exp_after:wN \exp_after:wN
+        \if_case:w \tex_catcode:D `#1 \exp_stop_f:
+             \__regex_replacement_c_O:w
+        \or: \__regex_replacement_c_B:w
+        \or: \__regex_replacement_c_E:w
+        \or: \__regex_replacement_c_M:w
+        \or: \__regex_replacement_c_T:w
+        \or: \__regex_replacement_c_O:w
+        \or: \__regex_replacement_c_P:w
+        \or: \__regex_replacement_c_U:w
+        \or: \__regex_replacement_c_D:w
+        \or: \__regex_replacement_c_O:w
+        \or: \__regex_replacement_c_S:w
+        \or: \__regex_replacement_c_L:w
+        \or: \__regex_replacement_c_O:w
+        \or: \__regex_replacement_c_A:w
+        \else: \__regex_replacement_c_O:w
+        \fi:
+      }
+    ? #1
+  }
 \cs_new_protected:Npn \__regex_replacement_escaped:N #1
   {
     \cs_if_exist_use:cF { __regex_replacement_#1:w }
@@ -25508,8 +25911,7 @@
         \if_int_compare:w 1 < 1#1 \exp_stop_f:
           \__regex_replacement_put_submatch:n {#1}
         \else:
-          \exp_args:No \__regex_replacement_normal:n
-            { \token_to_str:N #1 }
+          \__regex_replacement_normal:n {#1}
         \fi:
       }
   }
@@ -25517,6 +25919,9 @@
   {
     \if_int_compare:w #1 < \l__regex_capturing_group_int
       \__regex_replacement_put_submatch_aux:n {#1}
+    \else:
+      \__kernel_msg_expandable_error:nnff { regex } { submatch-too-big }
+        {#1} { \int_eval:n { \l__regex_capturing_group_int - 1 } }
     \fi:
   }
 \cs_new_protected:Npn \__regex_replacement_put_submatch_aux:n #1
@@ -25533,8 +25938,7 @@
   }
 \cs_new_protected:Npn \__regex_replacement_g:w #1#2
   {
-    \__regex_two_if_eq:NNNNTF
-      #1 #2 \__regex_replacement_normal:n \c_left_brace_str
+    \token_if_eq_meaning:NNTF #1 \__regex_replacement_lbrace:N
       { \l__regex_internal_a_int = \__regex_replacement_g_digits:NN }
       { \__regex_replacement_error:NNN g #1 #2 }
   }
@@ -25569,15 +25973,15 @@
   {
     \token_if_eq_meaning:NNTF #1 \__regex_replacement_normal:n
       {
-        \exp_after:wN \token_if_eq_charcode:NNTF \c_left_brace_str #2
+        \cs_if_exist:cTF { __regex_replacement_c_#2:w }
+          { \__regex_replacement_cat:NNN #2 }
+          { \__regex_replacement_error:NNN c #1#2 }
+      }
+      {
+        \token_if_eq_meaning:NNTF #1 \__regex_replacement_lbrace:N
           { \__regex_replacement_cu_aux:Nw \__regex_replacement_exp_not:N }
-          {
-            \cs_if_exist:cTF { __regex_replacement_c_#2:w }
-              { \__regex_replacement_cat:NNN #2 }
-              { \__regex_replacement_error:NNN c #1#2 }
-          }
+          { \__regex_replacement_error:NNN c #1#2 }
       }
-      { \__regex_replacement_error:NNN c #1#2 }
   }
 \cs_new_protected:Npn \__regex_replacement_cu_aux:Nw #1
   {
@@ -25592,8 +25996,7 @@
   }
 \cs_new_protected:Npn \__regex_replacement_u:w #1#2
   {
-    \__regex_two_if_eq:NNNNTF
-      #1 #2 \__regex_replacement_normal:n \c_left_brace_str
+    \token_if_eq_meaning:NNTF #1 \__regex_replacement_lbrace:N
       { \__regex_replacement_cu_aux:Nw \__regex_replacement_exp_not:V }
       { \__regex_replacement_error:NNN u #1#2 }
   }
@@ -25606,15 +26009,23 @@
       \__regex_replacement_normal:n {#1}
     \fi:
   }
+\cs_new_protected:Npn \__regex_replacement_lbrace:N #1
+  {
+    \if_int_compare:w \l__regex_replacement_csnames_int > 0 \exp_stop_f:
+      \__kernel_msg_error:nnn { regex } { cu-lbrace } { u }
+    \else:
+      \__regex_replacement_normal:n {#1}
+    \fi:
+  }
 \cs_new_protected:Npn \__regex_replacement_cat:NNN #1#2#3
   {
     \token_if_eq_meaning:NNTF \prg_do_nothing: #3
-      { \__kernel_msg_error:nn { kernel } { replacement-catcode-end } }
+      { \__kernel_msg_error:nn { regex } { replacement-catcode-end } }
       {
         \int_compare:nNnTF { \l__regex_replacement_csnames_int } > 0
           {
             \__kernel_msg_error:nnnn
-              { kernel } { replacement-catcode-in-cs } {#1} {#3}
+              { regex } { replacement-catcode-in-cs } {#1} {#3}
             #2 #3
           }
           {
@@ -25630,7 +26041,7 @@
                     \__regex_char_if_alphanumeric:NTF #3
                       {
                         \__kernel_msg_error:nnnn
-                          { kernel } { replacement-catcode-escaped }
+                          { regex } { replacement-catcode-escaped }
                           {#1} {#3}
                       }
                       { }
@@ -25693,7 +26104,7 @@
   \cs_new_protected:Npn \__regex_replacement_c_S:w #1#2
     {
       \if_int_compare:w `#2 = 0 \exp_stop_f:
-        \__kernel_msg_error:nn { kernel } { replacement-null-space }
+        \__kernel_msg_error:nn { regex } { replacement-null-space }
       \fi:
       \tex_lccode:D `\ = `#2 \scan_stop:
       \tex_lowercase:D { \__regex_replacement_put:n {~} }
@@ -25707,7 +26118,7 @@
 \group_end:
 \cs_new_protected:Npn \__regex_replacement_error:NNN #1#2#3
   {
-    \__kernel_msg_error:nnx { kernel } { replacement-#1 } {#3}
+    \__kernel_msg_error:nnx { regex } { replacement-#1 } {#3}
     #2 #3
   }
 \cs_new_protected:Npn \regex_new:N #1
@@ -25731,21 +26142,26 @@
     \__regex_compile:n {#2}
     \tl_const:Nx #1 { \exp_not:o \l__regex_internal_regex }
   }
-\cs_new_protected:Npn \regex_show:n #1
+\cs_new_protected:Npn \regex_show:n { \__regex_show:Nn \__kernel_msg_show:nnxxxx }
+\cs_new_protected:Npn \regex_log:n { \__regex_show:Nn \__kernel_msg_log:nnxxxx }
+\cs_new_protected:Npn \__regex_show:Nn #1#2
   {
-    \__regex_compile:n {#1}
+    \__regex_compile:n {#2}
     \__regex_show:N \l__regex_internal_regex
-    \msg_show:nnxxxx { LaTeX / kernel } { show-regex }
-      { \tl_to_str:n {#1} } { }
+    #1 { regex } { show }
+      { \tl_to_str:n {#2} } { }
       { \l__regex_internal_a_tl } { }
   }
-\cs_new_protected:Npn \regex_show:N #1
+\cs_new_protected:Npn \regex_show:N { \__regex_show:NN \__kernel_msg_show:nnxxxx }
+\cs_new_protected:Npn \regex_log:N { \__regex_show:NN \__kernel_msg_log:nnxxxx }
+\cs_new_protected:Npn \__regex_show:NN #1#2
   {
-    \__kernel_chk_defined:NT #1
+    \__kernel_chk_tl_type:NnnT #2 { regex }
+      { \exp_args:No \__regex_clean_regex:n {#2} }
       {
-        \__regex_show:N #1
-        \msg_show:nnxxxx { LaTeX / kernel } { show-regex }
-          { } { \token_to_str:N #1 }
+        \__regex_show:N #2
+        #1 { regex } { show }
+          { } { \token_to_str:N #2 }
           { \l__regex_internal_a_tl } { }
       }
   }
@@ -25917,7 +26333,7 @@
         }
           = 0
         {
-          \__kernel_msg_error:nnxxx { kernel } { result-unbalanced }
+          \__kernel_msg_error:nnxxx { regex } { result-unbalanced }
             { splitting~or~extracting~submatches }
             { \flag_height:n { __regex_end } }
             { \flag_height:n { __regex_begin } }
@@ -26034,7 +26450,7 @@
   {
     \if_int_compare:w \l__regex_balance_int = 0 \exp_stop_f:
     \else:
-      \__kernel_msg_error:nnxxx { kernel } { result-unbalanced }
+      \__kernel_msg_error:nnxxx { regex } { result-unbalanced }
         { replacing }
         { \int_max:nn { - \l__regex_balance_int } { 0 } }
         { \int_max:nn { \l__regex_balance_int } { 0 } }
@@ -26248,33 +26664,33 @@
   }
 \use:x
   {
-    \__kernel_msg_new:nnn { kernel } { trailing-backslash }
+    \__kernel_msg_new:nnn { regex } { trailing-backslash }
       { Trailing~escape~char~'\iow_char:N\\'~in~regex~or~replacement. }
-    \__kernel_msg_new:nnn { kernel } { x-missing-rbrace }
+    \__kernel_msg_new:nnn { regex } { x-missing-rbrace }
       {
         Missing~brace~'\iow_char:N\}'~in~regex~
         '...\iow_char:N\\x\iow_char:N\{...##1'.
       }
-    \__kernel_msg_new:nnn { kernel } { x-overflow }
+    \__kernel_msg_new:nnn { regex } { x-overflow }
       {
         Character~code~##1~too~large~in~
         \iow_char:N\\x\iow_char:N\{##2\iow_char:N\}~regex.
       }
   }
-\__kernel_msg_new:nnnn { kernel } { invalid-quantifier }
+\__kernel_msg_new:nnnn { regex } { invalid-quantifier }
   { Braced~quantifier~'#1'~may~not~be~followed~by~'#2'. }
   {
     The~character~'#2'~is~invalid~in~the~braced~quantifier~'#1'.~
     The~only~valid~quantifiers~are~'*',~'?',~'+',~'{<int>}',~
     '{<min>,}'~and~'{<min>,<max>}',~optionally~followed~by~'?'.
   }
-\__kernel_msg_new:nnnn { kernel } { missing-rbrack }
+\__kernel_msg_new:nnnn { regex } { missing-rbrack }
   { Missing~right~bracket~inserted~in~regular~expression. }
   {
     LaTeX~was~given~a~regular~expression~where~a~character~class~
     was~started~with~'[',~but~the~matching~']'~is~missing.
   }
-\__kernel_msg_new:nnnn { kernel } { missing-rparen }
+\__kernel_msg_new:nnnn { regex } { missing-rparen }
   {
     Missing~right~
     \int_compare:nTF { #1 = 1 } { parenthesis } { parentheses } ~
@@ -26284,13 +26700,13 @@
     LaTeX~was~given~a~regular~expression~with~\int_eval:n {#1} ~
     more~left~parentheses~than~right~parentheses.
   }
-\__kernel_msg_new:nnnn { kernel } { extra-rparen }
+\__kernel_msg_new:nnnn { regex } { extra-rparen }
   { Extra~right~parenthesis~ignored~in~regular~expression. }
   {
     LaTeX~came~across~a~closing~parenthesis~when~no~submatch~group~
     was~open.~The~parenthesis~will~be~ignored.
   }
-\__kernel_msg_new:nnnn { kernel } { bad-escape }
+\__kernel_msg_new:nnnn { regex } { bad-escape }
   {
     Invalid~escape~'\iow_char:N\\#1'~
     \__regex_if_in_cs:TF { within~a~control~sequence. }
@@ -26314,14 +26730,14 @@
         because~it~does~not~match~exactly~one~character.
       }
   }
-\__kernel_msg_new:nnnn { kernel } { range-missing-end }
+\__kernel_msg_new:nnnn { regex } { range-missing-end }
   { Invalid~end-point~for~range~'#1-#2'~in~character~class. }
   {
     The~end-point~'#2'~of~the~range~'#1-#2'~may~not~serve~as~an~
     end-point~for~a~range:~alphanumeric~characters~should~not~be~
     escaped,~and~non-alphanumeric~characters~should~be~escaped.
   }
-\__kernel_msg_new:nnnn { kernel } { range-backwards }
+\__kernel_msg_new:nnnn { regex } { range-backwards }
   { Range~'[#1-#2]'~out~of~order~in~character~class. }
   {
     In~ranges~of~characters~'[x-y]'~appearing~in~character~classes,~
@@ -26329,7 +26745,7 @@
     Here,~'#1'~has~character~code~\int_eval:n {`#1},~while~
     '#2'~has~character~code~\int_eval:n {`#2}.
   }
-\__kernel_msg_new:nnnn { kernel } { c-bad-mode }
+\__kernel_msg_new:nnnn { regex } { c-bad-mode }
   { Invalid~nested~'\iow_char:N\\c'~escape~in~regular~expression. }
   {
     The~'\iow_char:N\\c'~escape~cannot~be~used~within~
@@ -26337,33 +26753,40 @@
     nor~another~category~test.~
     To~combine~several~category~tests,~use~'\iow_char:N\\c[...]'.
   }
-\__kernel_msg_new:nnnn { kernel } { c-C-invalid }
+\__kernel_msg_new:nnnn { regex } { c-C-invalid }
   { '\iow_char:N\\cC'~should~be~followed~by~'.'~or~'(',~not~'#1'. }
   {
     The~'\iow_char:N\\cC'~construction~restricts~the~next~item~to~be~a~
     control~sequence~or~the~next~group~to~be~made~of~control~sequences.~
     It~only~makes~sense~to~follow~it~by~'.'~or~by~a~group.
   }
-\__kernel_msg_new:nnnn { kernel } { c-lparen-in-class }
+\__kernel_msg_new:nnnn { regex } { cu-lbrace }
+  { Left~braces~must~be~escaped~in~'\iow_char:N\\#1{...}'. }
+  {
+    Constructions~such~as~'\iow_char:N\\#1{...\iow_char:N\{...}'~are~
+    not~allowed~and~should~be~replaced~by~
+    '\iow_char:N\\#1{...\token_to_str:N\{...}'.
+  }
+\__kernel_msg_new:nnnn { regex } { c-lparen-in-class }
   { Catcode~test~cannot~apply~to~group~in~character~class }
   {
     Construction~such~as~'\iow_char:N\\cL(abc)'~are~not~allowed~inside~a~
     class~'[...]'~because~classes~do~not~match~multiple~characters~at~once.
   }
-\__kernel_msg_new:nnnn { kernel } { c-missing-rbrace }
+\__kernel_msg_new:nnnn { regex } { c-missing-rbrace }
   { Missing~right~brace~inserted~for~'\iow_char:N\\c'~escape. }
   {
     LaTeX~was~given~a~regular~expression~where~a~
     '\iow_char:N\\c\iow_char:N\{...'~construction~was~not~ended~
     with~a~closing~brace~'\iow_char:N\}'.
   }
-\__kernel_msg_new:nnnn { kernel } { c-missing-rbrack }
+\__kernel_msg_new:nnnn { regex } { c-missing-rbrack }
   { Missing~right~bracket~inserted~for~'\iow_char:N\\c'~escape. }
   {
     A~construction~'\iow_char:N\\c[...'~appears~in~a~
     regular~expression,~but~the~closing~']'~is~not~present.
   }
-\__kernel_msg_new:nnnn { kernel } { c-missing-category }
+\__kernel_msg_new:nnnn { regex } { c-missing-category }
   { Invalid~character~'#1'~following~'\iow_char:N\\c'~escape. }
   {
     In~regular~expressions,~the~'\iow_char:N\\c'~escape~sequence~
@@ -26371,19 +26794,19 @@
     capital~letter~representing~a~character~category,~namely~
     one~of~'ABCDELMOPSTU'.
   }
-\__kernel_msg_new:nnnn { kernel } { c-trailing }
+\__kernel_msg_new:nnnn { regex } { c-trailing }
   { Trailing~category~code~escape~'\iow_char:N\\c'... }
   {
     A~regular~expression~ends~with~'\iow_char:N\\c'~followed~
     by~a~letter.~It~will~be~ignored.
   }
-\__kernel_msg_new:nnnn { kernel } { u-missing-lbrace }
+\__kernel_msg_new:nnnn { regex } { u-missing-lbrace }
   { Missing~left~brace~following~'\iow_char:N\\u'~escape. }
   {
     The~'\iow_char:N\\u'~escape~sequence~must~be~followed~by~
     a~brace~group~with~the~name~of~the~variable~to~use.
   }
-\__kernel_msg_new:nnnn { kernel } { u-missing-rbrace }
+\__kernel_msg_new:nnnn { regex } { u-missing-rbrace }
   { Missing~right~brace~inserted~for~'\iow_char:N\\u'~escape. }
   {
     LaTeX~
@@ -26393,14 +26816,14 @@
     when~parsing~the~argument~of~an~
     '\iow_char:N\\u\iow_char:N\{...\}'~escape.
   }
-\__kernel_msg_new:nnnn { kernel } { posix-unsupported }
+\__kernel_msg_new:nnnn { regex } { posix-unsupported }
   { POSIX~collating~element~'[#1 ~ #1]'~not~supported. }
   {
     The~'[.foo.]'~and~'[=bar=]'~syntaxes~have~a~special~meaning~
     in~POSIX~regular~expressions.~This~is~not~supported~by~LaTeX.~
     Maybe~you~forgot~to~escape~a~left~bracket~in~a~character~class?
   }
-\__kernel_msg_new:nnnn { kernel } { posix-unknown }
+\__kernel_msg_new:nnnn { regex } { posix-unknown }
   { POSIX~class~'[:#1:]'~unknown. }
   {
     '[:#1:]'~is~not~among~the~known~POSIX~classes~
@@ -26409,10 +26832,10 @@
     '[:print:]',~'[:punct:]',~'[:space:]',~'[:upper:]',~
     '[:word:]',~and~'[:xdigit:]'.
   }
-\__kernel_msg_new:nnnn { kernel } { posix-missing-close }
+\__kernel_msg_new:nnnn { regex } { posix-missing-close }
   { Missing~closing~':]'~for~POSIX~class. }
   { The~POSIX~syntax~'#1'~must~be~followed~by~':]',~not~'#2'. }
-\__kernel_msg_new:nnnn { kernel } { result-unbalanced }
+\__kernel_msg_new:nnnn { regex } { result-unbalanced }
   { Missing~brace~inserted~when~#1. }
   {
     LaTeX~was~asked~to~do~some~regular~expression~operation,~
@@ -26420,33 +26843,33 @@
     of~begin-group~and~end-group~tokens.~Braces~were~inserted:~
     #2~left,~#3~right.
   }
-\__kernel_msg_new:nnnn { kernel } { unknown-option }
+\__kernel_msg_new:nnnn { regex } { unknown-option }
   { Unknown~option~'#1'~for~regular~expressions. }
   {
     The~only~available~option~is~'case-insensitive',~toggled~by~
     '(?i)'~and~'(?-i)'.
   }
-\__kernel_msg_new:nnnn { kernel } { special-group-unknown }
+\__kernel_msg_new:nnnn { regex } { special-group-unknown }
   { Unknown~special~group~'#1~...'~in~a~regular~expression. }
   {
     The~only~valid~constructions~starting~with~'(?'~are~
     '(?:~...~)',~'(?|~...~)',~'(?i)',~and~'(?-i)'.
   }
-\__kernel_msg_new:nnnn { kernel } { replacement-c }
+\__kernel_msg_new:nnnn { regex } { replacement-c }
   { Misused~'\iow_char:N\\c'~command~in~a~replacement~text. }
   {
     In~a~replacement~text,~the~'\iow_char:N\\c'~escape~sequence~
     can~be~followed~by~one~of~the~letters~'ABCDELMOPSTU'~
     or~a~brace~group,~not~by~'#1'.
   }
-\__kernel_msg_new:nnnn { kernel } { replacement-u }
+\__kernel_msg_new:nnnn { regex } { replacement-u }
   { Misused~'\iow_char:N\\u'~command~in~a~replacement~text. }
   {
     In~a~replacement~text,~the~'\iow_char:N\\u'~escape~sequence~
     must~be~~followed~by~a~brace~group~holding~the~name~of~the~
     variable~to~use.
   }
-\__kernel_msg_new:nnnn { kernel } { replacement-g }
+\__kernel_msg_new:nnnn { regex } { replacement-g }
   {
     Missing~brace~for~the~'\iow_char:N\\g'~construction~
     in~a~replacement~text.
@@ -26456,7 +26879,7 @@
     submatches~are~represented~either~as~'\iow_char:N \\g{dd..d}',~
     or~'\\d',~where~'d'~are~single~digits.~Here,~a~brace~is~missing.
   }
-\__kernel_msg_new:nnnn { kernel } { replacement-catcode-end }
+\__kernel_msg_new:nnnn { regex } { replacement-catcode-end }
   {
     Missing~character~for~the~'\iow_char:N\\c<category><character>'~
     construction~in~a~replacement~text.
@@ -26467,7 +26890,7 @@
     the~character~category.~Then,~a~character~must~follow.~LaTeX~
     reached~the~end~of~the~replacement~when~looking~for~that.
   }
-\__kernel_msg_new:nnnn { kernel } { replacement-catcode-escaped }
+\__kernel_msg_new:nnnn { regex } { replacement-catcode-escaped }
   {
     Escaped~letter~or~digit~after~category~code~in~replacement~text.
   }
@@ -26477,7 +26900,7 @@
     the~character~category.~Then,~a~character~must~follow,~not~
     '\iow_char:N\\#2'.
   }
-\__kernel_msg_new:nnnn { kernel } { replacement-catcode-in-cs }
+\__kernel_msg_new:nnnn { regex } { replacement-catcode-in-cs }
   {
     Category~code~'\iow_char:N\\c#1#3'~ignored~inside~
     '\iow_char:N\\c\{...\}'~in~a~replacement~text.
@@ -26487,7 +26910,7 @@
     '\iow_char:N\\c\{...\}'~are~ignored~when~building~the~control~
     sequence~name.
   }
-\__kernel_msg_new:nnnn { kernel } { replacement-null-space }
+\__kernel_msg_new:nnnn { regex } { replacement-null-space }
   { TeX~cannot~build~a~space~token~with~character~code~0. }
   {
     You~asked~for~a~character~token~with~category~space,~
@@ -26496,23 +26919,25 @@
     This~specific~case~is~impossible~and~will~be~replaced~
     by~a~normal~space.
   }
-\__kernel_msg_new:nnnn { kernel } { replacement-missing-rbrace }
+\__kernel_msg_new:nnnn { regex } { replacement-missing-rbrace }
   { Missing~right~brace~inserted~in~replacement~text. }
   {
     There~ \int_compare:nTF { #1 = 1 } { was } { were } ~ #1~
     missing~right~\int_compare:nTF { #1 = 1 } { brace } { braces } .
   }
-\__kernel_msg_new:nnnn { kernel } { replacement-missing-rparen }
+\__kernel_msg_new:nnnn { regex } { replacement-missing-rparen }
   { Missing~right~parenthesis~inserted~in~replacement~text. }
   {
     There~ \int_compare:nTF { #1 = 1 } { was } { were } ~ #1~
     missing~right~
     \int_compare:nTF { #1 = 1 } { parenthesis } { parentheses } .
   }
-\__kernel_msg_new:nnnn { kernel } { backwards-quantifier }
+\__kernel_msg_new:nnn { regex } { submatch-too-big }
+  { Submatch~#1~used~but~regex~only~has~#2~group(s) }
+\__kernel_msg_new:nnnn { regex } { backwards-quantifier }
   { Quantifer~"{#1,#2}"~is~backwards. }
   { The~values~given~in~a~quantifier~must~be~in~order. }
-\__kernel_msg_new:nnn { kernel } { show-regex }
+\__kernel_msg_new:nnn { regex } { show }
   {
     >~Compiled~regex~
     \tl_if_empty:nTF {#1} { variable~ #2 } { {#1} } :
@@ -26601,6 +27026,9 @@
 \cs_generate_variant:Nn \box_ht:N { c }
 \cs_generate_variant:Nn \box_dp:N { c }
 \cs_generate_variant:Nn \box_wd:N { c }
+\cs_new_protected:Npn \box_ht_plus_dp:N #1
+  { \__box_dim_eval:n { \box_ht:N #1 + \box_dp:N #1 } }
+\cs_generate_variant:Nn \box_ht_plus_dp:N { c }
 \cs_new_protected:Npn \box_set_dp:Nn #1#2
   {
     \tex_setbox:D #1 = \tex_copy:D #1
@@ -27891,23 +28319,34 @@
           #4 \s__color_stop
       }
   }
+\tl_const:cn { c__color_export_comma-sep-cmyk_tl } { cmyk }
+\tl_const:cn { c__color_export_comma-sep-rgb_tl } { rgb }
 \tl_const:Nn \c__color_export_HTML_tl { rgb }
 \tl_const:cn { c__color_export_space-sep-cmyk_tl } { cmyk }
 \tl_const:cn { c__color_export_space-sep-rgb_tl } { rgb }
-\cs_new_protected:cpx { __color_export_format_space-sep-cmyk:nnN } #1#2#3
-  {
-    \exp_not:N \__color_export:nnnNN { cmyk } {#1} {#2} #3
-      \exp_not:c { __color_export_space-sep-cmyk:Nw }
-  }
+\group_begin:
+  \cs_set_protected:Npn \__color_tmp:w #1#2
+    {
+      \cs_new_protected:cpx { __color_export_format_ #1 :nnN } ##1##2##3
+        {
+          \exp_not:N \__color_export:nnnNN {#2} {##1} {##2} ##3
+            \exp_not:c { __color_export_ #1 :Nw }
+        }
+    }
+  \__color_tmp:w { comma-sep-cmyk } { cmyk }
+  \__color_tmp:w { comma-sep-rgb }  { rgb }
+  \__color_tmp:w { HTML }           { rgb }
+  \__color_tmp:w { space-sep-cmyk } { cmyk }
+  \__color_tmp:w { space-sep-rgb }  { rgb }
+
+\group_end:
+\cs_new_protected:cpn { __color_export_comma-sep-cmyk:Nw }
+  #1#2 ~ #3 ~ #4 ~ #5 \s__color_stop
+  { \tl_set:Nn #1 { #2 , #3 , #4 , #5 } }
 \cs_new_protected:cpn { __color_export_space-sep-cmyk:Nw } #1#2 \s__color_stop
-  { \tl_set:Nx #1 {#2} }
-\cs_new_protected:Npn \__color_export_format_HTML:nnN #1#2#3
-  { \__color_export:nnnNN { rgb } {#1} {#2}#3 \__color_export_HTML:Nw }
-\cs_new_protected:cpx { __color_export_format_space-sep-rgb:nnN } #1#2#3
-  {
-    \exp_not:N \__color_export:nnnNN { rgb } {#1} {#2} #3
-      \exp_not:c { __color_export_space-sep-rgb:Nw }
-  }
+  { \tl_set:Nn #1 {#2} }
+\cs_new_protected:cpn { __color_export_comma-sep-rgb:Nw } #1#2 ~ #3 ~ #4 \s__color_stop
+  { \tl_set:Nx #1 { #2 , #3 , #4 } }
 \cs_new_protected:Npn \__color_export_HTML:Nw #1#2 ~ #3 ~ #4 \s__color_stop
   {
     \tl_set:Nx #1
@@ -27924,7 +28363,7 @@
       { \int_to_Hex:n { \fp_to_int:n { #1 * 255 } } }
   }
 \cs_new_protected:cpn { __color_export_space-sep-rgb:Nw } #1#2 \s__color_stop
-  { \tl_set:Nx #1 {#2} }
+  { \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 }
@@ -27983,6 +28422,28 @@
           }
       }
   }
+\cs_new_protected:Npn \__color_model_init:nnn #1#2#3
+  {
+    \int_gincr:N \g__color_model_int
+    \tl_const:cx { c__color_fallback_ #1 _tl }
+      { 1 \prg_replicate:nn { #2 - 1 } { ~ 1 } }
+    \clist_map_inline:nn { fill , stroke , select }
+      {
+        \cs_new_protected:cpx { __color_backend_ ##1 _ #1 :n } ####1
+          {
+            \exp_not:c { __color_backend_ ##1 _ #3 :nn }
+              { color \int_use:N \g__color_model_int } {####1}
+          }
+      }
+    \cs_new_protected:cpx { __color_model_ #1 _white: }
+      {
+        \prop_put:Nnn \exp_not:N \l__color_named_white_prop {#1}
+          { 0 \prg_replicate:nn { #2 - 1 } { ~ 0 } }
+        \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_new_protected:Npn \__color_model_separation:n #1
   {
     \prop_get:NnNTF \l__color_internal_prop { name }
@@ -28032,31 +28493,15 @@
 \cs_new_protected:Npn \__color_model_separation:w
   #1 , #2 , #3 , #4 , #5 \s__color_stop #6#7#8
   {
-    \int_gincr:N \g__color_model_int
-    \tl_const:cn { c__color_fallback_ #6 _tl } { 1 }
+    \__color_model_init:nnn {#6} { 1 } { separation }
     \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} } }
-    \clist_map_inline:nn { fill , stroke , select }
-      {
-        \cs_new_protected:cpx { __color_backend_ ##1 _ #6 :n } ####1
-          {
-            \exp_not:c { __color_backend_ ##1 _ separation:nn }
-              { color \int_use:N \g__color_model_int } {####1}
-          }
-      }
     \use:c { __color_model_separation_ #8 :nnnnnn }
       {#6} {#7} {#1} {#2} {#3} {#4}
     \prop_gput:Nnn \g__color_alternative_model_prop {#6} {#8}
     \prop_gput:Nnx \g__color_colorants_prop {#6}
       { \str_convert_pdfname:n {#7} }
-    \cs_new_protected:cpx { __color_model_ #6 _white: }
-      {
-        \prop_put:Nnn \exp_not:N \l__color_named_white_prop {#6} { 0 }
-        \exp_not:N \int_compare:nNnF { \tex_currentgrouplevel:D } = 0
-          { \group_insert_after:N \exp_not:c { __color_model_ #6 _ white: } }
-      }
-    \use:c { __color_model_ #6 _white: }
   }
 \cs_new_protected:Npn \__color_model_separation_cmyk:nnnnnn #1#2#3#4#5#6
   {
@@ -28202,28 +28647,10 @@
   }
 \cs_new_protected:Npn \__color_model_devicen:nnnn #1#2#3#4
   {
-    \int_gincr:N \g__color_model_int
-    \tl_const:cx { c__color_fallback_ #4 _tl }
-      { \prg_replicate:nn {#1} { 1 ~ } }
+    \__color_model_init:nnn {#4} {#1} { devicen }
     \cs_if_exist_use:cF { __color_model_devicen_parse_ #1 :nn }
       { \__color_model_devicen_parse_generic:nn }
         {#4} {#1}
-    \clist_map_inline:nn { fill , stroke , select }
-      {
-        \cs_new_protected:cpx { __color_backend_ ##1 _ #4 :n } ####1
-          {
-            \exp_not:c { __color_backend_ ##1 _ devicen:nn }
-              { color \int_use:N \g__color_model_int } {####1}
-          }
-      }
-    \cs_new_protected:cpx { __color_model_ #4 _white: }
-      {
-        \prop_put:Nnn \exp_not:N \l__color_named_white_prop {#4}
-          { \prg_replicate:nn {#1} { 0 ~ } }
-        \exp_not:N \int_compare:nNnF { \tex_currentgrouplevel:D } = 0
-          { \group_insert_after:N \exp_not:c { __color_model_ #4 _ white: } }
-      }
-    \use:c { __color_model_ #4 _white: }
     \__color_model_devicen_init:nnn {#1} {#2} {#3}
     \__color_model_devicen_convert:nnn {#4} {#2} {#3}
   }
@@ -28535,7 +28962,7 @@
   }
 \cs_new_protected:Npn \color_show:n #1
   {
-    \msg_show:nnxxxx { LaTeX / color } { show }
+    \__kernel_msg_show:nnxxxx { color } { show }
       {#1}
       {
         \__color_if_defined:nT {#1}
@@ -28827,7 +29254,7 @@
     \coffin_if_exist:NTF #1
       { #2 }
       {
-        \__kernel_msg_error:nnx { kernel } { unknown-coffin }
+        \__kernel_msg_error:nnx { coffin } { unknown }
           { \token_to_str:N #1 }
       }
   }
@@ -29047,7 +29474,7 @@
     \prop_get:cnNF
       { coffin ~ \__coffin_to_value:N #1 ~ poles } {#2} #3
       {
-        \__kernel_msg_error:nnxx { kernel } { unknown-coffin-pole }
+        \__kernel_msg_error:nnxx { coffin } { unknown-pole }
           { \exp_not:n {#2} } { \token_to_str:N #1 }
         \tl_set:Nn #3 { { 0pt } { 0pt } { 0pt } { 0pt } }
       }
@@ -29205,7 +29632,7 @@
         \l__coffin_pole_a_tl \l__coffin_pole_b_tl
     \bool_if:NT \l__coffin_error_bool
       {
-        \__kernel_msg_error:nn { kernel } { no-pole-intersection }
+        \__kernel_msg_error:nn { coffin } { no-pole-intersection }
         \dim_zero:N \l__coffin_x_dim
         \dim_zero:N \l__coffin_y_dim
       }
@@ -29969,16 +30396,16 @@
     \box_set_eq:NN \l__coffin_display_coffin \l__coffin_aligned_coffin
   }
 \cs_new_protected:Npn \coffin_show_structure:N
-  { \__coffin_show_structure:NN \msg_show:nnxxxx }
+  { \__coffin_show_structure:NN \__kernel_msg_show:nnxxxx }
 \cs_generate_variant:Nn \coffin_show_structure:N { c }
 \cs_new_protected:Npn \coffin_log_structure:N
-  { \__coffin_show_structure:NN \msg_log:nnxxxx }
+  { \__coffin_show_structure:NN \__kernel_msg_log:nnxxxx }
 \cs_generate_variant:Nn \coffin_log_structure:N { c }
 \cs_new_protected:Npn \__coffin_show_structure:NN #1#2
   {
     \__coffin_if_exist:NT #2
       {
-        #1 { LaTeX / kernel } { show-coffin }
+        #1 { coffin } { show }
           { \token_to_str:N #2 }
           {
             \iow_newline: >~ ht ~=~ \dim_eval:n { \coffin_ht:N #2 }
@@ -29993,23 +30420,23 @@
           { }
       }
   }
-\__kernel_msg_new:nnnn { kernel } { no-pole-intersection }
+\__kernel_msg_new:nnnn { coffin } { no-pole-intersection }
   { No~intersection~between~coffin~poles. }
   {
     LaTeX~was~asked~to~find~the~intersection~between~two~poles,~
     but~they~do~not~have~a~unique~meeting~point:~
     the~value~(0pt,~0pt)~will~be~used.
   }
-\__kernel_msg_new:nnnn { kernel } { unknown-coffin }
+\__kernel_msg_new:nnnn { coffin } { unknown }
   { Unknown~coffin~'#1'. }
   { The~coffin~'#1'~was~never~defined. }
-\__kernel_msg_new:nnnn { kernel } { unknown-coffin-pole }
+\__kernel_msg_new:nnnn { coffin } { unknown-pole }
   { Pole~'#1'~unknown~for~coffin~'#2'. }
   {
     LaTeX~was~asked~to~find~a~typesetting~pole~for~a~coffin,~
     but~either~the~coffin~does~not~exist~or~the~pole~name~is~wrong.
   }
-\__kernel_msg_new:nnn { kernel } { show-coffin }
+\__kernel_msg_new:nnn { coffin } { show }
   {
     Size~of~coffin~#1 : #2 \\
     Poles~of~coffin~#1 : #3 .
@@ -30038,7 +30465,7 @@
         \cs_set:Npn #1 ##1
           {
             \__kernel_msg_expandable_error:nnn
-              { kernel } { luatex-required } { #1 }
+              { luatex } { luatex-required } { #1 }
           }
       }
     \clist_map_inline:nn
@@ -30047,11 +30474,11 @@
         \cs_set_protected:Npn #1 ##1
           {
             \__kernel_msg_error:nnn
-              { kernel } { luatex-required } { #1 }
+              { luatex } { luatex-required } { #1 }
           }
       }
   }
-\__kernel_msg_new:nnnn { kernel } { luatex-required }
+\__kernel_msg_new:nnnn { luatex } { luatex-required }
   { LuaTeX~engine~not~in~use!~Ignoring~#1. }
   {
     The~feature~you~are~using~is~only~available~
@@ -30674,7 +31101,7 @@
     \__text_if_expandable:NTF #1
       {
         \token_if_eq_meaning:NNTF #1 \exp_not:n
-          { \__text_expand_noexpand:w }
+          { \__text_expand_unexpanded:w }
           { \exp_after:wN \__text_expand_loop:w #1 }
       }
       {
@@ -30682,11 +31109,31 @@
         \__text_expand_loop:w
       }
   }
-\cs_new:Npn \__text_expand_noexpand:w #1#
-  { \__text_expand_noexpand:nn {#1} }
-\cs_new:Npn \__text_expand_noexpand:nn #1#2
+\cs_new:Npn \__text_expand_unexpanded:w
   {
-    #1 \__text_expand_store:n #1 {#2}
+    \exp_after:wN \__text_expand_unexpanded_test:w
+    \exp:w \exp_end_continue_f:w
+  }
+\cs_new:Npn \__text_expand_unexpanded_test:w #1 \q__text_recursion_stop
+  {
+    \tl_if_head_is_group:nTF {#1}
+      { \__text_expand_unexpanded:n }
+      {
+        \__text_expand_unexpanded:w
+        \tl_if_head_is_N_type:nT {#1} { \__text_expand_unexpanded:N }
+      }
+    #1 \q__text_recursion_stop
+  }
+\cs_new:Npn \__text_expand_unexpanded:N #1
+  {
+    \exp_after:wN \if_meaning:w \exp_not:N #1 #1
+    \else:
+      \exp_after:wN #1
+    \fi:
+  }
+\cs_new:Npn \__text_expand_unexpanded:n #1
+  {
+    \__text_expand_store:n {#1}
     \__text_expand_loop:w
   }
 \cs_new_protected:Npn \text_declare_expand_equivalent:Nn #1#2
@@ -33109,6 +33556,113 @@
   { \seq_set_from_inline_x:Nnn #1 {#2} { #3 {##1} } }
 \cs_new_protected:Npn \seq_gset_from_function:NnN #1#2#3
   { \seq_gset_from_inline_x:Nnn #1 {#2} { #3 {##1} } }
+\cs_new_eq:NN \__seq_int_eval:w \tex_numexpr:D
+\cs_new_protected:Npn \seq_set_item:Nnn #1#2#3
+  { \__seq_set_item:NnnNN #1 {#2} {#3} \__kernel_tl_set:Nx \use_i:nn }
+\cs_new_protected:Npn \seq_gset_item:Nnn #1#2#3
+  { \__seq_set_item:NnnNN #1 {#2} {#3} \__kernel_tl_gset:Nx \use_i:nn }
+\cs_generate_variant:Nn \seq_set_item:Nnn { c }
+\cs_generate_variant:Nn \seq_gset_item:Nnn { c }
+\prg_new_protected_conditional:Npnn \seq_set_item:Nnn #1#2#3 { TF , T , F }
+  { \__seq_set_item:NnnNN #1 {#2} {#3} \__kernel_tl_set:Nx \use_ii:nn }
+\prg_new_protected_conditional:Npnn \seq_gset_item:Nnn #1#2#3 { TF , T , F }
+  { \__seq_set_item:NnnNN #1 {#2} {#3} \__kernel_tl_gset:Nx \use_ii:nn }
+\prg_generate_conditional_variant:Nnn \seq_set_item:Nnn { c } { TF , T , F }
+\prg_generate_conditional_variant:Nnn \seq_gset_item:Nnn { c } { TF , T , F }
+\cs_new_protected:Npn \__seq_set_item:NnnNN #1#2#3
+  {
+    \tl_set:Nn \l__seq_internal_a_tl { \__seq_item:n {#3} }
+    \exp_args:Nff \__seq_set_item:nnNNNN
+      { \int_eval:n {#2} } { \seq_count:N #1 } #1 \use_none:nn
+  }
+\cs_new_protected:Npn \__seq_set_item:nnNNNN #1#2
+  {
+    \int_compare:nNnTF {#1} > 0
+      { \int_compare:nNnF {#1} > {#2} { \__seq_set_item:nNnnNNNN { #1 - 1 } } }
+      {
+        \int_compare:nNnF {#1} < {-#2}
+          {
+            \int_compare:nNnF {#1} = 0
+              { \__seq_set_item:nNnnNNNN { #2 + #1 } }
+          }
+      }
+    \__seq_set_item_false:nnNNNN {#1} {#2}
+  }
+\cs_new_protected:Npn \__seq_set_item_false:nnNNNN #1#2#3#4#5#6
+  {
+    #6
+      {
+        \__kernel_msg_error:nnxxx { seq } { item-too-large }
+          { \token_to_str:N #3 } {#2} {#1}
+      }
+      { \prg_return_false: }
+  }
+\__kernel_msg_new:nnnn { seq } { item-too-large }
+  { Sequence~'#1'~does~not~have~an~item~#3 }
+  {
+    An~attempt~was~made~to~push~or~pop~the~item~at~position~#3~
+    of~'#1',~but~this~
+    \int_compare:nTF { #3 = 0 }
+      { position~does~not~exist. }
+      { sequence~only~has~#2~item \int_compare:nF { #2 = 1 } {s}. }
+  }
+\cs_new_protected:Npn \__seq_set_item:nNnnNNNN #1#2#3#4#5#6#7#8
+  {
+    #7 #5
+      {
+        \s__seq
+        \exp_after:wN \__seq_set_item:wn
+        \int_value:w \__seq_int_eval:w #1
+        #5 \s__seq_stop #6
+      }
+    #8 { } { \prg_return_true: }
+  }
+\cs_new:Npn \__seq_set_item:wn #1 \__seq_item:n #2
+  {
+    \if_meaning:w 0 #1 \__seq_set_item_end:w \fi:
+    \exp_not:n { \__seq_item:n {#2} }
+    \exp_after:wN \__seq_set_item:wn
+    \int_value:w \__seq_int_eval:w #1 - 1 \s__seq
+  }
+\cs_new:Npn \__seq_set_item_end:w #1 \exp_not:n #2 #3 \s__seq #4 \s__seq_stop #5
+  {
+    #1
+    \exp_not:o \l__seq_internal_a_tl
+    \exp_not:n {#4}
+    #5 #2
+  }
+\cs_new_protected:Npn \seq_pop_item:NnN #1#2#3
+  { \seq_pop_item:NnNTF #1 {#2} #3 { } { } }
+\cs_new_protected:Npn \seq_gpop_item:NnN #1#2#3
+  { \seq_gpop_item:NnNTF #1 {#2} #3 { } { } }
+\cs_generate_variant:Nn \seq_pop_item:NnN { c }
+\cs_generate_variant:Nn \seq_gpop_item:NnN { c }
+\prg_new_protected_conditional:Npnn \seq_pop_item:NnN #1#2#3 { TF , T , F }
+  { \__seq_pop_item:NnNN #1 {#2} #3 \__kernel_tl_set:Nx }
+\prg_new_protected_conditional:Npnn \seq_gpop_item:NnN #1#2#3 { TF , T , F }
+  { \__seq_pop_item:NnNN #1 {#2} #3 \__kernel_tl_gset:Nx }
+\prg_generate_conditional_variant:Nnn \seq_pop_item:NnN { c } { TF , T , F }
+\prg_generate_conditional_variant:Nnn \seq_gpop_item:NnN { c } { TF , T , F }
+\cs_new_protected:Npn \__seq_pop_item:NnNN #1#2#3#4
+  {
+    \tl_clear:N \l__seq_internal_a_tl
+    \tl_set:Nn \l__seq_internal_b_tl { \__kernel_tl_set:Nx #3 }
+    \exp_args:Nff \__seq_set_item:nnNNNN
+      { \int_eval:n {#2} } { \seq_count:N #1 }
+      #1 \__seq_pop_item_aux:w #4 \__seq_pop_item:nn
+  }
+\cs_new_protected:Npn \__seq_pop_item:nn #1#2
+  {
+    \if_meaning:w \prg_return_false: #2
+      \l__seq_internal_b_tl { \exp_not:N \q_no_value }
+    \fi:
+    #2
+  }
+\cs_new:Npn \__seq_pop_item_aux:w \__seq_item:n #1
+  {
+    \if_false: { \fi: }
+    \l__seq_internal_b_tl { \if_false: } \fi: \exp_not:n {#1}
+  }
 \str_const:Nx \c_sys_engine_version_str
   {
     \str_case:on \c_sys_engine_str
@@ -33166,18 +33720,18 @@
   {
     \sys_if_shell:TF
       { \exp_args:No \__ior_shell_open:nN { \tl_to_str:n {#2} } #1 }
-      { \__kernel_msg_error:nn { kernel } { pipe-failed } }
+      { \__kernel_msg_error:nn { ior } { pipe-failed } }
   }
 \cs_new_protected:Npn \__ior_shell_open:nN #1#2
   {
     \tl_if_in:nnTF {#1} { " }
       {
         \__kernel_msg_error:nnx
-          { kernel } { quote-in-shell } {#1}
+          { ior } { quote-in-shell } {#1}
       }
       { \__kernel_ior_open:Nn #2 { |#1 } }
   }
-\__kernel_msg_new:nnnn { kernel } { pipe-failed }
+\__kernel_msg_new:nnnn { ior } { pipe-failed }
   { Cannot~run~piped~system~commands. }
   {
     LaTeX~tried~to~call~a~system~process~but~this~was~not~possible.\\
@@ -33450,7 +34004,7 @@
         \__kernel_if_debug:TF
           {
             \exp_not:N \__kernel_msg_warning:nnxxx
-              { kernel } { deprecated-command }
+              { deprecation } { deprecated-command }
               {#1}
               { \token_to_str:N #3 }
               { \tl_to_str:n {#2} }
@@ -33478,7 +34032,7 @@
           \cs_if_eq:NNTF #3 \cs_gset_protected:Npn
             { \exp_not:N \__kernel_msg_error:nnnnnn }
             { \exp_not:N \__kernel_msg_expandable_error:nnnnnn }
-            { kernel } { deprecated-command }
+            { deprecation } { deprecated-command }
             {#1}
             { \token_to_str:N #4 }
             { \tl_to_str:n {#2} }
@@ -33491,14 +34045,14 @@
     \tex_protected:D \tex_outer:D \tex_edef:D #1
       {
         \exp_not:N \__kernel_msg_expandable_error:nnnnn
-          { kernel } { deprecated-command }
+          { deprecation } { deprecated-command }
           { \tl_to_str:n {#3} } { \token_to_str:N #1 } { \tl_to_str:n {#2} }
         \exp_not:N \__kernel_msg_error:nnxxx
-          { kernel } { deprecated-command }
+          { deprecation } { deprecated-command }
           { \tl_to_str:n {#3} } { \token_to_str:N #1 } { \tl_to_str:n {#2} }
       }
   }
-\__kernel_msg_new:nnn { kernel } { deprecated-command }
+\__kernel_msg_new:nnn { deprecation } { deprecated-command }
   {
     \tl_if_blank:nF {#3} { Use~ \tl_trim_spaces:n {#3} ~not~ }
     #2~deprecated~on~#1.
-- 
cgit v1.2.3

