Debian Codegraph @

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

raw
1 % \iffalse meta-comment
2 %
3 %% File: documentmetadata-support.dtx
4 % Copyright (C) 2021-2025 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.0w}
22 \def\documentmetadatasupportdate{2025-10-13}
23 % \end{macrocode}
24 %
25 %
26 %<*driver>
27 \DocumentMetadata{tagging=on,pdfstandard=ua-2}
28 \documentclass[kernel]{l3doc}
29 \usepackage{latex-lab-testphase-l3doc}
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 \pkg{pdfmanagement-testphase} 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-testphase} code and the latex-lab modules
84 % the first time it is called and then
85 % redefines itself to only manage key/value pairs in case it is
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 declares tag names for the structure.
122 % \item[\texttt{new-or-2}] This changes output routine sockets and adds support
123 % for the paragraph tagging. It also loads the new footnote code.
124 % \item[\texttt{block}] This reimplements lists and blocks environments and
125 % add tagging support.
126 % \item[\texttt{sec}] This adapts commands related to sectioning to make them tagging aware.%
127 % \item[\texttt{toc}] This adapts commands related to the table of contents and
128 % similar list to make them tagging aware.
129 % \item[\texttt{minipage}] This adds tagging support to \texttt{minipage}
130 % and \cs{parbox}.%
131 % \item[\texttt{graphic}] This enables tagging support for
132 % the \cs{includegraphics} command and the \texttt{picture} environment.
133 % \item[\texttt{float}] This adds tagging support to floats.
134 % \item[\texttt{bib}] This adds tagging support to citations and bibliographies.
135 % This code is also loaded by the \texttt{phase-III} key.
136 % \item[\texttt{text}] This module adds tagging support to the \LaTeX{} logo and
137 % to the \cs{emph} command.
138 % \item[\texttt{marginpar}] This module adds tagging support to the \cs{marginpar}
139 % command.
140 % \item[\texttt{title}] This module add tagging support to the \cs{maketitle}
141 % command if a standard class is used. It also enhances the \cs{title}
142 % and \cs{author} commands to fill the XMP-metadata and set the window title.
143 % It is not compatible with packages and classes which redefine these commands
144 % too.
145 % \item[\texttt{table}] This provides tagging for
146 % \texttt{tabular}, \texttt{longtable} and similar table environments.
147 % Its use (and restrictions is documented in \texttt{latex-lab-table.pdf}.
148 % \item[\texttt{math}] This adapts math for tagging.
149 % \item[\texttt{firstaid}] This contains small adjustments to external packages.
150 % \item[\texttt{tikz}] This add support for the \pkg{tikz} package.
151 % \end{description}
152 %
153 %
154 % \section{Keys and values}
155 %
156 % Currently the following keys are implemented for \cs{DocumentMetadata}:
157 % \DescribeMkey{backend}
158 % \DescribeMkey{colorprofiles}
159 % \DescribeMkey{debug}
160 % \DescribeMkey{lang}
161 % \DescribeMkey{pdfstandard}
162 % \DescribeMkey{xmp}
163 % \DescribeMkey{pdfversion}
164 % \DescribeMkey{testphase}
165 % \DescribeMkey{uncompress}
166 % \DescribeMkey{check-tagging-status}
167 %
168 % \begin{description}
169 % \item[\texttt{backend}] Passes the backend name to expl3. This is
170 % needed only if the needed backend can't be automatically
171 % determined or if the workflow used requires a special backend.
172 %
173 %^^A This will probably be extended to pass the value also to
174 %^^A packages.
175 %
176 % \item[\texttt{pdfversion}] Sets the PDF version explicitly, e.g., \texttt{pdfversion=1.7}
177 % \item[\texttt{uncompress}] (no value) Forces an uncompressed pdf
178 % --- mainly for debugging purposes.
179 %
180 % \item[\texttt{lang}] Explicitly sets the Lang entry in the Catalog,
181 % e.g., \texttt{lang=de-DE}. If not given the default value used is |en-US|.
182 %
183 % \item[\texttt{pdfstandard}] Choice key to set the pdf standard.
184 % Currently |A-1b|, |A-2a|, |A-2b|, |A-2u|, |A-3a|, |A-3b|, |A-3u|, |A-4|, |A-4E|
185 % and |A-4F| are accepted as A-standard.
186 % values. The casing is irrelevant, |a-1b| works too.
187 % Note that using this
188 % key doesn't mean that the document actually follows the standard. \LaTeX{}
189 % can neither ensure nor check all requirements of a standard, and not everything
190 % it can do theoretically has already been implemented.
191 % When setting an A-standard a color profile is included and the
192 % \texttt{/OutputIntent} is set and any javascript action in hyperref are suppressed.
193 % The |u| variants do not enforce unicode,
194 % but they will pass the information to hyperref. The |a| variants
195 % do \emph{not} enforce (or even test) a tagged pdf yet.
196 %
197 % Beside the A-standards it is also possible to use the values
198 % |X-4|, |X-4p|, |X-5g|, |X-5n|, |X-5pg|, |X-6|, |X-6n|, |X-6p| for
199 % a PDF/X and |UA-1| and |UA-2| for PDF/UA standard.
200 % |UA-2| should only be used together with PDF 2.0.
201 % Currently these keys set \emph{only} the relevant XMP-metadata.
202 % They do not validate or enforce special requirements
203 % (e.g., the |UA| standards do not automatically activate tagging).
204 %
205 % |pdfstandard| can be used more than once to set overlapping standards, e.g:\\
206 % |pdfstandard=A-2b,pdfstandard=X-4,pdfstandard=UA-1|. It is also possible
207 % to pass a list like |pdfstandard={UA-2,A-4F}|.
208 %
209 % If XMP-metadata are added (see the following key \texttt{xmp})
210 % the necessary conformance markers for the standards are set.
211 %
212 % More information can be found in the documentation
213 % of \pkg{l3pdfmeta}.
214 %
215 % \item[\texttt{xmp}] A boolean, if set to false no XMP metadata are added to the PDF.
216 % The initial value is true. Details are described in the documentation of \pkg{l3pdfmeta}.
217 %
218 % \item[\texttt{colorprofiles}] This allows to load icc-colorprofiles. Details
219 % are described in the documentation of \pkg{l3pdfmeta}.
220 %
221 % \item[\texttt{tagging}] This key allows to activate, deactivate or partially deactivate the tagging support.
222 % It accepts the three values \texttt{on}, \texttt{off} and \texttt{draft}.
223 % When used, the key loads the tagpdf package and all standard modules of the tagging support
224 % that were previously loaded with \texttt{testphase=latest}.
225 % \begin{itemize}
226 % \item |tagging=on| activates tagging.
227 % \item |tagging=off| deactivates in the \texttt{class/before} hook the tagging commands,
228 % including the \cs{tagpdfsetup} command. It also deactivates the use of real space chars.
229 % This can be reactivated by using |tagging-setup={activate/spaces}|.
230 % \item |tagging=draft| leaves the
231 % tagging commands active but it deactivates the writing of the structure tree
232 % at the end of the compilation. This can save
233 % time when drafting a longer document but preserves, e.g., MC-content marker
234 % in the PDF stream and warnings and errors from \pkg{tagpdf} if the structure is faulty.
235 % \end{itemize}
236 %
237 % \item[\texttt{tagging-setup}] This key allows to configure the tagging. It accepts all
238 % keys that can also be used in \cs{tagpdfsetup}; see the \pkg{tagpdf} documentation.
239 % Additionally, it accepts two keys to extend the list of modules loaded:
240 % \begin{description}
241 % \item[\texttt{modules}] This key previously allowed to change the
242 % list of modules. Starting with the release 2025-11-01 all standard modules
243 % are loaded always, so its only use is to load a non-standard module, e.g.
244 % |modules=verbatim-af| will load a experiment module changing the verbatim tagging.
245 %
246 % \item[\texttt{extra-modules}] This key allows to load non-standard modules and
247 % starting with the release 2025-11-01 it is an alias of |modules|.
248 % \end{description}
249 %
250 % \item[\texttt{check-tagging-status}] This key is provided to help to
251 % identify packages that are potentially problematic when used with the tagging code.
252 % When used (with no value or with the value |listfiles|,
253 % it reads the file |latex-tagging-status.ltx|
254 % from the \pkg{latex-tagging-status} package and then writes at the end of the compilation
255 % a report about the compatibility of the class and the packages with the tagging project.
256 % It follows the classification done at \url{https://latex3.github.io/tagging-project/tagging-status}.
257 %
258 % This is only a rough overview and a debugging aid, not a final report!
259 % Using packages that are classified as incompatible or partially incompatible
260 % does not mean that the tagging is necessarily broken. For example, \pkg{hyperref}
261 % is partially incompatible as the form fields are not properly tagged (this requires the use
262 % of the \pkg{l3pdffield} package), but in documents without form fields it is unproblematic.
263 % (In case of partially-compatible or incompatible packages check the table at
264 % \url{https://latex3.github.io/tagging-project/tagging-status} as it often contains
265 % an explanation what is not yet working.)
266 %
267 % The package \pkg{latex-tagging-status} will be regularly updated to reflect changes
268 % in package. Erroneous messages should be reported
269 % at \url{https://github.com/latex3/tagging-project/issues}. It is also possible
270 % to create a pull request which updates the data.
271 %
272 % \item[\texttt{testphase}] This key loaded in older \LaTeX{} versions
273 % specific sets of modules from the testphase code.
274 % Starting with the release 2025-11-01 all modules are
275 % loaded automatically by \cs{DocumentMetadata} and with this change the key
276 % lost most of its purpose and is now deprecated.
277 % The values \texttt{phase-I}, \texttt{phase-II}, \texttt{phase=III} of the
278 % \texttt{testphase} key will no longer load different code variants but only
279 % activate tagging. The key can still be used to load additional experimental modules,
280 % it then works similar to the \texttt{modules} and \texttt{extra-modules} key and does
281 % not automatically activate tagging.
282 %
283 % \item[\texttt{debug}] This key activates some debug options. It takes a list of key-values
284 % as value. Currently the following keys are known:
285 % \begin{description}
286 % \item[\texttt{para}] with the default and only value |show|. It will activate the |debug/show=para|
287 % option of \pkg{tagpdf};
288 % \item[\texttt{log}] with the values as described in the documentation of \pkg{tagpdf};
289 % \item[\texttt{uncompress}] which does the same as |uncompress| as main key;
290 % \item[\texttt{pdfmanagement}] a boolean which allows to deactivate the pdfmanagement;
291 % \item[\texttt{firstaidoff}] this accepts a comma lists of keywords and disables the patches
292 % related to them. More information can be found in the documentation of
293 % \pkg{pdfmanagement-firstaid};
294 % \item[\texttt{xmp-export}] this will export the XMP-metadata to a file \verb+\jobname.xmpi+.
295 % With \texttt{debug=\{xmp-export=filename\}} the file name can be changed;
296 % More information can be found in the documentation of \pkg{l3pdfmeta} of the \pkg{pdfmanagement-testphase}
297 % bundle;
298 % \item[\texttt{tagpdf}] This loads the package tagpdf-debug which enhances
299 % various commands from tagpdf with additional debugging options. This can slow down
300 % the compilation!
301 % \item[\texttt{BBox}] This helps to debug BBox values of graphics, see the documentation
302 % of latex-lab-graphic.
303 % \end{description}
304 % \end{description}
305 %
306 % \bibliographystyle{plain}
307 %
308 % \begin{thebibliography}{9}
309 %
310 % \bibitem{blueprint} Frank Mittelbach and Chris Rowley:
311 % \emph{\LaTeX{} Tagged PDF\,---\,A blueprint for a large project}.
312 % \url{https://latex-project.org/publications/indexbyyear/2020/}
313 %
314 % \end{thebibliography}
315 %
316 %
317 %
318 % \MaybeStop{\setlength\IndexMin{200pt} \PrintIndex }
319 %
320 % \begin{implementation}
321 %
322 % \section{The Implementation}
323 %
324 %
325 % \begin{macrocode}
326 %<@@=pdfmanagement>
327 %<*code>
328 % \end{macrocode}
329 %
330 % \begin{macrocode}
331
332 \RequirePackage{pdfmanagement-testphase}
333 % \end{macrocode}
334 %
335 % \begin{macrocode}
336 \ExplSyntaxOn\makeatletter
337 % \end{macrocode}
338
339 % \subsection{Variables}
340 % These variable definitions are currently also done in ltdocinit.
341 % They can be removed from there once latex-lab has been updated to
342 % provide them too.
343 % \begin{variable}{\g_@@_firstaidoff_clist}
344 % A list to store the firstaid code which should be disabled
345 % \begin{macrocode}
346 \clist_if_exist:NF \g_@@_firstaidoff_clist
347 { \clist_new:N \g_@@_firstaidoff_clist }
348 % \end{macrocode}
349 % \end{variable}
350 % \begin{variable}{\g_@@_testphase_tl}
351 % a tl to store the testphase loading code so that we can load them at
352 % the end of the command.
353 % \begin{macrocode}
354 \tl_if_exist:NF \g_@@_testphase_tl
355 { \tl_new:N \g_@@_testphase_tl }
356 % \end{macrocode}
357 % \end{variable}
358 %
359 % \subsection{Kernel changes with \cs{DocumentMetadata}}
360 % \begin{macro}{\@kernel@before@DocumentMetadata}
361 % \begin{macrocode}
362 \cs_new_protected:Npn \@kernel@before@DocumentMetadata
363 {
364 \ifx\Umathcode\@undefined
365 \fontencoding{T1}
366 \renewcommand\encodingdefault{T1}
367 \fi
368 }
369 % \end{macrocode}
370 % \end{macro}
371
372 % \subsection{\cs{DocumentMetadata}}
373 %
374 % \begin{macro}{\DocumentMetadata}
375 %
376 % \cs{DocumentMetadata} should not be used after
377 % \cs{documentclass} so we error in this case.
378 % It can be used more than once
379 % but follow-up calls should not do the initialization code.
380 % \begin{macrocode}
381 \cs_set_protected:Npn \DocumentMetadata #1
382 {
383 \cs_if_eq:NNTF \documentclass \@twoclasseserror
384 { \msg_error:nn { meta } { after-class } }
385 {
386 % \end{macrocode}
387 % Load general format changes
388 % \begin{macrocode}
389 \@kernel@before@DocumentMetadata
390 % \end{macrocode}
391 %
392 % The wanted backend must be detected first, we read the init
393 % key and then force the loading of the backend.
394 % The backend can contain management commands, so the boolean should
395 % be set to true first.
396 % \begin{macrocode}
397 \bool_gset_true:N \g_@@_active_bool
398 \keys_set_groups:nnn { document / metadata} {init}{ #1 }
399 %if no backend has been loaded force it now:
400 \str_if_exist:NF \c_sys_backend_str
401 {
402 \sys_load_backend:n {}
403 }
404 % \end{macrocode}
405 % Now we load the extra backend code:
406 % \begin{macrocode}
407 \ExplSyntaxOn\makeatletter
408 \file_input:n {l3backend-testphase-\c_sys_backend_str.def}
409 \ExplSyntaxOff\makeatother
410 % \end{macrocode}
411 % \changes{v1.0m}{2025/02/17}{Set PDF 2.0 as default}
412 % \begin{macrocode}
413 \pdf_version_gset:n { 2.0 }
414 % \end{macrocode}
415 % tagpdf currently requires that the pdf version is set first.
416 % \begin{macrocode}
417 \keys_set_groups:nnn { document / metadata} {pdf}{ #1 }
418 % \end{macrocode}
419 % Load the latex-lab modules:
420 % \changes{v1.0s}{2025/07/07}{Load latest set always.}
421 % \begin{macrocode}
422 \RequirePackage{latex-lab-testphase-latest}
423 \AddToDocumentProperties [document]{tagging}{inactive}
424 \AddToDocumentProperties [document]{tagging/para}{inactive}
425 % \end{macrocode}
426 % Process the non-init keys.
427 % \changes{v1.0s}{2025/07/07}{hyperref loads the generic driver itself}
428 % \changes{v1.0s}{2025/07/07}{pdf management is always active, so test removed}
429 % \begin{macrocode}
430 \keys_set_exclude_groups:nnn { document / metadata } { init } { #1 }
431 % \end{macrocode}
432 % Finally we setup the language default.
433 % This is done after the begindocument hook so that it can pick up settings
434 % from babel. If the Catalog dictionary already contains a lang value we do nothing,
435 % otherwise we use the value stored in \cs{BCPdata}, either the main language
436 % (if its exists) or the fall back language.
437 % Note: if babel is loaded without a language this gives the language \texttt{und}.
438 % \begin{macrocode}
439 \g@addto@macro\@kernel@after@begindocument
440 {
441 \pdfdict_get:nnN {g__pdf_Core/Catalog}{Lang}\l_@@_tmpa_tl
442 \quark_if_no_value:NT\l_@@_tmpa_tl
443 {
444 \tl_if_empty:eTF { \BCPdata{main.language} }
445 { \tl_set:Ne \l_@@_tmpb_tl { \BCPdata{language} } }
446 { \tl_set:Ne \l_@@_tmpb_tl { \BCPdata{main.language} } }
447 \msg_warning:nne { meta } { lang-missing }{ \l_@@_tmpb_tl }
448 \exp_last_unbraced:Ne
449 \AddToDocumentProperties{[document]{lang}{\l_@@_tmpb_tl}}
450 \pdfmanagement_add:nne {Catalog} {Lang}{(\l_@@_tmpb_tl)}
451 }
452 }
453 % \end{macrocode}
454 % \cs{pdfmanagement_add:nnn} has collected values in this hook.
455 % \begin{macrocode}
456 \hook_use_once:n {pdfmanagement/add}
457 % \end{macrocode}
458 % Now we redefine \cs{DocumentMetadata} so that it only process the
459 % keys on any further calls.
460 %
461 % \begin{macrocode}
462 \cs_set_protected:Npn \DocumentMetadata ##1
463 {
464 \keys_set_exclude_groups:nnn { document / metadata } { init } { ##1 }
465 }
466 % \end{macrocode}
467 % Load more modules, the testphase code and the firstaid code. The code is only
468 % loaded in the first \cs{DocumentMetadata} call!
469 % \begin{macrocode}
470 \g_@@_testphase_tl
471 \RequirePackage{pdfmanagement-firstaid}
472 }
473 }
474 % \end{macrocode}
475 % \end{macro}
476
477 % \subsection{Tagging status report}
478 % Hide our own files
479 % \begin{macrocode}
480 \clist_map_inline:nn
481 {
482 pdfmanagement-testphase.sty,
483 color-ltx.sty,
484 xcolor-patches-tmp-ltx.sty,
485 tagpdf-base.sty,
486 latex-lab-testphase-latest.sty,
487 tagpdf.sty,
488 tagpdf-mc-code-generic.sty,
489 tagpdf-mc-code-lua.sty,
490 latex-lab-testphase-names.sty,
491 latex-lab-testphase-new-or-2.sty,
492 latex-lab-testphase-block.sty,
493 latex-lab-kernel-changes.sty,
494 latex-lab-testphase-context.sty,
495 latex-lab-testphase-sec.sty,
496 latex-lab-testphase-toc.sty,
497 latex-lab-testphase-minipage.sty,
498 latex-lab-testphase-new-or-1.sty,
499 latex-lab-testphase-graphic.sty,
500 latex-lab-testphase-float.sty,
501 latex-lab-testphase-bib.sty,
502 latex-lab-testphase-text.sty,
503 latex-lab-testphase-marginpar.sty,
504 latex-lab-testphase-title.sty,
505 latex-lab-testphase-table.sty,
506 latex-lab-testphase-math.sty,
507 latex-lab-testphase-firstaid.sty,
508 latex-lab-testphase-tikz.sty,
509 pdfmanagement-firstaid.sty,
510 }
511 {\expandafter\chardef\csname t@status@#1\endcsname8\relax }
512 % \end{macrocode}
513 % \begin{macrocode}
514 \tl_new:c {l__tag_status_0_tl}
515 \tl_new:c {l__tag_status_1_tl}
516 \tl_new:c {l__tag_status_2_tl}
517 \tl_new:c {l__tag_status_3_tl}
518 \tl_new:c {l__tag_status_4_tl}
519 \tl_new:c {l__tag_status_-1_tl}
520 \cs_new_protected:Npn\__tag_status_sort:
521 {
522 \clist_map_inline:Nn\g__tag_status_filelist_tl
523 {
524 \filename@parse{##1}
525 \cs_if_exist:cTF { t@status@##1 }
526 {
527 \str_if_eq:onF{\filename@ext}{cls}
528 {
529 \tl_put_right:cn
530 {l__tag_status_\int_use:c { t@status@##1 }_tl}
531 {~~##1\iow_newline:}
532 }
533 }
534 {
535 \str_if_eq:onT{\filename@ext}{sty}
536 {
537 \tl_put_right:cn
538 {l__tag_status_-1_tl}
539 {~~##1\iow_newline:}
540 }
541 }
542 }
543 }
544 \cs_new_protected:Npn \__tag_status_type:nn #1 #2
545 % #1 number, -1 for not listed, #2 title
546 {
547 \iow_term:n{~~#2}
548 \iow_term:n{~~--------------------------}
549 \tl_if_empty:cTF{l__tag_status_#1_tl}
550 {
551 \iow_term:e{~~NONE\iow_newline:}
552 }
553 {
554 \iow_term:e{\tl_use:c{l__tag_status_#1_tl}}
555 }
556 }
557 \cs_new_protected:Npn \__tag_status_log:
558 {
559 \file_if_exist_input:n {latex-tagging-status.ltx}
560 \AddToHookNext{class/before}
561 {
562 \tl_const:Ne \c__tag_current_class_tl{\@currname.\@currext}
563 \tl_const:Ne \c__tag_status_class_tl
564 {
565 \cs_if_exist:cTF { t@status@\@currname.\@currext }
566 {
567 \int_case:nn { \int_use:c { t@status@\@currname.\@currext } }
568 {
569 {0}{unknown}
570 {1}{unsupported}
571 {2}{currently~incompatible}
572 {3}{partially~compatible}
573 {4}{compatible}
574 }
575 }
576 { not~in~the~status~list}
577 }
578 }
579 \AddToHook{begindocument}{\tl_gset_eq:NN \g__tag_status_filelist_tl\@filelist}
580 \AddToHook{enddocument/info}
581 {
582 \iow_term:n{}
583 \iow_term:n
584 {======================================}
585 \iow_term:n{~~Status~report~of~the~tagging~support}
586 \iow_term:n{======================================}
587 \iow_term:n{~~Details~at~https://latex3.github.io/tagging-project/tagging-status}
588 \iow_term:n{~~Report~erroneous~entries~at~https://github.com/latex3/tagging-project}
589 \iow_term:n{}
590 \iow_term:n{~~A.~CLASS}
591 \iow_term:n{~~********}
592 \iow_term:n{}
593 \iow_term:e{~~\c__tag_current_class_tl\c_space_tl is~\c__tag_status_class_tl}
594 \iow_term:n{}
595 \iow_term:n{~~B.~PACKAGES,~LIBRARIES,~etc}
596 \iow_term:n{~~***********}
597 \iow_term:n{}
598 \__tag_status_sort:
599 \__tag_status_type:nn{1}{1.~Unsupported}
600 \__tag_status_type:nn{2}{2.~Currently~incompatible}
601 \__tag_status_type:nn{3}{3.~Partially~compatible}
602 \__tag_status_type:nn{4}{4.~Compatible}
603 \__tag_status_type:nn{0}{5.~Unknown}
604 \__tag_status_type:nn{-1}{~6. Unclassified~files~with~extension~.sty}
605 \iow_term:n{====================================}
606 \iow_term:n{~~End~of~status~report}
607 \iow_term:n{====================================}
608 }
609 }
610 % \end{macrocode}
611 %\subsection{\cs{DocumentMetadata} keys}
612 %\changes{1.0k}{2024-12-17}{added latest value for testphase key.}
613 %\changes{1.0n}{2025/03/25}{Allow a list as pdfstandard value.}
614 %\changes{1.0n}{2025/03/25}{Add tagging key}
615 %\changes{1.0n}{2025/03/25}{Add tagging-setup}
616 %\changes{1.0o}{2025/04/03}{Add debug=BBox}
617 %\changes{1.0p}{2025/04/28}{Add tikz module to latest key}
618 %\changes{1.0u}{2025/10/09}{Added check-tagging-status}
619 %\changes{1.0v}{2025/10/12}{Extend check-tagging-status to libraries}
620 % \begin{macrocode}
621 \keys_define:nn { document / metadata }
622 {
623 backend .choices:nn =
624 { dvipdfmx , dvips , dvisvgm , luatex , pdftex , pdfmode , xdvipdfmx , xetex }
625 {
626 \sys_load_backend:n {#1}
627 },
628 backend .groups:n = { init } ,
629 }
630 \keys_define:nn { document / metadata }
631 {
632 ,check-tagging-status .choice:
633 ,check-tagging-status / off .code:n = {}
634 ,check-tagging-status / listfiles .code:n =
635 {
636 \__tag_status_log:
637 }
638 ,check-tagging-status .default:n = {listfiles}
639 }
640 \keys_define:nn { document / metadata }
641 {
642 ,pdfversion .code:n =
643 {
644 \pdf_version_gset:n { #1 }
645 \AddToDocumentProperties[document]{pdfversion}{#1}
646 }
647 ,pdfversion .groups:n = { pdf }
648 ,uncompress .code:n =
649 {
650 \pdf_uncompress:
651 }
652 ,uncompress .value_forbidden:n = true
653 ,lang .code:n =
654 {
655 \pdfmanagement_add:nnn {Catalog} {Lang}{(#1)}
656 \AddToDocumentProperties[document]{lang}{#1}
657 }
658 %,xmpmeta .bool_gset:N = \g_pdfmeta_xmp_bool %see pdfmeta unused and undefined for now!
659 % this uses internal command from pdfmeta, it should probably move there ...
660 ,pdfstandard .code:n =
661 {
662 \clist_map_inline:nn{#1}
663 {
664 \keys_set:ne {document / metadata} {_pdfstandard=\str_uppercase:n{##1}}
665 }
666 }
667 ,_pdfstandard .choices:nn =
668 {A-1B,A-2A,A-2B,A-2U,A-3A,A-3B,A-3U,A-4}
669 {
670 \prop_gset_eq:Nc \g__pdfmeta_standard_prop { g__pdfmeta_standard_pdf/#1 _prop }
671 \AddToDocumentProperties [document]{pdfstandard}{#1}
672 }
673 ,_pdfstandard / A-4F .code:n =
674 {
675 \prop_gset_eq:Nc \g__pdfmeta_standard_prop { g__pdfmeta_standard_pdf/A-4F_prop }
676 \AddToDocumentProperties [document]{pdfstandard}{A-4F}
677 }
678 ,_pdfstandard / A-4E .code:n =
679 {
680 \prop_gset_eq:Nc \g__pdfmeta_standard_prop { g__pdfmeta_standard_pdf/A-4E_prop }
681 \AddToDocumentProperties [document]{pdfstandard}{A-4E}
682 }
683 ,_pdfstandard / unknown .code:n =
684 {
685 \msg_error:nnn{pdf}{unknown-standard}{#1}
686 }
687 % \end{macrocode}
688 % As the latest set of modules is loaded by default, many testphase keys only activate tagging.
689 % \changes{v1.0s}{2025/07/07}{Adapted testphase keys to the default loading of the tagging code}
690 % \begin{macrocode}
691 ,testphase .multichoices:nn =
692 {latest,tagpdf,phase-I,phase-II,phase-III}
693 {
694 \keys_set:nn
695 {document / metadata}
696 {tagging=on}
697 }
698 ,testphase / unknown .code:n =
699 {
700 \tl_gput_right:Nn\g_@@_testphase_tl
701 {
702 \tl_if_empty:eT{\GetDocumentProperties{document/testphase/#1}}
703 {
704 \AddToDocumentProperties [document]{testphase/#1}{loaded}
705 \file_if_exist_input:nF {#1-latex-lab-testphase.ltx}
706 {
707 \msg_warning:nnn{meta}{latex-lab-pkg-missing}{#1}
708 \AddToDocumentProperties [document]{testphase/#1}{missing}
709 }
710 }
711 }
712 }
713 }
714 % \end{macrocode}
715 % Activating and deactivating tagging after tagpdf has been loaded requires a redefinition
716 % of various commands. We store the needed settings in auxiliaries that we
717 % can redefine if tagging should be used.
718 % \changes{1.0w}{2025-10-13}{Use commands to set tagging, tagging issue \#994}
719 % \begin{macro}{\__tag_document_set_tagging_off:,
720 % \__tag_document_set_tagging_on:,
721 % \__tag_document_set_tagging:}
722 % \begin{macrocode}
723 \cs_new_protected:Npn \__tag_document_set_tagging_off:
724 {
725 % \end{macrocode}
726 % Avoid warning from non-existing hook label. This can be removed after the
727 % next tagpdf update (2025-10-13).
728 % \begin{macrocode}
729 \sys_if_engine_luatex:F
730 { \AddToHook{shipout/firstpage}[tagpdf/space]{} }
731 \tagpdfsetup{activate/mc=false,activate/tree=false,
732 activate/struct=false,activate/socket=false,
733 activate/spaces=false,
734 para/tagging=false,math/setup=}
735 \AddToDocumentProperties [document]{tagging}{inactive}
736 \AddToDocumentProperties [document]{tagging/para}{inactive}
737 \AddToDocumentProperties [document]{tagging/interwordspace}{inactive}
738 % \end{macrocode}
739 % \changes{v1.0r}{2025/07/03}{Start a global suspend}
740 % We must avoid that a command like \cs{LaTeX} which contains a \cs{ResumeTagging} command restarts
741 % tagging, so we start a global suspend. Perhaps the commands should even be set to noop.
742 % \begin{macrocode}
743 \tag_suspend:n {global}
744 % \end{macrocode}
745 % \changes{v1.0t}{2025/09/25}{Disable \cs{tagpdfsetup}}
746 % We disable the setup command, as various keys assume that the tagging structure is there,
747 % see tagging-project issue \#994.
748 % \begin{macrocode}
749 \cs_set_protected:Npn\tagpdfsetup##1{}
750 % \end{macrocode}
751 %
752 % perhaps, need to test:
753 % \begin{macrocode}
754 %\cs_set_eq:NN\tag_suspend:n\use_none:n
755 %\cs_set_eq:NN\tag_resume:n \use_none:n
756 }
757 \cs_new_protected:Npn \__tag_document_set_tagging_on:
758 {
759 \tagpdfsetup{activate,para/tagging,activate/spaces}
760 \AddToDocumentProperties [document]{tagging}{active}
761 \AddToDocumentProperties [document]{tagging/para}{active}
762 \AddToDocumentProperties [document]{tagging/interwordspace}{active}
763 }
764 % \end{macrocode}
765 % By default tagging is off.
766 % \begin{macrocode}
767 \cs_new_eq:NN \__tag_document_set_tagging:\__tag_document_set_tagging_off:
768 \AddToHookNext{class/before}{\__tag_document_set_tagging:}
769 % \end{macrocode}
770 % \end{macro}
771 % \begin{macrocode}
772 \keys_define:nn { document / metadata }
773 {
774 ,tagging .choice:,
775 ,tagging / on .code:n =
776 {
777 \cs_set_eq:NN \__tag_document_set_tagging:\__tag_document_set_tagging_on:
778 }
779 ,tagging / off .code:n =
780 {
781 \cs_set_eq:NN \__tag_document_set_tagging:\__tag_document_set_tagging_off:
782 }
783 ,tagging / draft .code:n =
784 {
785 \keys_set:nn { document / metadata }{ tagging=on }
786 \AddToHook{shipout/lastpage}[tagging-setup]{\tagpdfsetup{activate/tree=false}}
787 \DeclareHookRule{shipout/lastpage}{tagging-setup}{before}{tagpdf}
788 }
789 ,tagging-setup .code:n =
790 {
791 \keys_set:nn { document / metadata }{ tagging=on }
792 \tl_gclear:N\g_@@_testphase_tl
793 \keys_set_groups:nnn{__tag/setup}{load}{#1}
794 \AddToHook{class/before}
795 {\keys_set_exclude_groups:nnn {__tag/setup}{load}{#1}}
796 }
797 ,debug .code:n =
798 {
799 \keys_set:nn { document / metadata / debug } {#1}
800 }
801 ,debug / para .code:n =
802 {
803 \AddToHook
804 {
805 package/tagpdf/after
806 }
807 {
808 \tagpdfsetup{debug/show=para}
809 }
810 }
811 ,debug / log .code:n =
812 {
813 \AddToHook
814 {
815 package/tagpdf/after
816 }
817 {
818 \tagpdfsetup{debug/log=#1}
819 }
820 }
821 ,debug / tagpdf .code:n =
822 {
823 \AddToHook
824 {
825 package/tagpdf/after
826 }
827 {
828 \RequirePackage{tagpdf-debug}
829 }
830 }
831 ,debug / uncompress .code:n =
832 {
833 \pdf_uncompress:
834 }
835 ,debug / pdfmanagement .bool_gset:N = \g_@@_active_bool
836 ,debug / firstaidoff .clist_gset:N = \g_@@_firstaidoff_clist
837 ,debug / BBox .code:n =
838 {
839 \AddToHook{package/latex-lab-testphase-graphic/after}
840 { \bool_set_true:N \l__tag_graphic_debug_bool}
841 }
842 }
843 \keys_define:nn{__tag/setup}
844 {
845 ,modules .code:n =
846 {
847 \keys_set:nn { document / metadata }{testphase={#1}}
848 }
849 ,modules .groups:n = { load }
850 ,extra-modules .code:n =
851 {
852 \keys_set:nn { document / metadata }{testphase={#1}}
853 }
854 ,extra-modules .groups:n = { load }
855 }
856 % \end{macrocode}
857 % \subsection{Messages}
858 % \begin{macrocode}
859 %UFi is meta the right module name here?
860 \prop_gput:Nnn \g_msg_module_type_prop { meta } { LaTeX }
861 \prop_gput:Nnn \g_msg_module_name_prop { meta } { DocumentMetadata }
862
863 \msg_new:nnn { meta } { after-class }
864 {
865 \token_to_str:N \DocumentMetadata \c_space_tl
866 should~be~used~only~before~\token_to_str:N\documentclass
867 }
868 \msg_new:nnn { meta } { latex-lab-pkg-missing }
869 {
870 LaTeX-lab~package~'#1'~not~found.
871 }
872 \msg_new:nnn { meta } { lang-missing }
873 {
874 The~language~has~not~been~set~in~\token_to_str:N
875 \DocumentMetadata.\\Setting~it~to~'#1'~as~fallback.
876 }
877 % \end{macrocode}
878 %
879 % \begin{macrocode}
880 \ExplSyntaxOff\makeatother
881 % \end{macrocode}
882 %
883 %
884 % \begin{macrocode}
885 %</code>
886 % \end{macrocode}
887 %
888 % \end{implementation}
889 %
890 % \Finale
891 %