[latex3-commits] [git/LaTeX3-latex3-latex3] main: Make \AssignTemplateKeys optional (ea73d0649)
Joseph Wright
joseph.wright at morningstar2.co.uk
Mon May 30 10:59:32 CEST 2022
Repository : https://github.com/latex3/latex3
On branch : main
Link : https://github.com/latex3/latex3/commit/ea73d0649a38472f73e22a1d27644ee535de2a0e
>---------------------------------------------------------------
commit ea73d0649a38472f73e22a1d27644ee535de2a0e
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Mon May 30 09:59:32 2022 +0100
Make \AssignTemplateKeys optional
This is needed to remove the command as a transition pathway,
but I suspect it probably works quite nicely as a permanent
change. This way one _can_ delay assignments but do not have to
always include them.
>---------------------------------------------------------------
ea73d0649a38472f73e22a1d27644ee535de2a0e
l3experimental/xgalley/xgalley-demo.tex | 1 -
l3experimental/xgalley/xgalley.dtx | 13 +----------
l3packages/CHANGELOG.md | 1 +
l3packages/xfrac/xfrac.dtx | 1 -
.../xtemplate/testfiles-broken/xtemplate004.lvt | 6 ++---
l3packages/xtemplate/testfiles/xtemplate002.lvt | 15 +++----------
l3packages/xtemplate/testfiles/xtemplate003.lvt | 18 +++++++--------
l3packages/xtemplate/testfiles/xtemplate003.tlg | 2 +-
l3packages/xtemplate/testfiles/xtemplate005.lvt | 3 ---
l3packages/xtemplate/xtemplate.dtx | 26 +++++++++++++++++-----
l3trial/l3ldb/testfiles/m3ldb003.lvt | 3 +--
11 files changed, 38 insertions(+), 51 deletions(-)
diff --git a/l3experimental/xgalley/xgalley-demo.tex b/l3experimental/xgalley/xgalley-demo.tex
index aa35810a6..676801a96 100644
--- a/l3experimental/xgalley/xgalley-demo.tex
+++ b/l3experimental/xgalley/xgalley-demo.tex
@@ -21,7 +21,6 @@
parshape-list = \l_galley_parshape_clist
}
{
- \AssignTemplateKeys
\bool_if:NT \l_galley_parshape_no_break_bool
{ \bool_gset_true:N \g_galley_no_break_next_bool }
\clist_clear:N \l_tmpa_clist
diff --git a/l3experimental/xgalley/xgalley.dtx b/l3experimental/xgalley/xgalley.dtx
index 1d721dd59..2ceab8e34 100644
--- a/l3experimental/xgalley/xgalley.dtx
+++ b/l3experimental/xgalley/xgalley.dtx
@@ -787,7 +787,6 @@
right-margin = \l_@@_right_margin_dim
}
{
- \AssignTemplateKeys
\galley_margins_set_absolute:nn \l_@@_left_margin_dim
\l_@@_right_margin_dim
}
@@ -801,7 +800,6 @@
right-margin = \l_@@_right_margin_dim
}
{
- \AssignTemplateKeys
\galley_margins_set_relative:nn \l_@@_left_margin_dim
\l_@@_right_margin_dim
}
@@ -850,7 +848,6 @@
lines = \l_@@_parshape_lines_int
}
{
- \AssignTemplateKeys
\bool_if:NTF \l_@@_parshape_on_left_bool
{
\galley_parshape_set_single:nVVN
@@ -874,7 +871,6 @@
lines = \l_@@_parshape_lines_int
}
{
- \AssignTemplateKeys
\clist_clear:N \l_@@_tmpa_clist
\clist_clear:N \l_@@_tmpb_clist
\prg_replicate:nn { \l_@@_parshape_lines_int }
@@ -961,7 +957,6 @@
}
}
{
- \AssignTemplateKeys
\int_set:Nn \tex_lefthyphenmin:D
{
\bool_if:NTF \l_galley_hyphen_enable_bool
@@ -1038,7 +1033,6 @@
stretch-last-line = \l_galley_par_stretch_last_bool
}
{
- \AssignTemplateKeys
\tl_clear:N \l_@@_justification_other_tl
\galley_interword_spacing_set:N \l_galley_fixed_spacing_bool
\bool_if:NTF \l_galley_par_stretch_last_bool
@@ -1171,7 +1165,6 @@
other-paragraphs = \@@_justification_other:
}
{
- \AssignTemplateKeys
\@@_justification_first:
\tl_set:Nn \l_@@_justification_other_tl
{ \@@_justification_other: }
@@ -1224,7 +1217,7 @@
relation-penalty = \l_@@_relation_penalty_int ,
tolerance = \l_galley_linebreak_tolerance_int
}
- { \AssignTemplateKeys }
+ { }
% \end{macrocode}
% The default values are set such that they are suitable for good
% quality typesetting. So the standard template changes nothing at
@@ -1280,7 +1273,6 @@
widow-penalty = \l_@@_widow_penalty_int
}
{
- \AssignTemplateKeys
\galley_club_penalties_set:V \l_@@_club_penalty_int
\galley_display_club_penalties_set:V \l_@@_display_club_penalty_int
\galley_display_widow_penalties_set:V \l_@@_display_widow_penalty_int
@@ -1357,7 +1349,6 @@
widow-penalty = \l_@@_widow_penalties_tl
}
{
- \AssignTemplateKeys
% \end{macrocode}
% The fuzz and interline penalties are handled explicitly as they have
% particular requirements.
@@ -1493,7 +1484,6 @@
space = \l_galley_display_begin_vspace_tl
}
{
- \AssignTemplateKeys
\tl_if_empty:NF \l_galley_display_begin_par_vpenalty_tl
{
\tl_set:Nx \l_galley_display_begin_par_vpenalty_tl
@@ -1523,7 +1513,6 @@
space = \l_galley_display_end_vspace_tl
}
{
- \AssignTemplateKeys
\tl_if_empty:NF \l_galley_display_end_par_vpenalty_tl
{
\tl_set:Nx \l_galley_display_end_par_vpenalty_tl
diff --git a/l3packages/CHANGELOG.md b/l3packages/CHANGELOG.md
index bae542aed..ef57aeb7c 100644
--- a/l3packages/CHANGELOG.md
+++ b/l3packages/CHANGELOG.md
@@ -9,6 +9,7 @@ this project uses date-based 'snapshot' version identifiers.
### Changed
- Allow for _ad hoc_ adjustment of template values
+- Make `\AssignTemplateKeys` optional
### Removed
- `\EvaluateNow` command
diff --git a/l3packages/xfrac/xfrac.dtx b/l3packages/xfrac/xfrac.dtx
index 4fb469ae5..3d32ae6c4 100644
--- a/l3packages/xfrac/xfrac.dtx
+++ b/l3packages/xfrac/xfrac.dtx
@@ -781,7 +781,6 @@
% whether the surroundings are text or math(s), and react accordingly.
% \begin{macrocode}
{
- \AssignTemplateKeys
\mode_if_math:TF
{
\cs_set_eq:NN \@@_text_or_math:n \text
diff --git a/l3packages/xtemplate/testfiles-broken/xtemplate004.lvt b/l3packages/xtemplate/testfiles-broken/xtemplate004.lvt
index a4529cefa..ae8d237a1 100644
--- a/l3packages/xtemplate/testfiles-broken/xtemplate004.lvt
+++ b/l3packages/xtemplate/testfiles-broken/xtemplate004.lvt
@@ -34,7 +34,7 @@
B = \typeout{huh}
}
}
- { \AssignTemplateKeys \typeout{(#1)}}
+ { \typeout{(#1)}}
\TIMO
@@ -55,7 +55,7 @@
unknown = \typeout{Hi} ,
}
}
- { \AssignTemplateKeys }
+ { }
\UseTemplate {test}{tname2}{}{X} % gives unknown case, ok
\UseTemplate {test}{tname2}{key=A}{X}
@@ -69,7 +69,7 @@
B = \typeout{huh}
}
}
- { \AssignTemplateKeys }
+ { }
\UseTemplate {test}{tname2}{key=don't say hi}{X} %still a bit strange
\UseTemplate {test}{tname2}{key=A}{X}
diff --git a/l3packages/xtemplate/testfiles/xtemplate002.lvt b/l3packages/xtemplate/testfiles/xtemplate002.lvt
index 7c3dfa2d4..33ce2a33a 100644
--- a/l3packages/xtemplate/testfiles/xtemplate002.lvt
+++ b/l3packages/xtemplate/testfiles/xtemplate002.lvt
@@ -33,10 +33,7 @@
bkey = \bbb ,
ckey = global \ccc ,
}
-{
- \AssignTemplateKeys
- \typeout{(a:~\aaa)~(b:~\bbb)~(c:~\ccc)}
-}
+{ \typeout{(a:~\aaa)~(b:~\bbb)~(c:~\ccc)} }
\DeclareInstance {obj}{inst} {tmpt1}{akey=foo}
\DeclareInstance {obj}{inst2}{tmpt1}{akey=bar,bkey=baz,ckey=glob}
\TIMO
@@ -61,10 +58,7 @@
{
akey = \def\aaa{#1},
}
-{
- \AssignTemplateKeys
- \TYPE{(a:~\aaa)}
-}
+{ \TYPE{(a:~\aaa)} }
\DeclareInstance {obj}{inst3} {tmpt2}{akey=a!}
\TIMO
@@ -89,10 +83,7 @@
unknown = \def\ccc{key?} ,
},
}
-{
- \AssignTemplateKeys
- \typeout{(c:~\ccc)}
-}
+{ \typeout{(c:~\ccc)} }
\DeclareInstance {obj}{inst4} {tmpt3}{ckey=xx}
\DeclareInstance {obj}{inst5} {tmpt3}{ckey=yy}
diff --git a/l3packages/xtemplate/testfiles/xtemplate003.lvt b/l3packages/xtemplate/testfiles/xtemplate003.lvt
index a8ac4aeca..564ec51e1 100644
--- a/l3packages/xtemplate/testfiles/xtemplate003.lvt
+++ b/l3packages/xtemplate/testfiles/xtemplate003.lvt
@@ -38,7 +38,7 @@
int = \l_test_int ,
text = \l_tmpa_tl
}
- { \AssignTemplateKeys \typeout{(#1 - \int_use:N \l_test_int )}}
+ { \typeout{(#1 - \int_use:N \l_test_int )}}
\TIMO
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -225,9 +225,7 @@
\DeclareTemplateCode{test} {tname} {1} {
k e y 1 = \l_X_tl , % missing key - detected, ok
- }{
- \AssignTemplateKeys
- }
+ }{ }
\UseTemplate{test} {tname} {key1=heh, key2=hi}{woah}
}
@@ -246,7 +244,7 @@
\DeclareTemplateCode{test} {tname} {1} {
k e y 1 = \l_X_tl , % using same var twice not detected
k ey 2 = \l_X_tl ,
- }{ } % missing \AssignTemplateKeys
+ }{ }
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -263,7 +261,7 @@
\DeclareTemplateCode{test} {tname3} {1} { % this is currently missing
k e y 1 = \l_X_tl , % error for undeclared vars
k ey 2 = \l_Y_tl ,
- }{ \AssignTemplateKeys}
+ }{ }
\ShowTemplateCode {test} {tname3}
\ShowTemplateVariables {test} {tname3}
@@ -294,7 +292,7 @@
k ey 2 = glabol \l_Y_tl , % error, ok - but should this be
% stored incorrectly?
k e y3 = global \l_X_int ,
- }{ \AssignTemplateKeys}
+ }{ }
\ShowTemplateCode {test} {tname3}
\ShowTemplateVariables {test} {tname3}
}
@@ -325,7 +323,7 @@
B = \typeout{huh}
}
}
- { \AssignTemplateKeys }
+ { }
\ShowTemplateCode {test} {tname3}
\ShowTemplateVariables {test} {tname3}
@@ -389,7 +387,7 @@
B = \typeout{huh}
}
}
- { \AssignTemplateKeys \typeout{(#1)}}
+ { \typeout{(#1)}}
\ShowTemplateDefaults {test} {tname3}
@@ -410,7 +408,7 @@
unknown = \typeout{hi}
}
}
- { \AssignTemplateKeys \typeout{(#1)}}
+ { \typeout{(#1)}}
\ShowTemplateDefaults {test} {tname3}
\EditTemplateDefaults {test} {tname3} {key = C }
diff --git a/l3packages/xtemplate/testfiles/xtemplate003.tlg b/l3packages/xtemplate/testfiles/xtemplate003.tlg
index ea38915d0..680b1fdf5 100644
--- a/l3packages/xtemplate/testfiles/xtemplate003.tlg
+++ b/l3packages/xtemplate/testfiles/xtemplate003.tlg
@@ -305,7 +305,7 @@ TEST 15: Testing code interface: choices
TEST 16: Testing interfaces in document preamble
============================================================
Package xtemplate Info: Declaring object type 'test' taking 1 argument(s) on
-(xtemplate) line 332.
+(xtemplate) line 330.
> \template code > test/tname3=\protected\long macro:#1->\AssignTemplateKeys .
<recently read> }
l. ...}
diff --git a/l3packages/xtemplate/testfiles/xtemplate005.lvt b/l3packages/xtemplate/testfiles/xtemplate005.lvt
index b369023ab..909dffab0 100644
--- a/l3packages/xtemplate/testfiles/xtemplate005.lvt
+++ b/l3packages/xtemplate/testfiles/xtemplate005.lvt
@@ -32,7 +32,6 @@
tl-b = \l_tmpb_tl
}
{
- \AssignTemplateKeys
\typeout { \dim_use:N \l_tmpb_dim }
\typeout { \tl_use:N \l_tmpb_tl }
}
@@ -57,7 +56,6 @@
tl-b = \l_tmpb_tl
}
{
- \AssignTemplateKeys
\typeout { \dim_use:N \l_tmpb_dim }
\typeout { \tl_use:N \l_tmpb_tl }
}
@@ -81,7 +79,6 @@
bool-b = \l_tmpb_bool
}
{
- \AssignTemplateKeys
\typeout { \bool_if:NTF \l_tmpa_bool { true } { false } }
\typeout { \bool_if:NTF \l_tmpb_bool { true } { false } }
}
diff --git a/l3packages/xtemplate/xtemplate.dtx b/l3packages/xtemplate/xtemplate.dtx
index 0156cf205..caea60d1c 100644
--- a/l3packages/xtemplate/xtemplate.dtx
+++ b/l3packages/xtemplate/xtemplate.dtx
@@ -358,9 +358,12 @@
% \cs{AssignTemplateKeys}
% \end{syntax}
% In the final argument of \cs{DeclareTemplateCode} the assignment of
-% keys defined by the template is carried out by using the function
-% \cs{AssignTemplateKeys}. Thus no keys are assigned if this is missing
-% from the \meta{code} used.
+% keys defined by the template may be delayed by including the command
+% \cs{AssignTemplateKeys}. If this is \emph{not} present, keys are assigned
+% immediately before the template code. If \cs{AssignTemplateKeys} is
+% present, assignment is delayed until this point. Note that the
+% command must be \emph{directly} present in the code, not placed
+% within a nested command/macro.
% \end{function}
%
% \section{Multiple choices}
@@ -1475,6 +1478,7 @@
% \subsection{Implementation part of template declaration}
%
% \begin{macro}{\@@_declare_template_code:nnnnn}
+% \begin{macro}{\@@_declare_template_code:nnn}
% The main function for implementing a template starts with a couple of
% simple checks to make sure that there are no obvious mistakes: the
% number of arguments must agree and the template keys must have been
@@ -1489,15 +1493,25 @@
\@@_if_keys_exist:nnT {#1} {#2}
{
\@@_store_key_implementation:nnn {#1} {#2} {#4}
- \cs_generate_from_arg_count:cNnn
- { \c_@@_code_root_tl #1 / #2 }
- \cs_gset_protected:Npn {#3} {#5}
+ \regex_match:nnTF { \c { AssignTemplateKeys } } {#5}
+ { \@@_declare_template_code:nnn { #1 / #2 } {#3} {#5} }
+ {
+ \@@_declare_template_code:nnn
+ { #1 / #2 } {#3} { \AssignTemplateKeys #5 }
+ }
}
}
}
}
+\cs_new_protected:Npn \@@_declare_template_code:nnn #1#2#3
+ {
+ \cs_generate_from_arg_count:cNnn
+ { \c_@@_code_root_tl #1 }
+ \cs_gset_protected:Npn {#2} {#3}
+ }
% \end{macrocode}
% \end{macro}
+% \end{macro}
%
% \begin{macro}{\@@_store_key_implementation:nnn}
% Actually storing the implementation part of a template is quite easy
diff --git a/l3trial/l3ldb/testfiles/m3ldb003.lvt b/l3trial/l3ldb/testfiles/m3ldb003.lvt
index ddf76603e..f064c7980 100644
--- a/l3trial/l3ldb/testfiles/m3ldb003.lvt
+++ b/l3trial/l3ldb/testfiles/m3ldb003.lvt
@@ -105,7 +105,6 @@
\cs_set:Npn \MaybeExecuteEndCode {\endlist}
\list { \list_label_text: }
{
- \AssignTemplateKeys
% if no value given for \labelwidth use default calculation:
\dim_compare:nNnT \labelwidth = \maxdimen
{ \dim_set:Nn \labelwidth { \leftmargin - \labelsep } }
@@ -125,7 +124,7 @@
\DeclareObjectType{listitem}{0}
\DeclareTemplateInterface {listitem} {std} {0} { }
\DeclareTemplateCode {listitem} {std} {0}
- { } { \AssignTemplateKeys \origitem }
+ { } { \origitem }
\ExplSyntaxOff
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
More information about the latex3-commits
mailing list.