diff options
Diffstat (limited to 'Master/texmf-dist/source/latex/xbase/template.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/xbase/template.dtx | 130 |
1 files changed, 63 insertions, 67 deletions
diff --git a/Master/texmf-dist/source/latex/xbase/template.dtx b/Master/texmf-dist/source/latex/xbase/template.dtx index 3e6a4050454..68e27966fa4 100644 --- a/Master/texmf-dist/source/latex/xbase/template.dtx +++ b/Master/texmf-dist/source/latex/xbase/template.dtx @@ -1,6 +1,6 @@ % \iffalse %% File: template.dtx (C) Copyright 1999-2001 David Carlisle, Frank Mittelbach -%% (C) Copyright 2004-2006 Frank Mittelbach, LaTeX3 Project +%% (C) Copyright 2004-2007 Frank Mittelbach, LaTeX3 Project %% %% It may be distributed and/or modified under the conditions of the %% LaTeX Project Public License (LPPL), either version 1.3c of this @@ -33,23 +33,18 @@ %% %% ----------------------------------------------------------------------- %% -%<package>\RequirePackage{l3names} -%<*dtx> +%<*driver|package> +\RequirePackage{l3names} +%</driver|package> %\fi -\def\GetIdInfo$Id: #1.dtx #2 #3-#4-#5 #6 #7$#8{% - \def\fileversion{#2}% - \def\filedate{#3/#4/#5}% - \ProvidesFile{#1.dtx}[#3/#4/#5 v#2 #8]% -} -%\iffalse -%</dtx> -%\fi -\GetIdInfo$Id: template.dtx 584 2006-12-12 17:29:34Z morten $ +\GetIdInfo$Id: template.dtx 652 2007-09-21 20:35:36Z morten $ {template} -% \iffalse -% -% +%\iffalse %<*driver> +%\fi +\ProvidesFile{\filename.\filenameext} + [\filedate\space v\fileversion\space\filedescription] +%\iffalse \documentclass{ltxdoc} \makeatletter \newenvironment{decl}[1][]% @@ -474,7 +469,7 @@ % passed to the internal parameter list (this has to happen explicitly % from within the code). |#1| may be used to access the value % specified. - +% % The main purpose for this type is of historical nature (originally % most of the other types have been implemented internally using |g|). % @@ -1126,17 +1121,15 @@ % \section{Implementation} % \begin{macrocode} %<*package> +\ProvidesExplPackage + {\filename}{\filedate}{\fileversion}{\filedescription} % \end{macrocode} % % \begin{macrocode} \RequirePackage{ldcsetup,xparse} -\RequirePackage{l3toks,l3tlp,l3skip,l3int,l3clist,l3token} +\RequirePackage{l3toks,l3tlp,l3skip,l3int,l3clist,l3token,l3calc} % \end{macrocode} % -% Ignore white space in this package. -% \begin{macrocode} -\CodeStart -% \end{macrocode} % % Declare a private token register for building parameter lists. % Having the number saves a few expandafters @@ -1236,38 +1229,26 @@ % \end{macro} % % \begin{macro}{\TP_push_assignments:n} -% Store a list of parameter assignments given as an argument -% in |\l_TP_KV_assignments_toks| and -% then push it -% onto the |\g_TP_assignments_stack_toks|. (My assumption is that -% the somewhat strange -% way to do this is in fact neccesary to preserve the |#| marks -% which would otherwise need doubling --- check). -% \begin{macrocode} -\def_new:Npn \TP_push_assignments:n{ - \tex_afterassignment:D \TP_push_assignments: - \l_TP_KV_assignments_toks} -% \end{macrocode} -% -% \end{macro} -% % \begin{macro}{\TP_push_assignments:} -% Pushes the parameter assignment list stored in -% |\l_TV_KV_assignments_toks| onto the stack -% |\g_TP_assignments_stack_toks|. +% Push a list of parameter assignments onto the +% |\g_TP_assignments_stack_toks|. As it all happens in token +% registers |#|s need no doubling. |\TP_push_assignments:| expects +% it to be |\l_TP_KV_assignments_toks| (needs fixing). % \begin{macrocode} +\def_long_new:Npn \TP_push_assignments:n#1{ + \toks_gput_left:Nn\g_TP_assignments_stack_toks{{#1}} +} \def_new:Npn \TP_push_assignments:{ \toks_gset:No \g_TP_assignments_stack_toks {\exp_after:NN -% \end{macrocode} -% this misuses the fact that |\toks_use:N| is really |\the| so expands -% a little strangely (fix). -% \begin{macrocode} {\toks_use:N\exp_after:NN\l_TP_KV_assignments_toks\exp_after:NN} - \toks_use:N\g_TP_assignments_stack_toks}} + \toks_use:N\g_TP_assignments_stack_toks} +} % \end{macrocode} % \end{macro} +% \end{macro} % +% % \begin{macro}{\DeclareTemplateType} % |{type}{nofarg}| % \begin{macrocode} @@ -2022,8 +2003,17 @@ \group_begin: \TP_templdecl_multiselection:nnnn ##1 \group_end: +% \end{macrocode} +% Extracting the correct item from the |\if_case:w| we are building +% requires a bit of care. Firstly we want to expand the appropirate +% number of times to get to the item but we also want to ensure we do +% not have any unwanted leftover |\fi:|s or other junk which is bound +% to cause errors later on. Therefore we start an |f| expansion (so we +% don't have to count |\exp_after:NN|s and then stop it again when we +% want to. +% \begin{macrocode} \toks_put_right:Nx\l_TP_KV_assignments_toks { - \exp_not:n{\tlp_set:No #1} { \toks_use:N \g_TP_multiselection_toks} + \exp_not:n{\tlp_set:Nf #1} { \toks_use:N \g_TP_multiselection_toks} } } { @@ -2037,12 +2027,18 @@ % \end{macro} % % \begin{macro}{\TP_templdecl_multiselection:nnnn} -% Start the |\if_case:w| +% Start the |\if_case:w|. When the item is retrieved using an |f| +% type expansion we better stop it at the right place once we have +% emerged on the other side of the conditional. % \begin{macrocode} \def_new:Npn \TP_templdecl_multiselection:nnnn #1#2#3#4{ \toks_gset:Nn \g_TP_multiselection_toks {\if_case:w #2} - \clist_map_inline:nn {#3}{ \TP_multiselection_add_or_case:n {##1} } - \toks_gput_right:Nn\g_TP_multiselection_toks { \else: #4\fi: } + \clist_map_inline:nn {#3}{ + \TP_multiselection_add_or_case:n {\exp_stop_f:##1} + } + \toks_gput_right:Nn\g_TP_multiselection_toks { + \else: \use_arg_i_after_fi:nw { \exp_stop_f: #4} \fi: + } } % \end{macrocode} % \end{macro} @@ -2182,9 +2178,9 @@ % {#1#2{##1}\def:Npx #3{\toks_use:N#2}} \toks_set:No \l_tmpa_toks {\use_arg_ii:nn ##1} \toks_put_right:Nx \l_TP_KV_assignments_toks { - {\exp_not:n{#1#2}{\toks_use:N \l_tmpa_toks} + \exp_not:n{#1#2}{\toks_use:N \l_tmpa_toks} \exp_not:n{ \def:Npx #3{\toks_use:N#2} } - } + } } % \end{macrocode} @@ -2232,12 +2228,12 @@ % \marg{operation} \marg{register} |\MultiSelection| % \marg{selector} \marg{case-list} \marg{else-case} % -% This command builds up the |\if_case:w| code from the three arguments -% of |\MultiSelection| and stores it in -% |\g_TP_multiselection_toks|. This code is supposed to be run in -% a group so a) we don't have to initialise -% |\g_TP_multiselection_toks| and b) all changes to the used -% registers not affecting the outside. +% This command builds up the |\if_case:w| code from the three +% arguments of |\MultiSelection| and stores it in +% |\g_TP_multiselection_toks|. This code is supposed to be run in a +% group so a) we don't have to initialise |\g_TP_multiselection_toks| +% and b) all changes to the used registers not affecting the +% outside. % % \begin{macrocode} \def_new:Npn \TP_multiselection_add:nnnnnn #1#2#3#4#5#6{ @@ -2249,28 +2245,28 @@ } { #1#2{##1} - \TP_multiselection_add_or_case:n { \toks_use:N #2 } + \TP_multiselection_add_or_case:o { \toks_use:N #2 } } } - \toks_gput_right:Nn \g_TP_multiselection_toks { \else: #6\fi: } + \toks_gput_right:Nn \g_TP_multiselection_toks { + \else: \use_arg_i_after_fi:nw{#6}\fi: + } } % \end{macrocode} % % \end{macro} % % \begin{macro}{\TP_multiselection_add_or_case:o} -% Since we intend to add |\or:| to |\g_TP_multiselection_toks| -% within the |\_for| loop we have to hide it carefully or else we -% will get some unmatched conditionals. -% -% Actually the |:o| is a slight lie here since the expanion happens -% when we add things to the toks register inside. +% No need to worry about where |\or:| is allowed to be added since +% all loops in \LaTeX3 process the item outside conditionals. % \begin{macrocode} \def_new:Npn \TP_multiselection_add_or_case:n #1 { - \toks_gput_right:Nn \g_TP_multiselection_toks { \or: #1 } + \toks_gput_right:Nn \g_TP_multiselection_toks { + \or: \use_arg_i_after_orelse:nw{#1} + } } \def_new:Npn \TP_multiselection_add_or_case:o { - \exp_args:NNo \TP_multiselection_add_or_case:n + \exp_args:No \TP_multiselection_add_or_case:n } % \end{macrocode} % \end{macro} @@ -2342,7 +2338,7 @@ % adds stuff to \l_TP_KV_assignments_toks \setkeys {\cs:w TPO>/#1/#3\cs_end:}{#4} - \tlp_set:co { TPR>/#1/#2 } + \tlp_set:cx { TPR>/#1/#2 } { \toks_use:N \l_TP_KV_assignments_toks } \cs_if_free:cTF { TPO>/#1/#3 } { \tlp_set:cn {TPO>/#1/#2}{#1/#3} } |