[latex3-commits] [git/LaTeX3-latex3-latex3] gh664-legacy-if: Implement \legacy_set_true_if:n and \legacy_set_if:nn (fixes #664) (ac07d4458)

Bruno Le Floch blflatex at gmail.com
Wed May 12 12:29:50 CEST 2021


Repository : https://github.com/latex3/latex3
On branch  : gh664-legacy-if
Link       : https://github.com/latex3/latex3/commit/ac07d44582f6cefe685b121400865bd65333c189

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

commit ac07d44582f6cefe685b121400865bd65333c189
Author: Bruno Le Floch <blflatex at gmail.com>
Date:   Tue May 11 00:59:07 2021 +0200

    Implement \legacy_set_true_if:n and \legacy_set_if:nn (fixes #664)


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

ac07d44582f6cefe685b121400865bd65333c189
 l3kernel/l3legacy.dtx                              | 56 ++++++++++++++++++++++
 l3kernel/testfiles/m3legacy001.lvt                 | 56 ++++++++++++++++++++++
 .../testfiles/{m3pdf001.tlg => m3legacy001.tlg}    | 18 ++++---
 3 files changed, 120 insertions(+), 10 deletions(-)

diff --git a/l3kernel/l3legacy.dtx b/l3kernel/l3legacy.dtx
index 05b98fed5..6d31c2002 100644
--- a/l3kernel/l3legacy.dtx
+++ b/l3kernel/l3legacy.dtx
@@ -63,6 +63,28 @@
 %   \meta{name} of the conditional should \emph{omit} the leading \texttt{if}.
 % \end{function}
 %
+% \begin{function}[added = 2021-05-10]
+%   {
+%     \legacy_set_true_if:n, \legacy_set_false_if:n,
+%     \legacy_gset_true_if:n, \legacy_gset_false_if:n
+%   }
+%   \begin{syntax}
+%     \cs{legacy_set_true_if:n} \Arg{name}
+%     \cs{legacy_set_false_if:n} \Arg{name}
+%   \end{syntax}
+%   Sets the \LaTeXe{}/plain \TeX{} conditional |\if|\meta{name}
+%   (generated by \tn{newif}) to be \texttt{true} or \texttt{false}.
+% \end{function}
+%
+% \begin{function}[added = 2021-05-10]{\legacy_set_if:nn, \legacy_gset_if:nn}
+%   \begin{syntax}
+%     \cs{legacy_set_if:nn} \Arg{name} \Arg{boolexpr}
+%   \end{syntax}
+%   Sets the \LaTeXe{}/plain \TeX{} conditional |\if|\meta{name}
+%   (generated by \tn{newif}) to the result of evaluating the
+%   \meta{boolean expression}.
+% \end{function}
+%
 % \end{documentation}
 %
 % \begin{implementation}
@@ -91,6 +113,40 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}
+%   {
+%     \legacy_set_true_if:n, \legacy_set_false_if:n,
+%     \legacy_gset_true_if:n, \legacy_gset_false_if:n
+%   }
+%   A friendly wrapper.
+%    \begin{macrocode}
+\cs_new_protected:Npn \legacy_set_true_if:n #1
+  { \cs_set_eq:cN { if#1 } \if_true: }
+\cs_new_protected:Npn \legacy_set_false_if:n #1
+  { \cs_set_eq:cN { if#1 } \if_false: }
+\cs_new_protected:Npn \legacy_gset_true_if:n #1
+  { \cs_gset_eq:cN { if#1 } \if_true: }
+\cs_new_protected:Npn \legacy_gset_false_if:n #1
+  { \cs_gset_eq:cN { if#1 } \if_false: }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\legacy_set_if:nn, \legacy_gset_if:nn}
+%   A more elaborate wrapper.
+%    \begin{macrocode}
+\cs_new_protected:Npn \legacy_set_if:nn #1#2
+  {
+    \bool_if:nTF {#2} \legacy_set_true_if:n \legacy_set_false_if:n
+    {#1}
+  }
+\cs_new_protected:Npn \legacy_gset_if:nn #1#2
+  {
+    \bool_if:nTF {#2} \legacy_gset_true_if:n \legacy_gset_false_if:n
+    {#1}
+  }
+%    \end{macrocode}
+% \end{macro}
+%
 %    \begin{macrocode}
 %</package>
 %    \end{macrocode}
diff --git a/l3kernel/testfiles/m3legacy001.lvt b/l3kernel/testfiles/m3legacy001.lvt
new file mode 100644
index 000000000..95b196e1b
--- /dev/null
+++ b/l3kernel/testfiles/m3legacy001.lvt
@@ -0,0 +1,56 @@
+%
+% Copyright (C) 2021 The LaTeX Project
+%
+
+\documentclass{minimal}
+\input{regression-test}
+% Leave some padding so that the line numbers
+% of the tests don't change later on.
+
+\RequirePackage[enable-debug]{expl3}
+\ExplSyntaxOn
+\debug_on:n { check-declarations , deprecation , log-functions }
+\ExplSyntaxOff
+
+\begin{document}
+\START
+\AUTHOR{Bruno Le Floch}
+\ExplSyntaxOn
+
+\def\Atrue{\let\ifA=\iftrue}
+\def\Afalse{\let\ifA=\iffalse}
+\Afalse
+\def\Btrue{\let\ifB=\iftrue}
+\def\Bfalse{\let\ifB=\iffalse}
+\Btrue
+\def\Ctrue{\let\ifC=\iftrue}
+\def\Cfalse{\let\ifC=\iffalse}
+\Ctrue
+
+\TEST { legacy~if }
+  {
+    \legacy_if:nTF { A } { \ERROR } { \FALSE }
+    \legacy_if:nF { B } { \ERROR }
+    \bool_if:nTF
+      { \legacy_if_p:n { A } || ! \legacy_if_p:n { B } }
+      { \ERROR } { \FALSE }
+  }
+
+\TEST { legacy~set }
+  {
+    \TYPE { \meaning \ifC }
+    \group_begin:
+      \legacy_set_if:nn { C } { \legacy_if_p:n { A } && \legacy_if_p:n { B } }
+      \TYPE { \meaning \ifC }
+    \group_end:
+    \TYPE { \meaning \ifC }
+    \group_begin:
+      \legacy_gset_false_if:n { C }
+      \TYPE { \meaning \ifC }
+    \group_end:
+    \TYPE { \meaning \ifC }
+  }
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\END
diff --git a/l3kernel/testfiles/m3pdf001.tlg b/l3kernel/testfiles/m3legacy001.tlg
similarity index 81%
copy from l3kernel/testfiles/m3pdf001.tlg
copy to l3kernel/testfiles/m3legacy001.tlg
index 42e0bd402..fe15927d9 100644
--- a/l3kernel/testfiles/m3pdf001.tlg
+++ b/l3kernel/testfiles/m3legacy001.tlg
@@ -1,20 +1,18 @@
 This is a generated file for the LaTeX (2e + expl3) validation system.
 Don't change this file in any respect.
-Author: Ulrike Fischer, Joseph Wright
+Author: Bruno Le Floch
 ============================================================
-TEST 1: Version comparison
+TEST 1: legacy if
 ============================================================
-TRUE
 FALSE
-TRUE
 FALSE
-FALSE
-TRUE
 ============================================================
 ============================================================
-TEST 2: Version
+TEST 2: legacy set
 ============================================================
-1.5
-1
-5
+\iftrue
+\iffalse
+\iftrue
+\iffalse
+\iffalse
 ============================================================





More information about the latex3-commits mailing list.