| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
%% File: ltmeta.dtx |
| 4 |
%% Copyright (C) 2021-2026 |
| 5 |
%% Frank Mittelbach, 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 |
% https://www.latex-project.org/lppl.txt |
| 13 |
% |
| 14 |
% |
| 15 |
%%% From File: ltmeta.dtx |
| 16 |
%<*driver> |
| 17 |
% \fi |
| 18 |
\ProvidesFile{ltmeta.dtx} |
| 19 |
[2026-05-06 v1.0f LaTeX Kernel (Document Metadata)] |
| 20 |
% \iffalse |
| 21 |
% |
| 22 |
\documentclass{l3in2edoc} |
| 23 |
\GetFileInfo{ltmeta.dtx} |
| 24 |
|
| 25 |
\EnableCrossrefs |
| 26 |
\CodelineIndex |
| 27 |
\begin{document} |
| 28 |
\DocInput{ltmeta.dtx} |
| 29 |
\end{document} |
| 30 |
%</driver> |
| 31 |
% |
| 32 |
% \fi |
| 33 |
% |
| 34 |
% \providecommand\hook[1]{\texttt{#1}} |
| 35 |
% \providecommand\env[1]{\texttt{#1}} |
| 36 |
% |
| 37 |
% |
| 38 |
% |
| 39 |
% \title{The \texttt{ltmeta.dtx} code\thanks{This file has version |
| 40 |
% \fileversion\ dated \filedate, \copyright\ \LaTeX\ |
| 41 |
% Project.}} |
| 42 |
% \author{Frank Mittelbach} |
| 43 |
% |
| 44 |
% \maketitle |
| 45 |
% |
| 46 |
% |
| 47 |
% \begin{abstract} |
| 48 |
% This code defines the \cs{DocumentMetadata} interface. |
| 49 |
% \end{abstract} |
| 50 |
% |
| 51 |
% \tableofcontents |
| 52 |
% |
| 53 |
% |
| 54 |
% \section{Introduction} |
| 55 |
% |
| 56 |
% |
| 57 |
% In the past there was no dedicated location to declare settings |
| 58 |
% concerning a document as a whole. Settings are placed somewhere |
| 59 |
% in the preamble or with the class options or even with some |
| 60 |
% package options. For some settings this can be too late, for |
| 61 |
% example the pdf version can no longer be changed if a package has |
| 62 |
% used code which already opened the PDF. |
| 63 |
% |
| 64 |
% \cs{DocumentMetadata} as a new command unifies such settings in |
| 65 |
% one place. It must be used before \cs{documentclass} but can be |
| 66 |
% issued more than once there. |
| 67 |
% |
| 68 |
% At the moment most of the code run by \cs{DocumentMetadata} is |
| 69 |
% external to the format and subject to change. This includes the |
| 70 |
% supported key/values. |
| 71 |
% |
| 72 |
% For that reason all that happens right now in the format is to |
| 73 |
% look for suitable support files and if found, to redirect the |
| 74 |
% processing to them. |
| 75 |
% |
| 76 |
% \subsection{\cs{DocumentMetadata}} |
| 77 |
% |
| 78 |
% \begin{function}{\DocumentMetadata} |
| 79 |
% \begin{syntax} |
| 80 |
% \cs{DocumentMetadata}\Arg{key-value list} |
| 81 |
% \end{syntax} |
| 82 |
% \end{function} |
| 83 |
% |
| 84 |
% |
| 85 |
% |
| 86 |
% The keys defined for \cs{DocumentMetadata} |
| 87 |
% currently allow to set the PDF version, to set the PDF \texttt{/Lang}, |
| 88 |
% to uncompress a PDF, to set the language and to declare a few PDF standards |
| 89 |
% and some color profiles. |
| 90 |
% |
| 91 |
% \cs{DocumentMetadata} is also used to |
| 92 |
% activate the new PDF management code and it loads |
| 93 |
% a number of required files for the PDF management code. |
| 94 |
% As this forces the loading of the backend files, a backend |
| 95 |
% which can't be detected automatically like |dvipdfmx|, |
| 96 |
% must be set in the first \cs{DocumentMetadata} call (if there is more than one). |
| 97 |
% |
| 98 |
% The full set of keys currently supported is documented in \texttt{documentmetadata-support.pdf} |
| 99 |
% for now. |
| 100 |
% |
| 101 |
% |
| 102 |
% \StopEventually{\setlength\IndexMin{200pt} \PrintIndex } |
| 103 |
% |
| 104 |
% |
| 105 |
% \section{The Implementation} |
| 106 |
% |
| 107 |
% |
| 108 |
% |
| 109 |
% \begin{macrocode} |
| 110 |
%<*2ekernel|latexrelease> |
| 111 |
% \end{macrocode} |
| 112 |
% Not needed yet but \ldots |
| 113 |
% \begin{macrocode} |
| 114 |
%\ExplSyntaxOn |
| 115 |
% \end{macrocode} |
| 116 |
% |
| 117 |
% \begin{macrocode} |
| 118 |
%<latexrelease>\NewModuleRelease{2022/06/01}{ltmeta} |
| 119 |
%<latexrelease> {Document Metadata handling} |
| 120 |
% \end{macrocode} |
| 121 |
% We start by making the conditionals testing for the use of |
| 122 |
% \cs{DocumentMetadata} execute the the false branch. Then, inside |
| 123 |
% \cs{DocumentMetadata}, we change them to select the true branch. |
| 124 |
% \changes{v1.0d}{2025/03/01}{Provide T F variants of |
| 125 |
% \cs{IfDocumentMetadataTF} (gh/1522)} |
| 126 |
% \begin{macrocode} |
| 127 |
\let \IfDocumentMetadataTF \@secondoftwo |
| 128 |
\let \IfDocumentMetadataT \@gobble |
| 129 |
\let \IfDocumentMetadataF \@firstofone |
| 130 |
\protected\def\DocumentMetadata{% |
| 131 |
\InputIfFileExists{documentmetadata-support.ltx}% |
| 132 |
{% |
| 133 |
% \end{macrocode} |
| 134 |
% Support for \cs{DocumentMetadata} is available, so change the conditionals. |
| 135 |
% \begin{macrocode} |
| 136 |
\let \IfDocumentMetadataTF \@firstoftwo |
| 137 |
\let \IfDocumentMetadataT \@firstofone |
| 138 |
\let \IfDocumentMetadataF \@gobble |
| 139 |
}% |
| 140 |
% \end{macrocode} |
| 141 |
% The above file is changing \cs{DocumentMetadata} to a suitable |
| 142 |
% definition (or so we hope) so that it can be safely used several times |
| 143 |
% in the premable. |
| 144 |
% |
| 145 |
% If the file can't be found we say so and carry on without it. |
| 146 |
% \begin{macrocode} |
| 147 |
{% |
| 148 |
\@latex@error{No support files for |
| 149 |
\noexpand\DocumentMetadata found} |
| 150 |
{Is the 'LaTeX-lab' bundle installed?% |
| 151 |
\MessageBreak |
| 152 |
Without it, the declaration is ignored.}% |
| 153 |
% \end{macrocode} |
| 154 |
% No point in trying this more than once if there are several calls |
| 155 |
% in the document. |
| 156 |
% \begin{macrocode} |
| 157 |
\let\DocumentMetadata\@gobble |
| 158 |
}% |
| 159 |
\DocumentMetadata |
| 160 |
} |
| 161 |
% \end{macrocode} |
| 162 |
% |
| 163 |
% To allow package and class author to support for document links |
| 164 |
% we provide also the new interface commands of the hyperref package |
| 165 |
% for the creation of targets. |
| 166 |
% The commands are not only useful for document links: |
| 167 |
% When tagging is active the commands can also be used to reference structures. |
| 168 |
% This is done in the \texttt{recordtarget} socket, which records the target name. |
| 169 |
% Both for links and structure references it can be useful to change the name of the |
| 170 |
% next target. We therefore insert a hook \texttt{target/setname/after} after the name |
| 171 |
% has be set. This hook is used in the \cs{NextLinkTarget} command to adapt the target name |
| 172 |
% \cs{@currentHref}. |
| 173 |
% \changes{v1.0b}{2022/05/17}{Default definition for targets added} |
| 174 |
% \changes{v1.0c}{2024/09/21}{Added tagging support} |
| 175 |
% \changes{v1.0e}{2026/04/22}{Add hook to change target name and use it in \cs{NextLinkTarget}} |
| 176 |
% \changes{v1.0f}{2026/05/06}{Add \cs{SaveLastSkip} and \cs{RestoreLastSkip} to better mimic |
| 177 |
% hyperref's spacing behavior, gh/2070} |
| 178 |
% \changes{v1.0f}{2026/05/06}{Use \cs{latelua} to mimic a whatsit to avoid spurious warning, gh/2070} |
| 179 |
% \begin{macro}{\MakeLinkTarget} |
| 180 |
% \begin{macro}{\LinkTargetOn} |
| 181 |
% \begin{macro}{\LinkTargetOff} |
| 182 |
% \begin{macro}{\NextLinkTarget} |
| 183 |
% \begin{macrocode} |
| 184 |
%<latexrelease>\IncludeInRelease{2026/06/01}% |
| 185 |
%<latexrelease> {\MakeLinkTarget}{Record target name for tagging support}% |
| 186 |
\ExplSyntaxOn |
| 187 |
% \end{macrocode} |
| 188 |
% luatex complains about non-PDF specials if \cs{special} is used, so we use \cs{latelua} instead |
| 189 |
% to create an empty whatsit node. |
| 190 |
% \begin{macrocode} |
| 191 |
\ifx\directlua\@undefined |
| 192 |
\def\@kernel@whatsit{\special{}} |
| 193 |
\else |
| 194 |
\def\@kernel@whatsit{\latelua{}} |
| 195 |
\fi |
| 196 |
% \end{macrocode} |
| 197 |
% This definition is copied from \pkg{hyperref}, only the command names are changed. It is the code |
| 198 |
% \pkg{hyperref} uses around anchors/destination to avoid that they affect the spacing. |
| 199 |
% \begin{macrocode} |
| 200 |
\let\RestoreLastSkip\relax |
| 201 |
\def\SaveLastSkip{% |
| 202 |
\let\RestoreLastSkip\relax |
| 203 |
\ifvmode |
| 204 |
\ifdim\lastskip=\z@ |
| 205 |
\ifnum\lastnodetype=11 % |
| 206 |
\let\RestoreLastSkip\nobreak |
| 207 |
\else |
| 208 |
\let\RestoreLastSkip\relax |
| 209 |
\fi |
| 210 |
\else |
| 211 |
\begingroup |
| 212 |
\skip@=-\lastskip |
| 213 |
\edef\x{% |
| 214 |
\endgroup |
| 215 |
\def\noexpand\RestoreLastSkip{% |
| 216 |
\noexpand\ifvmode |
| 217 |
\noexpand\nobreak |
| 218 |
\vskip\the\skip@ |
| 219 |
\vskip\the\lastskip\relax |
| 220 |
\noexpand\fi |
| 221 |
}% |
| 222 |
}% |
| 223 |
\x |
| 224 |
\fi |
| 225 |
\else |
| 226 |
\ifhmode |
| 227 |
\ifdim\lastskip=\z@ |
| 228 |
\let\RestoreLastSkip\nobreak |
| 229 |
\else |
| 230 |
\begingroup |
| 231 |
\skip@=-\lastskip |
| 232 |
\edef\x{% |
| 233 |
\endgroup |
| 234 |
\def\noexpand\RestoreLastSkip{% |
| 235 |
\noexpand\ifhmode |
| 236 |
\noexpand\nobreak |
| 237 |
\hskip\the\skip@ |
| 238 |
\hskip\the\lastskip\relax |
| 239 |
\noexpand\fi |
| 240 |
}% |
| 241 |
}% |
| 242 |
\x |
| 243 |
\fi |
| 244 |
\fi |
| 245 |
\fi |
| 246 |
} |
| 247 |
\hook_new:n{target/setname/after} |
| 248 |
\int_new:N\g__kernel_target_int |
| 249 |
\NewDocumentCommand\MakeLinkTarget{sO{}m}{% |
| 250 |
\ifvmode |
| 251 |
\SaveLastSkip\@kernel@whatsit\RestoreLastSkip |
| 252 |
\else |
| 253 |
\@savsf\spacefactor |
| 254 |
\SaveLastSkip\smash{}\RestoreLastSkip |
| 255 |
\spacefactor\@savsf |
| 256 |
\fi |
| 257 |
\IfBooleanTF {#1} |
| 258 |
{ |
| 259 |
\tl_gset:Ne \@currentHref {#3} |
| 260 |
} |
| 261 |
{ |
| 262 |
\int_gincr:N\g__kernel_target_int |
| 263 |
\tl_gset:Ne \@currentHref {target*.\int_use:N\g__kernel_target_int} |
| 264 |
} |
| 265 |
\hook_use:n{target/setname/after} |
| 266 |
\UseTaggingSocket{recordtarget} |
| 267 |
} |
| 268 |
\ExplSyntaxOff |
| 269 |
%<latexrelease>\EndIncludeInRelease |
| 270 |
%<latexrelease>\IncludeInRelease{2024/11/01}% |
| 271 |
%<latexrelease> {\MakeLinkTarget}{Record target name for tagging support}% |
| 272 |
%<latexrelease>\ExplSyntaxOn |
| 273 |
%<latexrelease>\NewDocumentCommand\MakeLinkTarget{sO{}m}{% |
| 274 |
%<latexrelease> \ifvmode |
| 275 |
%<latexrelease> \special{}% |
| 276 |
%<latexrelease> \else |
| 277 |
%<latexrelease> \@savsf\spacefactor |
| 278 |
%<latexrelease> \smash{}% |
| 279 |
%<latexrelease> \spacefactor\@savsf |
| 280 |
%<latexrelease> \fi |
| 281 |
%<latexrelease> \IfBooleanTF {#1} |
| 282 |
%<latexrelease> { |
| 283 |
%<latexrelease> \tl_gset:Ne \@currentHref {#3} |
| 284 |
%<latexrelease> } |
| 285 |
%<latexrelease> { |
| 286 |
%<latexrelease> \int_gincr:N\g__kernel_target_int |
| 287 |
%<latexrelease> \tl_gset:Ne \@currentHref {target*.\int_use:N\g__kernel_target_int} |
| 288 |
%<latexrelease> } |
| 289 |
%<latexrelease> \hook_use:n{target/setname/after} |
| 290 |
%<latexrelease> \UseTaggingSocket{recordtarget} |
| 291 |
%<latexrelease> } |
| 292 |
%<latexrelease>\ExplSyntaxOff |
| 293 |
%<latexrelease>\EndIncludeInRelease |
| 294 |
%<latexrelease>\IncludeInRelease{2022/06/01}% |
| 295 |
%<latexrelease> {\MakeLinkTarget}{Record target name for tagging support}% |
| 296 |
%<latexrelease>\NewDocumentCommand\MakeLinkTarget{sO{}m}{% |
| 297 |
%<latexrelease> \ifvmode |
| 298 |
%<latexrelease> \special{}% |
| 299 |
%<latexrelease> \else |
| 300 |
%<latexrelease> \@savsf\spacefactor |
| 301 |
%<latexrelease> \smash{}% |
| 302 |
%<latexrelease> \spacefactor\@savsf |
| 303 |
%<latexrelease> \fi} |
| 304 |
%<latexrelease>\EndIncludeInRelease |
| 305 |
\NewDocumentCommand\LinkTargetOn{}{} |
| 306 |
\NewDocumentCommand\LinkTargetOff{}{} |
| 307 |
\NewDocumentCommand\NextLinkTarget{m}{% |
| 308 |
\AddToHookNext{target/setname/after}{\xdef\@currentHref {#1}}} |
| 309 |
% \end{macrocode} |
| 310 |
% \end{macro} |
| 311 |
% \end{macro} |
| 312 |
% \end{macro} |
| 313 |
% \end{macro} |
| 314 |
% |
| 315 |
% |
| 316 |
% We do not undo \cs{MakeLinkTarget} and friends if we roll back, in |
| 317 |
% case they are used in packages that themselves do not offer |
| 318 |
% rollback. This way a roll forward adds them, but the dummies remain |
| 319 |
% if you roll back and you don't get missing csname errors if they |
| 320 |
% are used. |
| 321 |
% \begin{macrocode} |
| 322 |
%<latexrelease>\IncludeInRelease{0000/00/00}{ltmeta}% |
| 323 |
%<latexrelease> {Undo Document Metadata handling} |
| 324 |
%<latexrelease> |
| 325 |
%<latexrelease>\let\DocumentMetadata\@undefined |
| 326 |
%<latexrelease> |
| 327 |
%<latexrelease>\EndModuleRelease |
| 328 |
% \end{macrocode} |
| 329 |
% Again for the future \ldots |
| 330 |
% \begin{macrocode} |
| 331 |
%\ExplSyntaxOff |
| 332 |
% \end{macrocode} |
| 333 |
% \begin{macrocode} |
| 334 |
%</2ekernel|latexrelease> |
| 335 |
% \end{macrocode} |
| 336 |
% |
| 337 |
% Restore module prefix (if any): |
| 338 |
% \begin{macrocode} |
| 339 |
%<@@=> |
| 340 |
% \end{macrocode} |
| 341 |
% |
| 342 |
% |
| 343 |
% |
| 344 |
% |
| 345 |
% |
| 346 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 347 |
\endinput |
| 348 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 349 |
% |