Debian Codegraph @

texmf-dist/source/latex-dev/latex-lab/documentmetadata-support.dtx

raw
1 % \iffalse meta-comment
2 %
3 %% File: documentmetadata-support.dtx
4 % Copyright (C) 2021-2026 The LaTeX Project
5 %
6 % It may be distributed and/or modified under the conditions of the
7 % LaTeX Project Public License (LPPL), either version 1.3c of this
8 % license or (at your option) any later version. The latest version
9 % of this license is in the file
10 %
11 % https://www.latex-project.org/lppl.txt
12 %
13 %
14 % The development version of the bundle can be found below
15 %
16 % https://github.com/latex3/latex2e
17 %
18 % for those people who are interested or want to report an issue.
19 %
20 % \begin{macrocode}
21 \def\documentmetadatasupportversion{1.1b}
22 \def\documentmetadatasupportdate{2026-05-02}
23 % \end{macrocode}
24 %
25 %
26 %<*driver>
27 \DocumentMetadata{tagging=on,pdfstandard=ua-2}
28 \documentclass[kernel]{l3in2edoc}
29
30 \EnableCrossrefs
31 \CodelineIndex
32 \begin{document}
33 \DocInput{documentmetadata-support.dtx}
34 \end{document}
35 %</driver>
36 %
37 % \fi
38 %
39 %
40 %\NewDocElement[macrolike = false ,
41 % toplevel = true,
42 % idxtype = key ,
43 % noprint = true ,
44 % idxgroup = metadata keys ,
45 % printtype = \textit{key}
46 % ]{Mkey}{mkey}
47 %
48 %
49 % \title{The \texttt{documentmetadata-support} code\thanks{This file
50 % has version \documentmetadatasupportversion\ dated
51 % \documentmetadatasupportdate, \copyright\ \LaTeX\
52 % Project.}}
53 % \author{Frank Mittelbach, Ulrike Fischer, \LaTeX{} Project}
54 %
55 % \maketitle
56 %
57 %
58 % \section{Introduction}
59 %
60 % The kernel command \cs{DocumentMetadata}, which can be used as
61 % the very first declaration in a document (i.e., before
62 % \cs{documentclass}), defines metadata and other configuration
63 % data that applies to the document as a whole (using a key/value
64 % syntax). It loads and activates
65 % the PDF management code from the \pkg{pdfmanagement} package and loads
66 % and activated code currently stored in latex-lab modules
67 % needed for various features developed as part of the multi-year ``Tagged PDF''
68 % project.~\cite{blueprint}
69 %
70 % While the underlying functionality is still under
71 % development (e.g., further keys will be added over time and keys
72 % marked temporary may vanish again) the code for
73 % \cs{DocumentMetadata} is placed in a separate bundle, so that it
74 % is easier to update it without the need to build a full \LaTeX{}
75 % release. Over time the functionality will move fully into the
76 % kernel.
77 %
78 % As the loading of the PDF management forces the loading of the \pkg{l3backend} files,
79 % a backend that can't be detected automatically like |dvipdfmx|,
80 % must be set in the first \cs{DocumentMetadata}.
81 %
82 % From a process perspective \cs{DocumentMetadata} loads the
83 % \pkg{pdfmanagement} code and the latex-lab modules
84 % the first time it is called and then
85 % redefines itself to error if
86 % called more than once. In particular, this means that a document
87 % without a \cs{DocumentMetadata} declaration has no code available
88 % for extended management of PDF output and for tagging support.
89 %
90 % \section{The \cs{DocumentMetadata} command}
91 %
92 % \begin{function}{\DocumentMetadata}
93 % \begin{syntax}
94 % \cs{DocumentMetadata}\Arg{key-value list}
95 % \end{syntax}
96 %
97 % The command should be used as the first command in a document, before
98 % \cs{documentclass}. It takes a key-value argument.
99 % \end{function}
100 %
101 % Starting with the release 2025-11-01 \cs{DocumentMetadata} will always load
102 % the new modules which changes \LaTeX{} internals and add tagging support code.
103 %
104 % For documents that want to load the PDF management but do not want the new tagging support
105 % code we provide a dedicated package. Such documents should replace
106 % \begin{verbatim}
107 % \DocumentMetadata{pdfversion=1.7,
108 % pdfstandard=a-3b}
109 % \end{verbatim}
110 % by
111 % \begin{verbatim}
112 % \RequirePackage{pdfmanagement}
113 % \SetKeys[document/metadata]{pdfversion=1.7,
114 % pdfstandard=a-3b}
115 % \end{verbatim}
116 %
117 % Currently the modules loaded by \cs{DocumentMetadata} are the following.
118 % Details and documentation can be found in the various \texttt{latex-lab-\meta{module}.pdf}:
119 %
120 % \begin{description}
121 % \item[\texttt{names}] This module declares tag names for the structures.
122 % \item[\texttt{new-or-2}] This module changes output routine sockets and adds support
123 % for the paragraph tagging. It also loads the new footnote code.
124 % \item[\texttt{block}] This module reimplements lists and blocks environments and
125 % adds tagging support.
126 % \item[\texttt{context}] This module provides context for template instances and code that needs
127 % to know where and when it is executed.
128 % \item[\texttt{sec},\texttt{sec-template}] These modules reimplement heading commands
129 % and make them tagging aware.
130 % \item[\texttt{toc}] This module adapts commands related to the table of contents and
131 % similar list to make them tagging aware.
132 % \item[\texttt{minipage}] This module adds tagging support to \texttt{minipage}
133 % and \cs{parbox}.%
134 % \item[\texttt{graphic}] This module enables tagging support for
135 % the \cs{includegraphics} command and the \texttt{picture} environment.
136 % \item[\texttt{float}] This module adds tagging support to floats.
137 % \item[\texttt{bib}] This module adds tagging support to citations and bibliographies.
138 % \item[\texttt{text}] This module adds tagging support to small text commands like
139 % the \LaTeX{} logo, the \cs{emph} command and super and sub scripts.
140 % \item[\texttt{marginpar}] This module adds tagging support to the \cs{marginpar}
141 % command.
142 % \item[\texttt{title}] This module adds tagging support to the \cs{maketitle}
143 % command if a standard class is used. It also enhances the \cs{title}
144 % and \cs{author} commands to fill the XMP-metadata and set the window title.
145 % It is not compatible with packages and classes which redefine these commands
146 % too.
147 % \item[\texttt{table}] This module provides tagging for
148 % \texttt{tabular}, \texttt{longtable} and similar table environments.
149 % Its use and restrictions are documented in \texttt{latex-lab-table.pdf}.
150 % \item[\texttt{math}] This module adapts math for tagging.
151 % \item[\texttt{firstaid}] This module contains small adjustments to external packages.
152 % \item[\texttt{tikz}] This module adds support for the \pkg{tikz} package.
153 % \end{description}
154 %
155 %
156 % \section{Keys and values}
157 %
158 % Currently the following keys are implemented for \cs{DocumentMetadata}:
159 % \DescribeMkey{backend}
160 % \DescribeMkey{pdfversion}
161 % \DescribeMkey{uncompress}
162 % \DescribeMkey{language}
163 % \DescribeMkey{other-languages}
164 % \DescribeMkey{lang}
165 % \DescribeMkey{pdfstandard}
166 % \DescribeMkey{xmp}
167 % \DescribeMkey{colorprofiles}
168 % \DescribeMkey{tagging}
169 % \DescribeMkey{tagging-setup}
170 % \DescribeMkey{check-tagging-status}
171 % \DescribeMkey{testphase}
172 % \DescribeMkey{debug}
173 %
174 % \begin{description}
175 % \item[\texttt{backend}] Passes the backend name to expl3. This is
176 % needed only if the correct backend can't be automatically
177 % determined or if the workflow requires a special backend.
178 %
179 %^^A This will probably be extended to pass the value also to
180 %^^A packages.
181 %
182 % \item[\texttt{pdfversion}] Sets the PDF version explicitly, e.g., \texttt{pdfversion=1.7}.
183 % The key definition is in the pdfmanagement in l3pdfmeta.
184 %
185 % \item[\texttt{uncompress}] (no value) Forces an uncompressed pdf
186 % --- mainly for debugging purposes. Do not unnecessarily set it in normal production
187 % because it increases the size of the final PDF considerably.
188 %
189 % \item[\texttt{language}]
190 % The language key should be used to set the main language of the
191 % document. The value is given in BCP~47 format,
192 % so, e.g, \texttt{languade=de-DE} or \texttt{language=fr}.
193 % The value is stored in the document properties and can be retrieved (expandably) with
194 % \verb+\GetDocumentProperty{document/language}+.
195 %
196 % The key does \emph{not} change the language setup of a document: it doesn't change the
197 % hyphenation patterns or the fix names or forces the loading of a language package.
198 % The expectation is that packages that need to know the document language, like \pkg{babel} or
199 % \pkg{polyglossia}, read the value and react accordingly.
200 % The BCP~47 value,e.g., can be parsed with \cs{text_bcp_parse:n} which produces
201 % 7 brace groups, see interface3.
202 % To extract, for example, the main language in the first group this code could be used:
203 % \begin{verbatim}
204 % \cs_generate_variant:Nn\text_bcp_parse:n{e}
205 % \tl_set:Ne\mainlanguage
206 % {\exp_last_unbraced:Ne\use_i:nnnnnnn
207 % {\text_bcp_parse:e{\GetDocumentProperty{document/language}}}}
208 % \end{verbatim}
209 %
210 %
211 % The key updates the default \cs{BCPdata} command to use with the give language value.
212 % Note that this can lead to empty fields for region or script, if, e.g., only
213 % \texttt{language=de} instead of \texttt{language=de-Latn-AT} is used.
214 % This is only relevant if neither \pkg{babel} nor \pkg{polyglossia}
215 % are used as both packages overwrite the \cs{BCPdata} command with their own version.
216 %
217 % The value of the \texttt{language} key is also used to set the \texttt{/Lang} key in the PDF.
218 % If a different (shorter) value is wanted there, an optional argument can be used:
219 % \verb+language=[de]{de-DE}+, or the \texttt{lang} key can be
220 % used to overwrite the value: \verb+language=de-DE,lang=de+.
221 %
222 % \item[\texttt{otherlanguage}]
223 % The \texttt{other-languages} key can be used to declare more languages that are used
224 % in the document. The argument is a comma list of languages in BCP~47 format:
225 % \verb+other-languages={fr,en-US,ar}+.
226 % The comma list is stored in the document properties and can be retrieved
227 % (expandably) with \verb+\GetDocumentProperty{document/other-languages}+.
228 % As with the \texttt{language} key the expectation is, that language packages
229 % read the value and react accordingly.
230 %
231 % \item[\texttt{lang}] Explicitly sets the Lang entry in the Catalog,
232 % e.g., \texttt{lang=de-DE}. If not given, the value of \verb+\BCPdata{language}+
233 % or \verb+ \BCPdata{main.language}+ at the beginning of the document is used (these
234 % commands are set by \pkg{babel}, the default value is |en-US|).
235 % The key is implicitly set if the \texttt{language} key is used.
236 %
237 % \item[\texttt{pdfstandard}] Choice key to set the pdf standard.
238 % Currently |A-1b|, |A-2a|, |A-2b|, |A-2u|, |A-3a|, |A-3b|, |A-3u|, |A-4|, |A-4E|
239 % and |A-4F| are accepted as A-standard.
240 % values. The casing is irrelevant, |a-1b| works too.
241 % Note that using this
242 % key doesn't mean that the document actually follows the standard. \LaTeX{}
243 % can neither ensure nor check all requirements of a standard, and not everything
244 % it can do theoretically has already been implemented.
245 % When setting an A-standard a color profile is included and the
246 % \texttt{/OutputIntent} is set and any javascript action in hyperref are suppressed.
247 % The |u| variants do not enforce unicode,
248 % but they will pass the information to hyperref. The |a| variants
249 % do \emph{not} enforce (or even test) a tagged pdf yet.
250 %
251 % Beside the A-standards it is also possible to use the values
252 % |X-4|, |X-4p|, |X-5g|, |X-5n|, |X-5pg|, |X-6|, |X-6n|, |X-6p| for
253 % a PDF/X and |UA-1| and |UA-2| for PDF/UA standard.
254 % |UA-2| should only be used together with PDF 2.0.
255 % Currently these keys set \emph{only} the relevant XMP-metadata.
256 % They do not validate or enforce special requirements
257 % (e.g., the |UA| standards do not automatically activate tagging).
258 %
259 % |pdfstandard| can be used more than once to set overlapping standards, e.g:\\
260 % |pdfstandard=A-2b,pdfstandard=X-4,pdfstandard=UA-1|. It is also possible
261 % to pass a list like |pdfstandard={UA-2,A-4F}|.
262 %
263 % If XMP-metadata are added (see the following key \texttt{xmp})
264 % the necessary conformance markers for the standards are set.
265 %
266 % Standards can require some minimal or maximal PDF version and the keys will try to
267 % adjust the PDF version as necessary. At the beginning of the document the versions are checked
268 % again a warning is issued if PDF version and standard conflicts.
269 %
270 % The key is defined in the pdfmanagement in \pkg{l3pdfmeta} and more
271 % information can be found in the documentation.
272 %
273 % \item[\texttt{xmp}] A boolean, if set to false no XMP metadata are added to the PDF.
274 % The initial value is true. Details are described in the documentation of \pkg{l3pdfmeta}.
275 %
276 % \item[\texttt{colorprofiles}] This allows to load icc-colorprofiles. Details
277 % are described in the documentation of \pkg{l3pdfmeta}.
278 %
279 % \item[\texttt{tagging}] This key allows to activate, deactivate or partially deactivate the tagging support.
280 % It accepts the three values \texttt{on}, \texttt{off} and \texttt{draft}.
281 % The tagpdf package and all standard modules of the tagging support are loaded regardless of the use and the
282 % value of the key!
283 % \begin{itemize}
284 % \item |tagging=on| activates tagging.
285 % \item |tagging=off| deactivates in the \texttt{class/before} hook the tagging commands,
286 % including the \cs{tagpdfsetup} command. It also deactivates the use of real space chars.
287 % This can be reactivated by using |tagging-setup={activate/spaces}|.
288 % \item |tagging=draft| leaves the
289 % tagging commands active but it deactivates the writing of the structure tree
290 % at the end of the compilation. This can save
291 % time when drafting a longer document but preserves, e.g., MC-content marker
292 % in the PDF stream and warnings and errors from \pkg{tagpdf} if the structure is faulty.
293 % \end{itemize}
294 %
295 % \item[\texttt{tagging-setup}] This key allows to configure the tagging. It accepts all
296 % keys that can also be used in \cs{tagpdfsetup}; see the \pkg{tagpdf} documentation.
297 % Additionally, it accepts two keys to extend the list of modules loaded:
298 % \begin{description}
299 % \item[\texttt{modules}] This key previously allowed to change the
300 % list of modules. Starting with the release 2025-11-01 all standard modules
301 % are loaded always, so its only use is to load a non-standard module, e.g.
302 % |modules=verbatim-af| will load an experimental module changing the verbatim tagging.
303 %
304 % \item[\texttt{extra-modules}] This key allows to load non-standard modules and
305 % starting with the release 2025-11-01 it is an alias of |modules|.
306 % \end{description}
307 %
308 % \item[\texttt{check-tagging-status}] This key is provided to help to
309 % identify packages that are potentially problematic when used with the tagging code.
310 % When used (with no value or with the value |listfiles|,
311 % it reads the file |latex-tagging-status.ltx|
312 % from the \pkg{latex-tagging-status} package and then writes at the end of the compilation
313 % a report about the compatibility of the class and the packages with the tagging project.
314 % It follows the classification done at \url{https://latex3.github.io/tagging-project/tagging-status}.
315 %
316 % This is only a rough overview and a debugging aid, not a final report!
317 % Using packages that are classified as incompatible or partially incompatible
318 % does not mean that the tagging is necessarily broken. For example, \pkg{hyperref}
319 % is partially incompatible as the form fields are not properly tagged (this requires the use
320 % of the \pkg{l3pdffield} package), but in documents without form fields it is unproblematic.
321 % (In case of partially-compatible or incompatible packages check the table at
322 % \url{https://latex3.github.io/tagging-project/tagging-status} as it often contains
323 % an explanation what is not yet working.)
324 %
325 % The package \pkg{latex-tagging-status} will be regularly updated to reflect changes
326 % in package. Erroneous messages should be reported
327 % at \url{https://github.com/latex3/tagging-project/issues}. It is also possible
328 % to create a pull request which updates the data.
329 %
330 % \item[\texttt{testphase}] This key loaded in older \LaTeX{} versions
331 % specific sets of modules from the testphase code.
332 % Starting with the release 2025-11-01 all standard modules are
333 % loaded automatically by \cs{DocumentMetadata} and with this change the key
334 % lost most of its original purpose.
335 % The values \texttt{phase-I}, \texttt{phase-II}, \texttt{phase=III} of the
336 % \texttt{testphase} key will no longer load different code variants but only
337 % activate tagging. The key can still be used to load additional experimental modules,
338 % it then works similar to the \texttt{modules} and \texttt{extra-modules} key and does
339 % not automatically activate tagging.
340 %
341 % \item[\texttt{debug}] This key activates some debug options. It takes a list of key-values
342 % as value. Currently the following keys are known:
343 % \begin{description}
344 % \item[\texttt{para}] with the default and only value |show|. It will activate the |debug/show=para|
345 % option of \pkg{tagpdf};
346 % \item[\texttt{log}] with the values as described in the documentation of \pkg{tagpdf};
347 % \item[\texttt{uncompress}] which does the same as |uncompress| as main key;
348 % \item[\texttt{pdfmanagement}] a boolean which allows to deactivate the pdfmanagement (deprecated);
349 % \item[\texttt{firstaidoff}] this accepts a comma lists of keywords and disables the patches
350 % related to them. More information can be found in the documentation of
351 % \pkg{pdfmanagement-firstaid};
352 % \item[\texttt{xmp-export}] this will export the XMP-metadata to a file \verb+\jobname.xmpi+.
353 % With \texttt{debug=\{xmp-export=filename\}} the file name can be changed;
354 % More information can be found in the documentation of \pkg{l3pdfmeta} of the \pkg{pdfmanagement-testphase}
355 % bundle;
356 % \item[\texttt{tagpdf}] This loads the package tagpdf-debug which enhances
357 % various commands from tagpdf with additional debugging options. This can slow down
358 % the compilation!
359 % \item[\texttt{BBox}] This helps to debug BBox values of graphics, see the documentation
360 % of latex-lab-graphic.
361 % \end{description}
362 % \end{description}
363 %
364 % \bibliographystyle{plain}
365 %
366 % \begin{thebibliography}{9}
367 %
368 % \bibitem{blueprint} Frank Mittelbach and Chris Rowley:
369 % \emph{\LaTeX{} Tagged PDF\,---\,A blueprint for a large project}.
370 % \url{https://latex-project.org/publications/indexbyyear/2020/}
371 %
372 % \end{thebibliography}
373 %
374 %
375 %
376 % \MaybeStop{\setlength\IndexMin{200pt} \PrintIndex }
377 %
378 % \begin{implementation}
379 %
380 % \section{The Implementation}
381 %
382 %
383 % \begin{macrocode}
384 %<@@=pdfmanagement>
385 %<*code>
386 % \end{macrocode}
387 %
388 % \begin{macrocode}
389
390 \RequirePackage{pdfmanagement-init}
391 % \end{macrocode}
392 %
393 % \begin{macrocode}
394 \ExplSyntaxOn\makeatletter
395 % \end{macrocode}
396
397 % \subsection{Variables}
398 % These variable definitions are currently also done in ltdocinit.
399 % They can be removed from there once latex-lab has been updated to
400 % provide them too.
401 % \begin{variable}{\g_@@_firstaidoff_clist}
402 % A list to store the firstaid code which should be disabled
403 % \begin{macrocode}
404 \clist_if_exist:NF \g_@@_firstaidoff_clist
405 { \clist_new:N \g_@@_firstaidoff_clist }
406 % \end{macrocode}
407 % \end{variable}
408 % \begin{variable}{\g_@@_testphase_tl}
409 % a tl to store the testphase loading code so that we can load them at
410 % the end of the command.
411 % \begin{macrocode}
412 \tl_if_exist:NF \g_@@_testphase_tl
413 { \tl_new:N \g_@@_testphase_tl }
414 % \end{macrocode}
415 % \end{variable}
416 %
417 % \subsection{Kernel changes with \cs{DocumentMetadata}}
418 % \begin{macro}{\@kernel@before@DocumentMetadata}
419 % \begin{macrocode}
420 \cs_new_protected:Npn \@kernel@before@DocumentMetadata
421 {
422 \ifx\Umathcode\@undefined
423 \fontencoding{T1}
424 \renewcommand\encodingdefault{T1}
425 \fi
426 }
427 % \end{macrocode}
428 % \end{macro}
429
430 % \subsection{\cs{DocumentMetadata}}
431 %
432 % \begin{macro}{\DocumentMetadata}
433 %
434 % \cs{DocumentMetadata} should not be used after
435 % \cs{documentclass} so we error in this case.
436 % It can be used more than once
437 % but follow-up calls should not do the initialization code.
438 % \begin{macrocode}
439 \cs_set_protected:Npn \DocumentMetadata #1
440 {
441 \cs_if_eq:NNTF \documentclass \@twoclasseserror
442 { \msg_error:nn { meta } { after-class } }
443 {
444 % \end{macrocode}
445 % Load general format changes
446 % \begin{macrocode}
447 \@kernel@before@DocumentMetadata
448 % \end{macrocode}
449 %
450 % The wanted backend must be detected first, we read the init
451 % key and then force the loading of the backend.
452 % The backend can contain management commands, so the boolean should
453 % be set to true first.
454 % \begin{macrocode}
455 \bool_gset_true:N \g_@@_active_bool
456 \keys_set_groups:nnn { document / metadata} {init}{ #1 }
457 %if no backend has been loaded force it now:
458 \str_if_exist:NF \c_sys_backend_str
459 {
460 \sys_load_backend:n {}
461 }
462 % \end{macrocode}
463 % Now we load the extra backend code:
464 % \begin{macrocode}
465 \ExplSyntaxOn\makeatletter
466 \file_input:n {l3backend-testphase-\c_sys_backend_str.def}
467 \ExplSyntaxOff\makeatother
468 % \end{macrocode}
469 % \changes{v1.0m}{2025/02/17}{Set PDF 2.0 as default}
470 % \begin{macrocode}
471 \pdf_version_gset:n { 2.0 }
472 % \end{macrocode}
473 % tagpdf currently requires that the pdf version is set first.
474 % \begin{macrocode}
475 \keys_set_groups:nnn { document / metadata} {pdf}{ #1 }
476 % \end{macrocode}
477 % Load the latex-lab modules:
478 % \changes{v1.0s}{2025/07/07}{Load latest set always.}
479 % \begin{macrocode}
480 \RequirePackage{latex-lab-testphase-latest}
481 \AddToDocumentProperties [document]{tagging}{inactive}
482 \AddToDocumentProperties [document]{tagging/para}{inactive}
483 % \end{macrocode}
484 % Process the non-init keys.
485 % \changes{v1.0s}{2025/07/07}{hyperref loads the generic driver itself}
486 % \changes{v1.0s}{2025/07/07}{pdf management is always active, so test removed}
487 % \begin{macrocode}
488 \keys_set_exclude_groups:nnn { document / metadata } { init,pdf } { #1 }
489 % \end{macrocode}
490 % Finally we set up the language default.
491 % If the \texttt{language} key hasn't be set yet, we set it directly
492 % either to the value of the \texttt{lang} key or to en-US.
493 % \begin{macrocode}
494 \tl_if_empty:eTF{\GetDocumentProperty{document/language}}
495 {
496 \tl_set:Ne\l_@@_tmpa_tl{\GetDocumentProperty{document/lang}}
497 \tl_if_empty:NTF\l_@@_tmpa_tl
498 {\AddToDocumentProperties[document]{language}{en-Latn-US}}
499 {
500 \keys_set:ne{document/metadata}{language=\l_@@_tmpa_tl}
501 \@@_update_BCPdata:
502 }
503 }
504 {
505 \@@_update_BCPdata:
506 }
507 % \end{macrocode}
508 % At last we set up the lang default.
509 % This is done after the begindocument hook so that it can pick up settings
510 % from babel. If the Catalog dictionary already contains a lang value we do nothing,
511 % otherwise we use the value stored in \cs{BCPdata}, either the main language
512 % (if its exists) or the fall back language.
513 % Note: if babel is loaded without a language this gives the language \texttt{und}.
514 % \changes{v1.0x}{2025/12/15}{Remove warning, issue tagging/1115}
515 % \begin{macrocode}
516 \g@addto@macro\@kernel@after@begindocument
517 {
518 \pdfdict_get:nnN {g__pdf_Core/Catalog}{Lang}\l_@@_tmpa_tl
519 \quark_if_no_value:NT\l_@@_tmpa_tl
520 {
521 \tl_if_empty:eTF { \BCPdata{main.language} }
522 { \tl_set:Ne \l_@@_tmpb_tl { \BCPdata{language} } }
523 { \tl_set:Ne \l_@@_tmpb_tl { \BCPdata{main.language} } }
524 \exp_last_unbraced:Ne
525 \AddToDocumentProperties{[document]{lang}{\l_@@_tmpb_tl}}
526 \pdfmanagement_add:nne {Catalog} {Lang}{(\l_@@_tmpb_tl)}
527 }
528 }
529 % \end{macrocode}
530 % \cs{pdfmanagement_add:nnn} has collected values in this hook.
531 % \begin{macrocode}
532 \hook_use_once:n {pdfmanagement/add}
533 % \end{macrocode}
534 % Now we redefine \cs{DocumentMetadata} so that it errors on future calls
535 % \changes{1.0z}{2026-04-22}{Error if two \cs{DocumentMetadata} declarations are used.}
536 % \begin{macrocode}
537 \cs_set_protected:Npn \DocumentMetadata ##1
538 {
539 \@latex@error
540 {Two~\noexpand\DocumentMetadata~declarations}%
541 {The~document~may~use~only~one~\noexpand\DocumentMetadata~declaration.}
542 }
543 % \end{macrocode}
544 % Load more modules, the testphase code and the firstaid code.
545 % \begin{macrocode}
546 \g_@@_testphase_tl
547 \RequirePackage{pdfmanagement-firstaid}
548 }
549 }
550 % \end{macrocode}
551 % \end{macro}
552
553 % \subsection{Tagging status report}
554 % Hide our own files
555 % \begin{macrocode}
556 \clist_map_inline:nn
557 {
558 pdfmanagement-init.sty,
559 color-ltx.sty,
560 xcolor-patches-tmp-ltx.sty,
561 tagpdf-base.sty,
562 latex-lab-testphase-latest.sty,
563 tagpdf.sty,
564 tagpdf-mc-code-generic.sty,
565 tagpdf-mc-code-lua.sty,
566 luamml-patches-kernel.sty,
567 luamml-patches-amsmath.sty,
568 latex-lab-enumitem.sty,
569 latex-lab-kernel-changes.sty,
570 latex-lab-testphase-names.sty,
571 latex-lab-testphase-new-or-2.sty,
572 latex-lab-testphase-block.sty,
573 latex-lab-testphase-context.sty,
574 latex-lab-testphase-sec.sty,
575 latex-lab-testphase-sec-template.sty,
576 latex-lab-testphase-toc.sty,
577 latex-lab-testphase-minipage.sty,
578 latex-lab-testphase-graphic.sty,
579 latex-lab-testphase-float.sty,
580 latex-lab-testphase-bib.sty,
581 latex-lab-testphase-text.sty,
582 latex-lab-testphase-marginpar.sty,
583 latex-lab-testphase-title.sty,
584 latex-lab-testphase-table.sty,
585 latex-lab-testphase-math.sty,
586 latex-lab-testphase-firstaid.sty,
587 latex-lab-testphase-tikz.sty,
588 pdfmanagement-firstaid.sty,
589 }
590 {\expandafter\chardef\csname t@status@#1\endcsname8\relax }
591 % \end{macrocode}
592 % \begin{macrocode}
593 \tl_new:c {l__tag_status_0_tl}
594 \tl_new:c {l__tag_status_1_tl}
595 \tl_new:c {l__tag_status_2_tl}
596 \tl_new:c {l__tag_status_3_tl}
597 \tl_new:c {l__tag_status_4_tl}
598 \tl_new:c {l__tag_status_-1_tl}
599 \cs_new_protected:Npn\__tag_status_sort:
600 {
601 \clist_map_inline:Nn\g__tag_status_filelist_tl
602 {
603 \filename@parse{##1}
604 \cs_if_exist:cTF { t@status@##1 }
605 {
606 \str_if_eq:onF{\filename@ext}{cls}
607 {
608 \tl_put_right:cn
609 {l__tag_status_\int_use:c { t@status@##1 }_tl}
610 {~~##1\iow_newline:}
611 }
612 }
613 {
614 \str_if_eq:onT{\filename@ext}{sty}
615 {
616 \tl_put_right:cn
617 {l__tag_status_-1_tl}
618 {~~##1\iow_newline:}
619 }
620 }
621 }
622 }
623 \cs_new_protected:Npn \__tag_status_type:nn #1 #2
624 % #1 number, -1 for not listed, #2 title
625 {
626 \iow_term:n{~~#2}
627 \iow_term:n{~~--------------------------}
628 \tl_if_empty:cTF{l__tag_status_#1_tl}
629 {
630 \iow_term:e{~~NONE\iow_newline:}
631 }
632 {
633 \iow_term:e{\tl_use:c{l__tag_status_#1_tl}}
634 }
635 }
636 \cs_new_protected:Npn \__tag_status_log:
637 {
638 \file_if_exist_input:n {latex-tagging-status.ltx}
639 \AddToHookNext{class/before}
640 {
641 \tl_const:Ne \c__tag_current_class_tl{\@currname.\@currext}
642 \tl_const:Ne \c__tag_status_class_tl
643 {
644 \cs_if_exist:cTF { t@status@\@currname.\@currext }
645 {
646 \int_case:nn { \int_use:c { t@status@\@currname.\@currext } }
647 {
648 {0}{unknown}
649 {1}{unsupported}
650 {2}{currently~incompatible}
651 {3}{partially~compatible}
652 {4}{compatible}
653 }
654 }
655 { not~in~the~status~list}
656 }
657 }
658 \AddToHook{begindocument}{\tl_gset_eq:NN \g__tag_status_filelist_tl\@filelist}
659 \AddToHook{enddocument/info}
660 {
661 \iow_term:n{}
662 \iow_term:n
663 {======================================}
664 \iow_term:n{~~Status~report~of~the~tagging~support}
665 \iow_term:n{======================================}
666 \iow_term:n{~~Details~at~https://latex3.github.io/tagging-project/tagging-status}
667 \iow_term:n{~~Report~erroneous~entries~at~https://github.com/latex3/tagging-project}
668 \iow_term:n{}
669 \iow_term:n{~~A.~CLASS}
670 \iow_term:n{~~********}
671 \iow_term:n{}
672 \iow_term:e{~~\c__tag_current_class_tl\c_space_tl is~\c__tag_status_class_tl}
673 \iow_term:n{}
674 \iow_term:n{~~B.~PACKAGES,~LIBRARIES,~etc}
675 \iow_term:n{~~***********}
676 \iow_term:n{}
677 \__tag_status_sort:
678 \__tag_status_type:nn{1}{1.~Unsupported}
679 \__tag_status_type:nn{2}{2.~Currently~incompatible}
680 \__tag_status_type:nn{3}{3.~Partially~compatible}
681 \__tag_status_type:nn{4}{4.~Compatible}
682 \__tag_status_type:nn{0}{5.~Unknown}
683 \__tag_status_type:nn{-1}{6.~Unclassified~files~with~extension~.sty}
684 \iow_term:n{====================================}
685 \iow_term:n{~~End~of~status~report}
686 \iow_term:n{====================================}
687 }
688 }
689 % \end{macrocode}
690 %\subsection{\cs{DocumentMetadata} keys}
691 %\changes{1.0k}{2024-12-17}{added latest value for testphase key.}
692 %\changes{1.0n}{2025/03/25}{Allow a list as pdfstandard value.}
693 %\changes{1.0n}{2025/03/25}{Add tagging key}
694 %\changes{1.0n}{2025/03/25}{Add tagging-setup}
695 %\changes{1.0o}{2025/04/03}{Add debug=BBox}
696 %\changes{1.0p}{2025/04/28}{Add tikz module to latest key}
697 %\changes{1.0u}{2025/10/09}{Added check-tagging-status}
698 %\changes{1.0v}{2025/10/12}{Extend check-tagging-status to libraries}
699 %\changes{1.0z}{2026-04-22}{Removed duplicated key definitions that are already done in pdfmanagement-init}
700 %
701 % \begin{macro}{\@@_update_BCPdata:n}
702 % A helper command for the language key.
703 % This command updates the \cs{BCPdata} command.
704 % \begin{macrocode}
705 \cs_generate_variant:Nn \text_bcp_parse:n {e}
706 \cs_new_protected:Npn\@@_update_BCPdata:
707 {
708 \tl_set:Ne\l_@@_tmpa_tl { \text_bcp_parse:e{\GetDocumentProperty{document/language}} }
709 \use:e
710 {
711 \exp_not:N\renewcommand*\exp_not:N\BCPdata[1]
712 {
713 \exp_not:N \str_case:nn {##1}
714 {
715 { language } %was en
716 { \exp_last_unbraced:No\use_i:nnnnnnn { \l_@@_tmpa_tl} }
717 { region } %was US
718 { \exp_last_unbraced:No\use_iv:nnnnnnn { \l_@@_tmpa_tl} }
719 { script } %was Latn
720 { \exp_last_unbraced:No\use_iii:nnnnnnn { \l_@@_tmpa_tl} }
721 { tag } %was en-US
722 { \exp_last_unbraced:No\use_i:nnnnnnn { \l_@@_tmpa_tl}-
723 \exp_last_unbraced:No\use_iv:nnnnnnn { \l_@@_tmpa_tl}
724 }
725 }
726 }
727 }
728 }
729 % \end{macrocode}
730 % \end{macro}
731
732 % \begin{macro}{\@@_language_set:n,\@@_language_set_aux:wn}
733 % Command to handle the optional argument of the \texttt{language} key.
734 % \begin{macrocode}
735 \cs_new_protected:Npn \@@_language_set:n #1
736 {
737 \tl_if_head_eq_charcode:nNTF {#1}[ %]
738 {
739 \@@_language_set_aux:wn #1
740 }
741 {
742 \AddToDocumentProperties[document]{language}{#1}
743 \keys_set:ne{document/metadata}{lang={#1}}
744 }
745 }
746
747 \cs_new_protected:Npn \@@_language_set_aux:wn [#1] #2
748 {
749 \AddToDocumentProperties[document]{language}{#2}
750 \keys_set:ne{document/metadata}{lang={#1}}
751 }
752 % \end{macrocode}
753 % \end{macro}
754 % The key definition:
755 % \changes{1.1b}{2026-05-02}{Add keys \texttt{language} and \texttt{other-languages}.}
756 % \begin{macrocode}
757 \keys_define:nn { document / metadata }
758 {
759 language .code:n =
760 {
761 \@@_language_set:n {#1}
762 },
763 other-languages.code:n = {\AddToDocumentProperties [document]{other-languages}{#1}},
764 }
765 % \end{macrocode}
766 % \begin{macrocode}
767 \keys_define:nn { document / metadata }
768 {
769 backend .choices:nn =
770 { dvipdfmx , dvips , dvisvgm , luatex , pdftex , pdfmode , xdvipdfmx , xetex }
771 {
772 \sys_load_backend:n {#1}
773 },
774 backend .groups:n = { init } ,
775 }
776 \keys_define:nn { document / metadata }
777 {
778 ,check-tagging-status .choice:
779 ,check-tagging-status / off .code:n = {}
780 ,check-tagging-status / listfiles .code:n =
781 {
782 \__tag_status_log:
783 }
784 ,check-tagging-status .default:n = {listfiles}
785 }
786 \keys_define:nn { document / metadata }
787 {
788 ,pdfversion .groups:n = { pdf }
789 ,pdfstandard .groups:n = { pdf }
790 ,lang .code:n =
791 {
792 \pdfmanagement_add:nnn {Catalog} {Lang}{(#1)}
793 \AddToDocumentProperties[document]{lang}{#1}
794 }
795 % \end{macrocode}
796 % As the latest set of modules is loaded by default, many testphase keys only activate tagging.
797 % \changes{v1.0s}{2025/07/07}{Adapted testphase keys to the default loading of the tagging code}
798 % \begin{macrocode}
799 ,testphase .multichoices:nn =
800 {latest,tagpdf,phase-I,phase-II,phase-III}
801 {
802 \keys_set:nn
803 {document / metadata}
804 {tagging=on}
805 }
806 % \end{macrocode}
807 % The following modules are all always loaded, therefore they can be ignored when used in a testphase key:
808 % \changes{v1.1a}{2026-04-23}{Make testphase values for loaded modules noop}
809 % \begin{macrocode}
810 ,testphase .multichoices:nn =
811 {math,new-or,sec,sec-template,toc,graphic,block,minipage,float,
812 bib,context,text,firstaid,table,title,marginpar,tikz}
813 {}
814 ,testphase / unknown .code:n =
815 {
816 \tl_gput_right:Nn\g_@@_testphase_tl
817 {
818 \tl_if_empty:eT{\GetDocumentProperties{document/testphase/#1}}
819 {
820 \AddToDocumentProperties [document]{testphase/#1}{loaded}
821 \file_if_exist_input:nF {#1-latex-lab-testphase.ltx}
822 {
823 \msg_warning:nnn{meta}{latex-lab-pkg-missing}{#1}
824 \AddToDocumentProperties [document]{testphase/#1}{missing}
825 }
826 }
827 }
828 }
829 }
830 % \end{macrocode}
831 % Activating and deactivating tagging after tagpdf has been loaded requires a redefinition
832 % of various commands. We store the needed settings in auxiliaries that we
833 % can redefine if tagging should be used.
834 % \changes{1.0w}{2025-10-13}{Use commands to set tagging, tagging issue \#994}
835 % \begin{macro}{\__tag_document_set_tagging_off:,
836 % \__tag_document_set_tagging_on:,
837 % \__tag_document_set_tagging:}
838 % \begin{macrocode}
839 \cs_new_protected:Npn \__tag_document_set_tagging_off:
840 {
841 % \end{macrocode}
842 % Avoid warning from non-existing hook label. This can be removed after the
843 % next tagpdf update (2025-10-13).
844 % \begin{macrocode}
845 \sys_if_engine_luatex:F
846 { \AddToHook{shipout/firstpage}[tagpdf/space]{} }
847 \tagpdfsetup{activate/mc=false,activate/tree=false,
848 activate/struct=false,activate/socket=false,
849 activate/spaces=false,
850 para/tagging=false,math/setup=}
851 \AddToDocumentProperties [document]{tagging}{inactive}
852 \AddToDocumentProperties [document]{tagging/para}{inactive}
853 \AddToDocumentProperties [document]{tagging/interwordspace}{inactive}
854 % \end{macrocode}
855 % \changes{v1.0r}{2025/07/03}{Start a global suspend}
856 % We must avoid that a command like \cs{LaTeX} which contains a \cs{ResumeTagging} command restarts
857 % tagging, so we start a global suspend. Perhaps the commands should even be set to noop.
858 % \begin{macrocode}
859 \tag_suspend:n {global}
860 % \end{macrocode}
861 % \changes{v1.0t}{2025/09/25}{Disable \cs{tagpdfsetup}}
862 % We disable the setup command, as various keys assume that the tagging structure is there,
863 % see tagging-project issue \#994.
864 % \begin{macrocode}
865 \cs_set_protected:Npn\tagpdfsetup##1{}
866 % \end{macrocode}
867 %
868 % perhaps, need to test:
869 % \begin{macrocode}
870 %\cs_set_eq:NN\tag_suspend:n\use_none:n
871 %\cs_set_eq:NN\tag_resume:n \use_none:n
872 }
873 \cs_new_protected:Npn \__tag_document_set_tagging_on:
874 {
875 \tagpdfsetup{activate,para/tagging,activate/spaces}
876 \AddToDocumentProperties [document]{tagging}{active}
877 \AddToDocumentProperties [document]{tagging/para}{active}
878 \AddToDocumentProperties [document]{tagging/interwordspace}{active}
879 }
880 % \end{macrocode}
881 % By default tagging is off.
882 % \begin{macrocode}
883 \cs_new_eq:NN \__tag_document_set_tagging:\__tag_document_set_tagging_off:
884 \AddToHookNext{class/before}{\__tag_document_set_tagging:}
885 % \end{macrocode}
886 % \end{macro}
887 % \begin{macrocode}
888 \keys_define:nn { document / metadata }
889 {
890 ,tagging .choice:,
891 ,tagging / on .code:n =
892 {
893 \cs_set_eq:NN \__tag_document_set_tagging:\__tag_document_set_tagging_on:
894 }
895 ,tagging / off .code:n =
896 {
897 \cs_set_eq:NN \__tag_document_set_tagging:\__tag_document_set_tagging_off:
898 }
899 ,tagging / draft .code:n =
900 {
901 \keys_set:nn { document / metadata }{ tagging=on }
902 \AddToHook{shipout/lastpage}[tagging-setup]{\tagpdfsetup{activate/tree=false}}
903 \DeclareHookRule{shipout/lastpage}{tagging-setup}{before}{tagpdf}
904 }
905 ,tagging-setup .code:n =
906 {
907 \keys_set:nn { document / metadata }{ tagging=on }
908 \tl_gclear:N\g_@@_testphase_tl
909 \keys_set_groups:nnn{__tag/setup}{load}{#1}
910 \AddToHook{class/before}
911 {\keys_set_exclude_groups:nnn {__tag/setup}{load}{#1}}
912 }
913 ,debug .code:n =
914 {
915 \keys_set:nn { document / metadata / debug } {#1}
916 }
917 ,debug / para .code:n =
918 {
919 \AddToHook
920 {
921 package/tagpdf/after
922 }
923 {
924 \tagpdfsetup{debug/show=para}
925 }
926 }
927 ,debug / log .code:n =
928 {
929 \AddToHook
930 {
931 package/tagpdf/after
932 }
933 {
934 \tagpdfsetup{debug/log=#1}
935 }
936 }
937 ,debug / tagpdf .code:n =
938 {
939 \AddToHook
940 {
941 package/tagpdf/after
942 }
943 {
944 \RequirePackage{tagpdf-debug}
945 }
946 }
947 ,debug / uncompress .code:n =
948 {
949 \pdf_uncompress:
950 }
951 ,debug / pdfmanagement .bool_gset:N = \g_@@_active_bool
952 ,debug / firstaidoff .clist_gset:N = \g_@@_firstaidoff_clist
953 ,debug / BBox .code:n =
954 {
955 \AddToHook{package/latex-lab-testphase-graphic/after}
956 { \bool_set_true:N \l__tag_graphic_debug_bool}
957 }
958 }
959 \keys_define:nn{__tag/setup}
960 {
961 ,modules .code:n =
962 {
963 \keys_set:nn { document / metadata }{testphase={#1}}
964 }
965 ,modules .groups:n = { load }
966 ,extra-modules .code:n =
967 {
968 \keys_set:nn { document / metadata }{testphase={#1}}
969 }
970 ,extra-modules .groups:n = { load }
971 }
972 % \end{macrocode}
973 % \subsection{Messages}
974 % \begin{macrocode}
975 %UFi is meta the right module name here?
976 \prop_gput:Nnn \g_msg_module_type_prop { meta } { LaTeX }
977 \prop_gput:Nnn \g_msg_module_name_prop { meta } { DocumentMetadata }
978
979 \msg_new:nnn { meta } { after-class }
980 {
981 \token_to_str:N \DocumentMetadata \c_space_tl
982 should~be~used~only~before~\token_to_str:N\documentclass
983 }
984 \msg_new:nnn { meta } { latex-lab-pkg-missing }
985 {
986 LaTeX-lab~package~'#1'~not~found.
987 }
988 % \end{macrocode}
989 %
990 % \begin{macrocode}
991 \ExplSyntaxOff\makeatother
992 % \end{macrocode}
993 %
994 %
995 % \begin{macrocode}
996 %</code>
997 % \end{macrocode}
998 %
999 % \end{implementation}
1000 %
1001 % \Finale
1002 %