Skip to content

Commit

Permalink
Re-factor internals for template var setting
Browse files Browse the repository at this point in the history
  • Loading branch information
josephwright committed Apr 15, 2024
1 parent 990dfc6 commit 947d414
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 96 deletions.
3 changes: 3 additions & 0 deletions base/changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ to completeness or accuracy and it contains some references to files that are
not part of the distribution.
================================================================================

2024-04-15 Joseph Wright <Joseph.Wright@latex-project.org>
* lttemplates.dtx
Re-factor internals

2024-04-10 Frank Mittelbach <Frank.Mittelbach@latex-project.org>

Expand Down
143 changes: 47 additions & 96 deletions base/lttemplates.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
%<*driver>
% \fi
\ProvidesFile{lttemplates.dtx}
[2024-02-15 v1.0b LaTeX Kernel (Prototype document functions)]
[2024-04-15 v1.0c LaTeX Kernel (Prototype document functions)]
% \iffalse
\documentclass{l3doc}
\GetFileInfo{lttemplates.dtx}
Expand Down Expand Up @@ -274,6 +274,24 @@
% \end{verbatim}
% \end{function}
%
% \begin{function}{\DelayEvaluation}
% \begin{syntax}
% \cs{DelayEvaluation} \Arg{variable}
% \end{syntax}
% There are occasions where variables are set using information which is
% dependent on other document settings, for example the font using
% \texttt{em} or \texttt{ex} units. To allow for this, it may be necessary to
% delay setting of variables until an instance is used. This can be achieved
% using \cs{DelayEvaluation}:
% \begin{verbatim}
% \DeclareTemplateInterface { type } { template } { no. of args }
% {
% key-name-3 : key-type = \DelayEvaluation \SomeVariable,
% ...
% }
% \end{verbatim}
% \end{function}
%
% \begin{function}{\DeclareTemplateCode}
% \begin{syntax}
% \cs{DeclareTemplateCode}
Expand Down Expand Up @@ -318,7 +336,7 @@
% \toprule
% \multicolumn{1}{l}{Key-type} & Description of binding \\
% \midrule
% boolean & Boolean variable, \emph{e.g}.~\cs{l_tmpa_bool} \\
% \ & Boolean variable, \emph{e.g}.~\cs{l_tmpa_bool} \\
% choice
% & List of choice implementations
% (see Section~\ref{sec:choices-key}) \\
Expand Down Expand Up @@ -909,6 +927,18 @@
% \end{macrocode}
% \end{macro}
%
% \begin{macro}[TF]{\@@_if_delay_eval:n}

This comment has been minimized.

Copy link
@muzimuzhi

muzimuzhi Apr 17, 2024

Contributor

I saw the documentation and implementation of \DelayEvaluation added in this commit were reverted in f8791aa and 3a73f40. But this conditional \@@_if_delay_eval:n is kept.

Is it needed for now?

Update: resolved in 0542b14.

This comment has been minimized.

Copy link
@josephwright

josephwright Apr 17, 2024

Author Member

ER, no - I'll tidy up yet again

