% \iffalse meta-comment
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% memoize-ext.dtx
% Additions and changes Copyright (C) 2024-2026 Clea F. Rees.
% Code from skeleton.dtx Copyright (C) 2015-2024 Scott Pakin (see below).
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% of this license or (at your option) any later version.
% The latest version of this license is in
%   https://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX
% version 2008-05-04 or later.
%
% This work has the LPPL maintenance status 'muaintained'.
%
% The Current Maintainer of this work is Clea F. Rees.
%
% This work consists of all files listed in manifest.txt.
%
% The file memoize-ext.dtx is a derived work under the terms of the
% LPPL. It is based on version 2.4 of skeleton.dtx which is part of
% dtxtut by Scott Pakin. A copy of dtxtut, including the
% unmodified version of skeleton.dtx is available from
% https://www.ctan.org/pkg/dtxtut and released under the LPPL.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \fi
%
% \iffalse
%<*driver>
% ^^A  ref. ateb Max Chernoff: https://tex.stackexchange.com/a/723294/
\def\MyMakePrivateLetters{\makeatletter\ExplSyntaxOn\endlinechar13}
\GetIdInfo $Id: memoize-ext.dtx 11956 2026-06-04 03:13:27Z cfrees $ {Extensions for Memoize}
\ProvidesExplFile{\ExplFileName}{\ExplFileDate}{v0.4.2 \ExplFileVersion}{\ExplFileDescription}
\cs_new_eq:NN \MyExplFileName \ExplFileName
\cs_new_eq:NN \MyExplFileDate \ExplFileDate
\cs_new_eq:NN \MyExplFileVersion \ExplFileVersion
\cs_new_eq:NN \MyExplFileDescription \ExplFileDescription
\ExplSyntaxOff
\documentclass[11pt,british]{ltxdoc}
\usepackage{memoize-ext}
\def\memoizeextdocbase{memoize-ext}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
% ^^A  \OnlyDescription
\DoNotIndex{\verb,}
\usepackage{babel}
\usepackage{fancyhdr}
\usepackage[plain]{fancyref}
\usepackage{xcolor}
\usepackage{xurl}
\urlstyle{sf}
\usepackage[tt={mono,lining,tabular},sf={lining,prop},rm={oldstyle,prop}]{cfr-lm}
\usepackage{microtype}
\usepackage[a4paper,headheight=14pt,marginparwidth=45mm,hmarginratio=4:1,vscale=.8,hscale=.7,verbose]{geometry}	% use 14pt for 11pt text, 15pt for 12pt text
% ^^A  addaswyd o forest-ext.dtx
\newlength\tewadjust
\newlength\doctemplgth
\AddToHook {begindocument/end}[.]
{%
  \setlength\tewadjust{%
    \dimeval{%
      \marginparwidth+\marginparsep-\paperwidth+\textwidth+\oddsidemargin+1in
    }%
  }%
  \setlength\doctemplgth{0pt}%
  \newgeometry{%
    headheight=14pt,scale=.8,marginparwidth=0pt,marginparsep=0pt,
  }%
  \savegeometry{safonol}%
  \fancyheadoffset[lh]{0pt}% ^^A REQUIRED - do NOT remove this line!!
  \pagenumbering{arabic}%
}
\newcommand \twmarg {%
  \restoregeometry
  \fancyheadoffset[lh]{\tewadjust}%
}
\newcommand \twreg {%
  \loadgeometry{safonol}%
  \fancyheadoffset[lh]{0pt}% ^^A REQUIRED - do NOT remove this line!!
}
\usepackage{csquotes}
\MakeAutoQuote{‘}{’}
\MakeAutoQuote*{“}{”}
% ^^A  copïwyd o forest-ext.dtx
\usepackage[citestyle=authoryear-comp,bibstyle=authoryear,mergedate=basic,isbn=false,url=true,sortcites=true,backend=biber,mincrossrefs=6]{biblatex}
\DeclareFieldFormat{eprint:ctan}{%
  \mkbibacro{CTAN}\addcolon\space
  \ifhyperref
    {\href{https://www.ctan.org/pkg/#1}{\nolinkurl{#1}}}
  {\nolinkurl{#1}}%
}
\DeclareFieldAlias{eprint:CTAN}{eprint:ctan}
% ^^A \bibliography{abbrv, authors, journals-series, pub, lleoedd, ref}
\bibliography{memoize-ext_biber}% ^^A generate for upload (gweler uchod)
% ^^A  \usepackage{minted}
\usepackage{hypdoc}% ateb Ulrike Fischer: https://tex.stackexchange.com/a/695555/
\usepackage{bookmark}
\hypersetup{%
  colorlinks=true,
  citecolor={moss},
  extension=pdf,
  linkcolor={strawberry},
  linktocpage=true,
  pdfcreator={TeX},
  pdfproducer={pdfeTeX},
  urlcolor={blueberry}%
}
\makeatletter
\setcounter{IndexColumns}{2}
\IndexMin=\dimexpr 0.3\textheight\relax
\defbibheading{bibliography}[\refname]{%^^A
  \section*{#1}%^^A
  \markboth{#1}{}}
\newcommand\orig@xobey@sp{}
\newcommand\permissivelines{%
  \def\@xobeysp{\leavevmode\penalty100\ }%
}
\newcommand\strictlines{%
  \let\@xobey@sp\orig@xobey@sp
}
\AddToHook{begindocument}[memoizeextdoc]{%
  \let\orig@xobey@sp\@xobey@sp
  \addtocontents{toc}{%
    \tlstyle
  }%
}
\def\section{%
  \@startsection{section}{1}{\z@}
  {-3.5ex\@plus -1ex\@minus -.2ex}
  {2.3ex\@plus .2ex}{\normalfont\sffamily\Large}%
}
\renewcommand*\l@section[2]{%
  \ifnum \c@tocdepth >\z@
    \addpenalty\@secpenalty
    \addvspace{1.0em \@plus\p@}%
    \setlength\@tempdima{1.5em}%
    \begingroup
      \leftskip 1.5em\relax
      \parindent 1.5em\relax
      \@afterindenttrue
      \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode 
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      {#1}\nobreak
      \leaders\hbox{%
        $\m@th
        \mkern \@dotsep mu\hbox{.}\mkern \@dotsep
        mu$%
      }\hfill
      \nobreak\hb@xt@\@pnumwidth{\hss #2%
        \kern-\p@\kern\p@}\par
    \endgroup
  \fi
}
\renewcommand*\l@subsection{\@dottedtocline{2}{3.8em}{3.2em}}
\renewcommand*\l@subsubsection{\@dottedtocline{3}{7em}{4.1em}}
\makeatother
\NewDocElement[%
  macrolike,
  idxtype=fn.,
  idxgroup=expl3 functions,
  printtype=\textit{fn.},
]{Fn}{fn}
\NewDocElement[%
  idxtype=key,
  idxgroup=expl3 keys,
  printtype=\textit{expl3 key},
]{Key}{key}
\NewDocElement[%
  printtype=\textdagger,
  idxtype=,
  idxgroup=,
  macrolike,
]{DMacro}{dmacro}
\NewDocElement[%
  idxtype=opt.,
  idxgroup=options,
  printtype=\textit{opt.},
]{Opt}{option}
\NewDocElement[%
  idxtype=pgfkey,
  idxgroup=pgfkeys,
  printtype=\textit{pgfkey},
]{Pgfkey}{pgfkey}
\NewDocElement[%
  idxtype=pkg.,
  idxgroup=,
  printtype=\textit{pkg.},
]{Pkg}{package}
\NewDocElement[%
  idxtype=plug,
  idxgroup=plugs,
  printtype=\textit{plug},
]{SPlug}{plug}
\NewDocElement[%
  idxtype=socket,
  idxgroup=sockets,
  printtype=\textit{socket},
]{Sock}{socket}
\NewDocElement[%
  macrolike,
  idxtype=toks,
  idxgroup=token registers,
  printtype=\textit{toks},
]{Toks}{toksr}
\NewDocElement[%
  macrolike,
  idxtype=var,
  idxgroup=expl3 variables,
  printtype=\textit{var.},
]{Var}{var}
\NewDocumentCommand \val { m }
{%
  {\ttfamily =\,\meta{#1}}%
}
\ExplSyntaxOn
\NewDocumentCommand \vals { m }
{
  {
    \ttfamily = \, 
    \clist_use:nn { #1 } { \textbar }
  }
} 
\keys_define:nn { memoize-ext / doc }
{
  unknown .code:n = {
    \cs_if_free:cT { \l_keys_key_str }
    {
      \tl_gset:cn { \l_keys_key_str } { #1 }
    }
  },
}
\NewDocumentCommand \memoizeextdocset { +m }
{
  \keys_set:nn { memoize-ext / doc } { #1 }
}
\cs_new_eq:NN \__memoizeextdoc_cs_orig:n \cs
\cs_new_protected:Npn \__memoizeextdoc_cs_expl:n #1
{
  \exp_args:Ne \__memoizeextdoc_cs_orig:n {\tl_to_str:n {#1}}
}
\cs_new_eq:NN \ecs \__memoizeextdoc_cs_expl:n
\ExplSyntaxOff
\memoizeextdocset{%
  bug={\href{https://codeberg.org/cfr/memoize-ext/issues}{\textsc{bugtracker}}},
  codeberg={\href{https://codeberg.org/cfr/memoize-ext}{\textsc{codeberg}}},
  github={\href{https://github.com/cfr42/memoize-ext}{\textsc{github}}},
  ctan={\href{https://ctan.org/}{\textsc{ctan}}},
}
% \usepackage{cleveref}
\newcommand*{\lpack}[1]{\textsf{#1}}
\newcommand*{\fgroup}[1]{\textsf{#1}}
\newcommand*{\fname}[1]{\textsf{#1}}
\newcommand*{\file}[1]{\texttt{#1}}
\newcommand*{\env}[1]{\texttt{#1}}
\newcommand*\TikZ{Ti\emph{k}Z}
\newcommand*\pgf{\textsc{pgf}}
\newcommand*\pgftikz{\pgf/\TikZ}
\NewDocumentCommand\texse{om}{%
  \href{https://tex.stackexchange.com/#2}{\TeX{} \textsc{se}\IfValueT{#1}{: #1}}%
}
\NewDocumentCommand\texseans{O{Based on \texse{} answer:} m o}{%
  #1 \href{https://tex.stackexchange.com/a/#2}{#2}%
  \IfValueT{#3}{ by #3}.%
}
\NewDocumentCommand\githubref{O{See} m O{#2}}{%
  #1 \textsc{GitHub} \href{https://github.com/#2}{#3}.%
}
% \NewDocumentCommand\texseqn{O{Based on \texse{} question} m o}{%
%   #1 \href{https://tex.stackexchange.com/q/#2}{#2}%
%   \IfValueT{#3}{ by #3}.%
% }
\title{\pkg{\MyExplFileName}: Extensions for \pkg{memoize}}
\author{Clea F. Rees\thanks{%
    Bug tracker:
    \href{https://codeberg.org/cfr/memoize-ext/issues}{\url{codeberg.org/cfr/memoize-ext/issues}}
    \textbar{} Code:
    \href{https://codeberg.org/cfr/memoize-ext}{\url{codeberg.org/cfr/memoize-ext}}
    \textbar{} Mirror:
    \href{https://github.com/cfr42/memoize-ext}{\url{github.com/cfr42/memoize-ext}}% 
}}
\date{v0.4.2 \MyExplFileVersion{} \MyExplFileDate}
\pagestyle{fancy}
\fancyhf{}
\fancyhf[lh]{\itshape\MyExplFileName}
\fancyhf[rh]{\itshape\MyExplFileVersion}
\fancyhf[cf]{\itshape--- \thepage~/~\lastpage{} ---}
\ExplSyntaxOn
\hook_gput_code:nnn {shipout/lastpage} {.}
{
  \property_record:nn {t:lastpage}{abspage,page,pagenum}
}
\cs_new_protected_nopar:Npn \lastpage 
{
  \property_ref:nn {t:lastpage}{page}
}
\cs_new_eq:NN \OrigMakePrivateLetters \MakePrivateLetters
\hook_gput_code:nnn {begindocument/end} {.}
{
  \cs_set_eq:NN \MakePrivateLetters \MyMakePrivateLetters
  % \ShowCommand \OrigMakePrivateLetters
  % \ShowCommand \MyMakePrivateLetters
  % \ShowCommand \MakePrivateLetters
}
\ExplSyntaxOff
\definecolor{strawberry}{rgb}{1.000,0.000,0.502}
\definecolor{blueberry}{rgb}{0.000,0.000,1.000}
\definecolor{moss}{rgb}{0.000,0.502,0.251}
% ^^A \setminted{style=sas,breaklines=true,breakafter={\,},}
% ^^A \newminted {latex}{frame=single,rulecolor=darkgray,}
% ^^A \newminted {xml}{frame=single,rulecolor=darkgray,}

\begin{document}
% ^^A \let\MakePrivateLetters\MyMakePrivateLetters
\DocInput{\MyExplFileName.dtx}
\end{document}
%</driver>
% \fi
%
% ^^A \changes{v1.0}{???}{First public release.}
% ^^A lua will replace v0.0 and 0000/00/00 when tagging
% ^^A \changes{v0.1}{2026-02-21}{}
% 
% \maketitle\thispagestyle{empty}
% \pdfinfo{%
% 	/Creator		(TeX)
% 	/Producer		(pdfTeX)
% 	/Author			(Clea F. Rees)
% 	/Title			(memoize-ext)
% 	/Subject		(TeX)
% 	/Keywords		(TeX,LaTeX,Clea,Rees)}
% \setlength{\parindent}{0pt}
% \setlength{\parskip}{0.5em}
% 
% 
% \begin{abstract}
%   \noindent\lpack{memoize-ext} provides extensions for \citeauthor{saso-memoize}'s package \pkg{memoize} \autocite*{saso-memoize}.
%   In particular, it supports the memoization of content in tagged \textsc{pdf}s and presentations produced with \citeauthor{joseph-talk}'s \pkg{ltx-talk} \autocite*{joseph-talk}.
% \end{abstract}
%
% \tableofcontents
%
% \twmarg
% \part{Usage}
%
% \section{Basics}\label{sec:basics}
% ^^A sec:basics <<<
% \changes{v0.3}{2026-03-02}{Correct and update usage details for \pkg{ltx-talk}.}
%
% Usage is simple.
% {\obeylines\MacroFont
%   \cs{documentclass}\marg{class}
%   \cs{usepackage}\{memoize-ext\}
% }
%
% The package will automatically load \pkg{memoize} and pass any unrecognised options onto that package.
%
% Note that to create a tagged presentation with \pkg{ltx-talk}, the package should be loaded \emph{after} the class\footnote{%
%   Note that \pkg{ltx-talk} diverges from \pkg{beamer} here, a point to which I was oblivious when I wrote the initial version of this documentation.%
% }.
% \iffalse
%<*verb>
% \fi
% \begin{verbatim}
% \DocumentMetadata{tagging=on,lang=en-GB,pdfversion=2.0,pdfstandard=UA-2,}
% \documentclass{ltx-talk}
% \usepackage{memoize-ext}
% \end{verbatim}
% \iffalse
%</verb>
% \fi
% If for any reason it is necessary to load the package \emph{prior} to the class in a tagged \textsc{pdf}, then tagging must be explicitly requested.
% For example,
% \iffalse
%<*verb>
% \fi
% \begin{verbatim}
% \DocumentMetadata{tagging=on,lang=cy,pdfversion=2.0,pdfstandard=ua-2,}
% \RequirePackage[tag]{memoize-ext}
% \documentclass{book}
% \end{verbatim}
% \iffalse
%</verb>
% \fi
% 
% If necessary, a small number of package options are available to customise which code is loaded.
% 
% \DescribeOpt{expl3}\vals{true,false}
% 
% Loads code supporting \pkg{expl3} syntax.
%
% Default is \texttt{true}.
% Initially \texttt{false}.
%
% \DescribeOpt{l3draw}\vals{true,false}
% 
% Loads code supporting \pkg{l3draw}, if the package is loaded.
%
% Default is \texttt{true}.
% Initially \texttt{true}.
%
% \DescribeOpt{tag}\vals{true,false}
% 
% Loads code supporting tagged \textsc{pdf}, if \LaTeX's tagging code is activated when the package is loaded.
% Note that this is \emph{not} true prior to \cs{documentclass}.
%
% Default is \texttt{true}.
% Initially \texttt{true} if tagging is activated; \texttt{false} otherwise.
% 
% \DescribeOpt{talk}\vals{true,false}
% 
% Loads code supporting \cls{ltx-talk}, if the class is loaded.
%
% Default is \texttt{true}.
% Initially \texttt{true}.
%
% Note that the additional code is not loaded if a different class is used, regardless of this setting.
% The option is provided in case it is necessary to disable support for the class, without disabling other parts of \pkg{memoize-ext}.
%
% \section{\pkg{expl3}}\label{sec:expl3}
% ^^A sec:expl3 <<<
% \DescribePgfkey{replicate~expl~fn} Sets up advice to ‘replicate’ an \pkg{expl3} function.
%
% This works similarly to the builtin support for commands created with \cs{NewDocumentCommand} etc\@.
% This means that it is not necessary to specify \texttt{args}.
%
% \textbf{Functions with \texttt{w}-type arguments are NOT supported.}
% Attempting to use this key with such a function will result in an error.
% Such cases require custom handling and can be configured using the standard \pkg{memoize} keys.
%
% \file{memoize-ext-l3draw.sty} demonstrates use of \texttt{replicate expl fn}:
% \iffalse
%<*verb>
% \fi
% \begin{verbatim}
% \mmzset{%
%   auto~csname={draw_begin:}{memoize,collector=\AdviceCollectDrawArguments,},
%   auto~csname={__draw_record_origin:}{run~if~memoizing,replicate~expl~fn,},
% }
% \end{verbatim}
% \iffalse
%</verb>
% \fi
% This code sets up a custom ‘collector’ and installs ‘advice’ which memoizes \ecs{draw_begin:}.
% It further advises \ecs{__draw_record_origin:} so that if this function is found during memoization, it will be replicated in the \texttt{ccmemo}.
% This ensures that the origin is recorded correctly when the memoized picture is utilised, since we do not want to record its position when memoized.
% 
% The net result of this is that auto-memoization of \pkg{l3draw} pictures should (hopefully) ‘just work’.
%
% ^^A >>> sec:expl3
%
% \section{\pkg{l3draw}}\label{sec:draw}
% sec:draw <<<
% \pkg{l3draw} pictures are auto-memoized by default.
% \file{memoize-ext-l3draw.sty} mostly exists to demonstrate use of \texttt{replicate expl fn}.
% >>> sec:draw
%
% \section{\pkg{ltx-talk}}\label{sec:talk}
% ^^A sec:talk <<<
%
% The code is based on that provided by \pkg{memoize} for \pkg{beamer} and supports the same options, except that ‘\texttt{talk}’ is substituted for ‘\texttt{bemaer}’.
% 
% \DescribePgfkey{per~overlay} Equivalent to the \pkg{beamer} option of the same name.
%
% \DescribePgfkey{talk~mode~to~prefix} Equivalent to \pkg{beamer mode to prefix}.
%
% The code uses and/or changes internal code from both \cls{ltx-talk} and \pkg{memoize}.
% While the public interface for \pkg{memoize} is fairly stable, the internals may not be, and \pkg{ltx-talk} is highly experimental. 
% The latter also uses a large number of experimental packages and makes extensive use of experimental \LaTeX{} features.
% 
% The justification for publishing this part of \pkg{memoize-ext} is essentially that anybody using \cls{ltx-talk} and \pkg{memoize} is already playing with fire, so it is better to have an unreliable extinguisher to hand than none at all.
%
% A few things you should know, even if you do not want to:
% \begin{itemize}
%   \item the code uses an internal \pkg{ltx-talk} boolean to drive extern creation and utilisation;
%   \item \texttt{talk mode to prefix} relies on an internal \pkg{ltx-talk} string;
%   \item to workaround incompatibilities between \pkg{memoize} and \pkg{pdfmanagement}, the code redefines an internal \pkg{memoize} macro\footnote{%
%     The redefinition injects code into the box \pkg{memoize} ships out which resets opacity before and after the memoized code is executed.
%     This is required because \pkg{memoize} relies on primitive shipout, whereas the implementation of opacity in \pkg{pdfmanagement} relies on \LaTeX's shipout routine.%
%   }.
% \end{itemize}
% ^^A >>> sec:talk
%
% \section{Tagged \textsc{pdf}}\label{sec:tag}
% ^^A <<< sec:tag
%
% If using the package to produce tagged \textsc{pdf}, note that the tagging support 
% \begin{itemize}
%   \item redefines the internal macro \cs{mmzIncludeExtern} during utilisation;
%   \item relies on an internal string variable in \pkg{ltsockets}.
% \end{itemize}
%
% \textbf{Correct tagging \emph{requires} that unmemoizable code be marked as such, either manually or automatically.}
% The package does this automatically for \env{tikzpicture}s which use an unsupported tagging plug, but does nothing in any other case.
% So if your picture uses \texttt{remember picture}, for example, you \emph{must} mark the code as unmemoizable or disable tagging for the affected code.
% The package will warn you about this, but that is all it does.
%
% \subsection{\TikZ{} pictures}
%
% If the content you wish to memoize is a \TikZ{} picture, you probably do not need to do anything special, but note that the default \pkg{latex-lab} plug is \emph{not} supported. 
% You must use one of \texttt{alt}, \texttt{actualtext} or \texttt{artifact}.
%
% If you use \textt{alt} or \texttt{actualtext} in the optional argument to \env{tikzpicture}, the value will be recorded in the \emph{ccmemo} for use during utilisation.
% If you set the value outside the \env{tikzpicture}, this is not necessary.
% In the latter case, the \emph{extern} will not depend on the value given (unless you request that specifically).
%
% Note that if you change the selected plug \emph{and} you set this \emph{outside} the picture, you must manually tell \pkg{memoize} it should recompile the picture, since the plug is recorded in the ccmemo, but the hash will not have changed.
%
% Note that tagging is disabled during memoization and additionally \emph{disabled for content which has just been memoizsed}.
% So when a run produces an extern, the memoized code will not be tagged at all.
%
% \textbf{Note that this package does \emph{not} support \pkg{forest}.}
% If your document uses \pkg{forest} \autocite{saso-forest}, you should either disable memoization for these pictures or load \pkg{forest-ext}\footnote{%
%   This is not necessary if you use \pkg{prooftrees}, which will load the package automatically if required.%
% } \autocite{cfr-forest-ext}.
%
% The \TikZ{} support is implemented by replacing plugs provided by \pkg{latex-lab} with versions designed for memoized content \autocite{latex-project-latex-lab-tikz}.
% Code is also installed into the same hooks \pkg{latex-lab} uses with rules to ensure this package's has priority.
%
% \DescribeSPlug{mmzx}
% Plug for \texttt{tagsupport/tikz/picture/init}
%
% If memoization is not active, the plug executes the \pkg{latex-lab} \texttt{default} plug.
%
% If some option for this package is specifically configured, it is used.
% Otherwise, the code initialisation code at the start of the picture attempts to find a match for any configured \pkg{latex-lab} plug.
% In effect, this means that you should not need to change anything in your document if you use one of the three supported plugs.
%
% If memoization is enabled but no suitable plug is found, a warning is issued and memoization aborted.  
% Otherwise, code is inserted into the ccmemo to emulate the appropriate \pkg{latex-lab} plug.
% In most cases, this code simply calls the relevant \pkg{latex-lab} plugs.
% 
%
% Plugs for \texttt{tagsupport/tikz/picture/begin} and \texttt{tagsupport/tikz/picture/end}:
%
% \DescribeSPlug{mmzx/actualtext}
% Sets up the ccmemo to use the \pkg{latex-lab} \texttt{actualtext} plugs.
% 
% \DescribeSPlug{mmzx/artifact}
% Sets up the ccmemo to use the \pkg{latex-lab} \texttt{artifact} plugs.
%
% \DescribeSPlug{mmzx/alt}
% This pair of plugs is the exception.
% Rather than writing a ccmemo which will invoke the \pkg{latex-lab} \texttt{alt} plugs, these plugs write a ccmemo which uses an alternative implementation of those plugs.
% The reimplementation uses \emph{properties} (provided by the \LaTeX{} format) rather than  \emph{rememberpicture} (provided by \pgftikz)\footnote{%
%   I considered using the support provided for \cs{includegraphic}, but this would require more intrusive changes to the internals of \pkg{memoize} and would essentially duplicate bounding box calculations already completed during memoization.%
% }.
%
% \emph{If everything looks OK, tagging is disabled for the current picture.}
% This is efficient if memoization is successful, but may be problematic if memoization is aborted or fails. 
% In this case, it may be necessary to mark the content as unmemoizable or to disable memoization for particular pictures, in order to ensure content is tagged correctly\footnote{%
%   It would be possible to disable tagging only if memoization succeeds, but I am not sure whether the structure will be right in this case?%
% }.
% 
% \subsection{Other content}
%
% If the content you wish to memoize is \emph{not} a \TikZ{} picture, you may need to read the remainder of this section.
%
% Generic support is provided in the form of two sockets which are used directly before and directly after an extern is included during utilisation.
% By default, the sockets do nothing, but they may be used to inject code which wraps the included extern in a suitable tagging structure.
% 
% Plugs may be assigned to the sockets either by writing suitable code to the ccmemo or in the document itself.
% The \TikZ{} support, for example, writes commands to the ccmemo which assign plugs analogous to the \pkg{latex-lab} plugs available for non-memoized pictures.
%
% More precisely, the \TikZ{} support now uses one of the wrapper functions the package provides to assist users for the most common cases.
%
% \DescribeSock{tagsupport/memoize/include/extern/before}
%
% This socket receives three arguments during extern utilisation: the width, height and depth of the memoized content.
% The \texttt{alt} plug for \TikZ{}, for example, uses these values to calculate the bounding box required to create a \texttt{Figure} structure with \texttt{alt} text.
%
% This socket is used just before the extern is included in the document.
%
% \DescribeSock{tagsupport/memoize/include/extern/after}
%
% This socket absorbs no arguments.
% During extern utilisation, it is used immediately after inclusion of an extern.
%
% \subsubsection{\pkg{expl3} functions}
%
% Three functions are provided to help setup code for these sockets when an extern is utilised.
% They should be used either during memoization or to configure defaults for use during memoization.
% 
% In pseudo-code, all three write the equivalent of the following to the \emph{ccmemo} for execution during utilisation.
% \begin{verbatim}
% \mmzxtagtoks={<expansion of \the\mmzxtagtoks>}%
% \AssignSocketPlug{tagsupport/memoize/include/extern/before}{<plug for before>}%
% \AssignSocketPlug{tagsupport/memoize/include/extern/after}{<plug for after>}%
% \end{verbatim}
% The effect is that the specified plugs will be used before and after the \emph{extern} is utilised and these may use the \emph{toks} register \cs{mmzxtagtoks}, if appropriate.
% If \pkg{expl3} syntax is preferred, \ecs{mmzx_tag_get_recorded:N} may be used instead.
%
% \DescribeFn{\mmzx_tag_socket_plug_record:nnn} \hspace*{10mm}\marg{plug for before} \marg{plug for after} \marg{tokens}
%
% Write code to the \emph{ccmemo} which assigns
% \begin{itemize}
%   \item \meta{plug for before} to the socket \texttt{tagsupport/memoize/include/extern/before},
%   \item \meta{plug for after} to the socket \texttt{tagsupport/memoize/include/extern/after}
%   \item and \meta{tokens} to the toks register \cs{mmzxtagtoks}
% \end{itemize}
% \emph{during utilisation}.
%
% \DescribeFn{\mmzx_tag_socket_plug_record:nn} \hspace*{10mm}\marg{plug for before} \marg{plug for after}
%
% Write code to the \emph{ccmemo} which assigns
% \begin{itemize}
%   \item \meta{plug for before} to the socket \texttt{tagsupport/memoize/include/extern/before},
%   \item \meta{plug for after} to the socket \texttt{tagsupport/memoize/include/extern/after}
%   \item and the current contents of \cs{mmzxtagtoks} to the toks register \cs{mmzxtagtoks}
% \end{itemize}
% \emph{during utilisation}.
%
% \DescribeFn{\mmzx_tag_socket_plug_record:} \mbox{ } 
%
% Write code to the \emph{ccmemo} which assigns
% \begin{itemize}
%   \item the plug currently installed in the socket \texttt{tagsupport/memoize/include/extern/before} to the socket \texttt{tagsupport/memoize/include/extern/before},
%   \item the plug currently installed in the socket \texttt{tagsupport/memoize/include/extern/after} to the socket \texttt{tagsupport/memoize/include/extern/after}
%   \item and the current contents of \cs{mmzxtagtoks} to the toks register \cs{mmzxtagtoks}
% \end{itemize}
% \emph{during utilisation}.
%
% A fourth function is provided to access the contents of the toks register \cs{mmzxtagtoks}, in case \pkg{expl3} syntax is preferred. 
%
% \DescribeFn{\mmzx_tag_get_recorded:N} \meta{token list}
%
% Recovers the value from the toks register for the current extern during utilisation and stores it in the specified (local) token list variable.
% May be used in the definitions of plugs, as explained above for \cs{mmzxtagtoks}.
%
% ^^A >>> end sec:tag
%
% ^^A sec:basics >>>
% 
% \MaybeStop{%
%   \def\glossaryname{Changes}%
%   \printbibliography
%   \PrintChanges
%   \PrintIndex
% }
% 
% \part{Implementation}
%
% A double underscore (\texttt{\_\_}) \emph{or} an ‘at’ (\texttt{@}) indicates an internal macro or key. 
% These are liable to change without notice and should not be used elsewhere.
% Some additional macros are categorised in the same way, but are named differently to simplify use in memos\footnote{%
%   This follows \pkg{memoize}'s own practice.%
% }.
%
% \makeatletter
% \let\origmaketitle\maketitle
% \NewDocumentCommand \pkginput {O{#2}m}{%
%   \begingroup
%     \def\maketitle{%
%       \expandafter\ifx\expandafter\MyExplFileName\@title
%         \def\@title{\pkg{\MyExplFileName-#1}}%
%       \fi
%       \ifx\@author\@empty
%         \def\@author{Clea F. Rees}%
%       \fi
%       \ifx\@date\@empty
%         \def\@date{v0.4.2 \MyExplFileVersion: \MyExplFileDate}%
%       \fi
%       \let\saved@title\@title
%       \origmaketitle
%       \phantomsection
%       \addcontentsline{toc}{section}{\mdseries\pkg{\saved@title}}%
%       \fancyhf[lh]{\itshape memoize-ext-#1}%
%     }%
%     \let\Finale\relax
%     \let\PrintIndex\relax
%     \let\PrintChanges\relax
%     \input{\memoizeextdocbase -#2.dtx}%
%   \endgroup
% }
% \makeatother
%
% \section*{\pkg{\MyExplFileName}}
% \addcontentsline{toc}{section}{\mdseries\pkg{\MyExplFileName}}
%
%<*sty>
%<@@=mmzx>
% ^^A <<<
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}[2021-11-15]% ^^A should be later
%    \end{macrocode}
% copied verbatim, excepting format from Joseph Wright's \path{siunitx.sty} under LPPL
%    \begin{macrocode}
\@ifundefined{ExplLoaderFileDate}{%
  \RequirePackage{expl3}%
}{}
%    \end{macrocode}
% almost verbatim from \path{siunitx.sty}
%
% should check date requirement (copied from chronos)
%    \begin{macrocode}
\@ifl@t@r\ExplLoaderFileDate{2022-02-24}{%
}{%
  \PackageError{memoize-ext}{Support package expl3 too old}
  {%
    You need to update your installation of the bundles 'l3kernel' and
    'l3packages'.\MessageBreak
    Loading memoize-ext will abort!%
  }%
  \endinput
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\GetIdInfo $Id: memoize-ext.dtx 11956 2026-06-04 03:13:27Z cfrees $ {Extensions for Memoize}
%<!debug>    \ProvidesExplPackage{\ExplFileName}{\ExplFileDate}
%<!debug>     {v0.4.2 \ExplFileVersion}{\ExplFileDescription}
%<debug>    \ProvidesExplPackage{\ExplFileName-debug}
%<debug>      {\ExplFileDate}{v0.4.2 \ExplFileVersion}{\ExplFileDescription}
%
\str_new:N \g_@@_name_str
\str_gset:NV \g_@@_name_str \ExplFileName
%
%<!debug>    \disable@package@load {memoize-ext-debug}
%<debug>    \disable@package@load {memoize-ext}
{
  Only~one~of~memoize-ext~and~memoize-ext-debug~should~be~loaded.~
  Since~
%<!debug>    memoize-ext
%<debug>    memoize-ext-debug
  ~had~been~loaded,~I~will~ignore~your~request~for~
%<debug>    memoize-ext
%<!debug>    memoize-ext-debug
.}
\SetDefaultHookLabel{memoize-ext}
%    \end{macrocode}
% \begin{var}{\l_@@_opt_tag_bool}
%   Set according to activation status by default.
%    \begin{macrocode}
\bool_new:N \l_@@_opt_tag_bool
\tag_if_active:TF 
  { \bool_set_true:N \l_@@_opt_tag_bool }
  { \bool_set_false:N \l_@@_opt_tag_bool }
%    \end{macrocode}
% \end{var}
% \begin{var}{\l_@@_opt_draw_bool,\l_@@_opt_expl_bool}
% \changes{v0.4}{2026-03-30}{Fix non-recognition of memoize pkg options in \pkg{memoize-ext-debug}.}
%   Other bools.
%    \begin{macrocode}
\keys_define:nn {memoize-ext}
{
%<*!debug>
  debug       .code:n     = {
    \PackageWarning{memoize-ext}{
      To~load~the~debugging~code,~use~memoize-ext-debug~instead~of~this~package.
    }
  },
%</!debug>
  expl3       .bool_set:N = \l_@@_opt_expl_bool,
  expl3       .default:n  = true,
  expl3       .initial:n  = false,
  l3draw      .bool_set:N = \l_@@_opt_draw_bool,
  l3draw      .default:n  = true,
  l3draw      .initial:n  = true,
  tag         .bool_set:N = \l_@@_opt_tag_bool,
  tag         .default:n  = true,
  talk        .bool_set:N = \l_@@_opt_talk_bool,
  talk        .default:n  = true,
  talk        .initial:n  = true,
}
%    \end{macrocode}
% \changes{v0.4}{2026-06-02}{\githubref[Fix for]{latex3/latex2e/issues/2110}{\LaTeXe{} issue \#2110}.}
% Joseph Wright: \url{https://chat.stackexchange.com/transcript/message/69011532#69011532}.
%    \begin{macrocode}
\IfFormatAtLeastTF { 2026-06-01 }{
  \IfFormatAtLeastF { 2026-11-01 }{
    \DeclareDocumentCommand \DeclareUnknownKeyHandler { O { \@currname } +m }
    {
      \cs_set_protected:cpn { __keys_unknown_handler_ #1 :nn } ##1##2 {#2}
      \__keys_options_expand_module:Nn \keys_define:ne {#1}
      {
        unknown .code:n =
        \exp_not:N \exp_args:NV
        \exp_not:c { __keys_unknown_handler_ #1 :nn }
        \exp_not:N \l_keys_key_str {##1}
      }
    }
  }
}{}
%    \end{macrocode}
% Pass unknown options to \pkg{memoize}, loaded below.
%    \begin{macrocode}
\DeclareUnknownKeyHandler[memoize-ext]{
  \PassOptionsToPackage{\CurrentOption}{memoize}
}
%    \end{macrocode}
% \end{var}
% \begin{macro}{\IfFormatAtLeastTF}%^^A <<<
% Joseph Wright: from \path{siunitx.sty} ; \url{https://chat.stackexchange.com/transcript/message/64327823#64327823}
%    \begin{macrocode}
\providecommand \IfFormatAtLeastTF { \@ifl@t@r \fmtversion }
%    \end{macrocode}
% \end{macro}%^^A >>>
%    \begin{macrocode}
\IfFormatAtLeastTF { 2022-06-01 }
{
  \ProcessKeyOptions [ memoize-ext ] 
}{
  \RequirePackage { l3keys2e }
  \ProcessKeysOptions { memoize-ext }
}
%    \end{macrocode}
%^^A if we require 2022-02-24 expl3 above what is this for?
%^^A is it even possible to use that expl3 with somehow an older format?
%^^A (wasn't expl3 in the format by then?)
%    \begin{macrocode}
\IfFormatAtLeastTF { 2020-10-01 }{
}{
  \RequirePackage { xparse }
  \providecommand \ExpandArgs [1]
  { \cs_if_exist_use:c { exp_args:N #1 } }
}
%    \end{macrocode}
% Should specify next version here, most probably. 
% Or conditionalise input switch for ccmemos?
%
% \verb|^^| ????
%    \begin{macrocode}
\RequirePackage{memoize}
%<debug>    \mmzset{
%<debug>      trace,
%<debug>      include~context~in~ccmemo,
%<debug>    }
%    \end{macrocode}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Fix for \cs{toksapp} and friends courtesy of Max Chernoff
% \url{https://github.com/sasozivanovic/memoize/pull/57/commits}.
% \changes{v0.3.2}{2026-03-14}{Fix \cs{toksapp} and friends courtesy Max Chernoff. }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%    \begin{macrocode}
\sys_if_engine_luatex:F
{
  \clist_map_inline:nn {\toksapp,\etoksapp,\gtoksapp,\xtoksapp}
  {
    \tl_if_head_eq_meaning:VNF #1 \protected
    {
      \expandafter\protected\expandafter\def\expandafter#1\expandafter{#1}
    }
  }
}
%    \end{macrocode}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \begin{macro}{\@mmzx@kernel@after@shipout@background}
% bug fix: Ulrike Fischer: \url{https://chat.stackexchange.com/transcript/41?m=68852988#68852988}
% \changes{v0.3.5}{2026-03-24}{\githubref[Fix for]{sasozivanovic/memoize/issues/60}{issue \#60}.}
% \changes{v0.3.6}{2026-03-26}{Fix fix for \githubref[Fix for]{sasozivanovic/memoize/issues/60}{issue \#60}.}
% \changes{v0.3.6}{2026-03-27}{Use ‘less internal’ internal 2e macro, which does not need metadata test.}
% \githubref[‘Less internal’ internal macro: Jasper Habicht]{cfr42/prooftrees/issues/8}{issue \#8}.
% Lua\LaTeX{} can't tolerate this addition to the shipout hook, whereas pdf\LaTeX{} produces an invalid \textsc{pdf} without it.
% I have no clue about other engines, but probably better to err on the side of caution and leave possibly-well alone.
% 
% \changes{v0.3.6}{2026-03-30}{Try to be a bit more cautious, even on pdf\LaTeX{}.}
% My worry here is that if the contents of \cs{@kernel@after@shipout@background} changes, I have zero confidence the same problem won't arise for pdf\LaTeX{}.
% \emph{However}, a combination of \cs{protected} and \cs{noexpand} seems to work even if I use \cs{special}\{\} rather than the kernel hook \emph{and} it avoids looping with Lua\LaTeX{}.
% So, even though I have no clue what is happening and even though Ulrike said she can't see how it would help, since it does help, it seems better to err on the side of caution.
%
% Better create an invalid \textsc{pdf} than looping infinitely not creating one at all \dots{}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%    \begin{macrocode}
\cs_new_protected_nopar:Npn \@mmzx@kernel@after@shipout@background
{
  \use:c {@kernel@after@shipout@background}
}
\FirstAidNeededT{memoize}{sty}{2024/12/02~v1.4.1~Fast~and~flexible~externalization}{
  \sys_if_engine_pdftex:T {
    \hook_gput_code:nnn {begindocument/end} {.} {
      \hook_gput_code:nnn {cmd/mmz@shipout@extern/before} {.} {
        \noexpand\@mmzx@kernel@after@shipout@background
      }
    }
  }
}
%    \end{macrocode}
% \end{macro}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% temporary variables, quarks
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%    \begin{macrocode}
\bool_new:N \l_@@_tmpa_bool
\fp_new:N \l_@@_tmpa_fp
\int_new:N \l_@@_tmpa_int
\quark_new:N \q_@@_stop
\tl_new:N \l_@@_tmpa_tl
\tl_new:N \l_@@_tmpb_tl
\tl_new:N \l_@@_tmpc_tl
\seq_new:N \l_@@_tmpa_seq
\str_new:N \l_@@_tmpa_str
\str_new:N \l_@@_tmpb_str
%<*debug>
\cs_new_protected:Npn \@@_debug:n #1
{
  \iow_log:n {[mmzx~debug]::~#1}
}
\cs_generate_variant:Nn \@@_debug:n {e}
\cs_new_protected:Npn \@@_debug:N #1
{
  \@@_debug:e {\cs_to_str:N #1:~\exp_args:NV \exp_not:n #1}
}
%</debug>
%    \end{macrocode}
% \begin{macro}{\@@_noop:,\@@_noop:n}
%   \changes{v0.3.3}{2026-03-15}{Need this defined earlier.
%     I'm starting to understand why libraries are a thing.}
%   Do nothing successfully.
%   \changes{v0.4}{2026-06-02}{Fix \ecs{@@_noop:n}, though currently unused.}
%    \begin{macrocode}
\cs_new:Npn \@@_noop: {}
\cs_new_eq:NN \@@_noop:n \use_none:n
%    \end{macrocode}
% \end{macro}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \pkg{tag}, \pkg{expl}, \pkg{l3draw}, \pkg{talk} loaded conditionally
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%    \begin{macrocode}
\bool_if:NT \l_@@_opt_tag_bool
{
%<!debug>      \RequirePackage{\g_@@_name_str -tag}
%<debug>      \RequirePackage{\g_@@_name_str -tag-debug}
  \hook_gput_code:nnn {package/forest/after}{.}
  {
    \hook_gput_code:nnn {begindocument/before}{.}
    {
      \IfPackageLoadedF {forest-lib-ext.tagging}
      {
        \IfPackageLoadedF {forest-lib-ext.tagging-debug}
        {
          \msg_warning:nnnnnn {memoize-ext}{unsupported}{forest}
          {forest-lib-ext.tagging.sty}{forest-ext}
          {forest~trees~will~not~be~correctly~tagged~and~may~cause~fatal~
          compilation~errors.}
        }
      }
    }
  }
}
%    \end{macrocode}
% \pkg{memoize-ext-expl3}[\pkg{-debug}]
%    \begin{macrocode}
\bool_if:NT \l_@@_opt_expl_bool
{
%<!debug>      \RequirePackage{\g_@@_name_str -expl3}
%<debug>      \RequirePackage{\g_@@_name_str -expl3-debug}
}
%    \end{macrocode}
% \pkg{memoize-ext-l3draw}[\pkg{-debug}]
%    \begin{macrocode}
\hook_gput_code:nnn {package/l3draw/after}{.}
{
  \bool_if:NT \l_@@_opt_draw_bool
  { 
%<!debug>      \RequirePackage {\g_@@_name_str -l3draw}
%<debug>      \@@_debug:n {Loading~memoize-ext-l3draw-debug.}
%<debug>      \RequirePackage {\g_@@_name_str -l3draw-debug}
  }
}
%    \end{macrocode}
% \pkg{memoize-ext-talk}[\pkg{-debug}]
%    \begin{macrocode}
\hook_gput_code:nnn {class/ltx-talk/after} {.}
{
  \bool_if:NT \l_@@_opt_talk_bool
  {
%<!debug>      \RequirePackage{memoize-ext-talk}
%<debug>      \@@_debug:n {Loading~memoize-ext-talk-debug.}
%<debug>      \RequirePackage{memoize-ext-talk-debug}
  }
}
%    \end{macrocode}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% NaCl \textbar{} halen \textbar{} salt
% \changes{v0.3}{2026-03-05}{Add tagging status to salt.}
%    \begin{macrocode}
\toksapp\mmzSalt{
  Tagging~status:~\tag_if_active_p:
}
%    \end{macrocode}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% messages
%    \begin{macrocode}
\msg_new:nnnn {memoize-ext}{unsupported}
{
  \msg_warning_text:n {memoize-ext}:~
  Non-existent~or~inappropriate~version~of~#2~from~#3~\msg_line_context:.~
  #4
} {
  memoize-ext#1~requires~an~appropriate~version~of~#2~from~#3.
}
%    \end{macrocode}
% ^^A >>>
%</sty>
%
% \pkginput{expl3}
% \pkginput{l3draw}
% ^^A \pkginput{properties}
% \pkginput{sockets}
% \pkginput{tag}
% ^^A \pkginput{tagging-tikz}
% \pkginput{talk}
% 
% \twreg
% \printbibliography
%\Finale
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%^^A vim: et:tw=0:sw=2:ts=2:foldmethod=marker:fmr=<<<,>>>:
