summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/knowledge/knowledge-utils.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/source/latex/knowledge/knowledge-utils.dtx')
-rw-r--r--Master/texmf-dist/source/latex/knowledge/knowledge-utils.dtx55
1 files changed, 44 insertions, 11 deletions
diff --git a/Master/texmf-dist/source/latex/knowledge/knowledge-utils.dtx b/Master/texmf-dist/source/latex/knowledge/knowledge-utils.dtx
index 961ebf925b6..9e8ede9bd8b 100644
--- a/Master/texmf-dist/source/latex/knowledge/knowledge-utils.dtx
+++ b/Master/texmf-dist/source/latex/knowledge/knowledge-utils.dtx
@@ -102,6 +102,13 @@
{}
{\tl_set_eq:Nc\c_sys_jobname_str{c_job_name_tl}}
% \end{macrocode}
+% The interface of expl3 since Mars 2018 has changed and a small patch is required:
+% \begin{macrocode}
+%\tl_if_exist:NTF
+% \ior_str_get:NN
+% {}
+% {\tl_set_eq:NN\ior_str_get:NN\ior_get_str:NN}
+% \end{macrocode}
% Some useful adding (newset).
% \begin{macrocode}
\cs_new:Nn\tl_new:Nn
@@ -976,7 +983,7 @@
\bool_do_until:Nn\l_tmpa_bool{
\ior_if_eof:NTF\klg_tmpa_ior
{\bool_set_true:N\l_tmpa_bool}
- {\ior_get_str:NN
+ {\ior_str_get:NN
\klg_tmpa_ior
\l_tmpa_tl
\exp_args:NNV
@@ -1011,10 +1018,10 @@
{\ior_if_eof:NTF\klg_tmpb_ior
{\bool_set_true:N\l_tmpa_bool
\bool_set_false:N\l_tmp_bool}
- {\ior_get_str:NN
+ {\ior_str_get:NN
\klg_tmpa_ior
\l_tmpa_tl
- \ior_get_str:NN
+ \ior_str_get:NN
\klg_tmpb_ior
\l_tmpb_tl
\tl_if_eq:NNF
@@ -1064,17 +1071,43 @@
%
% \subsubsection{Overloading command}
% Overloading a command is similar in syntax to |\NewDocumentCommand|
-% of the \texttt{xparse} package, but it further offer the macro |\SUPERcommand|
+% of the \texttt{xparse} package, but it further offers the macro |\SUPERcommand|
% (where |\command| is the token under definition), which can be used for calling the original code.
-% It is often used in combination with |\XparseArgs| for recreating the arguments if necesssary.
-%
-%
+% Formally, the syntax is:\\
+% |\OverloadCommand\command{arguments}[variant name]{code}|\\
+% The arguments follox the \texttt{xparse} syntax. The variant name is by default ``\texttt{NEW}''.
+% Other variants of the commands can be defined by changing this text.
+% The macro |\ChooseCommand| allows to choose between the variant. It takes as first argument a control sequence (or a chain of control sequences), and as second argument the variant that should be taken.
+% Hence |\ChooseCommand\command{SUPER}| reverts |\command| to its original behaviour.
% \begin{macrocode}
+\cs_new:Npn\commandVariant#1#2{#2\cs_to_str:N#1}
+
\cs_generate_variant:Nn\cs_gset_eq:NN{cN,cc}
-\NewDocumentCommand\OverloadCommand{mmm}
- {\exp_args:Nc\cs_gset_eq:NN{SUPER\cs_to_str:N#1}#1
- \exp_args:Nc\NewDocumentCommand{NEW\cs_to_str:N#1}{#2}{#3}
- \cs_gset_eq:Nc#1{NEW\cs_to_str:N#1}}
+\NewDocumentCommand\OverloadCommand{mmO{NEW}m}
+ {\cs_if_exist:cTF
+ {\commandVariant#1{switch~}}
+ {}
+ {\exp_args:Nc\cs_gset_eq:NN
+ {\commandVariant#1{SUPER}}
+ #1
+ \exp_args:NNx\cs_gset:Npn
+ #1{\exp_not:c{\commandVariant#1{switch~}}}
+ }
+ \exp_args:Nc\NewDocumentCommand
+ {\commandVariant#1{#3}}{#2}{#4}
+ \ChooseCommand#1{#3}
+}
+\NewDocumentCommand\ChooseCommand{mm}{
+ \tl_map_inline:nn{#1}
+ {\cs_if_exist:cTF
+ {\commandVariant##1{#2}}
+ {\cs_gset_eq:cc
+ {\commandVariant##1{switch~}}
+ {\commandVariant##1{#2}}}
+ {\tl_show:n
+ {knowledge_utils~ERROR:~##1~has~no~variant~{#2}}}
+ }
+}
% \end{macrocode}
%
%