[latex3-commits] [latex3/latex3] main: initial (d4397fcbe)

github at latex-project.org github at latex-project.org
Sun Oct 15 22:04:00 CEST 2023


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

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

commit d4397fcbe167b7bf90d2d6edf7ad9c1b26e4f924
Author: Jonathan Spratte <jspratte at yahoo.de>
Date:   Sun Apr 24 23:08:54 2022 +0200

    initial


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

d4397fcbe167b7bf90d2d6edf7ad9c1b26e4f924
 l3kernel/l3token.dtx | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)

diff --git a/l3kernel/l3token.dtx b/l3kernel/l3token.dtx
index b698163be..369e5a34d 100644
--- a/l3kernel/l3token.dtx
+++ b/l3kernel/l3token.dtx
@@ -481,6 +481,18 @@
 %   \end{texnote}
 % \end{function}
 %
+% \begin{function}[EXP]{\token_to_catcode:N}
+%   \begin{syntax}
+%     \cs{token_to_catcode:N} \meta{token}
+%   \end{syntax}
+%   Converts the given \meta{token} into a number describing its category code.
+%   If \meta{token} is a macro this expands to $13$. This can't detect the
+%   categories $0$ (escape character), $5$ (end of line), $9$ (ignored
+%   character), $14$ (comment character), or $15$ (invalid character). Control
+%   sequences or active characters let to a token of one of the detectable
+%   category codes will yield that category.
+% \end{function}
+%
 % \section{Token conditionals}
 %
 % \begin{function}[EXP,pTF]{\token_if_group_begin:N}
@@ -1873,6 +1885,66 @@
 % \end{macro}
 % \end{macro}
 %
+% \begin{macro}{\token_to_catcode:N}
+% \begin{macro}{\@@_to_catcode:N}
+%   The macro works by comparing the input token with \cs{if_catcode:w} with all
+%   valid category codes. Since the most common tokens in an average argument
+%   list are of category $11$ or $12$ those are tested first. And since a space
+%   and braces are no ordinary |N|-type arguments, and only control sequences
+%   let to those categories can match them they are tested last.
+%    \begin{macrocode}
+\cs_new:Npn \token_to_catcode:N
+  { \int_value:w \group_align_safe_begin: \@@_to_catcode:N }
+\cs_new:Npn \@@_to_catcode:N #1
+  {
+    \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:
+        \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_parameter_token
+              6
+            \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_group_begin_token
+                    1
+                  \else:
+                    \if_catcode:w \exp_not:N #1 \c_group_end_token
+                      2
+                    \else:
+                      \if_catcode:w \exp_not:N #1 \c_space_token
+                        10
+                      \else:
+                        13
+                      \fi:
+                    \fi:
+                  \fi:
+                \fi:
+              \fi:
+            \fi:
+          \fi:
+        \fi:
+      \fi:
+    \fi:
+    \group_align_safe_end:
+    \exp_stop_f:
+  }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
 % \begin{macro}
 %   {
 %     \c_group_begin_token,





More information about the latex3-commits mailing list.