Debian Codegraph @

texmf-dist/source/latex-dev/base/ltproperties.dtx

raw
1 % \iffalse meta-comment
2 %
3 % File: ltproperties.dtx
4 %
5 % Copyright (C) 2023-2026 The LaTeX Project
6 %
7 % It may be distributed and/or modified under the conditions of the
8 % LaTeX Project Public License (LPPL), either version 1.3c of this
9 % license or (at your option) any later version. The latest version
10 % of this license is in the file
11 %
12 % http://www.latex-project.org/lppl.txt
13 %
14 % This file is part of the LaTeX base system. (The Work in LPPL)
15 % and all files in that bundle must be distributed together.
16 %
17 % -----------------------------------------------------------------------
18 %
19 % The development version of the bundle can be found at
20 %
21 % https://github.com/latex3/latex2e
22 %
23 % for those people who are interested.
24 %
25 % \fi
26 %
27 % \iffalse
28 %%% From File: ltproperties.dtx
29 %
30 %<*driver>
31 % \fi
32 \ProvidesFile{ltproperties.dtx}
33 [2026-05-01 v1.0n LaTeX Kernel (Properties)]
34 % \iffalse
35 %
36 \documentclass[full]{l3in2edoc}
37 \GetFileInfo{ltproperties.dtx}
38
39 \EnableCrossrefs
40 \CodelineIndex
41 \begin{document}
42 \DocInput{ltproperties.dtx}
43 \end{document}
44 %</driver>
45 % \fi
46 %
47 % \title{^^A
48 % Recording and cross-referencing document properties^^A
49 % \thanks{This module has version
50 % \fileversion\ dated \filedate, \copyright\ The \LaTeX\
51 % Project.}
52 % }
53 %
54 % \author{^^A
55 % The \LaTeX\ Project\thanks
56 % {^^A
57 % E-mail:
58 % \href{mailto:[email protected]}
59 % {[email protected]}^^A
60 % }^^A
61 % }
62 %
63 % \maketitle
64 %
65 % \begin{documentation}
66 % \begin{abstract}
67 % This code implements command to record and (expandably) reference
68 % document properties. It extends the standard \cs{label}/\cs{ref}/\cs{pageref}
69 % commands.
70 % \end{abstract}
71 %
72 % \tableofcontents
73 %
74 % \section{Introduction}
75 %
76 % The module allows to record the \enquote{current state} of various
77 % document properties (typically the content of macros and values of counters)
78 % and to access them in other places through a label.
79 % The list of properties that can be recorded and retrieved
80 % are not fix and can be extended by the user. The values of the properties
81 % are recorded in the \texttt{.aux} file and can be retrieved at the second compilation.
82 %
83 %
84 % The module uses the ideas of properties and labels. A label is
85 % a document reference point: a name for the user. An property is something
86 % that \LaTeX{} can track, such as a page number, section number or name.
87 % The names of labels and properties may be arbitrary. Note that there is
88 % a single namespace for each.
89 %
90 % \section{Design discussion}
91 %
92 % The design here largely follows ideas from \pkg{zref}. In particular, there
93 % are two independent concepts: properties that can be recorded between runs,
94 % and labels which consist of lists of these properties. The reason for the
95 % split is that individual labels will want to record some but not all
96 % properties. For examples, a label concerned with position would track
97 % the $x$ and $y$ coordinates of the current point, but not for example
98 % the page number.
99 %
100 % In the current implementation, properties share a single namespace. This
101 % allows multiple lists to re-use the same properties, for example page number,
102 % absolute page number, etc. This does mean that \emph{changing} a standard
103 % property is an issue. However, some properties have complex definitions
104 % (again, see \pkg{zref} at present): having them in a single shared space
105 % avoids the need to copy code.
106 %
107 % Labels could be implemented as |prop| data. That is not done at present as
108 % there is no obvious need to map to or copy the data. As such, faster
109 % performance is available using a hash table approach as in a \enquote{classical}
110 % set up. Data written to the |.aux| file uses simple paired \emph{balanced
111 % text} not keyvals: this avoids any restrictions on names and again offers
112 % increased performance.
113 %
114 % The \pkg{expl3} versions of the label command do not
115 % use \cs{@bsphack}/\cs{@esphack} to avoid double spaces,
116 % but the \LaTeXe{} command does as it lives at the document command level.
117 %
118 % The reference commands are expandable.
119 %
120 % Currently the code has nearly no impact on the main \cs{label} and \cs{ref} commands as
121 % too many external packages rely on the concrete implementation.
122 % There is one exception:
123 % the label names share the same namespace. That means that if both |\label{ABC}| and
124 % |\RecordProperties{ABC}{page}| are used there is a warning
125 % \texttt{Label `ABC' multiply defined}.
126 %
127 % \section{Handling unknown labels and properties}
128 % With the standard \cs{label}/\cs{ref} commands the requested label is
129 % either in the |.aux|-file (and so known) or not.
130 % In the first case the stored value can be used,
131 % in the second case the reference commands print two question marks.
132 %
133 % With flexible property lists a reference commands asks for the
134 % value of a specific property stored under a label name
135 % and we have to consider more variants:
136 % \begin{itemize}
137 % \item If the requested property is unknown (not declared) the system
138 % is not correctly set up and an error is issued.
139 % \item If the label is unknown, the default of the property is used.
140 % \item If the label is known, but doesn't provide a value for the
141 % property then again the default of the property is used.
142 % \item The command |\property_ref:nnn| allows to give a local default
143 % which is used instead of the property default in the two cases before.
144 % \end{itemize}
145 %
146 % \section{Rerun messages}
147 %
148 % As the reference commands are expandable they can neither issue a message that
149 % the label or the label-property combination is unknown, nor can they trigger the
150 % rerun message at the end of the \LaTeX{} run.
151 %
152 % Where needed such messages must therefore be triggered manually. For this two commands
153 % are provided: \cs{property_ref_undefined_warn:} and \cs{property_ref_undefined_warn:nn}.
154 % See below for a description.
155 %
156 % \section{Open points}
157 %
158 % \begin{itemize}
159 % \item The \texttt{xpos} and \texttt{ypos} properties require that the position is
160 % stored first but there is no (public) engine independent interface yet. Code must
161 % use \cs{tex_savepos:D}.
162 % \end{itemize}
163 %
164 % \section{Code interfaces}
165 %
166 % \begin{function}{\property_new:nnnn,\property_gset:nnnn}
167 % \begin{syntax}
168 % \cs{property_new:nnnn} \Arg{property} \Arg{setpoint} \Arg{default} \Arg{code}
169 % \cs{property_gset:nnnn} \Arg{property} \Arg{setpoint} \Arg{default} \Arg{code}
170 % \end{syntax}
171 % \LaTeXe-interface: see \cs{NewProperty}, \cs{SetProperty}.\\
172 % Sets the \meta{property} to have the \meta{default} specified, and at the
173 % \meta{setpoint} (either |now| or |shipout|) to write the result of the
174 % \meta{code} as part of a label. The \meta{code} should be expandable. The expansion
175 % of \meta{code} (the value of the property) is written to the |.aux| file and read
176 % back from there at the next compilation. Values should assume that the
177 % standard \LaTeX{} catcode régime with |@| a letter is active then.
178 %
179 % If the property is declared within a package it is suggested
180 % that its name is build from letters, hyphens and slashes,
181 % and is always structured as follows:\\
182 % \meta{package-name}\texttt{/}\meta{property-name}.
183 % \end{function}
184 %
185 % \begin{function}
186 % {
187 % \property_record:nN,
188 % \property_record:nn, \property_record:nV, \property_record:ee
189 % }
190 % \begin{syntax}
191 % \cs{property_record:nN} \Arg{label} \meta{clist var}
192 % \cs{property_record:nn} \Arg{label} \Arg{clist}
193 % \end{syntax}
194 % \LaTeXe{}-interface: see \cs{RecordProperties}.\\
195 % Writes the list of properties given by the \meta{clist} to the |.aux|
196 % file with the \meta{label} specified.
197 % \end{function}
198 %
199 % \begin{function}[EXP]{\property_ref:nn,\property_ref:ee}
200 % \begin{syntax}
201 % \cs{property_ref:nn} \Arg{label} \Arg{property}
202 % \end{syntax}
203 % \LaTeXe{}-interface: see \cs{RefProperty}.\\
204 % Expands to the value of the \meta{property} for the \meta{label}, if
205 % available, and the default value of the property otherwise.
206 % If \meta{property} has not been declared with |\property_new:nnnn|
207 % an error is issued. The command raises an internal, expandable, local flag
208 % if the reference can not be resolved.
209 % \end{function}
210 %
211 % \begin{function}[EXP,added=2025-11-20]{\property_item:nn,\property_item:ee}
212 % \begin{syntax}
213 % \cs{property_item:nn} \Arg{label} \Arg{property}
214 % \end{syntax}
215 %
216 % Retrieves the value of the \meta{property} for the \meta{label} like
217 % |\property_ref:nn| but the result is returned within the |\unexpanded| primitive
218 % (|\exp_not:n|), which means that the \meta{value} does not expand further
219 % when appearing in an \texttt{e}-type or \texttt{x}-type argument expansion. This allows for example
220 % to handle values containing user commands which are not safe in an expansion context.
221 % \end{function}
222 %
223 % \begin{function}[EXP]{\property_ref:nnn,\property_ref:een}
224 % \begin{syntax}
225 % \cs{property_ref:nnn} \Arg{label} \Arg{property} \Arg{local default}
226 % \end{syntax}
227 % \LaTeXe{}-interface: see \cs{RefProperty}.\\
228 % Expands to the value of the \meta{property} for the \meta{label}, if
229 % available, and to \meta{local default} otherwise.
230 % If \meta{property} has not been declared with |\property_new:nnnn|
231 % an error is issued. The command raises an internal, expandable local flag
232 % if the reference can not be resolved.
233 % \end{function}
234 %
235 % \begin{function}[EXP,added=2026-05-01]{\property_item:nnn,\property_item:een}
236 % \begin{syntax}
237 % \cs{property_item:nnn} \Arg{label} \Arg{property} \Arg{local default}
238 % \end{syntax}
239 %
240 % Retrieves the value of the \meta{property} for the \meta{label}, if available, and to
241 % \meta{local default} otherwise, but the result is returned within the |\unexpanded| primitive
242 % (|\exp_not:n|), which means that the \meta{value} does not expand further
243 % when appearing in an \texttt{e}-type or \texttt{x}-type argument expansion. This allows for example
244 % to handle values containing user commands which are not safe in an expansion context.
245 % \end{function}
246 %
247 % \begin{function}{\property_ref_undefined_warn:}
248 % \begin{syntax}
249 % \cs{property_ref_undefined_warn:}
250 % \end{syntax}
251 % \LaTeXe{}-interface: not provided.\\
252 % Triggers the standard warning
253 % \\
254 % \hspace*{1em}\texttt{LaTeX Warning: There were undefined references.}
255 % \\
256 % at the end of the document if there was a recent
257 % \cs{property_ref:nn} or \cs{property_ref:nnn} which couldn't be resolved
258 % and so raised the flag. \enquote{Recent} means in the same group
259 % or in some outer group!
260 % \end{function}
261 %
262 % \begin{function}{\property_ref_undefined_warn:n,\property_ref_undefined_warn:e}
263 % \begin{syntax}
264 % \cs{property_ref_undefined_warn:n} \Arg{label}
265 % \end{syntax}
266 % \LaTeXe{}-interface: not provided.\\
267 % Triggers the standard warning\\
268 % \hspace*{1em}\texttt{LaTeX Warning: There were undefined references.}
269 % \\
270 % at the end of the document if \meta{label} is not known.
271 % At the point where it is called it also issues the warning\\
272 % \hspace*{1em}%
273 % \texttt{Reference~`\meta{label}'~on~page~\meta{page}\space undefined}.
274 % \end{function}
275 %
276 % \begin{function}{\property_ref_undefined_warn:nn,\property_ref_undefined_warn:ee}
277 % \begin{syntax}
278 % \cs{property_ref_undefined_warn:nn} \Arg{label} \Arg{property}
279 % \end{syntax}
280 % \LaTeXe{}-interface: see \cs{RefUndefinedWarn}.\\
281 % Triggers the standard warning\\
282 % \hspace*{1em}%
283 % \texttt{LaTeX Warning: There were undefined references.}\\
284 % at the end of the document if the reference can not be resolved.
285 % At the point where it is called it also issues the warning\\
286 % \hspace*{1em}%
287 % \texttt{Reference~`\meta{label}'~on~page~\meta{page}\space undefined}\\
288 % if the label
289 % is unknown, or the more specific\\
290 % \hspace*{1em}%
291 % \texttt{Property `\meta{property}' undefined for reference
292 % `\meta{label}' on page \meta{page}}\\
293 % if the label is known but doesn't provide a value for the requested property.
294 % \end{function}
295 %
296 % \begin{function}[pTF]{\property_if_exist:n,\property_if_exist:e}
297 % \begin{syntax}
298 % \cs{property_if_exist_p:n} \Arg{property}
299 % \cs{property_if_exist:nTF} \Arg{property} \Arg{true code} \Arg{false code}
300 % \end{syntax}
301 % \LaTeXe{}-interface: \cs{IfPropertyExistsTF}.\\
302 % Tests if the \meta{property} has been declared.
303 % \end{function}
304 %
305 % \begin{function}[pTF]{\property_if_recorded:n,\property_if_recorded:e}
306 % \begin{syntax}
307 % \cs{property_if_recorded_p:n} \Arg{label}
308 % \cs{property_if_recorded:nTF} \Arg{label} \Arg{true code} \Arg{false code}
309 % \end{syntax}
310 % \LaTeXe{}-interface: \cs{IfLabelExistsTF}\\
311 % Tests if the \meta{label} is known. This is also true if the label has been
312 % set with the standard \cs{label} command.
313 % \end{function}
314 %
315 % \begin{function}[pTF]{\property_if_recorded:nn,\property_if_recorded:ee}
316 % \begin{syntax}
317 % \cs{property_if_recorded_p:nn} \Arg{label} \Arg{property}
318 % \cs{property_if_recorded:nnTF} \Arg{label} \Arg{property} \Arg{true code} \Arg{false code}
319 % \end{syntax}
320 % \LaTeXe{}-interface: \cs{IfPropertyRecordedTF}.\\
321 % Tests if the label \meta{label} is known and if it provides a value of the \meta{property}.
322 % \end{function}
323 %
324 % \section{Auxiliary file interfaces}
325 %
326 % \begin{function}{\new@label@record}
327 % \begin{syntax}
328 % \cs{new@label@record} \Arg{label} \Arg{data}
329 % \end{syntax}
330 % This is a command only for use in the |.aux| file. It loads the key--value
331 % list of \meta{data} to be available for the \meta{label}.
332 % \end{function}
333 %
334 % \section{\LaTeXe{} interface}
335 %
336 % The LaTeXe{} interfaces always expand label and property arguments.
337 % This means that one must be careful when using active chars or commands in the
338 % names. UTF8-chars are protected and should be safe, similar most babel shorthands.
339 %
340 % \begin{function}{\NewProperty,\SetProperty}
341 % \begin{syntax}
342 % \cs{NewProperty} \Arg{property} \Arg{setpoint} \Arg{default} \Arg{code}
343 % \cs{SetProperty} \Arg{property} \Arg{setpoint} \Arg{default} \Arg{code}
344 % \end{syntax}
345 % Sets the \meta{property} to have the \meta{default} specified, and at the
346 % \meta{setpoint} (either |now| or |shipout|) to write the result of the
347 % \meta{code} as part of a label. The \meta{code} should be expandable. The expansion
348 % of \meta{code} (the value of the property) is written to the |.aux| file and read
349 % back from there at the next compilation (at which point normally
350 % the standard \LaTeX{} catcode régime with |@| a letter is active).
351 %
352 % \end{function}
353 %
354 % \begin{function}{\RecordProperties}
355 % \begin{syntax}
356 % \cs{RecordProperties} \Arg{label} \Arg{clist}
357 % \end{syntax}
358 % Writes the list of properties given by the \meta{clist} to the |.aux|
359 % file with the \meta{label} specified. Similar to the standard \cs{label} command
360 % the arguments are expanded. So \meta{clist} can be a macro containing a list
361 % of properties. Also similar to the standard \cs{label} command, the command is surrounded
362 % by an \cs{@bsphack}/\cs{@esphack} pair to preserve spacing.
363 % \end{function}
364 %
365 % \begin{function}[EXP]{\RefProperty}
366 % \begin{syntax}
367 % \cs{RefProperty} \oarg{local default} \Arg{label} \Arg{property}
368 % \end{syntax}
369 % Expands to the value of the \meta{property} for the \meta{label}, if
370 % available, and the default value of the property or -- if given --
371 % to \meta{local default} otherwise.
372 % If \Arg{property} has not been declared an error is issued.
373 % \end{function}
374 %
375 % \begin{function}{\IfPropertyExistsTF,\IfPropertyExistsT,\IfPropertyExistsF}
376 % \begin{syntax}
377 % \cs{IfPropertyExistsTF} \Arg{property} \Arg{true code} \Arg{false code}
378 % \end{syntax}
379 % Tests if the \meta{property} has been declared.
380 % \end{function}
381 %
382 % \begin{function}{\IfLabelExistsTF,\IfLabelExistsT,\IfLabelExistsF}
383 % \begin{syntax}
384 % \cs{IfLabelExistsTF} \Arg{label} \Arg{true code} \Arg{false code}
385 % \end{syntax}
386 % Tests if the \meta{label} has been recorded. This is also true if a label
387 % has been set with the standard \cs{label} command.
388 % \end{function}
389 %
390 % \begin{function}{\IfPropertyRecordedTF,\IfPropertyRecordedT,\IfPropertyRecordedF}
391 % \begin{syntax}
392 % \cs{IfPropertyRecordedTF} \Arg{label} \Arg{property} \Arg{true code} \Arg{false code}
393 % \end{syntax}
394 % Tests if the label and a value of the \meta{property} for the \meta{label} are both known.
395 % \end{function}
396 %
397 % \begin{function}{\RefUndefinedWarn}
398 % \begin{syntax}
399 % \cs{RefUndefinedWarn} \Arg{label} \Arg{property}
400 % \end{syntax}
401 % Triggers the standard warning\\
402 % \hspace*{1em}%
403 % \texttt{LaTeX Warning: There were undefined references.}\\
404 % at the end of the document if the reference for \meta{label} and \meta{property}
405 % can not be resolved.
406 % At the point where it is called it also issues the warning\\
407 % \hspace*{1em}%
408 % \texttt{Reference `\meta{label}' on page \meta{page} undefined}\\
409 % if the label is unknown, or the more specific\\
410 % \hspace*{1em}%
411 % \texttt{Property `\meta{property}' undefined for reference
412 % `\meta{label}' on page \meta{page}}
413 % if the label is known but doesn't provide a value for the requested property.
414 % \end{function}
415 %
416 % \section{Pre-declared properties}
417 %
418 % \begin{variable}{abspage}
419 % (shipout) The absolute value of the current page: starts at $1$ and increases
420 % monotonically at each shipout.
421 % \end{variable}
422 %
423 % \begin{variable}{page}
424 % (shipout) The current page as given by \cs{thepage}: this may or may not
425 % be a numerical value, depending on the current style. Contrast with
426 % \cs{abspage}. You get this value also with the standard \cs{label}/\cs{pageref}.
427 % \end{variable}
428 %
429 % \begin{variable}{pagenum}
430 % (shipout) The current page as arabic number. This is suitable for integer operations and
431 % comparisons.
432 % \end{variable}
433 %
434 % \begin{variable}{label}
435 % (now) The content of \cs{@currentlabel}. This is the value that
436 % you get also with the standard \cs{label}/\cs{ref}.
437 % \end{variable}
438 %
439 % \begin{variable}{title}
440 % (now) The content of \cs{@currentlabelname}.
441 % This command is filled beside others by the \pkg{nameref} package and some
442 % classes (e.g.~\pkg{memoir}).
443 % \end{variable}
444 %
445 % \begin{variable}{target}
446 % (now) The content of \cs{@currentHref}.
447 % This command is normally filled by for example
448 % \pkg{hyperref} and gives the name of the last destination it created.
449 % \end{variable}
450 %
451 % \begin{variable}{pagetarget}
452 % (shipout) The content of \cs{@currentHpage}.
453 % This command is filled for example by a recent version of
454 % \pkg{hyperref} and then gives the name of the last page
455 % destination it created.
456 % \end{variable}
457 %
458 % \begin{variable}{counter}
459 % (now) The content of \cs{@currentcounter}.
460 % This command contains after a \cs{refstepcounter} the name of the counter.
461 % \end{variable}
462 %
463 % \begin{variable}{xpos,ypos}
464 % (shipout) This stores the $x$~and $y$ coordinates of a point previously
465 % stored with \cs{pdfsavepos}/\cs{savepos}.
466 % E.g.~(if bidi is used it can be necessary to save the position
467 % before and after the label):
468 % \begin{verbatim}
469 % \tex_savepos:D
470 % \property_record:nn{myposition}{xpos,ypos}
471 % \tex_savepos:D
472 % \end{verbatim}
473 % \end{variable}
474 % \end{documentation}
475 %
476 % \begin{implementation}
477 %
478 % \section{The Implementation}
479 %
480 % \begin{macrocode}
481 %<*2ekernel|latexrelease>
482 % \end{macrocode}
483 % \begin{macrocode}
484 \ExplSyntaxOn
485 % \end{macrocode}
486 %
487 % \begin{macrocode}
488 %<@@=property>
489 % \end{macrocode}
490 %
491 % \begin{macrocode}
492 %<latexrelease>\NewModuleRelease{2023/11/01}{ltproperties}
493 %<latexrelease> {Cross-referencing~properties}
494 % \end{macrocode}
495 %
496 % \changes{v1.0m}{2026-03-12}{Switch from \texttt{x}- to \texttt{e}-type
497 % expansion in expl3 code}
498 %
499 % The approach here is based closely on that from \pkg{zref}; separate out
500 % lists of properties and the properties themselves, so the latter can be
501 % used multiple times and in varying combinations.
502 % However, not everything is a straight copy. Firstly,
503 % we treat lists of properties as simple comma lists: that allows us to have
504 % either saved or dynamic lists and to avoid another data structure. The cost
505 % is that errors are detected at point-of-use, but in any real case that should
506 % be true anyway (and is true for \tn{zref@labelbyprop} already). Secondly,
507 % we allow properties to have
508 % arbitrary names, as the code does not require them to tokenize as control
509 % sequences.
510 %
511 % \begin{macro}{\property_new:nnnn, \property_gset:nnnn, \@@_gset:nnnn}
512 % As properties can be reset, they are not constants. But they also have
513 % various pieces of required data. So we use the same approach as color and
514 % make them declarations. Data-wise, we need the detail of the implementation,
515 % the default and a flag to show if the code works now or at shipout. This
516 % last entry is done using text so needs a check. We could use a set of
517 % |prop| here, but as we never need to map or copy the lists, we can gain
518 % performance using the hash table approach.
519 % \changes{v1.0j}{2025-08-01}{correct name of shipout boolean}
520 % \begin{macrocode}
521 \cs_new_protected:Npn \property_new:nnnn #1#2#3#4
522 {
523 \cs_if_free:cTF { @@_code_ #1 : }
524 {
525 \exp_args:Ne \@@_gset:nnnn { \tl_to_str:n {#1} }
526 {#2} {#3} {#4}
527 }
528 {
529 \msg_error:nn { property }{ exists }{#1}
530 }
531 }
532 \cs_new_protected:Npn \property_gset:nnnn #1#2#3#4
533 {
534 \@@_gset:ennn { \tl_to_str:n {#1} }
535 {#2} {#3} {#4}
536 }
537 \cs_new_protected:Npn \@@_gset:nnnn #1#2#3#4
538 {
539 \cs_gset:cpn { @@_code_ #1 : } {#4}
540 \tl_gclear_new:c { g_@@_default_ #1 _tl }
541 \tl_gset:cn { g_@@_default_ #1 _tl } {#3}
542 \bool_if_exist:cF { g_@@_shipout_ #1 _bool }
543 { \bool_new:c { g_@@_shipout_ #1 _bool } }
544 \str_case:nnF {#2}
545 {
546 { now } { { \bool_gset_false:c { g_@@_shipout_ #1 _bool } } }
547 { shipout }
548 { \bool_gset_true:c { g_@@_shipout_ #1 _bool } }
549 }
550 { \msg_error:nnnn { property } { unknown-setpoint } {#1} {#2} }
551 }
552 \cs_generate_variant:Nn \@@_gset:nnnn {ennn}
553 % \end{macrocode}
554 % \end{macro}
555 %
556 % \begin{macro}{\NewProperty,\SetProperty}
557 % For consistency we expand the property name, but this doesn't warant a
558 % variant of the L3-commands.
559 % \changes{v1.0c}{2023-09-20}{use \cs{protected@edef}}
560 % \begin{macrocode}
561 \cs_new_protected:Npn \NewProperty #1#2#3#4
562 {
563 \protected@edef\reserved@a{#1}
564 \exp_args:No \property_new:nnnn {\reserved@a} {#2}{#3}{#4}
565 }
566 \cs_new_protected:Npn \SetProperty #1#2#3#4
567 {
568 \protected@edef\reserved@a{#1}
569 \exp_args:No \property_gset:nnnn {\reserved@a} {#2}{#3}{#4}
570 }
571 % \end{macrocode}
572 % \end{macro}
573 %
574 % \begin{macro}{\property_record:nN}
575 % \begin{macro}
576 % {
577 % \property_record:nn,
578 % \property_record:nV,
579 % \property_record:ee,
580 % \property_record:oo,
581 % \@@_record:nn,
582 % \@@_record:en
583 % }
584 % \begin{macro}[EXP]
585 % {\@@_record_value:n, \@@_record_value_aux:n, \@@_record_value_aux:e}
586 % Writing data when it is labelled means expanding at this stage and possibly
587 % later too. That is all pretty easy using \pkg{expl3}: we accept a stray
588 % comma at the end of the list as that is easier to deal with than trying
589 % to tidy up, and there is no real downside.
590 % \changes{v1.0d}{2024-01-17}{Use \cs{protected@write}}%
591 % \changes{v1.0f}{2024-09-05}{Remove \cs{if@filesw} test to be in line with \cs{label},
592 % tagging-project issue 696}%
593 % \begin{macrocode}
594 \cs_new_protected:Npn \property_record:nN #1#2
595 { \property_record:nV {#1} #2 }
596 \cs_new_protected:Npn \property_record:nn #1#2
597 { \@@_record:en { \tl_to_str:n {#1} } {#2} }
598 \cs_generate_variant:Nn \property_record:nn { nV , ee, oo }
599 \cs_new_protected:Npn \@@_record:nn #1#2
600 {
601 \protected@write \@auxout {}
602 {
603 \token_to_str:N \new@label@record
604 {#1}
605 { \clist_map_function:nN {#2} \@@_record_value:n }
606 }
607 }
608 \cs_generate_variant:Nn \@@_record:nn { e }
609 \cs_new:Npn \@@_record_value:n #1
610 { \@@_record_value_aux:e { \tl_to_str:n {#1} } }
611 \cs_new:Npn \@@_record_value_aux:n #1
612 {
613 \cs_if_exist:cTF { @@_code_ #1 : }
614 {
615 {#1}
616 {
617 \bool_if:cTF { g_@@_shipout_ #1 _bool }
618 { \exp_not:c }
619 { \use:c }
620 { @@_code_ #1 : }
621 }
622 }
623 { \msg_expandable_error:nnn { property } { not-declared } {#1} }
624 }
625 \cs_generate_variant:Nn \@@_record_value_aux:n { e }
626 % \end{macrocode}
627 % \end{macro}
628 % \end{macro}
629 % \end{macro}
630 %
631 % \begin{macro}{\RecordProperties}
632 % \changes{v1.0c}{2023-09-20}{use \cs{protected@edef} for safer handling of active chars.} %
633 % \begin{macrocode}
634 \NewDocumentCommand\RecordProperties { m m }
635 {
636 \@bsphack
637 \protected@edef\reserved@a{#1}
638 \protected@edef\reserved@b{#2}
639 \property_record:oo {\reserved@a}{\reserved@b}
640 \@esphack
641 }
642 % \end{macrocode}
643 % \end{macro}
644 %
645 % \subsection{Reference commands}
646 %
647 % \begin{variable}{ l_@@_ref_flag }
648 % A flag that is set if a reference couldn't be resolved.
649 % \begin{macrocode}
650 \flag_new:n { l_@@_ref_flag }
651 % \end{macrocode}
652 % \end{variable}
653 %
654 % \begin{macro}[EXP]{\property_ref:nn,\property_ref:ee}
655 % Search for the label/property combination, and if not found fall back
656 % to the default of the property.
657 % \begin{macrocode}
658 \cs_new:Npn \property_ref:nn #1#2
659 {
660 \@@_ref:een
661 { \tl_to_str:n {#1} }
662 { \tl_to_str:n {#2} }
663 { \tl_use:c { g_@@_default_ #2 _tl } }
664 }
665 \cs_generate_variant:Nn \property_ref:nn {ee}
666 % \end{macrocode}
667 % \end{macro}
668 %
669 % \begin{macro}[EXP]{\property_ref:nnn,\property_ref:een, \@@_ref:nnn, \@@_ref:een}
670 % This allows to set a local default value which overrides the default value
671 % of the property.
672 % \begin{macrocode}
673 \cs_new:Npn \property_ref:nnn #1#2#3
674 {
675 \@@_ref:een
676 { \tl_to_str:n {#1} }
677 { \tl_to_str:n {#2} }
678 {#3}
679 }
680 \cs_new:Npn \@@_ref:nnn #1#2#3
681 {
682 \tl_if_exist:cTF { g_@@_label_ #1 _ #2 _tl }
683 { \tl_use:c { g_@@_label_ #1 _ #2 _tl } }
684 {
685 \flag_if_raised:nF
686 { l_@@_ref_flag } { \flag_raise:n { l_@@_ref_flag } }
687 % \end{macrocode}
688 % We test for the default of the property only to check if the property has
689 % been declared.
690 % \begin{macrocode}
691 \tl_if_exist:cTF { g_@@_default_ #2 _tl }
692 { #3 }
693 { \msg_expandable_error:nnn { property } { not-declared } {#2} }
694 }
695 }
696 \cs_generate_variant:Nn \@@_ref:nnn { ee }
697 \cs_generate_variant:Nn \property_ref:nnn {een}
698 % \end{macrocode}
699 % \end{macro}
700 %
701 % \begin{macro}{\property_item:nn,\property_item:ee}
702 % Retrieve the value but wrap it into an \cs{exp_not:n} to avoid further expansion.
703 % \changes{v1.0l}{2025-11-20}{added \cs{property_item:nn}, gh1194}
704 % \begin{macrocode}
705 \cs_new:Npn \property_item:nn #1#2
706 {
707 \tl_if_exist:cTF { g_@@_label_ \tl_to_str:n {#1} _ \tl_to_str:n {#2} _tl }
708 {
709 \exp_not:v { g_@@_label_ \tl_to_str:n {#1} _ \tl_to_str:n {#2} _tl }
710 }
711 { \tl_use:c { g_@@_default_ \tl_to_str:n {#2} _tl } }
712 }
713 \cs_generate_variant:Nn \property_item:nn {ee}
714 % \end{macrocode}
715 % \end{macro}
716 % \begin{macro}{\property_item:nnn,\property_item:een}
717 % Same as \cs{property_item:nn} but allows setting a local default.
718 % \changes{v1.0n}{2026-05-01}{added \cs{property_item:nnn}, gh2018}
719 % \begin{macrocode}
720 \cs_new:Npn \property_item:nnn #1#2#3
721 {
722 \tl_if_exist:cTF { g_@@_label_ \tl_to_str:n {#1} _ \tl_to_str:n {#2} _tl }
723 {
724 \exp_not:v { g_@@_label_ \tl_to_str:n {#1} _ \tl_to_str:n {#2} _tl }
725 }
726 {
727 \tl_if_exist:cTF { g_@@_default_ \tl_to_str:n {#2} _tl }
728 { #3 }
729 { \msg_expandable_error:nnn { property } { not-declared } {#2} }
730 }
731 }
732 \cs_generate_variant:Nn \property_item:nnn {ee}
733 % \end{macrocode}
734 % \end{macro}
735 % \begin{macro}[EXP]{\RefProperty}
736 % Search for the label/property combination, and if not found fall back
737 % to the default of the property or the given default.
738 % \begin{macrocode}
739 \NewExpandableDocumentCommand \RefProperty { o m m }
740 {
741 \IfNoValueTF {#1}
742 {
743 \property_ref:ee {#2}{#3}
744 }
745 {
746 \property_ref:een {#2}{#3}{#1}
747 }
748 }
749 % \end{macrocode}
750 % \end{macro}
751 %
752 % \begin{macro}{\new@label@record}
753 % \begin{macro}{\@@_data:nnn}
754 % A standard recursion loop.
755 % \begin{macrocode}
756 \cs_new_protected:Npn \new@label@record #1#2
757 {
758 \tl_if_exist:cTF { r@#1 }
759 {
760 \gdef \@multiplelabels
761 { \@latex@warning@no@line { There~were~multiply-defined~labels } }
762 \@latex@warning@no@line { Label~`#1'~multiply~defined }
763 }
764 {
765 \tl_new:c { r@#1 }
766 \tl_gset:cn { r@#1 }{#2}
767 }
768 \@@_data:nnn {#1} #2 { \q_recursion_tail } { ? } \q_recursion_stop
769 }
770 \cs_new_protected:Npn \@@_data:nnn #1#2#3
771 {
772 \quark_if_recursion_tail_stop:n {#2}
773 \tl_gclear_new:c { g_@@_label_ \tl_to_str:n {#1} _ \tl_to_str:n {#2} _tl }
774 \tl_gset:cn { g_@@_label_ \tl_to_str:n {#1} _ \tl_to_str:n {#2} _tl } {#3}
775 \@@_data:nnn {#1}
776 }
777 % \end{macrocode}
778 %
779 % This command is used in \cs{enddocument} to test if some label values have changed.
780 % \begin{macrocode}
781 \cs_new_protected:Npn \@kernel@new@label@record@testdef #1 #2
782 {
783 \tl_if_eq:cnF { r@#1 } {#2}
784 { \@tempswatrue }
785 }
786 % \end{macrocode}
787 % \end{macro}
788 % \end{macro}
789 %
790 % \subsection{Tests and warnings}
791 %
792 % \begin{macro}[pTF]{\property_if_exist:n}
793 % Tests if property has been declared.
794 % \begin{macrocode}
795 \prg_new_conditional:Npnn \property_if_exist:n #1 { p , T , F, TF }
796 % #1 property
797 {
798 \cs_if_exist:cTF { @@_code_ #1 : }
799 {
800 \prg_return_true:
801 }
802 {
803 \prg_return_false:
804 }
805 }
806 \prg_generate_conditional_variant:Nnn \property_if_exist:n {e} { p , T , F, TF }
807 % \end{macrocode}
808 % \end{macro}
809 %
810 % \begin{macro}{\IfPropertyExistsTF,\IfPropertyExistsT,\IfPropertyExistsF}
811 % \changes{v1.0e}{2024-04-17}{Renamed \cs{IfPropertyExistTF} to
812 % \cs{IfPropertyExistsTF} (gh/1262)}
813 % \begin{macrocode}
814 \cs_new_eq:NN \IfPropertyExistsTF \property_if_exist:eTF
815 \cs_new:Npn \IfPropertyExistsT #1#2 {\property_if_exist:eTF {#1}{#2}{} }
816 \cs_new:Npn \IfPropertyExistsF #1 {\property_if_exist:eTF {#1}{} }
817 % \end{macrocode}
818 % \end{macro}
819 %
820 % \begin{macro}[pTF]{\property_if_recorded:n}
821 % Tests if the label has been set.
822 % This can then be used to setup e.g.~rerun messages.
823 % \begin{macrocode}
824 \prg_new_conditional:Npnn \property_if_recorded:n #1 { p , T , F, TF }
825 % #1 label
826 {
827 \tl_if_exist:cTF { r@#1 }
828 {
829 \prg_return_true:
830 }
831 {
832 \prg_return_false:
833 }
834 }
835 \prg_generate_conditional_variant:Nnn \property_if_recorded:n {e} { p , T , F, TF }
836 % \end{macrocode}
837 % \end{macro}
838 %
839 % \begin{macro}{\IfLabelExistsTF,\IfLabelExistsT,\IfLabelExistsF}
840 % \changes{v1.0e}{2024-04-17}{Renamed \cs{IfLabelExistTF} to
841 % \cs{IfLabelExistsTF} (gh/1262)}
842 % \changes{v1.0g}{2024-09-25}{Fixed definitions of \cs{IfLabelExistsT}
843 % and \cs{IfLabelExistsF}}
844 % \begin{macrocode}
845 \cs_new_eq:NN \IfLabelExistsTF \property_if_recorded:eTF
846 \cs_new:Npn \IfLabelExistsT #1#2 {\property_if_recorded:eTF {#1}{#2}{} }
847 \cs_new:Npn \IfLabelExistsF #1 {\property_if_recorded:eTF {#1}{} }
848 % \end{macrocode}
849 % \end{macro}
850 %
851 % \begin{macro}[pTF]{\property_if_recorded:nn}
852 % tests if the label/property combination has been set
853 % This can then be used to setup e.g.~rerun messages.
854 % \begin{macrocode}
855 \prg_new_conditional:Npnn \property_if_recorded:nn #1#2 { p , T , F, TF }
856 % #1 label #2 property
857 {
858 \tl_if_exist:cTF { g_@@_label_ \tl_to_str:n {#1} _ \tl_to_str:n {#2} _tl }
859 {
860 \prg_return_true:
861 }
862 {
863 \prg_return_false:
864 }
865 }
866 \prg_generate_conditional_variant:Nnn \property_if_recorded:nn {ee} { p , T , F, TF }
867 % \end{macrocode}
868 % \end{macro}
869 %
870 % \begin{macro}{\IfPropertyRecordedTF,\IfPropertyRecordedT,\IfPropertyRecordedF}
871 % \changes{v1.0h}{2024-10-21}{Define \cs{IfPropertyRecordedT}, \cs{IfPropertyRecordedF}}
872 % \begin{macrocode}
873 \cs_new_eq:NN \IfPropertyRecordedTF \property_if_recorded:eeTF
874 \cs_new:Npn \IfPropertyRecordedT #1#2#3 { \property_if_recorded:eeTF {#1}{#2}{#3}{} }
875 \cs_new:Npn \IfPropertyRecordedF #1#2#3 { \property_if_recorded:eeTF {#1}{#2}{}{#3} }
876 % \end{macrocode}
877 % \end{macro}
878 %
879 % \begin{macro}{\property_ref_undefined_warn:}
880 % \cs{G@refundefinedtrue} is defined in \texttt{ltxref} and redefines a warning message.
881 % \begin{macrocode}
882 \cs_new_protected:Npn \property_ref_undefined_warn:
883 {
884 \flag_if_raised:nT { l_@@_ref_flag }
885 {
886 \G@refundefinedtrue
887 }
888 }
889 % \end{macrocode}
890 % \end{macro}
891 %
892 % \begin{macro}{\property_ref_undefined_warn:n,
893 % \property_ref_undefined_warn:e}
894 % \changes{v1.0k}{2025-09-05}{Add missing |e| variant (gh/1854)}
895 % \begin{macrocode}
896 \cs_new_protected:Npn \property_ref_undefined_warn:n #1 %#1 label
897 {
898 \property_if_recorded:nF {#1}
899 {
900 \G@refundefinedtrue
901 \@latex@warning{Reference~`#1'~on~page~\thepage\space undefined}%
902 }
903 }
904 \cs_generate_variant:Nn \property_ref_undefined_warn:n {e}
905 % \end{macrocode}
906 % \end{macro}
907 %
908 % \begin{macro}{\property_ref_undefined_warn:nn,
909 % \property_ref_undefined_warn:ee,
910 % \RefUndefinedWarn}
911 % \begin{macrocode}
912 \cs_new_protected:Npn \property_ref_undefined_warn:nn #1#2 %#1 label, #2 property
913 {
914 \property_if_recorded:nTF {#1}
915 {
916 \property_if_recorded:nnF {#1}{#2}
917 {
918 \G@refundefinedtrue
919 \@latex@warning
920 { Property~`#2'~undefined~for~reference~`#1'~on~page~\thepage }
921 }
922 }
923 {
924 \G@refundefinedtrue
925 \@latex@warning { Reference~`#1'~on~page~\thepage\space undefined }%
926 }
927 }
928 \cs_generate_variant:Nn \property_ref_undefined_warn:nn {ee}
929 \cs_set_eq:NN \RefUndefinedWarn \property_ref_undefined_warn:ee
930 % \end{macrocode}
931 % \end{macro}
932 %
933 % \subsection{Predeclared properties}
934 %
935 % \begin{variable}{abspage}
936 % \begin{macrocode}
937 \property_new:nnnn { abspage } { shipout }
938 { 0 } { \int_use:N \g_shipout_readonly_int }
939 % \end{macrocode}
940 % \end{variable}
941 %
942 % \begin{variable}{page}
943 % \begin{macrocode}
944 \property_new:nnnn { page } { shipout } { 0 } { \thepage }
945 % \end{macrocode}
946 % \end{variable}
947 %
948 % \begin{variable}{pagenum}
949 % \begin{macrocode}
950 \property_new:nnnn { pagenum } { shipout } { 0 } { \the \value { page } }
951 % \end{macrocode}
952 % \end{variable}
953 %
954 % \begin{variable}{label}
955 % \begin{macrocode}
956 \property_new:nnnn { label } { now } { ?? } { \@currentlabel }
957 % \end{macrocode}
958 % \end{variable}
959 %
960 % \begin{variable}{title}
961 % \begin{macrocode}
962 \property_new:nnnn { title } { now }
963 { \exp_not:n { \textbf { ?? } } } { \@currentlabelname }
964 % \end{macrocode}
965 % \end{variable}
966 %
967 % \begin{variable}{target}
968 % \begin{macrocode}
969 \property_new:nnnn { target } { now } { } { \@currentHref }
970 % \end{macrocode}
971 % \end{variable}
972 %
973 % \begin{variable}{pagetarget}
974 % \begin{macrocode}
975 \newcommand\@currentHpage{}
976 \property_new:nnnn { pagetarget } { shipout } { } { \@currentHpage }
977 % \end{macrocode}
978 % \end{variable}
979
980 % \begin{variable}{counter}
981 % \begin{macrocode}
982 \property_new:nnnn { counter } { now } { } { \@currentcounter }
983 % \end{macrocode}
984 % \end{variable}
985 %
986 % \begin{variable}{xpos,ypos}
987 % \begin{macrocode}
988 \property_new:nnnn { xpos } { shipout } { 0} { \int_use:N \tex_lastxpos:D }
989 \property_new:nnnn { ypos } { shipout } { 0} { \int_use:N \tex_lastypos:D }
990 % \end{macrocode}
991 % \end{variable}
992 %
993 % \subsection{Messages}
994 % \begin{macrocode}
995 \msg_new:nnnn { property } { exists }
996 { Property~'#1'~ has~ already~ been~ declared. }
997 { There~ already~ exists~ a~ property~ declaration~ with~ this~
998 name.\\
999 Please~ use~ a~ different~ name~ for~ your~ property.}
1000
1001 \msg_new:nnnn { property } { not-declared }
1002 { Property~'#1'~not~declared. }
1003 {
1004 LaTeX~has~been~asked~to~use~property~'#1',~but~this~
1005 name~has~not~been~declared.
1006 }
1007 \msg_new:nnnn { property } { unknown-setpoint }
1008 { Unknown~keyword~'#2'~for~setting~property~'#1'. }
1009 {
1010 LaTeX~has~been~asked~to~set~the~property~'#1',~but~the~keyword~
1011 '#2'~is~not~one~of~the~two~known~values:~'now'~or~'shipout'.
1012 }
1013 % \end{macrocode}
1014 %
1015 % \begin{macrocode}
1016 %
1017 %<latexrelease>\IncludeInRelease{0000/00/00}{ltproperties}
1018 %<latexrelease> {cross-referencing~properties~(undo)}%
1019 %<latexrelease>
1020 %<latexrelease>\let \NewProperty \@undefined
1021 %<latexrelease>\let \SetProperty \@undefined
1022 %<latexrelease>
1023 %<latexrelease>\let \RecordProperties \@undefined
1024 %<latexrelease>\let \RefProperty \@undefined
1025 %<latexrelease>\let \RefUndefinedWarn \@undefined
1026 %<latexrelease>
1027 %<latexrelease>\let \IfPropertyExistsTF \@undefined
1028 %<latexrelease>\let \IfLabelExistsTF \@undefined
1029 %<latexrelease>\let \IfPropertyRecordedTF \@undefined
1030 %<latexrelease>
1031 %<latexrelease>\let\new@label@record \@undefined
1032 %<latexrelease>\let\@kernel@new@label@record@testdef\@undefined
1033 %<latexrelease>\EndModuleRelease
1034 % \end{macrocode}
1035 %
1036 % \begin{macrocode}
1037 \ExplSyntaxOff
1038 % \end{macrocode}
1039 %
1040 % \begin{macrocode}
1041 %</2ekernel|latexrelease>
1042 % \end{macrocode}
1043 %
1044 % Reset module prefix:
1045 % \begin{macrocode}
1046 %<@@=>
1047 % \end{macrocode}
1048 %
1049 %
1050 % \end{implementation}
1051 %
1052 % \Finale