[latex3-commits] [git/LaTeX3-latex3-latex3] case-exceptions: Add \text_declare_<thing>case_mapping:nn(n) (213f449b7)

Joseph Wright joseph.wright at morningstar2.co.uk
Mon Apr 17 10:36:45 CEST 2023


Repository : https://github.com/latex3/latex3
On branch  : case-exceptions
Link       : https://github.com/latex3/latex3/commit/213f449b7b7d3e6854407f60574130f3fef2bee5

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

commit 213f449b7b7d3e6854407f60574130f3fef2bee5
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Tue Apr 11 16:07:45 2023 +0100

    Add \text_declare_<thing>case_mapping:nn(n)
    
    This allows customisation of case changing outcomes,
    and will be the basis of a fix for latex3/latex2e#1033.


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

213f449b7b7d3e6854407f60574130f3fef2bee5
 l3kernel/CHANGELOG.md                   |   4 ++
 l3kernel/l3text-case.dtx                | 104 +++++++++++++++++++++++++++++++-
 l3kernel/l3text.dtx                     |  20 ++++++
 l3kernel/testfiles/m3text002.luatex.tlg |   9 +++
 l3kernel/testfiles/m3text002.lvt        |  17 ++++++
 l3kernel/testfiles/m3text002.ptex.tlg   |   9 +++
 l3kernel/testfiles/m3text002.tlg        |   9 +++
 l3kernel/testfiles/m3text002.uptex.tlg  |   9 +++
 l3kernel/testfiles/m3text002.xetex.tlg  |   9 +++
 9 files changed, 189 insertions(+), 1 deletion(-)

diff --git a/l3kernel/CHANGELOG.md b/l3kernel/CHANGELOG.md
index cc9109562..c396a6e9c 100644
--- a/l3kernel/CHANGELOG.md
+++ b/l3kernel/CHANGELOG.md
@@ -9,6 +9,10 @@ this project uses date-based 'snapshot' version identifiers.
 
 ### Added
 - `\box_set_clipped:N` and variants (renamed from `\box_clip:N`)
+- `\text_declare_lowercase_mapping:nn(n)`,
+   `\text_declare_titlecase_mapping:nn(n)`
+   and `\text_declare_uppercase_mapping:nn(n)` to allow customization of
+   case changing outcomes
 
 ### Changed
 - `\box_set_trim:Nnnnn` and `\box_set_viewport:Nnnnn` moved to
