[latex3-commits] [git/LaTeX3-latex3-latex3] master: Add \tl_if_eq:NnTF and document tl_if_eq/str_if_eq relation (fixes #691) (9f09eb56c)
Bruno Le Floch
bruno at le-floch.fr
Tue Jul 14 17:45:48 CEST 2020
Repository : https://github.com/latex3/latex3
On branch : master
Link : https://github.com/latex3/latex3/commit/9f09eb56cfc619df7c90dea98ce311171e3c0b03
>---------------------------------------------------------------
commit 9f09eb56cfc619df7c90dea98ce311171e3c0b03
Author: Bruno Le Floch <bruno at le-floch.fr>
Date: Tue Jul 14 17:45:48 2020 +0200
Add \tl_if_eq:NnTF and document tl_if_eq/str_if_eq relation (fixes #691)
>---------------------------------------------------------------
9f09eb56cfc619df7c90dea98ce311171e3c0b03
l3kernel/l3str.dtx | 6 +++--
l3kernel/l3tl.dtx | 50 +++++++++++++++++++++++++++++++++++++-----
l3kernel/testfiles/m3tl001.lvt | 18 +++++++++++++--
l3kernel/testfiles/m3tl001.tlg | 16 +++++++++++++-
4 files changed, 79 insertions(+), 11 deletions(-)
diff --git a/l3kernel/l3str.dtx b/l3kernel/l3str.dtx
index a6fad22d0..7b1f9ef64 100644
--- a/l3kernel/l3str.dtx
+++ b/l3kernel/l3str.dtx
@@ -306,7 +306,8 @@
% \end{syntax}
% Compares the content of two \meta{str variables} and
% is logically \texttt{true} if the two contain the same characters
-% in the same order.
+% in the same order. See \cs{tl_if_eq:NNTF} to compare tokens
+% (including their category codes) rather than characters.
% \end{function}
%
% \begin{function}[EXP,pTF, updated = 2018-06-18]
@@ -326,7 +327,8 @@
% \begin{verbatim}
% \str_if_eq_p:no { abc } { \tl_to_str:n { abc } }
% \end{verbatim}
-% is logically \texttt{true}.
+% is logically \texttt{true}. See \cs{tl_if_eq:nnTF} to compare
+% tokens (including their category codes) rather than characters.
% \end{function}
%
% \begin{function}[TF, added = 2017-10-08]{\str_if_in:Nn, \str_if_in:cn}
diff --git a/l3kernel/l3tl.dtx b/l3kernel/l3tl.dtx
index b10167ca2..56d558bbf 100644
--- a/l3kernel/l3tl.dtx
+++ b/l3kernel/l3tl.dtx
@@ -401,6 +401,19 @@
% \tl_if_eq:NNTF \l_tmpa_tl \l_tmpb_tl { true } { false }
% \end{verbatim}
% yields \texttt{false}.
+% See also \cs{str_if_eq:nnTF} for a comparison that ignores category codes.
+% \end{function}
+%
+% \begin{function}[TF, added = 2020-07-14]{\tl_if_eq:Nn, \tl_if_eq:cn}
+% \begin{syntax}
+% \cs{tl_if_eq:NnTF} \meta{tl~var_1} \Arg{token list_2} \Arg{true code} \Arg{false code}
+% \end{syntax}
+% Tests if the \meta{token list variable_1} and the \meta{token
+% list_2} contain the same list of tokens, both in respect of
+% character codes and category codes. This conditional is not
+% expandable: see \cs{tl_if_eq:NNTF} for an expandable version when
+% both token lists are stored in variables, or \cs{str_if_eq:nnTF} if
+% category codes are not important.
% \end{function}
%
% \begin{function}[TF]{\tl_if_eq:nn}
@@ -409,7 +422,9 @@
% \end{syntax}
% Tests if \meta{token list_1} and \meta{token list_2} contain the
% same list of tokens, both in respect of character codes and category
-% codes.
+% codes. This conditional is not expandable: see \cs{tl_if_eq:NNTF}
+% for an expandable version when token lists are stored in variables,
+% or \cs{str_if_eq:nnTF} if category codes are not important.
% \end{function}
%
% \begin{function}[TF]{\tl_if_in:Nn, \tl_if_in:cn}
@@ -1203,7 +1218,7 @@
% will \emph{not} match the simple text input |-NoValue-|, \emph{i.e.}
% that
% \begin{verbatim}
-% \tl_if_eq:VnTF \c_novalue_tl { -NoValue- }
+% \tl_if_eq:NnTF \c_novalue_tl { -NoValue- }
% \end{verbatim}
% is logically \texttt{false}. The \cs{c_novalue_tl} marker is intended for
% use in creating document-level interfaces, where it serves as an indicator
@@ -2125,8 +2140,34 @@
% \end{macrocode}
% \end{macro}
%
-% \begin{macro}[TF]{\tl_if_eq:nn}
% \begin{variable}{\l_@@_internal_a_tl, \l_@@_internal_b_tl}
+% Temporary storage.
+% \begin{macrocode}
+\tl_new:N \l_@@_internal_a_tl
+\tl_new:N \l_@@_internal_b_tl
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{macro}[TF]{\tl_if_eq:Nn}
+% A simple store and compare routine.
+% \begin{macrocode}
+\prg_new_protected_conditional:Npnn \tl_if_eq:Nn #1#2 { T , F , TF }
+ {
+ \group_begin:
+ \tl_set:Nn \l_@@_internal_b_tl {#2}
+ \exp_after:wN
+ \group_end:
+ \if_meaning:w #1 \l_@@_internal_b_tl
+ \prg_return_true:
+ \else:
+ \prg_return_false:
+ \fi:
+ }
+\prg_generate_conditional_variant:Nnn \tl_if_eq:Nn { c } { TF , T , F }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[TF]{\tl_if_eq:nn}
% A simple store and compare routine.
% \begin{macrocode}
\prg_new_protected_conditional:Npnn \tl_if_eq:nn #1#2 { T , F , TF }
@@ -2142,10 +2183,7 @@
\prg_return_false:
\fi:
}
-\tl_new:N \l_@@_internal_a_tl
-\tl_new:N \l_@@_internal_b_tl
% \end{macrocode}
-% \end{variable}
% \end{macro}
%
% \begin{macro}[TF]{\tl_if_in:Nn, \tl_if_in:cn}
diff --git a/l3kernel/testfiles/m3tl001.lvt b/l3kernel/testfiles/m3tl001.lvt
index f30f1d1d4..d6eafaccf 100644
--- a/l3kernel/testfiles/m3tl001.lvt
+++ b/l3kernel/testfiles/m3tl001.lvt
@@ -1,5 +1,5 @@
%
-% Copyright (C) 2008-2012,2015,2018 The LaTeX3 Project
+% Copyright (C) 2008-2012,2015,2018,2020 The LaTeX3 Project
%
\documentclass{minimal}
\input{regression-test}
@@ -11,7 +11,7 @@
\begin{document}
\START
-\AUTHOR{Frank Mittelbach}
+\AUTHOR{Frank Mittelbach, Bruno Le Floch}
\ExplSyntaxOn
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -185,6 +185,20 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\TEST{test~ for~ equal:~ YES,YES,!,!,NO,YES,!,!,NO,NO }{
+\tl_if_eq:NnTF \l_tmpa_tl { } \YES \NO
+\tl_if_eq:NnT \l_tmpb_tl {abc} \YES
+\TYPE{!}\tl_if_eq:cnF { l_tmpb_tl } {abc} \NO\TYPE{!}
+\tl_if_eq:NnTF \l_tmpa_tl { \c_empty_tl } \YES \NO
+\NEWLINE
+\tl_if_eq:nnTF { } { } \YES \NO
+\TYPE{!}\tl_if_eq:nnT {abc} {b} \YES\TYPE{!}
+\tl_if_eq:nnF {abc} {~abc} \NO
+\tl_if_eq:nnTF { } { \c_empty_tl } \YES \NO
+}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
\END
diff --git a/l3kernel/testfiles/m3tl001.tlg b/l3kernel/testfiles/m3tl001.tlg
index b9a8e376b..df1ca29e2 100644
--- a/l3kernel/testfiles/m3tl001.tlg
+++ b/l3kernel/testfiles/m3tl001.tlg
@@ -1,6 +1,6 @@
This is a generated file for the LaTeX (2e + expl3) validation system.
Don't change this file in any respect.
-Author: Frank Mittelbach
+Author: Frank Mittelbach, Bruno Le Floch
============================================================
TEST 1: allocate new variables
============================================================
@@ -71,3 +71,17 @@ TEST 11: test for equal: expect YES YES !! NO
============================================================
YES YES !! NO
============================================================
+============================================================
+TEST 12: test for equal: YES,YES,!,!,NO,YES,!,!,NO,NO
+============================================================
+YES
+YES
+!
+!
+NO
+YES
+!
+!
+NO
+NO
+============================================================
More information about the latex3-commits
mailing list.