[latex3-commits] [git/LaTeX3-latex3-latex3] main: Add finer control to case changing (66838cc7a)
Joseph Wright
joseph.wright at morningstar2.co.uk
Mon Jul 4 21:40:06 CEST 2022
Repository : https://github.com/latex3/latex3
On branch : main
Link : https://github.com/latex3/latex3/commit/66838cc7a74fa291538b2ab0d789dc94d8be2b9b
>---------------------------------------------------------------
commit 66838cc7a74fa291538b2ab0d789dc94d8be2b9b
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Mon Jul 4 20:40:06 2022 +0100
Add finer control to case changing
>---------------------------------------------------------------
66838cc7a74fa291538b2ab0d789dc94d8be2b9b
l3kernel/CHANGELOG.md | 5 +++
l3kernel/l3text-case.dtx | 79 ++++++++++++++++++++++++++++++++-
l3kernel/l3text.dtx | 24 ++++++++++
l3kernel/testfiles/m3text002.luatex.tlg | 18 ++++++++
l3kernel/testfiles/m3text002.lvt | 24 ++++++++++
l3kernel/testfiles/m3text002.tlg | 18 ++++++++
l3kernel/testfiles/m3text002.uptex.tlg | 18 ++++++++
l3kernel/testfiles/m3text002.xetex.tlg | 18 ++++++++
8 files changed, 203 insertions(+), 1 deletion(-)
diff --git a/l3kernel/CHANGELOG.md b/l3kernel/CHANGELOG.md
index cf83e8f03..13cbcfcdc 100644
--- a/l3kernel/CHANGELOG.md
+++ b/l3kernel/CHANGELOG.md
@@ -7,6 +7,11 @@ this project uses date-based 'snapshot' version identifiers.
## [Unreleased]
+### Added
+- `\text_declare_case_equivalent:Nn`, `\text_case_switch:nnnn` and
+ related mechanism to allow specialisation of case changing output
+ for selected commands
+
## [2022-07-01]
### Added
diff --git a/l3kernel/l3text-case.dtx b/l3kernel/l3text-case.dtx
index 0f6a78cbe..857cce8e4 100644
--- a/l3kernel/l3text-case.dtx
+++ b/l3kernel/l3text-case.dtx
@@ -151,6 +151,15 @@
% \begin{macro}[EXP]{\@@_change_case_exclude:nnNN}
% \begin{macro}[EXP]{\@@_change_case_exclude:nnNw}
% \begin{macro}[EXP]{\@@_change_case_exclude:nnNnn}
+% \begin{macro}[EXP]{\@@_change_case_replace:nnN}
+% \begin{macro}[EXP]{\@@_change_case_replace:nnn}
+% \begin{macro}[EXP]{\@@_change_case_switch:nnN}
+% \begin{macro}[EXP]
+% {
+% \@@_change_case_switch_lower:nnNnnnn ,
+% \@@_change_case_switch_upper:nnNnnnn ,
+% \@@_change_case_switch_title:nnNnnnn
+% }
% \begin{macro}[EXP]
% {
% \@@_change_case_letterlike_lower:nnN ,
@@ -446,7 +455,7 @@
\cs_new:Npn \@@_change_case_exclude:nnNN #1#2#3#4
{
\@@_if_recursion_tail_stop_do:Nn #4
- { \use:c { @@_change_case_letterlike_ #1 :nnN } {#1} {#2} #3 }
+ { \@@_change_case_replace:nnN {#1} {#2} #3 }
\str_if_eq:nnTF {#3} {#4}
{
\@@_use_i_delimit_by_q_recursion_stop:nw
@@ -471,6 +480,45 @@
\@@_change_case_loop:nnw {#1} {#2}
}
% \end{macrocode}
+% Deal with any specialist replacement for case changing.
+% \begin{macrocode}
+\cs_new:Npn \@@_change_case_replace:nnN #1#2#3
+ {
+ \cs_if_exist:cTF { l_@@_case_ \token_to_str:N #3 _tl }
+ {
+ \exp_args:Nv \@@_change_case_replace:nnn
+ { l_@@_case_ \token_to_str:N #3 _tl } {#1} {#2}
+ }
+ { \@@_change_case_switch:nnN {#1} {#2} #3 }
+ }
+\cs_new:Npn \@@_change_case_replace:nnn #1#2#3
+ { \@@_change_case_loop:nnw {#2} {#3} #1 }
+% \end{macrocode}
+% Allow for manually-controlled case switching.
+% \begin{macrocode}
+\cs_new:Npn \@@_change_case_switch:nnN #1#2#3
+ {
+ \cs_if_eq:NNTF #3 \text_case_switch:nnnn
+ { \use:c { @@_change_case_switch_ #1 :nnNnnnn } }
+ { \use:c { @@_change_case_letterlike_ #1 :nnN } }
+ {#1} {#2} #3
+ }
+\cs_new:Npn \@@_change_case_switch_lower:nnNnnnn #1#2#3#4#5#6#7
+ {
+ \@@_change_case_store:n {#5}
+ \@@_change_case_loop:nnw {#1} {#2}
+ }
+\cs_new:Npn \@@_change_case_switch_upper:nnNnnnn #1#2#3#4#5#6#7
+ {
+ \@@_change_case_store:n {#6}
+ \@@_change_case_loop:nnw {#1} {#2}
+ }
+\cs_new:Npn \@@_change_case_switch_title:nnNnnnn #1#2#3#4#5#6#7
+ {
+ \@@_change_case_store:n {#7}
+ \@@_change_case_loop:nnw {#1} {#2}
+ }
+% \end{macrocode}
% Letter-like commands may still be present: they are set up using a simple
% lookup approach, so can easily be handled with no loop. If there is no
% hit, we are at the end of the process: we loop around. Letter-like chars
@@ -771,6 +819,35 @@
% \end{macro}
% \end{macro}
% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\text_declare_case_equivalent:Nn}
+% Create equivalents to allow replacement.
+% \begin{macrocode}
+\cs_new_protected:Npn \text_declare_case_equivalent:Nn #1#2
+ {
+ \tl_clear_new:c { l_@@_case_ \token_to_str:N #1 _tl }
+ \tl_set:cn { l_@@_case_ \token_to_str:N #1 _tl } {#2}
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\text_case_switch:nnnn}
+% \begin{macro}{\@@_case_switch_marker:}
+% Set up the mechanism for manual case switching.
+% \begin{macrocode}
+\cs_new:Npn \text_case_switch:nnnn #1#2#3#4
+ {
+ \@@_case_switch_marker:
+ #1
+ }
+\cs_new:Npn \@@_case_switch_marker: { }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
%
% \begin{macro}[EXP]{\@@_change_case_upper_de-x-eszett:nnnN, \@@_change_case_upper_de-alt:nnnN}
% \begin{macro}[EXP]{\@@_change_case_upper_de-x-eszett:nnnNN}
diff --git a/l3kernel/l3text.dtx b/l3kernel/l3text.dtx
index 15b6025b4..891612a94 100644
--- a/l3kernel/l3text.dtx
+++ b/l3kernel/l3text.dtx
@@ -205,6 +205,29 @@
% character is uppercased, and the rest lowercased, irrespective of the nature
% of the character.
%
+% \begin{function}[added = 2022-07-04]
+% {
+% \text_declare_case_equivalent:Nn ,
+% \text_declare_case_equivalent:cn
+% }
+% \begin{syntax}
+% \cs{text_declare_case_equivalent:Nn} \meta{cmd} \Arg{replacement}
+% \end{syntax}
+% Declares that the \meta{replacement} tokens should be used whenever the
+% \meta{cmd} (a single token) is encountered during case changing.
+% \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}
+% \end{syntax}
+% Context-sensitive function which will expand to one of the \meta{normal},
+% \meta{upper}, \meta{lower} or \meta{title} tokens depending on the current
+% case changing operation. Outside of case changing, the \meta{normal} tokens
+% are produced. Within case changing, the appropriate mapping tokens are
+% inserted.
+% \end{function}
+%
% \section{Removing formatting from text}
%
% \begin{function}[EXP, added = 2020-03-05, updated = 2020-05-14]{\text_purify:n}
@@ -945,6 +968,7 @@
{
\exp_not:V \l_text_math_arg_tl
\exp_not:V \l_text_expand_exclude_tl
+ \exp_not:N \text_case_switch:nnnn
}
#1
}
diff --git a/l3kernel/testfiles/m3text002.luatex.tlg b/l3kernel/testfiles/m3text002.luatex.tlg
index 648742941..48f2914f7 100644
--- a/l3kernel/testfiles/m3text002.luatex.tlg
+++ b/l3kernel/testfiles/m3text002.luatex.tlg
@@ -338,3 +338,21 @@ l. ... }
<recently read> }
l. ... }
============================================================
+============================================================
+TEST 29: Case change switching
+============================================================
+UPPER
+lower
+Title
+WORDS UPPER
+words lower
+Words lower
+============================================================
+============================================================
+TEST 30: Case change replacements
+============================================================
+Defining \l__text_case_\foo_tl on line ...
+> fooreplaced.
+<recently read> }
+l. ... }
+============================================================
diff --git a/l3kernel/testfiles/m3text002.lvt b/l3kernel/testfiles/m3text002.lvt
index 838f57960..838c69e89 100644
--- a/l3kernel/testfiles/m3text002.lvt
+++ b/l3kernel/testfiles/m3text002.lvt
@@ -360,4 +360,28 @@
{ \text_lowercase:n { \use:n { FOO } \NoCaseChange { BAR } } }
}
+\cs_set:Npn \test:n #1
+ {
+ \text_uppercase:n {#1} \NEWLINE
+ \text_lowercase:n {#1} \NEWLINE
+ \text_titlecase:n {#1} \NEWLINE
+ }
+
+\TESTEXP { Case~change~switching }
+ {
+ \test:n { \text_case_switch:nnnn { normal } { lower } { UPPER } { Title } }
+ \test:n
+ {
+ words ~
+ \text_case_switch:nnnn { normal } { lower } { UPPER } { Title }
+ }
+ }
+
+\TEST { Case~change~replacements }
+ {
+ \text_declare_case_equivalent:Nn \foo { REPLACED }
+ \tl_show:x
+ { \text_lowercase:n { \use:n { FOO } \foo } }
+ }
+
\END
diff --git a/l3kernel/testfiles/m3text002.tlg b/l3kernel/testfiles/m3text002.tlg
index 7e9989eb3..4c8992e95 100644
--- a/l3kernel/testfiles/m3text002.tlg
+++ b/l3kernel/testfiles/m3text002.tlg
@@ -334,3 +334,21 @@ l. ... }
<recently read> }
l. ... }
============================================================
+============================================================
+TEST 29: Case change switching
+============================================================
+UPPER
+lower
+Title
+WORDS UPPER
+words lower
+Words lower
+============================================================
+============================================================
+TEST 30: Case change replacements
+============================================================
+Defining \l__text_case_\foo_tl on line ...
+> fooreplaced.
+<recently read> }
+l. ... }
+============================================================
diff --git a/l3kernel/testfiles/m3text002.uptex.tlg b/l3kernel/testfiles/m3text002.uptex.tlg
index 54b17748f..430127527 100644
--- a/l3kernel/testfiles/m3text002.uptex.tlg
+++ b/l3kernel/testfiles/m3text002.uptex.tlg
@@ -334,3 +334,21 @@ l. ... }
<recently read> }
l. ... }
============================================================
+============================================================
+TEST 29: Case change switching
+============================================================
+UPPER
+lower
+Title
+WORDS UPPER
+words lower
+Words lower
+============================================================
+============================================================
+TEST 30: Case change replacements
+============================================================
+Defining \l__text_case_\foo_tl on line ...
+> fooreplaced.
+<recently read> }
+l. ... }
+============================================================
diff --git a/l3kernel/testfiles/m3text002.xetex.tlg b/l3kernel/testfiles/m3text002.xetex.tlg
index 648742941..48f2914f7 100644
--- a/l3kernel/testfiles/m3text002.xetex.tlg
+++ b/l3kernel/testfiles/m3text002.xetex.tlg
@@ -338,3 +338,21 @@ l. ... }
<recently read> }
l. ... }
============================================================
+============================================================
+TEST 29: Case change switching
+============================================================
+UPPER
+lower
+Title
+WORDS UPPER
+words lower
+Words lower
+============================================================
+============================================================
+TEST 30: Case change replacements
+============================================================
+Defining \l__text_case_\foo_tl on line ...
+> fooreplaced.
+<recently read> }
+l. ... }
+============================================================
More information about the latex3-commits
mailing list.