diff --git a/l3kernel/l3text-case.dtx b/l3kernel/l3text-case.dtx
index 96e1199da..e50002bd5 100644
--- a/l3kernel/l3text-case.dtx
+++ b/l3kernel/l3text-case.dtx
@@ -172,6 +172,14 @@
 % \begin{macro}[EXP]{\@@_change_case_letterlike:nnnnN}
 % \begin{macro}[EXP]
 %   {
+%     \@@_change_case_custom_lower:nnn ,
+%     \@@_change_case_custom_title:nnn ,
+%     \@@_change_case_custom_upper:nnn ,
+%     \@@_change_case_custom_titleonly:nnn
+%   }
+% \begin{macro}[EXP]{\@@_change_case_custom:nnn}
+% \begin{macro}[EXP]
+%   {
 %     \@@_change_case_codepoint_lower:nnn ,
 %     \@@_change_case_codepoint_upper:nnn ,
 %     \@@_change_case_codepoint_title:nnn ,
@@ -439,7 +447,7 @@
       { \@@_change_case_exclude:nnN {#1} {#2} }
       {
         \@@_codepoint_process:nN
-          { \use:c { @@_change_case_codepoint_ #1 :nnn } {#1} {#2} }
+          { \use:c { @@_change_case_custom_ #1 :nnn } {#1} {#2} }
       }
         #3
   }
@@ -571,6 +579,42 @@
       }
   }
 %    \end{macrocode}
+%  Check for a customised codepoint result.
+%    \begin{macrocode}
+\cs_new:Npn \@@_change_case_custom_lower:nnn #1#2#3
+  {
+    \@@_change_case_custom:nnnnn {#1} {#2} {#3} {#1}
+      { \use:c { @@_change_case_codepoint_ #1 :nnn } {#1} {#2} {#3} }
+  }
+\cs_new_eq:NN \@@_change_case_custom_upper:nnn
+  \@@_change_case_custom_lower:nnn
+\cs_new:Npn \@@_change_case_custom_title:nnn #1#2#3
+  {
+    \@@_change_case_custom:nnnnn { title } {#2} {#3} {#1}
+      {
+        \@@_change_case_custom:nnnnn { upper } {#2} {#3} {#1}
+          { \use:c { @@_change_case_codepoint_ #1 :nnn } {#1} {#2} {#3} }
+      }
+  }
+\cs_new_eq:NN \@@_change_case_custom_titleonly:nnn
+  \@@_change_case_custom_title:nnn
+\cs_new:Npn \@@_change_case_custom:nnnnn #1#2#3#4#5
+  {
+    \tl_if_exist:cTF { l_@@_ #1 case _ \tl_to_str:n {#3} _ #2 _tl }
+      {
+        \@@_change_case_replace:vnn
+          { l_@@_ #1 case _ \tl_to_str:n {#3} _ #2 _tl } {#4} {#2}
+      }
+      {
+        \tl_if_exist:cTF { l_@@_ #1 case _ \tl_to_str:n {#3} _tl }
+          {
+            \@@_change_case_replace:vnn
+              { l_@@_ #1 case _ \tl_to_str:n {#3} _tl } {#4} {#2}
+          }
+          {#5}
+      }
+  }
+%    \end{macrocode}
 %   For upper- and lowercase changes, once we get to this stage there are only
 %   a couple of questions remaining: is there a language-specific mapping and
 %   is there the special case of a terminal sigma. If not, then we pass to
@@ -807,6 +851,8 @@
 % \end{macro}
 % \end{macro}
 % \end{macro}
+% \end{macro}
+% \end{macro}
 %
 % \begin{macro}{\text_declare_case_equivalent:Nn}
 %  Create equivalents to allow replacement.
@@ -819,6 +865,62 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}
+%   {
+%     \text_declare_lowercase_mapping:nn ,
+%     \text_declare_titlecase_mapping:nn ,
+%     \text_declare_uppercase_mapping:nn
+%   }
+% \begin{macro}
+%   {\@@_declare_case_mapping:nnn, \@@_declare_case_mapping_aux:nnn}
+% \begin{macro}
+%   {
+%     \text_declare_lowercase_mapping:nnn ,
+%     \text_declare_titlecase_mapping:nnn ,
+%     \text_declare_uppercase_mapping:nnn
+%   }
+% \begin{macro}
+%   {\@@_declare_case_mapping:nnnn, \@@_declare_case_mapping_aux:nnnn}
+%   Codepoint customisation.
+%    \begin{macrocode}
+\cs_new_protected:Npn \text_declare_lowercase_mapping:nn #1#2
+  { \@@_declare_case_mapping:nnn { lower } {#1} {#2} }
+\cs_new_protected:Npn \text_declare_titlecase_mapping:nn #1#2
+  { \@@_declare_case_mapping:nnn { title } {#1} {#2} }
+\cs_new_protected:Npn \text_declare_uppercase_mapping:nn #1#2
+  { \@@_declare_case_mapping:nnn { upper } {#1} {#2} }
+\cs_new_protected:Npn \@@_declare_case_mapping:nnn #1#2#3
+  {
+    \exp_args:Ne \@@_declare_case_mapping_aux:nnn
+      { \codepoint_str_generate:n {#2} } {#1} {#3}
+  }
+\cs_new_protected:Npn \@@_declare_case_mapping_aux:nnn #1#2#3
+  {
+    \tl_clear_new:c { l_@@_ #2 case _ #1 _tl }
+    \tl_set:cn { l_@@_ #2 case _ #1 _ tl } {#3}
+  }
+\cs_new_protected:Npn \text_declare_lowercase_mapping:nnn #1#2#3
+  { \@@_declare_case_mapping:nnnn { lower } {#1} {#2} {#3} }
+\cs_new_protected:Npn \text_declare_titlecase_mapping:nnn #1#2#3
+  { \@@_declare_case_mapping:nnnn { title } {#1} {#2} {#3} }
+\cs_new_protected:Npn \text_declare_uppercase_mapping:nnn #1#2#3
+  { \@@_declare_case_mapping:nnnn { upper } {#1} {#2} {#3} }
+\cs_new_protected:Npn \@@_declare_case_mapping:nnnn #1#2#3#4
+  {
+    \exp_args:Ne \@@_declare_case_mapping_aux:nnnn
+      { \codepoint_str_generate:n {#2} } {#1} {#3} {#4}
+  }
+\cs_new_protected:Npn \@@_declare_case_mapping_aux:nnnn #1#2#3#4
+  {
+    \tl_clear_new:c { l_@@_ #2 case _ #1 _ #3 _tl }
+    \tl_set:cn { l_@@_ #2 case _ #1 _ #3 _ tl } {#4}
+  }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
 % \begin{macro}{\text_case_switch:nnnn}
 % \begin{macro}{\@@_case_switch_marker:}
 %   Set up the mechanism for manual case switching.
diff --git a/l3kernel/l3text.dtx b/l3kernel/l3text.dtx
index fa5f01625..5eff55147 100644
--- a/l3kernel/l3text.dtx
+++ b/l3kernel/l3text.dtx
@@ -216,6 +216,26 @@
 %   \meta{cmd} (a single token) is encountered during case changing.
 % \end{function}
 %
+% \begin{function}[added = 2023-04-11]
+%   {
+%     \text_declare_lowercase_mapping:nn  ,
+%     \text_declare_lowercase_mapping:nnn ,
+%     \text_declare_titlecase_mapping:nn  ,
+%     \text_declare_titlecase_mapping:nnn ,
+%     \text_declare_uppercase_mapping:nn  ,
+%     \text_declare_uppercase_mapping:nnn
+%   }
+%   \begin{syntax}
+%     \cs{text_declare_lowercase_mapping:nn} \Arg{codeppoint}  \Arg{replacement}
+%     \cs{text_declare_lowercase_mapping:nnn} \Arg{codeppoint} \Arg{BCP-47} \Arg{replacement}
+%   \end{syntax}
+%   Declares that the \meta{replacement} tokens should be used when case mapping
+%   the \meta{codepoint}, rather than the standard mapping given in the
+%   Unicode data files. The \texttt{nnn} version takes a BCP-47 tag, which
+%   can be used to specify that the customisation only applies to that
+%   locale.
+% \end{function}
+%
 % \begin{function}[EXP, added = 2022-07-04]{\text_case_switch:nnnn}
 %   \begin{syntax}
 %     \cs{text_case_switch:nnnn} \Arg{normal} \Arg{upper} \Arg{lower} \Arg{title}
diff --git a/l3kernel/testfiles/m3text002.luatex.tlg b/l3kernel/testfiles/m3text002.luatex.tlg
index 90c88c75b..9a830d284 100644
--- a/l3kernel/testfiles/m3text002.luatex.tlg
+++ b/l3kernel/testfiles/m3text002.luatex.tlg
@@ -403,3 +403,12 @@ Defining \l__text_case_\foo_tl on line ...
 <recently read> }
 l. ...  }
 ============================================================
+============================================================
+TEST 33: Case change customisation
+============================================================
+Defining \l__text_uppercase_ǰ_tl on line ...
+Defining \l__text_uppercase_ǰ_xx_tl on line ...
+> ǰ\v J\v JXǰǰ\v I\v IXǰ.
+<recently read> }
+l. ...  }
+============================================================
diff --git a/l3kernel/testfiles/m3text002.lvt b/l3kernel/testfiles/m3text002.lvt
index 57d88ba3b..499ade0ac 100644
--- a/l3kernel/testfiles/m3text002.lvt
+++ b/l3kernel/testfiles/m3text002.lvt
@@ -407,4 +407,21 @@
       { \text_lowercase:n { \use:n { FOO } \foo } }
   }
 
+\TEST { Case~change~customisation }
+  {
+    \text_declare_uppercase_mapping:nn { "01F0 }  { \v J }
+    \text_declare_uppercase_mapping:nnn { "01F0 } { xx } { \v I }
+    \tl_show:x
+      {
+        \text_lowercase:n { ǰ }
+        \text_uppercase:n { ǰ }
+        \text_titlecase:n { ǰ }
+        \text_titlecase:n { xǰ }
+        \text_lowercase:nn { xx } { ǰ }
+        \text_uppercase:nn { xx } { ǰ }
+        \text_titlecase:nn { xx } { ǰ }
+        \text_titlecase:nn { xx } { xǰ }
+      }
+  }
+
 \END
diff --git a/l3kernel/testfiles/m3text002.ptex.tlg b/l3kernel/testfiles/m3text002.ptex.tlg
index c521810ea..95a330234 100644
--- a/l3kernel/testfiles/m3text002.ptex.tlg
+++ b/l3kernel/testfiles/m3text002.ptex.tlg
@@ -403,3 +403,12 @@ Defining \l__text_case_\foo_tl on line ...
 <recently read> }
 l. ...  }
 ============================================================
+============================================================
+TEST 33: Case change customisation
+============================================================
+Defining \l__text_uppercase_^^c7^^b0_tl on line ...
+Defining \l__text_uppercase_^^c7^^b0_xx_tl on line ...
+> ^^c7^^b0\v J\v JX^^c7^^b0^^c7^^b0\v I\v IX^^c7^^b0.
+<recently read> }
+l. ...  }
+============================================================
diff --git a/l3kernel/testfiles/m3text002.tlg b/l3kernel/testfiles/m3text002.tlg
index 543e7780b..62df11547 100644
--- a/l3kernel/testfiles/m3text002.tlg
+++ b/l3kernel/testfiles/m3text002.tlg
@@ -403,3 +403,12 @@ Defining \l__text_case_\foo_tl on line ...
 <recently read> }
 l. ...  }
 ============================================================
+============================================================
+TEST 33: Case change customisation
+============================================================
+Defining \l__text_uppercase_^^c7^^b0_tl on line ...
+Defining \l__text_uppercase_^^c7^^b0_xx_tl on line ...
+> ^^c7^^b0\v J\v JX^^c7^^b0^^c7^^b0\v I\v IX^^c7^^b0.
+<recently read> }
+l. ...  }
+============================================================
diff --git a/l3kernel/testfiles/m3text002.uptex.tlg b/l3kernel/testfiles/m3text002.uptex.tlg
index 457ce5beb..9551bd17e 100644
--- a/l3kernel/testfiles/m3text002.uptex.tlg
+++ b/l3kernel/testfiles/m3text002.uptex.tlg
@@ -403,3 +403,12 @@ Defining \l__text_case_\foo_tl on line ...
 <recently read> }
 l. ...  }
 ============================================================
+============================================================
+TEST 33: Case change customisation
+============================================================
+Defining \l__text_uppercase_^^c7^^b0_tl on line ...
+Defining \l__text_uppercase_^^c7^^b0_xx_tl on line ...
+> ^^c7^^b0\v J\v JX^^c7^^b0^^c7^^b0\v I\v IX^^c7^^b0.
+<recently read> }
+l. ...  }
+============================================================
diff --git a/l3kernel/testfiles/m3text002.xetex.tlg b/l3kernel/testfiles/m3text002.xetex.tlg
index 90c88c75b..9a830d284 100644
--- a/l3kernel/testfiles/m3text002.xetex.tlg
+++ b/l3kernel/testfiles/m3text002.xetex.tlg
@@ -403,3 +403,12 @@ Defining \l__text_case_\foo_tl on line ...
 <recently read> }
 l. ...  }
 ============================================================
+============================================================
+TEST 33: Case change customisation
+============================================================
+Defining \l__text_uppercase_ǰ_tl on line ...
+Defining \l__text_uppercase_ǰ_xx_tl on line ...
+> ǰ\v J\v JXǰǰ\v I\v IXǰ.
+<recently read> }
+l. ...  }
+============================================================





More information about the latex3-commits mailing list.