summaryrefslogtreecommitdiff
path: root/macros/generic/memoize/memoize.edtx
diff options
context:
space:
mode:
Diffstat (limited to 'macros/generic/memoize/memoize.edtx')
-rw-r--r--macros/generic/memoize/memoize.edtx116
1 files changed, 63 insertions, 53 deletions
diff --git a/macros/generic/memoize/memoize.edtx b/macros/generic/memoize/memoize.edtx
index e77be9a39f..d974aff72a 100644
--- a/macros/generic/memoize/memoize.edtx
+++ b/macros/generic/memoize/memoize.edtx
@@ -90,55 +90,55 @@
%
% \paragraph{Identification} of |memoize|, |memoizable| and |nomemoize|.
%<*mmz>
-%<latex>\ProvidesPackage{memoize}[2024/03/15 v1.2.0 Fast and flexible externalization]
+%<latex>\ProvidesPackage{memoize}[2024/04/02 v1.3.0 Fast and flexible externalization]
%<context>%D \module[
%<context>%D file=t-memoize.tex,
-%<context>%D version=1.2.0,
+%<context>%D version=1.3.0,
%<context>%D title=Memoize,
%<context>%D subtitle=Fast and flexible externalization,
%<context>%D author=Saso Zivanovic,
-%<context>%D date=2024-03-15,
+%<context>%D date=2024-04-02,
%<context>%D copyright=Saso Zivanovic,
%<context>%D license=LPPL,
%<context>%D ]
%<context>\writestatus{loading}{ConTeXt User Module / memoize}
%<context>\unprotect
%<context>\startmodule[memoize]
-%<plain>% Package memoize 2024/03/15 v1.2.0
+%<plain>% Package memoize 2024/04/02 v1.3.0
%</mmz>
%<*mmzable>
-%<latex>\ProvidesPackage{memoizable}[2024/03/15 v1.2.0 A programmer's stub for Memoize]
+%<latex>\ProvidesPackage{memoizable}[2024/04/02 v1.3.0 A programmer's stub for Memoize]
%<context>%D \module[
%<context>%D file=t-memoizable.tex,
-%<context>%D version=1.2.0,
+%<context>%D version=1.3.0,
%<context>%D title=Memoizable,
%<context>%D subtitle=A programmer's stub for Memoize,
%<context>%D author=Saso Zivanovic,
-%<context>%D date=2024-03-15,
+%<context>%D date=2024-04-02,
%<context>%D copyright=Saso Zivanovic,
%<context>%D license=LPPL,
%<context>%D ]
%<context>\writestatus{loading}{ConTeXt User Module / memoizable}
%<context>\unprotect
%<context>\startmodule[memoizable]
-%<plain>% Package memoizable 2024/03/15 v1.2.0
+%<plain>% Package memoizable 2024/04/02 v1.3.0
%</mmzable>
%<*nommz>
-%<latex>\ProvidesPackage{nomemoize}[2024/03/15 v1.2.0 A no-op stub for Memoize]
+%<latex>\ProvidesPackage{nomemoize}[2024/04/02 v1.3.0 A no-op stub for Memoize]
%<context>%D \module[
%<context>%D file=t-nomemoize.tex,
-%<context>%D version=1.2.0,
+%<context>%D version=1.3.0,
%<context>%D title=Memoize,
%<context>%D subtitle=A no-op stub for Memoize,
%<context>%D author=Saso Zivanovic,
-%<context>%D date=2024-03-15,
+%<context>%D date=2024-04-02,
%<context>%D copyright=Saso Zivanovic,
%<context>%D license=LPPL,
%<context>%D ]
%<context>\writestatus{loading}{ConTeXt User Module / nomemoize}
%<context>\unprotect
%<context>\startmodule[nomemoize]
-%<mmz>% Package nomemoize 2024/03/15 v1.2.0
+%<mmz>% Package nomemoize 2024/04/02 v1.3.0
%</nommz>
%
% \paragraph{Required packages} and \hologo{LaTeX}ization of \hologo{plainTeX}
@@ -457,16 +457,10 @@
recompile/.code={\let\mmz@mode\mmz@mode@recompile},
}
% \end{key}
-%
% \begin{key}{prefix}
-% Key |path| executes the given keylist in path |/mmz/path|, to determine the
-% full \emph{path prefix} to memo and extern files
-% (\MS\ref{sec:tut:memodir},\ref{sec:memos}): |relative|, true by default,
-% determines whether the location of these files is relative to the current
-% directory; |dir| sets their directory; and |prefix| sets the first, fixed
-% part of their basename; the second part containing the MD5 sum(s) is not
-% under user control, and neither is the suffix. These subkeys will be
-% initialized a bit later, via |no memo dir|.
+% Key |prefix| determines the location of memo and extern files
+% (|\mmz@prefix@dir|) and the first, fixed part of their basename
+% (|\mmz@prefix@name|).
\mmzset{%
prefix/.code={\mmz@parse@prefix{#1}},
}
@@ -474,7 +468,7 @@
% This macro stores the detokenized expansion of |#1| into |\mmz@prefix|,
% which it then splits into |\mmz@prefix@dir| and |\mmz@prefix@name| at the
% final |/|. The slash goes into |\mmz@prefix@dir|. If there is no slash,
-% |\mmz@prefix@dir| is empty.
+% |\mmz@prefix@dir| is empty; in particular, it is empty under |no memo dir|.
\begingroup
\catcode`\/=12
\gdef\mmz@parse@prefix#1{%
@@ -514,14 +508,18 @@
%
% \begin{key}{mkdir, mkdir command}
% Should we create the memo/extern directory if it doesn't exist? And which
-% command should we use to create it? There is no initial value for the
-% latter, because |mkdir| cannot be executed out of the box, but note that
-% |extract=perl| and |extract=python| will set the extraction script with
-% option |--mkdir| as the value of |mkdir command|.
+% command should we use to create it? Initially, we attempt to create this
+% directory, and we attempt to do this via |memoize-extract.pl --mkdir|. The
+% roundabout way of setting the initial value of |mkdir command| allows
+% |extract=python| to change the initial value to |memoize-extract.py
+% --mkdir| only in the case the user did not modify it.
+\def\mmz@initial@mkdir@command{\mmzvalueof{perl extraction command} --mkdir}
\mmzset{
+ % This conditional is perhaps a useless leftover from the early versions, but
+ % we let it be.
mkdir/.is if=mmz@mkdir,
mkdir command/.store in=\mmz@mkdir@command,
- mkdir command={},
+ mkdir command/.expand once=\mmz@initial@mkdir@command,
}
% The underlying conditional \cs{ifmmz@mkdir} is only ever used in
% |\mmz@maybe@mkmemodir| below, which is itself only executed at the end of
@@ -530,7 +528,8 @@
\mmz@mkdirtrue
% We only attempt to create the memo directory if |\ifmmz@mkdir| is in effect
% and if both |\mmz@mkdir@command| and |\mmz@prefix@dir| are specified (i.e.\
-% non-empty).
+% non-empty). In particular, no attempt to create it will be made when |no
+% memo dir| is in effect.
\def\mmz@maybe@mkmemodir{%
\ifmmz@mkdir
\ifdefempty\mmz@mkdir@command{}{%
@@ -544,18 +543,17 @@
% \end{key}
%
% \begin{key}{memo dir, no memo dir}
-% Shortcuts for two common settings of |path| keys. The default |no memo
-% dir| will place the memos and externs in the current directory, prefixed
-% with |#1.|, where |#1| defaults to (unquoted) |\jobname|. Key |memo dir|
+% Shortcuts for two handy settings of |prefix|. Key |no memo dir| will
+% place the memos and externs in the current directory, prefixed with |#1.|,
+% where |#1| defaults to (unquoted) |\jobname|. The default |memo dir|
% places the memos and externs in a dedicated directory, |#1.memo.dir|; the
-% filenames themselves have no prefix. Furthermore, |memo dir| triggers the
-% creation of the directory.
+% filenames themselves have no prefix.
\mmzset{%
memo dir/.style={prefix={#1.memo.dir/}},
memo dir/.default=\jobname,
no memo dir/.style={prefix={#1.}},
no memo dir/.default=\jobname,
- no memo dir,
+ memo dir,
}
% \end{key}
%
@@ -2376,7 +2374,6 @@
\mmzvalueof{perl extraction options}%
}%
\mmz@check@extraction@log{perl}%
- \def\mmz@mkdir@command{\mmzvalueof{perl extraction command} --mkdir}%
},
perl extraction command/.initial=memoize-extract.pl,
perl extraction options/.initial={\space
@@ -2393,7 +2390,11 @@
\mmzvalueof{python extraction options}%
}%
\mmz@check@extraction@log{python}%
- \def\mmz@mkdir@command{\mmzvalueof{python extraction command} --mkdir}%
+ % Change the initial value of |mkdir command| to |memoize-extract.py
+ % --mkdir|, but only in the case the user did not modify it.
+ \ifx\mmz@mkdir@command\mmz@initial@mkdir@command
+ \def\mmz@mkdir@command{\mmzvalueof{python extraction command} --mkdir}%
+ \fi
},
python extraction command/.initial=memoize-extract.py,
python extraction options/.initial={\space
@@ -3414,7 +3415,7 @@
}%
}
%
-% \subsection{\pkg{PGF}}
+% \subsection[PGF]{\pkg{PGF}}
%
\mmz@if@package@loaded{pgf}{%
%<plain>\pgfpicture
@@ -3566,7 +3567,7 @@
raw collector options=\collargsReturnPlain,
},
% \begin{mmzautokey}{cite,volcite,cites,volcites}
- % Define handlers for citation commands.
+ % \indentmacrocode Define handlers for citation commands.
auto/cite/.style={
run conditions=\mmz@biblatex@cite@rc,
outer handler=\mmz@biblatex@cite@outer,
@@ -3574,9 +3575,9 @@
raw collector options=\mmz@biblatex@def@star\collargsReturnNo,
inner handler=\mmz@biblatex@cite@inner,
},
- % We need a dedicated |volcite| even though |\volcite| executes |\cite|
- % because otherwise, we would end up with |\cite{volume}{key}| in the cc-memo
- % when |biblatex ccmemo cite=replicate|.
+ % \noindentmacrocode We need a dedicated |volcite| even though |\volcite|
+ % executes |\cite| because otherwise, we would end up with
+ % |\cite{volume}{key}| in the cc-memo when |biblatex ccmemo cite=replicate|.
auto/volcite/.style={
run if memoizing,
outer handler=\mmz@biblatex@cite@outer,
@@ -3585,17 +3586,19 @@
inner handler=\mmz@biblatex@cite@inner,
},
auto/cites/.style={
- run conditions=\mmz@biblatex@cite@rc,
+ run conditions=\mmz@biblatex@cites@rc,
outer handler=\mmz@biblatex@cites@outer,
args=l*m,
- raw collector options=\mmz@biblatex@def@star\collargsClearArgsfalse\collargsReturnNo,
+ raw collector options=
+ \mmz@biblatex@def@star\collargsClearArgsfalse\collargsReturnNo,
inner handler=\mmz@biblatex@cites@inner,
},
auto/volcites/.style={
run if memoizing,
outer handler=\mmz@biblatex@cites@outer,
args=lml*m,
- raw collector options=\mmz@biblatex@def@star\collargsClearArgsfalse\collargsReturnNo,
+ raw collector options=
+ \mmz@biblatex@def@star\collargsClearArgsfalse\collargsReturnNo,
inner handler=\mmz@biblatex@cites@inner,
},
% \end{mmzautokey}
@@ -3618,21 +3621,28 @@
\mmz@scantokens{\AdviceOriginal{#1}#2}%
}
% \end{macro}
-% \begin{macro}{\mmz@biblatex@cite@rc}
-% Run if memoizing but not within a |\volcite| command. Applied to |\cite(s)|.
+% \begin{macro}{\mmz@biblatex@cite@rc,\mmz@biblatex@cites@rc}
+% \indentmacrocode Run if memoizing but not within a |\volcite|
+% command. Applied to |\cite(s)|.
\def\mmz@biblatex@cite@rc{%
\ifmemoizing
- % We cannot use the official |\ifvolcite|, or even the |blx@volcite| toggle
- % it depends on, because these are defined\slash set within the
- % next-citation hook, which is yet to be executed. So we depend on the
- % internal detail that |\volcite| and friends redefine |\blx@citeargs| to
- % |\blx@volciteargs|.
+ % \noindentmacrocode We cannot use the official |\ifvolcite|, or even the
+ % |blx@volcite| toggle it depends on, because these are defined\slash set
+ % within the next-citation hook, which is yet to be executed. So we
+ % depend on the internal detail that |\volcite| and friends redefine
+ % |\blx@citeargs| to |\blx@volciteargs|.
\ifx\blx@citeargs\blx@volciteargs
\else
\AdviceRuntrue
\fi
\fi
}
+\def\mmz@biblatex@cites@rc{%
+ \ifmemoizing
+ % The internal detail with |\volcites|: it defines a hook.
+ \ifdef\blx@hook@mcite@before{}{\AdviceRuntrue}%
+ \fi
+}
% \end{macro}
% \begin{macro}{\mmz@biblatex@cite@outer}
% Initialize the macro receiving the citation key(s), and execute the
@@ -3654,9 +3664,9 @@
}
% \end{macro}
% \begin{macro}{\mmz@biblatex@cite@inner}
+% This macro puts the cites reference keys into the context, and adds
+% |\nocite|, or the handled citation command, to the cc-memo.
\def\mmz@biblatex@cite@inner{%
- % This macro puts the cites reference keys into the context, and adds
- % |\nocite|, or the handled citation command, to the cc-memo.
\mmz@biblatex@do@context
\mmz@biblatex@do@ccmemo
\expandafter\AdviceOriginal\the\collargsArgs