Debian Codegraph @

texmf-dist/source/latex/memoize-ext/memoize-ext-tag.dtx

raw
1 % \iffalse meta-comment
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 % memoize-ext.dtx
4 % Additions and changes Copyright (C) 2024-2026 Clea F. Rees.
5 % Code from skeleton.dtx Copyright (C) 2015-2024 Scott Pakin (see below).
6 %
7 % This work may be distributed and/or modified under the
8 % conditions of the LaTeX Project Public License, either version 1.3c
9 % of this license or (at your option) any later version.
10 % The latest version of this license is in
11 % https://www.latex-project.org/lppl.txt
12 % and version 1.3c or later is part of all distributions of LaTeX
13 % version 2008-05-04 or later.
14 %
15 % This work has the LPPL maintenance status 'muaintained'.
16 %
17 % The Current Maintainer of this work is Clea F. Rees.
18 %
19 % This work consists of all files listed in manifest.txt.
20 %
21 % The file memoize-ext.dtx is a derived work under the terms of the
22 % LPPL. It is based on version 2.4 of skeleton.dtx which is part of
23 % dtxtut by Scott Pakin. A copy of dtxtut, including the
24 % unmodified version of skeleton.dtx is available from
25 % https://www.ctan.org/pkg/dtxtut and released under the LPPL.
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27 % \fi
28 %
29 % \iffalse
30 %<*driver>
31 \GetIdInfo $Id: memoize-ext-tag.dtx 11815 2026-03-25 19:50:49Z cfrees $ {Extensions for Memoize}
32 \ProvidesExplFile{\ExplFileName}{\ExplFileDate}{v0.3.5 \ExplFileVersion}{\ExplFileDescription}
33 \begin{document}
34 \let\MakePrivateLetters\MyMakePrivateLetters
35 \DocInput{\filename}
36 \end{document}
37 %</driver>
38 % \fi
39 %
40 %
41 % \title{\ExplFileName}
42 % \date{\ExplFileVersion~\ExplFileDate}
43 % \maketitle
44 %
45 % \begin{abstract}
46 % \noindent\pkg{memoize-ext-tag} is part of \pkg{memoize-ext}.
47 % It supports tagging memoized content/the memoization of tagged content.
48 % \end{abstract}
49 %
50 %
51 % \tableofcontents
52 %
53 %
54 % \MaybeStop{%
55 % \PrintChanges
56 % \PrintIndex
57 % }
58 %
59 % ^^A \section{Implementation}
60 %
61 % Uses and/or redefines the following internals, primitives and other nefarious methods:
62 % \begin{itemize}
63 % \item \verb|\l__socket_assigned_plug:n| thing
64 % \begin{itemize}
65 % \item If a public interface for retrieving the plug is provided at some point, I will see if I can use that.
66 % However, they do not wish it to be expandable.
67 % This is manageable, but it is very nice having an expandable function here, so I will see if I realise, remember and can do it not-too-painfully, I guess.
68 % \end{itemize}
69 % \item \pkg{latex-lab} variables, keys etc.
70 % \begin{itemize}
71 % \item This is fairly fragile: patching patches to make them work with patched patches \dots.
72 % \item But I guess the \pkg{l3keys} and \pkg{pgfkeys} are public.
73 % I'm not sure about the sockets/plugs.
74 % Are these supposed to be used by external code?
75 % \item The use of \verb|l__tikz_tagging_alt_tl| and \verb|l__tikz_tagging_actualtext_tl| is definitely ungood, but I do not currently see a better way.
76 % Hopefully most people will use the \pkg{pgfkeys} interface, as that's much more natural here?
77 % \end{itemize}
78 % \item \verb|\tex_savepos:D|
79 % \begin{itemize}
80 % \item This is more-or-less routine and actually documented, so no worries really here?
81 % \end{itemize}
82 % \item \cs{mmzIncludeExtern}
83 % \begin{itemize}
84 % \item Documented as internal, certainly not something to redefine, but maybe I can persuade Sašo to add the sockets I need here?
85 % \end{itemize}
86 % \end{itemize}
87 %
88 %<*sty>
89 %<@@=mmzx>
90 % \begin{macrocode}
91 \GetIdInfo $Id: memoize-ext-tag.dtx 11815 2026-03-25 19:50:49Z cfrees $ {Extensions for Memoize for tagged tikz pictures}
92 %<!debug> \ProvidesExplPackage{\ExplFileName}{\ExplFileDate}
93 %<!debug> {v0.3.5 \ExplFileVersion}{\ExplFileDescription}
94 %<debug> \ProvidesExplPackage{\ExplFileName-debug}{\ExplFileDate}
95 %<debug> {v0.3.5 \ExplFileVersion}{\ExplFileDescription}
96 %
97 %<!debug> \disable@package@load {memoize-ext-tag-debug}
98 %<debug> \disable@package@load {memoize-ext-tag}
99 { Only~one~of~memoize-ext-tag~and~memoize-ext-tag-debug~
100 should~be~loaded.
101 Since~
102 %<!debug> memoize-ext-tag
103 %<debug> memoize-ext-tag-debug
104 ~has~been~loaded,~I~will~ignore~your~request~for~
105 %<debug> memoize-ext-tag
106 %<!debug> memoize-ext-tag-debug
107 .}
108 % \end{macrocode}
109 % \begin{macrocode}
110 %<!debug> \RequirePackage{memoize-ext}
111 %<debug> \RequirePackage{memoize-ext-debug}
112 %
113 % \end{macrocode}
114 % We don't want inconsistent names in hooks.
115 % \begin{macrocode}
116 \SetDefaultHookLabel{memoize-ext}
117 %
118 \cs_generate_variant:Nn \socket_assign_plug:nn {nV}
119 % \end{macrocode}
120 % \begin{var}{\g_@@_tagpic_int,\l_@@_toks_tl,\l_@@_ok_bool,\g_@@_plug_orig_str}
121 % \begin{toksr}{\mmzxtagtoks}
122 % Tracking \& storage variables.
123 % \begin{macrocode}
124 \bool_new:N \l_@@_ok_bool
125 \int_new:N \g_@@_tagpic_int
126 \str_new:N \g_@@_plug_orig_str
127 \tl_new:N \l_@@_toks_tl
128 \newtoks\mmzxtagtoks
129 % \end{macrocode}
130 % \end{toksr}
131 % \end{var}
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 % \begin{socket}{tagsupport/memoize/include/extern/before,tagsupport/memoize/include/extern/after}
134 % New sockets for extern utilisation.
135 % \begin{macrocode}
136 \socket_new:nn {tagsupport/memoize/include/extern/before} {3}
137 \socket_new:nn {tagsupport/memoize/include/extern/after} {0}
138 % \end{macrocode}
139 % \end{socket}
140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 % Ulrike's pgf/tikz keys don't do anything with the arguments they receive?
142 % It only seems they do because \texttt{init} passes them also to the l3keys?
143 %
144 % And so we have to pass them from tikz to l3keys and back to tikz \dots.
145 %
146 % This creates a problem of synchronisation.
147 % It would be nice to use module-specific names to track \pkg{latex-lab} internal variables for ease of maintenance, but I don't think this is possible.
148 % If I let a new name to a token list variable, I'll just get the current value.
149 %
150 % On the one hand, if users use \pkg{pgfkeys} to set the values for \texttt{alt} and \texttt{actualtext}, we can easily avoid \pkg{latex-lab} internals, at least.
151 % But we do that by introducing additional variables and then have the problem of synchronisation.
152 %
153 % On the other hand, we could avoid the synchronisation problems by using \pkg{latex-lab} internals more consistently, but then even the \pkg{pgfkeys} interface will be dependent on the internal implementation\footnote{%
154 % I get the prohibition on internals.
155 % I really do.
156 % But there are cases where it just makes things much more complicated and error-prone.
157 % And sometimes it just doesn't not seem worth the additional fragility that introduces, even at the cost of some additional fragility due to the use of internals.%
158 % }.
159 % \changes{v0.2}{2026-02-27}{See \texttt{init}.}
160 %
161 % Note: will need revising when the \pkg{pgfkeys} version of the \pkg{latex-lab} code gets published.
162 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163 % \begin{macrocode}
164 \hook_gput_code:nnn {package/tikz/after} {.}
165 {
166 \pgfqkeys{/tikz}{
167 alt/.forward~to=/mmz/alt,
168 actualtext/.forward~to=/mmz/actualtext,
169 artifact/.forward~to=/mmz/artifact,
170 tagging-setup/.forward~to=/mmz/tagging-setup,
171 /mmzx/tagging@setup/.is~family,
172 alt/.belongs~to~family=/mmzx/tagging@setup,
173 artifact/.belongs~to~family=/mmzx/tagging@setup,
174 actualtext/.belongs~to~family=/mmzx/tagging@setup,
175 tagging-setup/.belongs~to~family=/mmzx/tagging@setup,
176 }
177 \mmzset{
178 alt/.code={
179 \keys_set:nn {tikz/tagging}{alt={#1}}
180 \bool_set_true:N \l_@@_ok_bool
181 \str_gset:Nn \g_@@_plug_orig_str {alt}
182 \exp_args:Ne \mmzxtagtoks { \text_purify:n {#1} }
183 \socket_assign_plug:nn
184 {tagsupport/memoize/include/extern/before} {mmzx/alt}
185 \socket_assign_plug:nn
186 {tagsupport/memoize/include/extern/after} {mmzx/alt}
187 %<debug> \tl_log:e {\exp_args:No \exp_not:n {\the\mmzCCMemo}}
188 },
189 actualtext/.code={
190 \keys_set:nn {tikz/tagging}{actualtext={#1}}
191 \bool_set_true:N \l_@@_ok_bool
192 \str_gset:Nn \g_@@_plug_orig_str {actualtext}
193 \exp_args:Ne \mmzxtagtoks { \text_purify:n {#1} }
194 \socket_assign_plug:nn
195 {tagsupport/memoize/include/extern/before} {mmzx/actualtext}
196 \socket_assign_plug:nn
197 {tagsupport/memoize/include/extern/after} {mmzx/actualtext}
198 %<debug> \tl_log:e {\exp_args:No \exp_not:n {\the\mmzCCMemo}}
199 },
200 artifact/.code={
201 \keys_set:nn {tikz/tagging}{artifact}
202 \bool_set_true:N \l_@@_ok_bool
203 \str_gset:Nn \g_@@_plug_orig_str {artifact}
204 \mmzxtagtoks {}
205 \socket_assign_plug:nn
206 {tagsupport/memoize/include/extern/before} {mmzx/artifact}
207 \socket_assign_plug:nn
208 {tagsupport/memoize/include/extern/after} {mmzx/artifact}
209 %<debug> \tl_log:e {\exp_args:No \exp_not:n {\the\mmzCCMemo}}
210 },
211 tagging-setup/.is~choice,
212 tagging-setup/alt/.forward~to=/mmz/alt,
213 tagging-setup/actualtext/.forward~to=/mmz/actualtext,
214 tagging-setup/artifact/.forward~to=/mmz/artifact,
215 tagging-setup/.unknown/.code =
216 {
217 \exp_args:Nno
218 \keys_set:nn {tikz/tagging}{\pgfkeyscurrentname={#1}}
219 },
220 alt/.belongs~to~family=/mmzx/tagging@setup,
221 actualtext/.belongs~to~family=/mmzx/tagging@setup,
222 artifact/.belongs~to~family=/mmzx/tagging@setup,
223 tagging-setup/.belongs~to~family=/mmzx/tagging@setup,
224 tagging-setup/alt/.belongs~to~family=/mmzx/tagging@setup,
225 tagging-setup/actualtext/.belongs~to~family=/mmzx/tagging@setup,
226 tagging-setup/artifact/.belongs~to~family=/mmzx/tagging@setup,
227 }
228 }
229 % \end{macrocode}
230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
231 % So it is possible to do without this, but it is \emph{much} more straightforward to do with.
232 %
233 % The basic idea is this:
234 % \begin{itemize}
235 % \item At the start of memoization, we redefine the (internal) command \cs{mmzIncludeExtern}.
236 % \item In its place, we use simple wrapper around a copy of the original.
237 % \item The wrapper defines a socket before and after executing the original.
238 % \end{itemize}
239 % This lets us wrap utilisation of the extern in an appropriate tagging structure.
240 % At least, that's the idea.
241 %
242 % It would be nice to assign the plug here just based on whichever plugs are installed, but it is too early, while \cs{mmzAtEndMemoization} is too late.
243 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
244 % \begin{macrocode}
245 \appto\mmzAtBeginMemoization{
246 \gtoksapp\mmzCCMemo{
247 \let\mmzxIncludeExternOrig\mmzIncludeExtern
248 \let\mmzIncludeExtern\mmzxIncludeExtern
249 }
250 }
251 % \end{macrocode}
252 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
253 % \begin{fn}{\@@_noop:nNnnnnnnn,\@@_include_extern:nNnnnnnnn}
254 % \begin{macro}{\mmzxIncludeExtern,\mmzxIncludeExternOrig}
255 % \cs{mmzIncludeExtern} only seems to be defined during utilisation, so we set up a command \cs{mmzxIncludeExternOrig} and set it to noop here, then redefine it locally when the extern is utilised.
256 % \cs{mmzIncludeExtern} is then redefined to \cs{mmzxIncludeExtern}, which wraps \cs{mmzxIncludeExternOrig} in a tagging structure\footnote{%
257 % Note to self: check output of tests visually if you do not want documents to be inaccessible to that tiny group of people who rely on vision to read.%
258 % }.
259 %
260 % Note this not only uses, but redefines an internal command which the manual says users should never need to even use \dots.
261 %
262 % On the other hand, this is exactly the kind of thing \pkg{memoize} does to \emph{other} packages' internals and, indeed, to the \LaTeX{} Project's.
263 % Which is more than can be said to defend my use of their internals \dots.
264 %
265 % But does that lessen my guilt? :-)
266 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
267 % \begin{macrocode}
268 \cs_new_protected_nopar:Npn
269 \@@_noop:nNnnnnnnn #1#2#3#4#5#6#7#8#9 {}
270 \cs_new_protected_nopar:Npn \@@_include_extern:nNnnnnnnn #1#2#3#4#5#6#7#8#9
271 {
272 \int_gincr:N \g_@@_tagpic_int
273 %<debug> \@@_debug:n {Args:~#1;~#2;~#3;~#4;~#5;~#6;~#7;~#8;~#9}
274 \socket_use:nnnn {tagsupport/memoize/include/extern/before}
275 {#3}{#4}{#5}
276 %<debug> \@@_debug:n {Executing~original~inclusion~macro.}
277 \mmzxIncludeExternOrig {#1}#2{#3}{#4}{#5}{#6}{#7}{#8}{#9}
278 %<debug> \@@_debug:n {Closing~tagging~structures.}
279 \socket_use:n {tagsupport/memoize/include/extern/after}
280 }
281 \cs_new_eq:NN \mmzxIncludeExtern \@@_include_extern:nNnnnnnnn
282 \cs_new_eq:NN \mmzxIncludeExternOrig \@@_noop:nNnnnnnnn
283 % \end{macrocode}
284 % \end{macro}
285 % \end{fn}
286 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
287 % \begin{plug}{tagsupport/memoize/include/extern/before~mmzx/alt}
288 % pgf/tikz
289 % addaswyd o latex-lab-testphase-tika.sty
290 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% <<<
291 % \begin{macrocode}
292 \socket_new_plug:nnn {tagsupport/memoize/include/extern/before} {mmzx/alt}
293 {
294 %<debug> \@@_debug:n {Executing~plug~mmzx/alt~in~socket~
295 %<debug> tagsupport/memoize/include/extern/before.}
296 \mode_if_vertical:T
297 {
298 \if@inlabel
299 \mode_leave_vertical:
300 \else
301 \tag_socket_use:n {para/begin}
302 \fi
303 }
304 \tag_mc_end_push:
305 \tl_set:No \l_@@_toks_tl {\the\mmzxtagtoks}
306 \tag_struct_begin:n
307 {
308 tag=Figure,
309 alt=\l_@@_toks_tl,
310 }
311 \tag_mc_begin:n {tag=Figure}
312 \cs_new:cpe {mmzx@tag@tikz@mark@pos@\int_to_arabic:n {\g_@@_tagpic_int}}
313 {
314 \@@_pgftikz_tag_bbox:ennn {mmzx-id\int_to_arabic:n {\g_@@_tagpic_int}}
315 {#1}{#2}{#3}
316 }
317 %<debug> \cs_log:c {mmzx@tag@tikz@mark@pos@\int_to_arabic:n
318 %<debug> {\g_@@_tagpic_int}}
319 \tag_struct_gput:ene
320 {\tag_get:n {struct_num}}
321 {attribute}
322 {
323 /O /Layout /BBox~
324 [
325 \use:c
326 {mmzx@tag@tikz@mark@pos@\int_to_arabic:n {\g_@@_tagpic_int}}
327 ]
328 }
329 %<debug> \@@_debug:e {Recording~xpos,~
330 %<debug> ypos~of~mmxc-id\int_to_arabic:n {\g_@@_tagpic_int}.}
331 \tex_savepos:D
332 \@@_property_record_orig:ee
333 {mmzx-id\int_to_arabic:n {\g_@@_tagpic_int}}
334 {xpos,ypos}
335 \tex_savepos:D
336 }
337 % \end{macrocode}
338 % \end{plug}
339 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% >>>
340 % \begin{plug}{tagsupport/memoize/include/extern/after~mmzx/alt}
341 % pgf/tikz
342 % addaswyd o latex-lab-testphase-tika.sty
343 % bod yn onest, cafodd ei ddwyn o \pkg{latex-lab} yn hollol
344 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% <<<
345 % \begin{macrocode}
346 \socket_new_plug:nnn {tagsupport/memoize/include/extern/after} {mmzx/alt}
347 {
348 %<debug> \@@_debug:n {Executing~plug~mmzx/alt~in~socket~
349 %<debug> tagsupport/memoize/include/extern/after.}
350 \tag_mc_end:
351 \tag_struct_end:
352 \tag_mc_begin_pop:n {}
353 }
354 % \end{macrocode}
355 % \end{plug}
356 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% >>>
357 % \begin{plug}{%
358 % tagsupport/memoize/include/extern/before~mmzx/actualtext,
359 % tagsupport/memoize/include/extern/after~mmzx/actualtext,
360 % }
361 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% <<<
362 % addaswyd o latex-lab-testphase-tika.sty
363 % \begin{macrocode}
364 \socket_new_plug:nnn {tagsupport/memoize/include/extern/before} {mmzx/actualtext}
365 {
366 %<debug> \@@_debug:n {Executing~plug~mmzx/actualtext~in~socket~
367 %<debug> tagsupport/memoize/include/extern/before.}
368 \keys_set:nn {tikz/tagging} {actualtext:o = {\the\mmzxtagtoks},}
369 \socket_use:n {tagsupport/tikz/picture/begin}
370 }
371 \socket_new_plug:nnn {tagsupport/memoize/include/extern/after} {mmzx/actualtext}
372 {
373 %<debug> \@@_debug:n {Executing~plug~mmzx/actualtext~in~socket~
374 %<debug> tagsupport/memoize/include/extern/after.}
375 \socket_use:n {tagsupport/tikz/picture/end}
376 }
377 % \end{macrocode}
378 % \end{plug}
379 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% >>>
380 % \begin{plug}{%
381 % tagsupport/memoize/include/extern/before~mmzx/artifact,
382 % tagsupport/memoize/include/extern/after~mmzx/artifact,
383 % }
384 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% <<<
385 % addaswyd o latex-lab-testphase-tika.sty
386 % \begin{macrocode}
387 \socket_new_plug:nnn {tagsupport/memoize/include/extern/before} {mmzx/artifact}
388 {
389 %<debug> \@@_debug:n {Executing~plug~mmzx/artifact~in~socket~
390 %<debug> tagsupport/memoize/include/extern/before.}
391 \keys_set:nn {tikz/tagging} {artifact,}
392 \socket_use:n {tagsupport/tikz/picture/begin}
393 }
394 \socket_new_plug:nnn {tagsupport/memoize/include/extern/after} {mmzx/artifact}
395 {
396 %<debug> \@@_debug:n {Executing~plug~mmzx/artifact~in~socket~
397 %<debug> tagsupport/memoize/include/extern/after.}
398 \socket_use:n {tagsupport/tikz/picture/end}
399 }
400 % \end{macrocode}
401 % \end{plug}
402 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% >>>
403 % \begin{fn}{\@@_pgftikz_tag_bbox:nnnn,\@@_pgftikz_tag_bbox:ennn}
404 % A \pkg{memoize}-friendly alternative to get the bounding box for the \texttt{alt} plug.
405 % \begin{macrocode}
406 \cs_new_nopar:Npn \@@_pgftikz_tag_bbox:nnnn #1#2#3#4
407 {
408 \_@@_pgftikz_tag_bbox_aux:eennn
409 {
410 \mmzx_property_ref_orig:ee {#1}{xpos}
411 }
412 {
413 \mmzx_property_ref_orig:ee {#1}{ypos}
414 }
415 {#2}{#3}{#4}
416 }
417 \cs_generate_variant:Nn \@@_pgftikz_tag_bbox:nnnn {ennn}
418 % \end{macrocode}
419 % \end{fn}
420 % \begin{fn}{\@@_pgftikz_tag_bbox_aux:nnnnn,\@@_pgftikz_tag_bbox_aux:eennn}
421 % Auxiliary.
422 % \begin{macrocode}
423 \cs_new_nopar:Npn \@@_pgftikz_tag_bbox_aux:nnnnn #1#2#3#4#5
424 {
425 \dim_to_decimal_in_bp:n {#1sp}
426 \c_space_tl
427 \dim_to_decimal_in_bp:n {#2sp-#5}
428 \c_space_tl
429 \dim_to_decimal_in_bp:n {#1sp+#3}
430 \c_space_tl
431 \dim_to_decimal_in_bp:n {#2sp+#4+#5}
432 }
433 \cs_generate_variant:Nn \@@_pgftikz_tag_bbox_aux:nnnnn {eennn}
434 % \end{macrocode}
435 % \end{fn}
436 % \begin{macrocode}
437 \hook_gput_code_with_args:nnn {cmd/tikz@picture/before} {mmzx}
438 {
439 \tag_if_active:T
440 {
441 %<debug> \@@_debug:n {Executing~mmzx~code~in~hook~cmd/tikz@picture/before.}
442 \socket_assign_plug:nn {tagsupport/tikz/picture/init} {mmzx}
443 }
444 }
445 % \end{macrocode}
446 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% >>>
447 % \begin{plug}{tagsupport/tikz/picture/init~mmzx}
448 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% <<<
449 % Originally, I made something much more complicated, which worked, but meh.
450 % Here the idea is that \emph{if we are memoizing, we do not tag at all}.
451 % There's no real downside to this: a document which includes code memoized during the current run is not usable anyway and tagging the memoized code is pointless and inefficient.
452 % (Actually, so is executing the original code for use during the current run, which is, I believe, how it works.
453 % But that is not my fault.)
454 %
455 % Instead, we tag \emph{only the utilisation of memos}.
456 % We don't need to get the bounding box --- \pkg{memoize} already does that.
457 % All we need do is get the position on the page during utilisation.
458 % Everything else is for free.
459 %
460 % Note that this code uses multiple format/\pkg{latex-lab} internals.
461 % If the support for \pkg{tikz} used exclusively \pkg{pgfkeys}, this would be easily avoided: we could stick to the public interface for all but one of these usages.
462 % But because it supports also \pkg{l3keys}, I don't see a way to avoid depending on internal variables there, too.
463 % \pkg{l3keys} does not have a \verb|.forward_to:n| or similar.
464 % There is \verb|.inherit:n|, but that does not work at all in the same way.
465 % \changes{v0.2}{2026-02-27}{Avoid processing non-tagging keys too early and too often.
466 % Save and restore existing filter state.%
467 % }
468 % Filtering and family code (below) is copied from the code I suggested for \pkg{latex-lab}'s \TikZ{} support (\href{https://github.com/latex3/latex2e/pull/2004}{\#2004}).
469 % \begin{macrocode}
470 \socket_new_plug:nnn {tagsupport/tikz/picture/init} {mmzx}
471 {
472 %<debug> \@@_debug:n {Executing~plug~mmzx~in~socket~
473 %<debug> tagsupport/tikz/picture/init.}
474 \bool_set_false:N \l_@@_ok_bool
475 \legacy_if:nT {memoizing}
476 {
477 %<debug> \@@_debug:n {Arg~to~tagsupport/tikz/picture/init~is~#1.}
478 \pgfkeyssavekeyfilterstateto\mmzx@tagging@setup@saved@filterstate
479 \pgfkeysinstallkeyfilter{/pgf/key~filters/active~families}{}
480 \pgfqkeysactivatesinglefamilyandfilteroptions{/mmzx/tagging@setup}{/tikz}{#1}
481 %<debug> \@@_debug:e { Restoring~filter~state:~\exp_not:V
482 %<debug> \mmzx@tagging@setup@saved@filterstate }
483 \mmzx@tagging@setup@saved@filterstate
484 \bool_if:NF \l_@@_ok_bool
485 {
486 %<debug> \@@_debug:n {
487 %<debug> No~plug~set~for~utilisation.~Trying~to~match~latex-lab~plug.
488 %<debug> }
489 % \end{macrocode}
490 % If the argument to the picture set the plug, it is already in the code hash.
491 % Otherwise, we add the value of the \pkg{latex-lab} plug to the context, using \cs{mmzContextExtra} and appending globally as we are memoizing by hypothesis.
492 % \changes{v0.3.1}{2026-03-06}{Default to OK.}
493 % \begin{macrocode}
494 \xtoksapp\mmzContextExtra {
495 tagging~plug=\@@_socket_assigned_plug:n {tagsupport/tikz/picture/begin},
496 }
497 \str_case_e:nn
498 {\@@_socket_assigned_plug:n {tagsupport/tikz/picture/begin}}
499 {
500 {alt} {
501 \exp_args:Ne \mmzset{
502 alt = \exp_not:V \l__tikz_tagging_alt_tl,
503 }
504 %<debug> \@@_debug:n {Using~alt~plug.}
505 }
506 {actualtext} {
507 \exp_args:Ne \mmzset{
508 actualtext = \exp_not:V \l__tikz_tagging_actualtext_tl,
509 }
510 %<debug> \@@_debug:n {Using~actualtext~plug.}
511 }
512 {artifact} {
513 \mmzset{artifact,}
514 %<debug> \@@_debug:n {Using~artifact~plug.}
515 }
516 {text} {
517 \bool_set_false:N \l_@@_ok_bool
518 %<debug> \@@_debug:e {Found~unsupported~
519 %<debug> text~
520 %<debug> {tagsupport/tikz/picture/begin}~plug.}
521 \PackageWarning{memoize-ext}{Unsupported~tag~config~for~tikz~picture.~
522 Please~use~alt,~actualtext,~artifact~or~another supported~plug.~
523 Note~that~text~(the~latex-lab~default)~is~NOT~supported.~
524 Aborting~memoization~and~marking~code~unmemoizable.
525 }
526 \mmzUnmemoizable
527 }
528 }
529 }
530 }
531 \bool_if:NT \l_@@_ok_bool
532 {
533 % ^^A uses the currently assigned plugs for the before/after sockets
534 \@@_tag_socket_plug_record:
535 %<debug> \@@_debug:n {Disabling~tagging~for~current~tikz~picture~during~
536 %<debug> current~run.}
537 \socket_assign_plug:nn {tagsupport/tikz/picture/begin} {noop}
538 \socket_assign_plug:nn {tagsupport/tikz/picture/end} {noop}
539 \socket_assign_plug:nn {tagsupport/tikz/picture/text/begin} {noop}
540 \socket_assign_plug:nn {tagsupport/tikz/picture/text/end} {noop}
541 }
542 }
543 % \end{macrocode}
544 % \end{plug}
545 % \begin{macrocode}
546 \hook_gput_code:nnn {cmd/mmzAbort/after} {.}
547 {
548 \legacy_if:nT {memoizing} {
549 \PackageWarning{memoize-ext}{
550 Memoization~has~been~aborted.~If~something~like~a~reference~needs~
551 resolving,~just~compile~again.~If~the~content~is~unmemoizable~--~
552 e.g.~contains~remember~picture,~a~breakable~tcolorbox~or~suchlike,~
553 you~**must**~mark~the~content~unmemoizable~or~the~tagging~will~be~
554 incorrect.~You~may~do~this~automatically~or~manually.~Aborted~
555 }
556 }
557 }
558 % \end{macrocode}
559 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% >>>
560 % \begin{fn}{\@@_tag_socket_plug_record:nnn,
561 % \@@_tag_socket_plug_record:nn,
562 % \@@_tag_socket_plug_record:ee,
563 % \@@_tag_socket_plug_record:,
564 % %
565 % }
566 % Wrappers for the most common cases of recording plugs for use in utilisation.
567 % \changes{v0.3.4}{2026-03-24}{Add fns.\ \ecs{@@_tag_socket_plug_record:nnn}, \ecs{@@_tag_socket_plug_record:nn}, \ecs{@@_tag_socket_plug_record:ee} and \ecs{@@_tag_socket_plug_record:}.}
568 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% <<<
569 % \begin{macrocode}
570 \cs_new_protected:Npn \@@_tag_socket_plug_record:nn #1#2
571 {
572 \xtoksapp\mmzCCMemo{
573 \exp_not:N \mmzxtagtoks
574 =
575 \c_left_brace_str
576 \the\mmzxtagtoks
577 \c_right_brace_str
578 \exp_not:N \AssignSocketPlug
579 \c_left_brace_str
580 tagsupport/memoize/include/extern/before
581 \c_right_brace_str
582 \c_left_brace_str
583 #1
584 \c_right_brace_str
585 \exp_not:N \AssignSocketPlug
586 \c_left_brace_str
587 tagsupport/memoize/include/extern/after
588 \c_right_brace_str
589 \c_left_brace_str
590 #2
591 \c_right_brace_str
592 }
593 }
594 \cs_generate_variant:Nn \@@_tag_socket_plug_record:nn {ee}
595 \cs_new_protected:Npn \@@_tag_socket_plug_record:
596 {
597 \@@_tag_socket_plug_record:ee
598 {\@@_socket_assigned_plug:n {tagsupport/memoize/include/extern/before}}
599 {\@@_socket_assigned_plug:n {tagsupport/memoize/include/extern/after}}
600 }
601 \cs_new_protected:Npn \@@_tag_socket_plug_record:nnn #1#2#3
602 {
603 \mmzxtagtoks { \text_purify:n {#3} }
604 \@@_tag_socket_plug_record:nn {#1} {#2}
605 }
606 % \end{macrocode}
607 % \end{fn}
608 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% >>>
609 % \begin{fn}{\mmzx_tag_get_recorded:N}
610 % \changes{v0.3.4}{2026-03-25}{New expl3 fn.\ to get recorded text.}
611 % Intended for use in plugs.
612 %
613 % \verb|#1| should be a local token list variable.
614 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% <<<
615 % \begin{macrocode}
616 \cs_new_protected_nopar:Npn \mmzx_tag_get_recorded:N #1
617 {
618 \tl_set:No #1 {\the\mmzxtagtoks}
619 }
620 % \end{macrocode}
621 % \end{fn}
622 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% >>>
623 % \begin{fn}{\mmzx_tag_socket_plug_record:nnn,
624 % \mmzx_tag_socket_plug_record:nn,
625 % \mmzx_tag_socket_plug_record:%
626 % }
627 % \changes{v0.3.4}{2026-03-24}{Add fns.\ \ecs{mmzx_tag_socket_plug_record:nn} and \ecs{mmzx_tag_socket_plug_record:}.}
628 % Public names for recording and auto-recording plugs.
629 % Note \cs{mmzxtagtoks} is available here and is auto-recorded regardless.
630 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% <<<
631 % \begin{macrocode}
632 \cs_new_eq:NN \mmzx_tag_socket_plug_record:nnn \@@_tag_socket_plug_record:nnn
633 \cs_new_eq:NN \mmzx_tag_socket_plug_record:nn \@@_tag_socket_plug_record:nn
634 \cs_new_eq:NN \mmzx_tag_socket_plug_record: \@@_tag_socket_plug_record:
635 % \end{macrocode}
636 % \end{fn}
637 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% >>>
638 % pgf/tikz
639 % addaswyd o latex-lab-testphase-tika.sty
640 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
641 % Hook rules to ensure our substitutes override the format's.
642 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% <<<
643 % \begin{macrocode}
644 \hook_gset_rule:nnnn {cmd/tikz@picture/before}{latex-lab-testphase-tikz}{>}{.}
645 \hook_gset_rule:nnnn {cmd/tikz@picture/before}{tagpdf}{>}{.}
646 \hook_gset_rule:nnnn {cmd/tikz@picture/before}{tikz}{>}{.}
647 \hook_gset_rule:nnnn {cmd/endpgfpicture/after}{latex-lab-testphase-tikz}{>}{.}
648 \hook_gset_rule:nnnn {cmd/endpgfpicture/after}{tikz}{>}{.}
649 \hook_gset_rule:nnnn {cmd/endpgfpicture/after}{tagpdf}{>}{.}
650 \hook_gset_rule:nnnn {package/tikz/after} {.} {>} {latex-lab-testphase-tikz}
651 \hook_gset_rule:nnnn {package/tikz/after} {.} {>} {tagpdf}
652 \hook_gset_rule:nnnn {package/tikz/after} {.} {>} {tikz}
653 %<debug> \hook_log:n {package/tikz/after}
654 \hook_gput_code:nnn {begindocument/end} {.}
655 {
656 %<debug> \hook_log:n {cmd/tikz@picture/before}
657 %<debug> \hook_log:n {cmd/endpgfpicture/after}
658 % \end{macrocode}
659 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% >>>
660 % \begin{fn}{\mmzx_property_ref_orig:nn}
661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% <<<
662 % Avoid dependency on \pkg{memoize-ext-properties}.
663 % \begin{macrocode}
664 \cs_if_free:NT \mmzx_property_ref_orig:nn
665 {
666 \cs_new_eq:NN \mmzx_property_ref_orig:nn \property_ref:nn
667 \cs_generate_variant:Nn \mmzx_property_ref_orig:nn {ee}
668 }
669 % \end{macrocode}
670 % \end{fn}
671 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% >>>
672 % \begin{fn}{\@@_property_record_orig:nn}
673 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% <<<
674 % Avoid dependency on \pkg{memoize-ext-properties}.
675 % \begin{macrocode}
676 \cs_if_free:NT \@@_property_record_orig:nn
677 {
678 \cs_new_eq:NN \@@_property_record_orig:nn \property_record:nn
679 \cs_generate_variant:Nn \@@_property_record_orig:nn {ee}
680 }
681 % \end{macrocode}
682 % \end{fn}
683 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% >>>
684 % \begin{macrocode}
685 }
686 % \end{macrocode}
687 %</sty>
688 %
689 %\Finale
690 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
691 %^^A vim: et:tw=0:sw=2:ts=2:foldmethod=marker:fmr=<<<,>>>: