[latex3-commits] [git/LaTeX3-latex3-latex3] l3text: Ensure text chars have correct catcode (fb9c71105)

Joseph Wright joseph.wright at morningstar2.co.uk
Mon Dec 2 21:06:32 CET 2019


Repository : https://github.com/latex3/latex3
On branch  : l3text
Link       : https://github.com/latex3/latex3/commit/fb9c71105cadcc4e90e22f716a4676b35faed005

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

commit fb9c71105cadcc4e90e22f716a4676b35faed005
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Mon Dec 2 20:06:28 2019 +0000

    Ensure text chars have correct catcode


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

fb9c71105cadcc4e90e22f716a4676b35faed005
 l3kernel/l3text.dtx | 62 ++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 50 insertions(+), 12 deletions(-)

diff --git a/l3kernel/l3text.dtx b/l3kernel/l3text.dtx
index 0e6699a8c..d3111534e 100644
--- a/l3kernel/l3text.dtx
+++ b/l3kernel/l3text.dtx
@@ -330,6 +330,45 @@
 % \end{macro}
 % \end{macro}
 %
+% \begin{macro}{\@@_char_catcode:N}
+%   An idea from \pkg{l3char}: we need to get the category code of
+%   a specific token, not the general case.
+%    \begin{macrocode}
+\cs_new:Npn \@@_char_catcode:N #1
+  {
+    \if_catcode:w \exp_not:N #1 \c_math_toggle_token
+      3
+    \else:
+      \if_catcode:w \exp_not:N #1 \c_alignment_token
+        4
+      \else:
+        \if_catcode:w \exp_not:N #1 \c_math_superscript_token
+          7
+        \else:
+          \if_catcode:w \exp_not:N #1 \c_math_subscript_token
+            8
+          \else:
+            \if_catcode:w \exp_not:N #1 \c_space_token
+              10
+            \else:
+             \if_catcode:w \exp_not:N #1 \c_catcode_letter_token
+               11
+             \else:
+               \if_catcode:w \exp_not:N #1 \c_catcode_other_token
+                 12
+               \else:
+                 13
+               \fi:
+             \fi:
+            \fi:
+          \fi:
+        \fi:
+      \fi:
+    \fi:
+  }
+%    \end{macrocode}
+% \end{macro}
+%
 % \subsection{Configuration variables}
 %
 % \begin{variable}{\l_text_accents_tl, \l_text_letterlike_tl}
@@ -1133,7 +1172,7 @@
         \tl_if_head_is_N_type:nTF {#4}
           { \@@_change_case_lower_sigma:NnnN #3 }
           {
-            \char_generate:nn { "03C2 } { \char_value_catcode:n { `#3 } }
+            \char_generate:nn { "03C2 } { \@@_char_catcode:N #3 }
             \@@_change_case_loop:nnw
           }
             {#1} {#2} #4 \q_recursion_stop
@@ -1141,8 +1180,8 @@
     \cs_new:Npn \@@_change_case_lower_sigma:NnnN #1#2#3#4
       {
         \token_if_letter:NTF #4
-          { \char_generate:nn { "03C3 } { \char_value_catcode:n { `#1 } } }
-          { \char_generate:nn { "03C2 } { \char_value_catcode:n { `#1 } } }
+          { \char_generate:nn { "03C3 } { \@@_char_catcode:N #1 } }
+          { \char_generate:nn { "03C2 } { \@@_char_catcode:N #1 } }
         \@@_change_case_loop:nnw {#2} {#3} #4
       }
   }
@@ -1293,8 +1332,7 @@
       {
         \int_compare:nNnTF { `#4 } = { "00DF }
           {
-            \char_generate:nn { "1E9E }
-              { \char_value_catcode:n { `#4 } }
+            \char_generate:nn { "1E9E } { \@@_char_catcode:N #4 }
             \use:c { @@_change_case_char_next_ #2 :nn }
               {#2} {#3}
           }
@@ -1355,9 +1393,9 @@
               {#2} {#3} #4
           }
           {
-            \char_generate:nn { "0069 } { \char_value_catcode:n { `#4 } }
+            \char_generate:nn { "0069 } { \@@_char_catcode:N #4 }
             \char_generate:nn { "0307 } { \char_value_catcode:n { "0307 } }
-            \char_generate:nn {#1} { \char_value_catcode:n { `#4 } }
+            \char_generate:nn {#1} { \char_value_catcode:n {#1} }
             \@@_change_case_loop:nnw {#2} {#3}
           }
       }
@@ -1371,7 +1409,7 @@
         \tl_if_blank:nTF {#1}
           { \@@_change_case_lower_sigma:nnnN {#2} {#2} {#3} #4 }
           {
-            \char_generate:nn {#1} { \char_value_catcode:n { `#4 } }
+            \char_generate:nn {#1} { \@@_char_catcode:N #4 }
             \@@_change_case_lower_lt:nnw {#2} {#3}
           }
       }
@@ -1434,7 +1472,7 @@
        \tl_if_blank:nTF {#1}
          { \@@_change_case_char:nnnN { upper } {#2} {#3} #4 }
          {
-           \char_generate:nn {#1} { \char_value_catcode:n { `#4 } }
+           \char_generate:nn {#1} { \@@_char_catcode:N #4 }
            \@@_change_case_upper_lt:nnw {#2} {#3}
          }
      }
@@ -1472,7 +1510,7 @@
       { \int_compare_p:nNn { `#4 } = { "0049 } }
       { \int_compare_p:nNn { `#4 } = { "0069 } }
       {
-        \char_generate:nn { "0049 } { \char_value_catcode:n { `#4 } }
+        \char_generate:nn { "0049 } { \@@_char_catcode:N #4 }
         \@@_change_case_title_nl:nnw {#2} {#3}
       }
       { \@@_change_case_char:nnnN {#1} {#2} {#3} #4 }
@@ -1494,7 +1532,7 @@
           { \int_compare_p:nNn { `#3 } = { "006A } }
       }
       {
-        \char_generate:nn { "004A } { \char_value_catcode:n { `#3 } }
+        \char_generate:nn { "004A } { \@@_char_catcode:N #3 }
         \use:c { @@_change_case_char_next_ #1 :nn } {#1} {#2}
       }
       { \use:c { @@_change_case_char_next_ #1 :nn } {#1} {#2} #3 }
@@ -1524,7 +1562,7 @@
           {
             \int_compare:nNnTF { `#4 } = { "0130 }
               {
-                \char_generate:nn { "0069 } { \char_value_catcode:n { `#4 } }
+                \char_generate:nn { "0069 } { \@@_char_catcode:N #4 }
                 \@@_change_case_loop:nnw {#1} {#3}
               }
               { \@@_change_case_lower_sigma:nnnN {#1} {#2} {#3} #4 }





More information about the latex3-commits mailing list