% Tests for the first token in a string being \cs{DelayEvaluation}.
% \begin{macrocode}
\prg_new_conditional:Npnn \@@_if_delay_eval:n #1 { T , F , TF }
{
\str_if_eq:noTF { \DelayEvaluation } { \tl_head:w #1 \q_nil \q_stop }
\prg_return_true:
\prg_return_false:
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}[TF]{\@@_if_key_value:n, \@@_if_key_value:V}
% Tests for the first token in a string being \cs{KeyValue}.
% \begin{macrocode}
Expand Down Expand Up @@ -1913,7 +1943,8 @@
{ \@@_find_global: }
}
\tl_set:Nn \l_@@_key_name_tl {#1}
\use:c { @@_assign_ \l_@@_keytype_tl : }
\cs_if_exist_use:cF { @@_assign_ \l_@@_keytype_tl : }
{ \@@_assign_variable: }
}
{ \msg_error:nnn { template } { unknown-attribute } {#1} }
}
Expand Down Expand Up @@ -2096,103 +2127,20 @@
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@_assign_integer:}
% \begin{macro}{\@@_assign_length:}
% \begin{macro}{\@@_assign_muskip:}
% \begin{macro}{\@@_assign_real:}
% \begin{macro}{\@@_assign_skip:}
% All of the calculated assignments use the same underlying code, with
% only the low-level assignment function changing.
% \begin{macrocode}
\cs_new_protected:Npn \@@_assign_integer:
{
\bool_if:NTF \l_@@_global_bool
{ \@@_assign_variable:N \int_gset:Nn }
{ \@@_assign_variable:N \int_set:Nn }
}
\cs_new_protected:Npn \@@_assign_length:
{
\bool_if:NTF \l_@@_global_bool
{ \@@_assign_variable:N \dim_gset:Nn }
{ \@@_assign_variable:N \dim_set:Nn }
}
\cs_new_protected:Npn \@@_assign_muskip:
{
\bool_if:NTF \l_@@_global_bool
{ \@@_assign_variable:N \muskip_gset:Nn }
{ \@@_assign_variable:N \muskip_set:Nn }
}
\cs_new_protected:Npn \@@_assign_real:
{
\bool_if:NTF \l_@@_global_bool
{ \@@_assign_variable:N \fp_gset:Nn }
{ \@@_assign_variable:N \fp_set:Nn }
}
\cs_new_protected:Npn \@@_assign_skip:
{
\bool_if:NTF \l_@@_global_bool
{ \@@_assign_variable:N \skip_gset:Nn }
{ \@@_assign_variable:N \skip_set:Nn }
}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@_assign_tokenlist:}
% \begin{macro}{\@@_assign_tokenlist_aux:NN}
% Life would be easy here if it were not for \cs{KeyValue}. To deal
% correctly with that, we need to allow for the recovery a stored value
% at point of use.
% \begin{macro}{\@@_assign_variable:}
% \begin{macro}{\@@_assign_variable:N, \@@_assign_variable:c}
% A general-purpose function for all of the other assignments.
% As long as the value is not coming from another variable, the stored
% value is simply transferred for output.
% \begin{macrocode}
\cs_new_protected:Npn \@@_assign_tokenlist:
{
\bool_if:NTF \l_@@_global_bool
{ \@@_assign_tokenlist_aux:NN \tl_gset:NV \tl_gset:Nn }
{ \@@_assign_tokenlist_aux:NN \tl_set:NV \tl_set:Nn }
}
\cs_new_protected:Npn \@@_assign_tokenlist_aux:NN #1#2
\cs_new_protected:Npn \@@_assign_variable:
{
\@@_if_key_value:VTF \l_@@_value_tl
\@@_assign_variable:c
{
\@@_key_to_value:
\tl_put_right:Ne \l_@@_assignments_tl
{
#1 \exp_not:V \l_@@_var_tl
{ \exp_not:V \l_@@_value_tl }
}
}
{
\tl_put_right:Ne \l_@@_assignments_tl
{
#2 \exp_not:V \l_@@_var_tl
{ \exp_not:V \l_@@_value_tl }
}
\@@_map_var_type: _
\bool_if:NT \l_@@_global_bool { g } set:Nn
}
}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@_assign_commalist:}
% Very similar for commas lists, so some code is shared.
% \begin{macrocode}
\cs_new_protected:Npn \@@_assign_commalist:
{
\bool_if:NTF \l_@@_global_bool
{ \@@_assign_tokenlist_aux:NN \clist_gset:NV \clist_gset:Nn }
{ \@@_assign_tokenlist_aux:NN \clist_set:NV \clist_set:Nn }
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_assign_variable:N}
% A general-purpose function for all of the numerical assignments.
% As long as the value is not coming from another variable, the stored
% value is simply transferred for output.
% \begin{macrocode}
\cs_new_protected:Npn \@@_assign_variable:N #1
{
\@@_if_key_value:VT \l_@@_value_tl
Expand All @@ -2203,8 +2151,10 @@
{ \exp_not:V \l_@@_value_tl }
}
}
\cs_generate_variant:Nn \@@_assign_variable:N { c }
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@_key_to_value:}
% \begin{macro}{\@@_key_to_value_auxi:w}
Expand Down Expand Up @@ -2666,9 +2616,10 @@
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\KeyValue}
% \begin{macro}{\DelayEvalution, \KeyValue}
% Simply dump the argument when executed: this should not happen.
% \begin{macrocode}
\cs_new_protected:Npn \DelayEvalution #1 {#1}
\cs_new_protected:Npn \KeyValue #1 {#1}
% \end{macrocode}
% \end{macro}
Expand Down

0 comments on commit 947d414

Please sign in to comment.