Debian Codegraph @

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

raw
1 % \iffalse meta-comment
2 %
3 % File: ltproperties.dtx
4 %
5 % Copyright (C) 2023-2025 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 [2025/09/05 v1.0k LaTeX Kernel (Properties)]
34 % \iffalse
35 %
36 \documentclass[full]{l3doc}
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]{\property_ref:nnn,\property_ref:een}
212 % \begin{syntax}
213 % \cs{property_ref:nnn} \Arg{label} \Arg{property} \Arg{local default}
214 % \end{syntax}
215 % \LaTeXe{}-interface: see \cs{RefProperty}.\\
216 % Expands to the value of the \meta{property} for the \meta{label}, if
217 % available, and to \meta{local default} otherwise.
218 % If \meta{property} has not been declared with |\property_new:nnnn|
219 % an error is issued. The command raises an internal, expandable local flag
220 % if the reference can not be resolved.
221 % \end{function}
222 %
223 % \begin{function}{\property_ref_undefined_warn:}
224 % \begin{syntax}
225 % \cs{property_ref_undefined_warn:}
226 % \end{syntax}
227 % \LaTeXe{}-interface: not provided.\\
228 % Triggers the standard warning
229 % \\
230 % \hspace*{1em}\texttt{LaTeX Warning: There were undefined references.}
231 % \\
232 % at the end of the document if there was a recent
233 % \cs{property_ref:nn} or \cs{property_ref:nnn} which couldn't be resolved
234 % and so raised the flag. \enquote{Recent} means in the same group
235 % or in some outer group!
236 % \end{function}
237 %
238 % \begin{function}{\property_ref_undefined_warn:n,\property_ref_undefined_warn:e}
239 % \begin{syntax}
240 % \cs{property_ref_undefined_warn:n} \Arg{label}
241 % \end{syntax}
242 % \LaTeXe{}-interface: not provided.\\
243 % Triggers the standard warning\\
244 % \hspace*{1em}\texttt{LaTeX Warning: There were undefined references.}
245 % \\
246 % at the end of the document if \meta{label} is not known.
247 % At the point where it is called it also issues the warning\\
248 % \hspace*{1em}%
249 % \texttt{Reference~`\meta{label}'~on~page~\meta{page}\space undefined}.
250 % \end{function}
251 %
252 % \begin{function}{\property_ref_undefined_warn:nn,\property_ref_undefined_warn:ee}
253 % \begin{syntax}
254 % \cs{property_ref_undefined_warn:nn} \Arg{label} \Arg{property}
255 % \end{syntax}
256 % \LaTeXe{}-interface: see \cs{RefUndefinedWarn}.\\
257 % Triggers the standard warning\\
258 % \hspace*{1em}%
259 % \texttt{LaTeX Warning: There were undefined references.}\\
260 % at the end of the document if the reference can not be resolved.
261 % At the point where it is called it also issues the warning\\
262 % \hspace*{1em}%
263 % \texttt{Reference~`\meta{label}'~on~page~\meta{page}\space undefined}\\
264 % if the label
265 % is unknown, or the more specific\\
266 % \hspace*{1em}%
267 % \texttt{Property `\meta{property}' undefined for reference
268 % `\meta{label}' on page \meta{page}}\\
269 % if the label is known but doesn't provide a value for the requested property.
270 % \end{function}
271 %
272 % \begin{function}[pTF]{\property_if_exist:n,\property_if_exist:e}
273 % \begin{syntax}
274 % \cs{property_if_exist_p:n} \Arg{property}
275 % \cs{property_if_exist:nTF} \Arg{property} \Arg{true code} \Arg{false code}
276 % \end{syntax}
277 % \LaTeXe{}-interface: \cs{IfPropertyExistsTF}.\\
278 % Tests if the \meta{property} has been declared.
279 % \end{function}
280 %
281 % \begin{function}[pTF]{\property_if_recorded:n,\property_if_recorded:e}
282 % \begin{syntax}
283 % \cs{property_if_recorded_p:n} \Arg{label}
284 % \cs{property_if_recorded:nTF} \Arg{label} \Arg{true code} \Arg{false code}
285 % \end{syntax}
286 % \LaTeXe{}-interface: \cs{IfLabelExistsTF}\\
287 % Tests if the \meta{label} is known. This is also true if the label has been
288 % set with the standard \cs{label} command.
289 % \end{function}
290 %
291 % \begin{function}[pTF]{\property_if_recorded:nn,\property_if_recorded:ee}
292 % \begin{syntax}
293 % \cs{property_if_recorded_p:nn} \Arg{label} \Arg{property}
294 % \cs{property_if_recorded:nnTF} \Arg{label} \Arg{property} \Arg{true code} \Arg{false code}
295 % \end{syntax}
296 % \LaTeXe{}-interface: \cs{IfPropertyRecordedTF}.\\
297 % Tests if the label \meta{label} is known and if it provides a value of the \meta{property}.
298 % \end{function}
299 %
300 % \section{Auxiliary file interfaces}
301 %
302 % \begin{function}{\new@label@record}
303 % \begin{syntax}
304 % \cs{new@label@record} \Arg{label} \Arg{data}
305 % \end{syntax}
306 % This is a command only for use in the |.aux| file. It loads the key--value
307 % list of \meta{data} to be available for the \meta{label}.
308 % \end{function}
309 %
310 % \section{\LaTeXe{} interface}
311 %
312 % The LaTeXe{} interfaces always expand label and property arguments.
313 % This means that one must be careful when using active chars or commands in the
314 % names. UTF8-chars are protected and should be safe, similar most babel shorthands.
315 %
316 % \begin{function}{\NewProperty,\SetProperty}
317 % \begin{syntax}
318 % \cs{NewProperty} \Arg{property} \Arg{setpoint} \Arg{default} \Arg{code}
319 % \cs{SetProperty} \Arg{property} \Arg{setpoint} \Arg{default} \Arg{code}
320 % \end{syntax}
321 % Sets the \meta{property} to have the \meta{default} specified, and at the
322 % \meta{setpoint} (either |now| or |shipout|) to write the result of the
323 % \meta{code} as part of a label. The \meta{code} should be expandable. The expansion
324 % of \meta{code} (the value of the property) is written to the |.aux| file and read
325 % back from there at the next compilation (at which point normally
326 % the standard \LaTeX{} catcode régime with |@| a letter is active).
327 %
328 % \end{function}
329 %
330 % \begin{function}{\RecordProperties}
331 % \begin{syntax}
332 % \cs{RecordProperties} \Arg{label} \Arg{clist}
333 % \end{syntax}
334 % Writes the list of properties given by the \meta{clist} to the |.aux|
335 % file with the \meta{label} specified. Similar to the standard \cs{label} command
336 % the arguments are expanded. So \meta{clist} can be a macro containing a list
337 % of properties. Also similar to the standard \cs{label} command, the command is surrounded
338 % by an \cs{@bsphack}/\cs{@esphack} pair to preserve spacing.
339 % \end{function}
340 %
341 % \begin{function}[EXP]{\RefProperty}
342 % \begin{syntax}
343 % \cs{RefProperty} \oarg{local default} \Arg{label} \Arg{property}
344 % \end{syntax}
345 % Expands to the value of the \meta{property} for the \meta{label}, if
346 % available, and the default value of the property or -- if given --
347 % to \meta{local default} otherwise.
348 % If \Arg{property} has not been declared an error is issued.
349 % \end{function}
350 %
351 % \begin{function}{\IfPropertyExistsTF,\IfPropertyExistsT,\IfPropertyExistsF}
352 % \begin{syntax}
353 % \cs{IfPropertyExistsTF} \Arg{property} \Arg{true code} \Arg{false code}
354 % \end{syntax}
355 % Tests if the \meta{property} has been declared.
356 % \end{function}
357 %
358 % \begin{function}{\IfLabelExistsTF,\IfLabelExistsT,\IfLabelExistsF}
359 % \begin{syntax}
360 % \cs{IfLabelExistsTF} \Arg{label} \Arg{true code} \Arg{false code}
361 % \end{syntax}
362 % Tests if the \meta{label} has been recorded. This is also true if a label
363 % has been set with the standard \cs{label} command.
364 % \end{function}
365 %
366 % \begin{function}{\IfPropertyRecordedTF,\IfPropertyRecordedT,\IfPropertyRecordedF}
367 % \begin{syntax}
368 % \cs{IfPropertyRecordedTF} \Arg{label} \Arg{property} \Arg{true code} \Arg{false code}
369 % \end{syntax}
370 % Tests if the label and a value of the \meta{property} for the \meta{label} are both known.
371 % \end{function}
372 %
373 % \begin{function}{\RefUndefinedWarn}
374 % \begin{syntax}
375 % \cs{RefUndefinedWarn} \Arg{label} \Arg{property}
376 % \end{syntax}
377 % Triggers the standard warning\\
378 % \hspace*{1em}%
379 % \texttt{LaTeX Warning: There were undefined references.}\\
380 % at the end of the document if the reference for \meta{label} and \meta{property}
381 % can not be resolved.
382 % At the point where it is called it also issues the warning\\
383 % \hspace*{1em}%
384 % \texttt{Reference `\meta{label}' on page \meta{page} undefined}\\
385 % if the label is unknown, or the more specific\\
386 % \hspace*{1em}%
387 % \texttt{Property `\meta{property}' undefined for reference
388 % `\meta{label}' on page \meta{page}}
389 % if the label is known but doesn't provide a value for the requested property.
390 % \end{function}
391 %
392 % \section{Pre-declared properties}
393 %
394 % \begin{variable}{abspage}
395 % (shipout) The absolute value of the current page: starts at $1$ and increases
396 % monotonically at each shipout.
397 % \end{variable}
398 %
399 % \begin{variable}{page}
400 % (shipout) The current page as given by \cs{thepage}: this may or may not
401 % be a numerical value, depending on the current style. Contrast with
402 % \cs{abspage}. You get this value also with the standard \cs{label}/\cs{pageref}.
403 % \end{variable}
404 %
405 % \begin{variable}{pagenum}
406 % (shipout) The current page as arabic number. This is suitable for integer operations and
407 % comparisons.
408 % \end{variable}
409 %
410 % \begin{variable}{label}
411 % (now) The content of \cs{@currentlabel}. This is the value that
412 % you get also with the standard \cs{label}/\cs{ref}.
413 % \end{variable}
414 %
415 % \begin{variable}{title}
416 % (now) The content of \cs{@currentlabelname}.
417 % This command is filled beside others by the \pkg{nameref} package and some
418 % classes (e.g.~\pkg{memoir}).
419 % \end{variable}
420 %
421 % \begin{variable}{target}
422 % (now) The content of \cs{@currentHref}.
423 % This command is normally filled by for example
424 % \pkg{hyperref} and gives the name of the last destination it created.
425 % \end{variable}
426 %
427 % \begin{variable}{pagetarget}
428 % (shipout) The content of \cs{@currentHpage}.
429 % This command is filled for example by a recent version of
430 % \pkg{hyperref} and then gives the name of the last page
431 % destination it created.
432 % \end{variable}
433 %
434 % \begin{variable}{counter}
435 % (now) The content of \cs{@currentcounter}.
436 % This command contains after a \cs{refstepcounter} the name of the counter.
437 % \end{variable}
438 %
439 % \begin{variable}{xpos,ypos}
440 % (shipout) This stores the $x$~and $y$ coordinates of a point previously
441 % stored with \cs{pdfsavepos}/\cs{savepos}.
442 % E.g.~(if bidi is used it can be necessary to save the position
443 % before and after the label):
444 % \begin{verbatim}
445 % \tex_savepos:D
446 % \property_record:nn{myposition}{xpos,ypos}
447 % \tex_savepos:D
448 % \end{verbatim}
449 % \end{variable}
450 % \end{documentation}
451 %
452 % \begin{implementation}
453 %
454 % \section{The Implementation}
455 %
456 % \begin{macrocode}
457 %<*2ekernel|latexrelease>
458 % \end{macrocode}
459 % \begin{macrocode}
460 \ExplSyntaxOn
461 % \end{macrocode}
462 %
463 % \begin{macrocode}
464 %<@@=property>
465 % \end{macrocode}
466 %
467 % \begin{macrocode}
468 %<latexrelease>\NewModuleRelease{2023/11/01}{ltproperties}
469 %<latexrelease> {Cross-referencing~properties}
470 % \end{macrocode}
471 %
472 % The approach here is based closely on that from \pkg{zref}; separate out
473 % lists of properties and the properties themselves, so the latter can be
474 % used multiple times and in varying combinations.
475 % However, not everything is a straight copy. Firstly,
476 % we treat lists of properties as simple comma lists: that allows us to have
477 % either saved or dynamic lists and to avoid another data structure. The cost
478 % is that errors are detected at point-of-use, but in any real case that should
479 % be true anyway (and is true for \tn{zref@labelbyprop} already). Secondly,
480 % we allow properties to have
481 % arbitrary names, as the code does not require them to tokenize as control
482 % sequences.
483 %
484 % \begin{macro}{\property_new:nnnn, \property_gset:nnnn, \@@_gset:nnnn}
485 % As properties can be reset, they are not constants. But they also have
486 % various pieces of required data. So we use the same approach as color and
487 % make them declarations. Data-wise, we need the detail of the implementation,
488 % the default and a flag to show if the code works now or at shipout. This
489 % last entry is done using text so needs a check. We could use a set of
490 % |prop| here, but as we never need to map or copy the lists, we can gain
491 % performance using the hash table approach.
492 % \changes{v1.0j}{2025-08-01}{correct name of shipout boolean}
493 % \begin{macrocode}
494 \cs_new_protected:Npn \property_new:nnnn #1#2#3#4
495 {
496 \cs_if_free:cTF { @@_code_ #1 : }
497 {
498 \exp_args:Nx \@@_gset:nnnn { \tl_to_str:n {#1} }
499 {#2} {#3} {#4}
500 }
501 {
502 \msg_error:nn { property }{ exists }{#1}
503 }
504 }
505 \cs_new_protected:Npn \property_gset:nnnn #1#2#3#4
506 {
507 \@@_gset:ennn { \tl_to_str:n {#1} }
508 {#2} {#3} {#4}
509 }
510 \cs_new_protected:Npn \@@_gset:nnnn #1#2#3#4
511 {
512 \cs_gset:cpn { @@_code_ #1 : } {#4}
513 \tl_gclear_new:c { g_@@_default_ #1 _tl }
514 \tl_gset:cn { g_@@_default_ #1 _tl } {#3}
515 \bool_if_exist:cF { g_@@_shipout_ #1 _bool }
516 { \bool_new:c { g_@@_shipout_ #1 _bool } }
517 \str_case:nnF {#2}
518 {
519 { now } { { \bool_gset_false:c { g_@@_shipout_ #1 _bool } } }
520 { shipout }
521 { \bool_gset_true:c { g_@@_shipout_ #1 _bool } }
522 }
523 { \msg_error:nnnn { property } { unknown-setpoint } {#1} {#2} }
524 }
525 \cs_generate_variant:Nn \@@_gset:nnnn {ennn}
526 % \end{macrocode}
527 % \end{macro}
528 %
529 % \begin{macro}{\NewProperty,\SetProperty}
530 % For consistency we expand the property name, but this doesn't warant a
531 % variant of the L3-commands.
532 % \changes{v1.0c}{2023-09-20}{use \cs{protected@edef}}
533 % \begin{macrocode}
534 \cs_new_protected:Npn \NewProperty #1#2#3#4
535 {
536 \protected@edef\reserved@a{#1}
537 \exp_args:No \property_new:nnnn {\reserved@a} {#2}{#3}{#4}
538 }
539 \cs_new_protected:Npn \SetProperty #1#2#3#4
540 {
541 \protected@edef\reserved@a{#1}
542 \exp_args:No \property_gset:nnnn {\reserved@a} {#2}{#3}{#4}
543 }
544 % \end{macrocode}
545 % \end{macro}
546 %
547 % \begin{macro}{\property_record:nN}
548 % \begin{macro}
549 % {
550 % \property_record:nn,
551 % \property_record:nV,
552 % \property_record:ee,
553 % \property_record:oo,
554 % \@@_record:nn,
555 % \@@_record:en
556 % }
557 % \begin{macro}[EXP]
558 % {\@@_record_value:n, \@@_record_value_aux:n, \@@_record_value_aux:e}
559 % Writing data when it is labelled means expanding at this stage and possibly
560 % later too. That is all pretty easy using \pkg{expl3}: we accept a stray
561 % comma at the end of the list as that is easier to deal with than trying
562 % to tidy up, and there is no real downside.
563 % \changes{v1.0d}{2024-01-17}{Use \cs{protected@write}}%
564 % \changes{v1.0f}{2024-09-05}{Remove \cs{if@filesw} test to be in line with \cs{label},
565 % tagging-project issue 696}%
566 % \begin{macrocode}
567 \cs_new_protected:Npn \property_record:nN #1#2
568 { \property_record:nV {#1} #2 }
569 \cs_new_protected:Npn \property_record:nn #1#2
570 { \@@_record:en { \tl_to_str:n {#1} } {#2} }
571 \cs_generate_variant:Nn \property_record:nn { nV , ee, oo }
572 \cs_new_protected:Npn \@@_record:nn #1#2
573 {
574 \protected@write \@auxout {}
575 {
576 \token_to_str:N \new@label@record
577 {#1}
578 { \clist_map_function:nN {#2} \@@_record_value:n }
579 }
580 }
581 \cs_generate_variant:Nn \@@_record:nn { e }
582 \cs_new:Npn \@@_record_value:n #1
583 { \@@_record_value_aux:e { \tl_to_str:n {#1} } }
584 \cs_new:Npn \@@_record_value_aux:n #1
585 {
586 \cs_if_exist:cTF { @@_code_ #1 : }
587 {
588 {#1}
589 {
590 \bool_if:cTF { g_@@_shipout_ #1 _bool }
591 { \exp_not:c }
592 { \use:c }
593 { @@_code_ #1 : }
594 }
595 }
596 { \msg_expandable_error:nnn { property } { not-declared } {#1} }
597 }
598 \cs_generate_variant:Nn \@@_record_value_aux:n { e }
599 % \end{macrocode}
600 % \end{macro}
601 % \end{macro}
602 % \end{macro}
603 %
604 % \begin{macro}{\RecordProperties}
605 % \changes{v1.0c}{2023-09-20}{use \cs{protected@edef} for safer handling of active chars.} %
606 % \begin{macrocode}
607 \NewDocumentCommand\RecordProperties { m m }
608 {
609 \@bsphack
610 \protected@edef\reserved@a{#1}
611 \protected@edef\reserved@b{#2}
612 \property_record:oo {\reserved@a}{\reserved@b}
613 \@esphack
614 }
615 % \end{macrocode}
616 % \end{macro}
617 %
618 % \subsection{Reference commands}
619 %
620 % \begin{variable}{ l_@@_ref_flag }
621 % A flag that is set if a reference couldn't be resolved.
622 % \begin{macrocode}
623 \flag_new:n { l_@@_ref_flag }
624 % \end{macrocode}
625 % \end{variable}
626 %
627 % \begin{macro}[EXP]{\property_ref:nn,\property_ref:ee}
628 % Search for the label/property combination, and if not found fall back
629 % to the default of the property.
630 % \begin{macrocode}
631 \cs_new:Npn \property_ref:nn #1#2
632 {
633 \@@_ref:een
634 { \tl_to_str:n {#1} }
635 { \tl_to_str:n {#2} }
636 { \tl_use:c { g_@@_default_ #2 _tl } }
637 }
638 \cs_generate_variant:Nn \property_ref:nn {ee}
639 % \end{macrocode}
640 % \end{macro}
641 %
642 % \begin{macro}[EXP]{\property_ref:nnn,\property_ref:een, \@@_ref:nnn, \@@_ref:een}
643 % This allows to set a local default value which overrides the default value
644 % of the property.
645 % \begin{macrocode}
646 \cs_new:Npn \property_ref:nnn #1#2#3
647 {
648 \@@_ref:een
649 { \tl_to_str:n {#1} }
650 { \tl_to_str:n {#2} }
651 {#3}
652 }
653 \cs_new:Npn \@@_ref:nnn #1#2#3
654 {
655 \tl_if_exist:cTF { g_@@_label_ #1 _ #2 _tl }
656 { \tl_use:c { g_@@_label_ #1 _ #2 _tl } }
657 {
658 \flag_if_raised:nF
659 { l_@@_ref_flag } { \flag_raise:n { l_@@_ref_flag } }
660 % \end{macrocode}
661 % We test for the default of the property only to check if the property has
662 % been declared.
663 % \begin{macrocode}
664 \tl_if_exist:cTF { g_@@_default_ #2 _tl }
665 { #3 }
666 { \msg_expandable_error:nnn { property } { not-declared } {#2} }
667 }
668 }
669 \cs_generate_variant:Nn \@@_ref:nnn { ee }
670 \cs_generate_variant:Nn \property_ref:nnn {een}
671 % \end{macrocode}
672 % \end{macro}
673 %
674 % \begin{macro}[EXP]{\RefProperty}
675 % Search for the label/property combination, and if not found fall back
676 % to the default of the property or the given default.
677 % \begin{macrocode}
678 \NewExpandableDocumentCommand \RefProperty { o m m }
679 {
680 \IfNoValueTF {#1}
681 {
682 \property_ref:ee {#2}{#3}
683 }
684 {
685 \property_ref:een {#2}{#3}{#1}
686 }
687 }
688 % \end{macrocode}
689 % \end{macro}
690 %
691 % \begin{macro}{\new@label@record}
692 % \begin{macro}{\@@_data:nnn}
693 % A standard recursion loop.
694 % \begin{macrocode}
695 \cs_new_protected:Npn \new@label@record #1#2
696 {
697 \tl_if_exist:cTF { r@#1 }
698 {
699 \gdef \@multiplelabels
700 { \@latex@warning@no@line { There~were~multiply-defined~labels } }
701 \@latex@warning@no@line { Label~`#1'~multiply~defined }
702 }
703 {
704 \tl_new:c { r@#1 }
705 \tl_gset:cn { r@#1 }{#2}
706 }
707 \@@_data:nnn {#1} #2 { \q_recursion_tail } { ? } \q_recursion_stop
708 }
709 \cs_new_protected:Npn \@@_data:nnn #1#2#3
710 {
711 \quark_if_recursion_tail_stop:n {#2}
712 \tl_gclear_new:c { g_@@_label_ \tl_to_str:n {#1} _ \tl_to_str:n {#2} _tl }
713 \tl_gset:cn { g_@@_label_ \tl_to_str:n {#1} _ \tl_to_str:n {#2} _tl } {#3}
714 \@@_data:nnn {#1}
715 }
716 % \end{macrocode}
717 %
718 % This command is used in \cs{enddocument} to test if some label values have changed.
719 % \begin{macrocode}
720 \cs_new_protected:Npn \@kernel@new@label@record@testdef #1 #2
721 {
722 \tl_if_eq:cnF { r@#1 } {#2}
723 { \@tempswatrue }
724 }
725 % \end{macrocode}
726 % \end{macro}
727 % \end{macro}
728 %
729 % \subsection{Tests and warnings}
730 %
731 % \begin{macro}[pTF]{\property_if_exist:n}
732 % Tests if property has been declared.
733 % \begin{macrocode}
734 \prg_new_conditional:Npnn \property_if_exist:n #1 { p , T , F, TF }
735 % #1 property
736 {
737 \cs_if_exist:cTF { @@_code_ #1 : }
738 {
739 \prg_return_true:
740 }
741 {
742 \prg_return_false:
743 }
744 }
745 \prg_generate_conditional_variant:Nnn \property_if_exist:n {e} { p , T , F, TF }
746 % \end{macrocode}
747 % \end{macro}
748 %
749 % \begin{macro}{\IfPropertyExistsTF,\IfPropertyExistsT,\IfPropertyExistsF}
750 % \changes{v1.0e}{2024-04-17}{Renamed \cs{IfPropertyExistTF} to
751 % \cs{IfPropertyExistsTF} (gh/1262)}
752 % \begin{macrocode}
753 \cs_new_eq:NN \IfPropertyExistsTF \property_if_exist:eTF
754 \cs_new:Npn \IfPropertyExistsT #1#2 {\property_if_exist:eTF {#1}{#2}{} }
755 \cs_new:Npn \IfPropertyExistsF #1 {\property_if_exist:eTF {#1}{} }
756 % \end{macrocode}
757 % \end{macro}
758 %
759 % \begin{macro}[pTF]{\property_if_recorded:n}
760 % Tests if the label has been set.
761 % This can then be used to setup e.g.~rerun messages.
762 % \begin{macrocode}
763 \prg_new_conditional:Npnn \property_if_recorded:n #1 { p , T , F, TF }
764 % #1 label
765 {
766 \tl_if_exist:cTF { r@#1 }
767 {
768 \prg_return_true:
769 }
770 {
771 \prg_return_false:
772 }
773 }
774 \prg_generate_conditional_variant:Nnn \property_if_recorded:n {e} { p , T , F, TF }
775 % \end{macrocode}
776 % \end{macro}
777 %
778 % \begin{macro}{\IfLabelExistsTF,\IfLabelExistsT,\IfLabelExistsF}
779 % \changes{v1.0e}{2024-04-17}{Renamed \cs{IfLabelExistTF} to
780 % \cs{IfLabelExistsTF} (gh/1262)}
781 % \changes{v1.0g}{2024-09-25}{Fixed definitions of \cs{IfLabelExistsT}
782 % and \cs{IfLabelExistsF}}
783 % \begin{macrocode}
784 \cs_new_eq:NN \IfLabelExistsTF \property_if_recorded:eTF
785 \cs_new:Npn \IfLabelExistsT #1#2 {\property_if_recorded:eTF {#1}{#2}{} }
786 \cs_new:Npn \IfLabelExistsF #1 {\property_if_recorded:eTF {#1}{} }
787 % \end{macrocode}
788 % \end{macro}
789 %
790 % \begin{macro}[pTF]{\property_if_recorded:nn}
791 % tests if the label/property combination has been set
792 % This can then be used to setup e.g.~rerun messages.
793 % \begin{macrocode}
794 \prg_new_conditional:Npnn \property_if_recorded:nn #1#2 { p , T , F, TF }
795 % #1 label #2 property
796 {
797 \tl_if_exist:cTF { g_@@_label_ \tl_to_str:n {#1} _ \tl_to_str:n {#2} _tl }
798 {
799 \prg_return_true:
800 }
801 {
802 \prg_return_false:
803 }
804 }
805 \prg_generate_conditional_variant:Nnn \property_if_recorded:nn {ee} { p , T , F, TF }
806 % \end{macrocode}
807 % \end{macro}
808 %
809 % \begin{macro}{\IfPropertyRecordedTF,\IfPropertyRecordedT,\IfPropertyRecordedF}
810 % \changes{v1.0h}{2024-10-21}{Define \cs{IfPropertyRecordedT}, \cs{IfPropertyRecordedF}}
811 % \begin{macrocode}
812 \cs_new_eq:NN \IfPropertyRecordedTF \property_if_recorded:eeTF
813 \cs_new:Npn \IfPropertyRecordedT #1#2#3 { \property_if_recorded:eeTF {#1}{#2}{#3}{} }
814 \cs_new:Npn \IfPropertyRecordedF #1#2#3 { \property_if_recorded:eeTF {#1}{#2}{}{#3} }
815 % \end{macrocode}
816 % \end{macro}
817 %
818 % \begin{macro}{\property_ref_undefined_warn:}
819 % \cs{G@refundefinedtrue} is defined in \texttt{ltxref} and redefines a warning message.
820 % \begin{macrocode}
821 \cs_new_protected:Npn \property_ref_undefined_warn:
822 {
823 \flag_if_raised:nT { l_@@_ref_flag }
824 {
825 \G@refundefinedtrue
826 }
827 }
828 % \end{macrocode}
829 % \end{macro}
830 %
831 % \begin{macro}{\property_ref_undefined_warn:n,
832 % \property_ref_undefined_warn:e}
833 % \changes{v1.0k}{2025-09-05}{Add missing |e| variant (gh/1854)}
834 % \begin{macrocode}
835 \cs_new_protected:Npn \property_ref_undefined_warn:n #1 %#1 label
836 {
837 \property_if_recorded:nF {#1}
838 {
839 \G@refundefinedtrue
840 \@latex@warning{Reference~`#1'~on~page~\thepage\space undefined}%
841 }
842 }
843 \cs_generate_variant:Nn \property_ref_undefined_warn:n {e}
844 % \end{macrocode}
845 % \end{macro}
846 %
847 % \begin{macro}{\property_ref_undefined_warn:nn,
848 % \property_ref_undefined_warn:ee,
849 % \RefUndefinedWarn}
850 % \begin{macrocode}
851 \cs_new_protected:Npn \property_ref_undefined_warn:nn #1#2 %#1 label, #2 property
852 {
853 \property_if_recorded:nTF {#1}
854 {
855 \property_if_recorded:nnF {#1}{#2}
856 {
857 \G@refundefinedtrue
858 \@latex@warning
859 { Property~`#2'~undefined~for~reference~`#1'~on~page~\thepage }
860 }
861 }
862 {
863 \G@refundefinedtrue
864 \@latex@warning { Reference~`#1'~on~page~\thepage\space undefined }%
865 }
866 }
867 \cs_generate_variant:Nn \property_ref_undefined_warn:nn {ee}
868 \cs_set_eq:NN \RefUndefinedWarn \property_ref_undefined_warn:ee
869 % \end{macrocode}
870 % \end{macro}
871 %
872 % \subsection{Predeclared properties}
873 %
874 % \begin{variable}{abspage}
875 % \begin{macrocode}
876 \property_new:nnnn { abspage } { shipout }
877 { 0 } { \int_use:N \g_shipout_readonly_int }
878 % \end{macrocode}
879 % \end{variable}
880 %
881 % \begin{variable}{page}
882 % \begin{macrocode}
883 \property_new:nnnn { page } { shipout } { 0 } { \thepage }
884 % \end{macrocode}
885 % \end{variable}
886 %
887 % \begin{variable}{pagenum}
888 % \begin{macrocode}
889 \property_new:nnnn { pagenum } { shipout } { 0 } { \the \value { page } }
890 % \end{macrocode}
891 % \end{variable}
892 %
893 % \begin{variable}{label}
894 % \begin{macrocode}
895 \property_new:nnnn { label } { now } { ?? } { \@currentlabel }
896 % \end{macrocode}
897 % \end{variable}
898 %
899 % \begin{variable}{title}
900 % \begin{macrocode}
901 \property_new:nnnn { title } { now }
902 { \exp_not:n { \textbf { ?? } } } { \@currentlabelname }
903 % \end{macrocode}
904 % \end{variable}
905 %
906 % \begin{variable}{target}
907 % \begin{macrocode}
908 \property_new:nnnn { target } { now } { } { \@currentHref }
909 % \end{macrocode}
910 % \end{variable}
911 %
912 % \begin{variable}{pagetarget}
913 % \begin{macrocode}
914 \newcommand\@currentHpage{}
915 \property_new:nnnn { pagetarget } { shipout } { } { \@currentHpage }
916 % \end{macrocode}
917 % \end{variable}
918
919 % \begin{variable}{counter}
920 % \begin{macrocode}
921 \property_new:nnnn { counter } { now } { } { \@currentcounter }
922 % \end{macrocode}
923 % \end{variable}
924 %
925 % \begin{variable}{xpos,ypos}
926 % \begin{macrocode}
927 \property_new:nnnn { xpos } { shipout } { 0} { \int_use:N \tex_lastxpos:D }
928 \property_new:nnnn { ypos } { shipout } { 0} { \int_use:N \tex_lastypos:D }
929 % \end{macrocode}
930 % \end{variable}
931 %
932 % \subsection{Messages}
933 % \begin{macrocode}
934 \msg_new:nnnn { property } { exists }
935 { Property~'#1'~ has~ already~ been~ declared. }
936 { There~ already~ exists~ a~ property~ declaration~ with~ this~
937 name.\\
938 Please~ use~ a~ different~ name~ for~ your~ property.}
939
940 \msg_new:nnnn { property } { not-declared }
941 { Property~'#1'~not~declared. }
942 {
943 LaTeX~has~been~asked~to~use~property~'#1',~but~this~
944 name~has~not~been~declared.
945 }
946 \msg_new:nnnn { property } { unknown-setpoint }
947 { Unknown~keyword~'#2'~for~setting~property~'#1'. }
948 {
949 LaTeX~has~been~asked~to~set~the~property~'#1',~but~the~keyword~
950 '#2'~is~not~one~of~the~two~known~values:~'now'~or~'shipout'.
951 }
952 % \end{macrocode}
953 %
954 % \begin{macrocode}
955 %
956 %<latexrelease>\IncludeInRelease{0000/00/00}{ltproperties}
957 %<latexrelease> {cross-referencing~properties~(undo)}%
958 %<latexrelease>
959 %<latexrelease>\let \NewProperty \@undefined
960 %<latexrelease>\let \SetProperty \@undefined
961 %<latexrelease>
962 %<latexrelease>\let \RecordProperties \@undefined
963 %<latexrelease>\let \RefProperty \@undefined
964 %<latexrelease>\let \RefUndefinedWarn \@undefined
965 %<latexrelease>
966 %<latexrelease>\let \IfPropertyExistsTF \@undefined
967 %<latexrelease>\let \IfLabelExistsTF \@undefined
968 %<latexrelease>\let \IfPropertyRecordedTF \@undefined
969 %<latexrelease>
970 %<latexrelease>\let\new@label@record \@undefined
971 %<latexrelease>\let\@kernel@new@label@record@testdef\@undefined
972 %<latexrelease>\EndModuleRelease
973 % \end{macrocode}
974 %
975 % \begin{macrocode}
976 \ExplSyntaxOff
977 % \end{macrocode}
978 %
979 % \begin{macrocode}
980 %</2ekernel|latexrelease>
981 % \end{macrocode}
982 %
983 % Reset module prefix:
984 % \begin{macrocode}
985 %<@@=>
986 % \end{macrocode}
987 %
988 %
989 % \end{implementation}
990 %
991 % \Finale