[latex3-commits] [git/LaTeX3-latex3-latex2e] template: Include \IfInstanceExist(TF) in lttemplate (39905349)
Joseph Wright
joseph.wright at morningstar2.co.uk
Sun Jun 5 13:39:16 CEST 2022
Repository : https://github.com/latex3/latex2e
On branch : template
Link : https://github.com/latex3/latex2e/commit/39905349dc754fa9b0279fd0d81cd4daf1d2b497
>---------------------------------------------------------------
commit 39905349dc754fa9b0279fd0d81cd4daf1d2b497
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Sun Jun 5 12:39:16 2022 +0100
Include \IfInstanceExist(TF) in lttemplate
This is used in a number of packages:
suggests it should be stable.
>---------------------------------------------------------------
39905349dc754fa9b0279fd0d81cd4daf1d2b497
base/doc/usrguide3.tex | 8 ++++++++
base/lttemplate.dtx | 25 +++++++++++++++++++++++++
base/testfiles-lttemplate/lttemplate003.lvt | 26 ++++++++++++++++++++++++++
base/testfiles-lttemplate/lttemplate003.tlg | 12 ++++++++++--
4 files changed, 69 insertions(+), 2 deletions(-)
diff --git a/base/doc/usrguide3.tex b/base/doc/usrguide3.tex
index 399539c1..943263d3 100644
--- a/base/doc/usrguide3.tex
+++ b/base/doc/usrguide3.tex
@@ -1444,6 +1444,14 @@ read:
Of course, the key names here are entirely imaginary, but illustrate
the general idea of fixing some settings.
+\begin{decl}
+ |\IfInstanceExistT| \arg{obj.~type} \arg{instance} \arg{true code} \\
+ |\IfInstanceExistF| \arg{obj.~type} \arg{instance} \arg{false code} \\
+ |\IfInstanceExistTF| \arg{obj.~type} \arg{instance} \arg{true code} \arg{false code}
+\end{decl}
+Tests if the named \meta{instance} of a \meta{object type} exists, and
+then inserts the appropriate code into the input stream.
+
\subsection{Document interface}
After the instances have been chosen, document commands must be
diff --git a/base/lttemplate.dtx b/base/lttemplate.dtx
index a006d162..d55e173a 100644
--- a/base/lttemplate.dtx
+++ b/base/lttemplate.dtx
@@ -358,6 +358,19 @@
% \end{macrocode}
% \end{macro}
%
+% \begin{macro}[TF]{\@@_if_instance_exist:nn}
+% Testing for an instance.
+% \begin{macrocode}
+\prg_new_conditional:Npnn \@@_if_instance_exist:nn #1#2
+ { T, F, TF }
+ {
+ \cs_if_exist:cTF { \c_@@_instances_root_tl #1 / #2 }
+ { \prg_return_true: }
+ { \prg_return_false: }
+ }
+% \end{macrocode}
+% \end{macro}
+%
% \begin{macro}{\@@_if_use_template:nTF}
% Tests for the first token in a string being \cs{UseTemplate}.
% \begin{macrocode}
@@ -1954,6 +1967,18 @@
% \end{macro}
% \end{macro}
%
+% \begin{macro}[TF]{\IfInstanceExist}
+% Simple copies.
+% \begin{macrocode}
+\cs_new:Npn \IfInstanceExistTF #1#2
+ { \@@_if_instance_exist:nnTF {#1} {#2} }
+\cs_new:Npn \IfInstanceExistT #1#2
+ { \@@_if_instance_exist:nnT {#1} {#2} }
+\cs_new:Npn \IfInstanceExistF #1#2
+ { \@@_if_instance_exist:nnF {#1} {#2} }
+% \end{macrocode}
+% \end{macro}
+%
% \begin{macro}{\KeyValue}
% Simply dump the argument when executed: this should not happen.
% \begin{macrocode}
diff --git a/base/testfiles-lttemplate/lttemplate003.lvt b/base/testfiles-lttemplate/lttemplate003.lvt
index 951bf353..8811d142 100644
--- a/base/testfiles-lttemplate/lttemplate003.lvt
+++ b/base/testfiles-lttemplate/lttemplate003.lvt
@@ -329,6 +329,32 @@
\ShowTemplateVariables {test} {tname3}
}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% 17
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\TEST{Testing~instances:~existance~check}{
+
+ \IfInstanceExistTF {test} {nono} % instance unknwon, ok
+ {\typeout{Yes}} {\typeout{No}}
+
+ \IfInstanceExistTF {missingobjecttype} {nono} % objecttype unknown, ok
+ {\typeout{Yes}} {\typeout{No}}
+
+ \group_begin:
+
+ \DeclareInstance {test} {myinstance} {tname2} {}
+
+ \IfInstanceExistTF {test} {myinstance} % test inside group, ok
+ {\typeout{Yes}} {\typeout{No}}
+
+ \group_end:
+
+ \IfInstanceExistTF {test} {myinstance} % test outside group
+ {\typeout{Yes}} {\typeout{No}} % no longer defined, ok
+
+}
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 18
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/base/testfiles-lttemplate/lttemplate003.tlg b/base/testfiles-lttemplate/lttemplate003.tlg
index f703f8a6..bf7cb034 100644
--- a/base/testfiles-lttemplate/lttemplate003.tlg
+++ b/base/testfiles-lttemplate/lttemplate003.tlg
@@ -318,7 +318,16 @@ The template 'tname3' of object type 'test' has variable mapping:
l. ...}
============================================================
============================================================
-TEST 17: Testing instances: declare instance
+TEST 17: Testing instances: existance check
+============================================================
+No
+No
+Defining \template values > test/myinstance on line ...
+Yes
+No
+============================================================
+============================================================
+TEST 18: Testing instances: declare instance
============================================================
! Package template Error: The template 'never-defined' of type 'test' is
(template) unknown or has no implementation.
@@ -327,7 +336,6 @@ For immediate help type H <return>.
l. ...}
There is no code available for the template name given.
This should be given using \DeclareTemplateCode .
-Defining \template values > test/myinstance on line ...
Defining \template values > test/myinstance2 on line ...
hello
(X-99)
More information about the latex3-commits
mailing list.