| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
%% File: latex-lab-float.dtx (C) Copyright 2023 LaTeX Project |
| 4 |
% |
| 5 |
% It may be distributed and/or modified under the conditions of the |
| 6 |
% LaTeX Project Public License (LPPL), either version 1.3c of this |
| 7 |
% license or (at your option) any later version. The latest version |
| 8 |
% of this license is in the file |
| 9 |
% |
| 10 |
% https://www.latex-project.org/lppl.txt |
| 11 |
% |
| 12 |
% |
| 13 |
% The development version of the bundle can be found below |
| 14 |
% |
| 15 |
% https://github.com/latex3/latex2e/required/latex-lab |
| 16 |
% |
| 17 |
% for those people who are interested or want to report an issue. |
| 18 |
% |
| 19 |
\def\ltlabfloatdate{2025-10-17} |
| 20 |
\def\ltlabfloatversion{0.81l} |
| 21 |
%<*driver> |
| 22 |
\DocumentMetadata{tagging=on,pdfstandard=ua-2} |
| 23 |
\documentclass{l3doc} |
| 24 |
\usepackage{latex-lab-testphase-l3doc} |
| 25 |
\EnableCrossrefs |
| 26 |
\CodelineIndex |
| 27 |
\begin{document} |
| 28 |
\DocInput{latex-lab-float.dtx} |
| 29 |
\end{document} |
| 30 |
%</driver> |
| 31 |
% |
| 32 |
% \fi |
| 33 |
% |
| 34 |
% |
| 35 |
% \title{The \textsf{latex-lab-floats} package\\ |
| 36 |
% Tagging of floats } |
| 37 |
% \author{\LaTeX{} Project\thanks{Initial implementation done by Ulrike Fischer}} |
| 38 |
% \date{v\ltlabfloatversion\ \ltlabfloatdate} |
| 39 |
% |
| 40 |
% \maketitle |
| 41 |
% |
| 42 |
% \newcommand{\xt}[1]{\textsl{\textsf{#1}}} |
| 43 |
% \newcommand{\TODO}[1]{\textbf{[TODO:} #1\textbf{]}} |
| 44 |
% \newcommand{\docclass}{document class \marginpar{\raggedright document class |
| 45 |
% customizations}} |
| 46 |
% |
| 47 |
% \providecommand\hook[1]{\texttt{#1}} |
| 48 |
% \ProvideDocElement[printtype=\textit{plug},idxtype=plug,idxgroup=Plugs]{Plug}{plugdecl} |
| 49 |
% \ProvideDocElement[printtype=\textit{socket},idxtype=socket,idxgroup=Sockets]{Socket}{socketdecl} |
| 50 |
% |
| 51 |
% \begin{documentation} |
| 52 |
% \begin{abstract} |
| 53 |
% The following code implements a first draft for the tagging of float |
| 54 |
% environments |
| 55 |
% \end{abstract} |
| 56 |
% |
| 57 |
% |
| 58 |
% \section{Introduction} |
| 59 |
% |
| 60 |
% The code here handle the tagging of float environments. |
| 61 |
% |
| 62 |
% Figures (and tables) are in \LaTeX{} typically typeset in float environments. |
| 63 |
% These are boxes which can \emph{float} away to special float areas on the pages, |
| 64 |
% e.g., to the top or the bottom of a page or to special float pages. |
| 65 |
% If the rules allow it they can also be placed in the main text stream (\enquote{here}). |
| 66 |
% Floats can also be collected at the end of the document. |
| 67 |
% In either case the order within each type of floats |
| 68 |
% (e.g., figures, tables, algorithms, etc.) is preserved. |
| 69 |
% |
| 70 |
% A special type, called a H-float, (provided by the float package) |
| 71 |
% is always placed in the main text stream and does not |
| 72 |
% necessarily preserve the order with normal floats of the same type: It is basically |
| 73 |
% a minipage with a caption. |
| 74 |
% |
| 75 |
% Floats typically contain a figure (or a table, etc.) and a caption, |
| 76 |
% but more complex constructions with subfigures, |
| 77 |
% copyright statements, sources or additional description are possible too. |
| 78 |
% |
| 79 |
% In the \LaTeX{} source a float is normally more or less at the place of |
| 80 |
% the first call-out, but when preparing a document for print the code |
| 81 |
% is sometimes moved to place floats in a more visually pleasing way. |
| 82 |
% |
| 83 |
% \section{Tagging} |
| 84 |
% |
| 85 |
% Floats (with the exception of H-floats) do not belong into the text stream, they |
| 86 |
% are \enquote{consultation objects}: Readers must be able to choose if and when they read the float. |
| 87 |
% Floats have captions, the PDF rules require that a \texttt{Caption} is the first or last |
| 88 |
% structure in its parent structure. |
| 89 |
% This poses some challenges on a good tagging. |
| 90 |
% |
| 91 |
% In PDF~2.0 there is the suitable \texttt{Aside} tag which hopefully will |
| 92 |
% be handled correctly regarding the reading order once processor actually support |
| 93 |
% PDF~2.0. But in PDF~1.7 we rolemap it to \texttt{Note} and this doesn't lead to |
| 94 |
% a good reading order. The code therefore collects the float structures and moves |
| 95 |
% them to a \texttt{Sect} at the end of the document or the chapter |
| 96 |
% (H-floats once they are handled will not be moved). |
| 97 |
% |
| 98 |
% To fulfill the requirement that a \texttt{Caption} should be at the begin or end, we always |
| 99 |
% move it to the begin of the structure. If a float has two captions the author |
| 100 |
% has to insert a command which splits the float in two. |
| 101 |
% |
| 102 |
% Subfigures and subcaptions are currently not handled, but will be implemented |
| 103 |
% as simple \texttt{Part} with their own \texttt{Caption}. |
| 104 |
% |
| 105 |
% \section{Links} |
| 106 |
% The code disable the caption patches from hyperref. It will add an anchor at the |
| 107 |
% begin of the float or a split. It changes caption so that a link to a caption label |
| 108 |
% will go to the begin of the float. |
| 109 |
% |
| 110 |
% \section{Tools} |
| 111 |
% |
| 112 |
% The code add two keys for the \cs{tagtool} command |
| 113 |
% |
| 114 |
% |
| 115 |
% \begin{function}{flush-floats,split-float} |
| 116 |
% \begin{description} |
| 117 |
% \item[flush-floats] This will flush out the collected floats sofar (currently |
| 118 |
% table and figure. The value is a sectioning level, e.g. \texttt{section} or \texttt{chapter}, |
| 119 |
% the floats will then inserted as a \texttt{Sect} of this level (all \texttt{Sect} of smaller or equal |
| 120 |
% level are closed). The key then starts a new container for following floats. |
| 121 |
% If no value is given, the \texttt{Sect} is at the document level. The code automatically |
| 122 |
% flush all open floats at the end of the document. |
| 123 |
% |
| 124 |
% \item[split-float] This can be used inside a float if there are two captions. |
| 125 |
% It will only work reasonably well if the content of the float parts are in a sensible order |
| 126 |
% and can be separated by this command. More complex setups with tabulars will need more |
| 127 |
% thoughts. |
| 128 |
% \end{description} |
| 129 |
% \end{function} |
| 130 |
% |
| 131 |
% \section{Kernel commands} |
| 132 |
% \begin{function}{\@current@float@struct} |
| 133 |
% This variable holds the number of the current float structure. With tagging |
| 134 |
% this is the structure number, without tagging a unique counter. A float |
| 135 |
% can contain more than one float structure (e.g. if there is more than one |
| 136 |
% caption). |
| 137 |
% \end{function} |
| 138 |
% |
| 139 |
% \begin{function}{\@makecaption} |
| 140 |
% \cs{@makecaption} is defined by the classes so we overwrite it for now |
| 141 |
% at begin document. |
| 142 |
% \end{function} |
| 143 |
% |
| 144 |
% |
| 145 |
% \begin{macrocode} |
| 146 |
%<@@=tag> |
| 147 |
%<*package> |
| 148 |
% \end{macrocode} |
| 149 |
% \end{documentation} |
| 150 |
% \begin{implementation} |
| 151 |
% \section{Implementation} |
| 152 |
% \begin{macrocode} |
| 153 |
\ProvidesExplPackage {latex-lab-testphase-float} {\ltlabfloatdate} {\ltlabfloatversion} |
| 154 |
{Code related to the tagging of floats} |
| 155 |
% \end{macrocode} |
| 156 |
% \subsection{Variables} |
| 157 |
% We rolemap floats to Aside, and float sections to Sect. |
| 158 |
% |
| 159 |
% \begin{variable}{ |
| 160 |
% \g_@@_float_sect_prop, |
| 161 |
% \g_@@_float_types_seq, |
| 162 |
% \@current@float@struct, |
| 163 |
% \g_@@_float_int |
| 164 |
% } |
| 165 |
% These variables will hold the structure number for the float container |
| 166 |
% and the list of float types. Currently only figure and table are supported |
| 167 |
% TODO: interface to declare new float types. |
| 168 |
% To set the target for links we need also a unique counter. |
| 169 |
% With tagging we could use the structure number, but |
| 170 |
% the structure commands now are hidden inside tagging sockets |
| 171 |
% so we use a dedicated counter. |
| 172 |
% \begin{macrocode} |
| 173 |
\prop_new:N \g_@@_float_sect_prop |
| 174 |
\seq_new:N \g_@@_float_types_seq |
| 175 |
\seq_gput_right:Nn \g_@@_float_types_seq {figure} |
| 176 |
\seq_gput_right:Nn \g_@@_float_types_seq {table} |
| 177 |
\tl_new:N\@current@float@struct |
| 178 |
\int_new:N\g_@@_float_int |
| 179 |
% \end{macrocode} |
| 180 |
% \end{variable} |
| 181 |
% |
| 182 |
% \begin{variable}{\g_@@_float_sect_bool} |
| 183 |
% With this boolean float collection is switched on and off. |
| 184 |
% Currently it is always on and set globally. |
| 185 |
% TODO: think if an interface is needed. |
| 186 |
% TODO: would a local variable make more sense? |
| 187 |
% \begin{macrocode} |
| 188 |
\bool_new:N \g_@@_float_sect_bool |
| 189 |
\bool_gset_true:N \g_@@_float_sect_bool |
| 190 |
% \end{macrocode} |
| 191 |
% \end{variable} |
| 192 |
% |
| 193 |
% \begin{macro}{\@@_float_init:} |
| 194 |
% To be able to set unique targets for links, we |
| 195 |
% need a counter outside the tagging sockets. |
| 196 |
% TODO: check if this command should be public or |
| 197 |
% a socket or a hook. |
| 198 |
% \begin{macrocode} |
| 199 |
\cs_new_protected:Npn \@@_float_init: |
| 200 |
{ |
| 201 |
\int_gincr:N \g_@@_float_int |
| 202 |
\tl_set:Ne \@current@float@struct { \int_use:N \g_@@_float_int} |
| 203 |
} |
| 204 |
% \end{macrocode} |
| 205 |
% \end{macro} |
| 206 |
% |
| 207 |
%\subsection{Moving float structures} |
| 208 |
% |
| 209 |
% Currently it is for all float types or none. |
| 210 |
% Probably we will need some more options here to select some float types. |
| 211 |
% |
| 212 |
% \begin{macro}{\@@_float_init_collect:} |
| 213 |
% This initializes a container structure for every float type. |
| 214 |
% It can be used more than once in a document, this allows to have e.g. |
| 215 |
% chapter wise containers. |
| 216 |
% \begin{macrocode} |
| 217 |
\cs_new_protected:Npn\@@_float_init_collect: |
| 218 |
{ |
| 219 |
\bool_if:NT\g_@@_float_sect_bool |
| 220 |
{ |
| 221 |
\seq_map_inline:Nn\g_@@_float_types_seq |
| 222 |
{ |
| 223 |
\tag_struct_begin:n{tag=##1s,stash} |
| 224 |
\prop_gput:Nne\g_@@_float_sect_prop {##1-struct}{\int_use:N\c@g__tag_struct_abs_int} |
| 225 |
\tag_struct_end: |
| 226 |
} |
| 227 |
} |
| 228 |
} |
| 229 |
% \end{macrocode} |
| 230 |
% \end{macro} |
| 231 |
% |
| 232 |
% |
| 233 |
% \begin{macro}{\@@_float_stop_sect:} |
| 234 |
% This pushes out the floats. For every type is checks if there is actually |
| 235 |
% a float of this type and then writes out the container structure. |
| 236 |
% \begin{macrocode} |
| 237 |
\cs_new_protected:Npn \@@_float_stop_sect: |
| 238 |
{ |
| 239 |
\bool_if:NT\g_@@_float_sect_bool |
| 240 |
{ |
| 241 |
\seq_map_inline:Nn\g_@@_float_types_seq |
| 242 |
{ |
| 243 |
\prop_get:NnNT\g_@@_float_sect_prop{##1-used}\l_@@_tmpa_tl |
| 244 |
{ |
| 245 |
\exp_args:Ne |
| 246 |
\tag_struct_use_num:n{\prop_item:Nn\g_@@_float_sect_prop{##1-struct}} |
| 247 |
\prop_gremove:Nn \g_@@_float_sect_prop{##1-used} |
| 248 |
} |
| 249 |
} |
| 250 |
} |
| 251 |
} |
| 252 |
% \end{macrocode} |
| 253 |
% \end{macro} |
| 254 |
|
| 255 |
% \begin{macro}{flush-floats} |
| 256 |
% This is a key for \cs{tagtool} to flush out the collected floats. |
| 257 |
% The value allows to set to which level the create Sect contains. |
| 258 |
% So \texttt{section} will close all previous Sect until the section level |
| 259 |
% and create a new section. |
| 260 |
% \begin{macrocode} |
| 261 |
\keys_define:nn { tag / tool} |
| 262 |
{ |
| 263 |
flush-floats .code:n = |
| 264 |
{ |
| 265 |
\keys_set:nn {tag / tool} {sec-stop=#1} |
| 266 |
\@@_float_stop_sect: |
| 267 |
\@@_float_init_collect: |
| 268 |
}, |
| 269 |
flush-float .default:n = Document |
| 270 |
} |
| 271 |
% \end{macrocode} |
| 272 |
% \end{macro} |
| 273 |
% We need at least one pair |
| 274 |
% \begin{macrocode} |
| 275 |
\AddToHook{begindocument/end}[latex-lab/float] |
| 276 |
{\@@_float_init_collect:} |
| 277 |
\AddToHook{tagpdf/finish/before}[latex-lab/float] |
| 278 |
{\par\__tag_sec_end:n{-10}\@@_float_stop_sect:} |
| 279 |
\DeclareHookRule{tagpdf/finish/before}{latex-lab/float}{before}{tagpdf} |
| 280 |
% \end{macrocode} |
| 281 |
% |
| 282 |
% \subsection{Splitting floats} |
| 283 |
% \begin{macro}{split-float} |
| 284 |
% TODO: check if the target affect spacing!! |
| 285 |
% \begin{macrocode} |
| 286 |
\keys_define:nn { tag / tool} |
| 287 |
{ |
| 288 |
split-float .code:n = |
| 289 |
{ |
| 290 |
\UseTaggingSocket{float/end} |
| 291 |
\@@_float_init: |
| 292 |
\UseTaggingSocket{float/begin} |
| 293 |
\MakeLinkTarget*{floatstructure.\@current@float@struct} |
| 294 |
} |
| 295 |
} |
| 296 |
% \end{macrocode} |
| 297 |
% \end{macro} |
| 298 |
% |
| 299 |
% \subsection{Tagging sockets} |
| 300 |
% For now we test if the sockets are already defined |
| 301 |
% \begin{macrocode} |
| 302 |
\socket_if_exist:nF {tagsupport/float/begin} |
| 303 |
{ |
| 304 |
\NewTaggingSocket{float/hmode/begin}{0} |
| 305 |
\NewTaggingSocket{float/hmode/end}{0} |
| 306 |
\NewTaggingSocket{float/begin}{0} |
| 307 |
\NewTaggingSocket{float/end}{0} |
| 308 |
} |
| 309 |
% \end{macrocode} |
| 310 |
% |
| 311 |
% \begin{plugdecl}{default (tagsupport/float/hmode/begin)} |
| 312 |
% This plug should be used if a float is called in hmode. |
| 313 |
% It then closes the MC-chunks and starts the structure. |
| 314 |
% \begin{macrocode} |
| 315 |
\NewTaggingSocketPlug{float/hmode/begin}{default} |
| 316 |
{ |
| 317 |
\@@_float_stop_par: |
| 318 |
} |
| 319 |
\AssignTaggingSocketPlug{float/hmode/begin}{default} |
| 320 |
% \end{macrocode} |
| 321 |
% \end{plugdecl} |
| 322 |
% |
| 323 |
% \begin{plugdecl}{default (tagsupport/float/hmode/end)} |
| 324 |
% This plug should be used if a float is called in hmode |
| 325 |
% and the end of the float it then restarts the MC. |
| 326 |
% \begin{macrocode} |
| 327 |
\NewTaggingSocketPlug{float/hmode/end}{default} |
| 328 |
{ |
| 329 |
\@@_float_start_par: |
| 330 |
} |
| 331 |
\AssignTaggingSocketPlug{float/hmode/end}{default} |
| 332 |
% \end{macrocode} |
| 333 |
% \end{plugdecl} |
| 334 |
% |
| 335 |
% \begin{plugdecl}{default (tagsupport/float/begin)} |
| 336 |
% \begin{macrocode} |
| 337 |
\NewTaggingSocketPlug{float/begin}{default} |
| 338 |
{ |
| 339 |
\@@_float_begin: |
| 340 |
} |
| 341 |
\AssignTaggingSocketPlug{float/begin}{default} |
| 342 |
% \end{macrocode} |
| 343 |
% \end{plugdecl} |
| 344 |
% |
| 345 |
% \begin{plugdecl}{default (tagsupport/float/end)} |
| 346 |
% \begin{macrocode} |
| 347 |
\NewTaggingSocketPlug{float/end}{default} |
| 348 |
{ |
| 349 |
\@@_float_end: |
| 350 |
} |
| 351 |
\AssignTaggingSocketPlug{float/end}{default} |
| 352 |
% \end{macrocode} |
| 353 |
% \end{plugdecl} |
| 354 |
% |
| 355 |
% \begin{macro}{\@@_float_stop_par:,\@@_float_start_par:} |
| 356 |
% if a float is in a par, we need commands to stop and restart the P-mc |
| 357 |
% \begin{macrocode} |
| 358 |
\cs_new_protected:Npn \@@_float_stop_par: |
| 359 |
{ |
| 360 |
\tag_mc_end: |
| 361 |
\bool_if:NF \g_@@_float_sect_bool |
| 362 |
{ |
| 363 |
\tag_struct_end: |
| 364 |
} |
| 365 |
} |
| 366 |
\cs_new_protected:Npn \@@_float_start_par: |
| 367 |
{ |
| 368 |
\bool_if:NF \g_@@_float_sect_bool |
| 369 |
{ |
| 370 |
\tag_struct_begin:n{tag=text}% |
| 371 |
} |
| 372 |
\tag_mc_begin:n{tag=P} |
| 373 |
} |
| 374 |
% \end{macrocode} |
| 375 |
% \end{macro} |
| 376 |
% These commands are the main commands to start and end the float tagging. |
| 377 |
% |
| 378 |
% \begin{macrocode} |
| 379 |
\cs_new_protected:Npn \@@_float_begin: |
| 380 |
{% |
| 381 |
% \end{macrocode} |
| 382 |
% We test if the float structure should be included directly or move to a dedicated section. |
| 383 |
% \begin{macrocode} |
| 384 |
\bool_if:NTF\g_@@_float_sect_bool |
| 385 |
{ |
| 386 |
\exp_args:Ne |
| 387 |
\tag_struct_begin:n{tag=float,parent=0\prop_item:No\g_@@_float_sect_prop{\@captype-struct}}% |
| 388 |
\prop_gput:Nee \g_@@_float_sect_prop {\@captype-used}{true} |
| 389 |
} |
| 390 |
{ |
| 391 |
\tag_struct_begin:n{tag=float} |
| 392 |
} |
| 393 |
\tl_set:Ne\@current@float@struct{\tag_get:n{struct_num}}% |
| 394 |
\typeout{Float structure: \@current@float@struct} |
| 395 |
} |
| 396 |
|
| 397 |
\cs_new_protected:Npn\@@_float_end:{\tag_struct_end:} %end Aside |
| 398 |
|
| 399 |
% \end{macrocode} |
| 400 |
% \subsection{Patching} |
| 401 |
% This patches the main command \cs{@xfloat}. |
| 402 |
% There is a : in the code, so we disable expl3 syntax |
| 403 |
% \begin{macrocode} |
| 404 |
\ExplSyntaxOff |
| 405 |
\def\@xfloat #1[#2]{% |
| 406 |
\@nodocument |
| 407 |
\def \@captype {#1}% |
| 408 |
\def \@fps {#2}% |
| 409 |
\@onelevel@sanitize \@fps |
| 410 |
\def \reserved@b {!}% |
| 411 |
\ifx \reserved@b \@fps |
| 412 |
\@fpsadddefault |
| 413 |
\else |
| 414 |
\ifx \@fps \@empty |
| 415 |
\@fpsadddefault |
| 416 |
\fi |
| 417 |
\fi |
| 418 |
\ifhmode |
| 419 |
\@bsphack |
| 420 |
% \end{macrocode} |
| 421 |
% If the float is in hmode we have to interrupt the P |
| 422 |
% \begin{macrocode} |
| 423 |
\UseTaggingSocket{float/hmode/begin}% |
| 424 |
\@floatpenalty -\@Mii |
| 425 |
\else |
| 426 |
\@floatpenalty-\@Miii |
| 427 |
\fi |
| 428 |
\ifinner |
| 429 |
\@parmoderr\@floatpenalty\z@ |
| 430 |
\else |
| 431 |
\@next\@currbox\@freelist |
| 432 |
{% |
| 433 |
\@tempcnta \sixt@@@@n |
| 434 |
\expandafter \@tfor \expandafter \reserved@a |
| 435 |
\expandafter :\expandafter =\@fps |
| 436 |
\do |
| 437 |
{% |
| 438 |
\if \reserved@a h% |
| 439 |
\ifodd \@tempcnta |
| 440 |
\else |
| 441 |
\advance \@tempcnta \@ne |
| 442 |
\fi |
| 443 |
\else\if \reserved@a t% |
| 444 |
\@setfpsbit \tw@ |
| 445 |
\else\if \reserved@a b% |
| 446 |
\@setfpsbit 4% |
| 447 |
\else\if \reserved@a p% |
| 448 |
\@setfpsbit 8% |
| 449 |
\else\if \reserved@a !% |
| 450 |
\ifnum \@tempcnta>15 |
| 451 |
\advance\@tempcnta -\sixt@@@@n\relax |
| 452 |
\fi |
| 453 |
\else |
| 454 |
\@latex@error{Unknown float option `\reserved@a'}% |
| 455 |
{Option `\reserved@a' ignored and `p' used.}% |
| 456 |
\@setfpsbit 8% |
| 457 |
\fi\fi\fi\fi\fi |
| 458 |
}% |
| 459 |
\@tempcntb \csname ftype@\@captype \endcsname |
| 460 |
\multiply \@tempcntb \@xxxii |
| 461 |
\advance \@tempcnta \@tempcntb |
| 462 |
\global \count\@currbox \@tempcnta |
| 463 |
}% |
| 464 |
\@fltovf |
| 465 |
\fi |
| 466 |
% \end{macrocode} |
| 467 |
% This starts the structure for the float. |
| 468 |
% \begin{macrocode} |
| 469 |
\csname @@_float_init:\endcsname |
| 470 |
\UseTaggingSocket{float/begin}% |
| 471 |
\global \setbox\@currbox |
| 472 |
\color@vbox |
| 473 |
\normalcolor |
| 474 |
\vbox \bgroup |
| 475 |
\hsize\columnwidth |
| 476 |
\@parboxrestore |
| 477 |
\@floatboxreset |
| 478 |
% \end{macrocode} |
| 479 |
% We add a target for links. TODO: check that it doesn't affect spacing!! |
| 480 |
% \begin{macrocode} |
| 481 |
\MakeLinkTarget*{\@captype.struct.\@current@float@struct}% |
| 482 |
}% |
| 483 |
% \end{macrocode} |
| 484 |
% The end code of the float ... |
| 485 |
% \begin{macrocode} |
| 486 |
\def\end@float{% |
| 487 |
\@endfloatbox |
| 488 |
\UseTaggingSocket{float/end}% |
| 489 |
\ifnum\@floatpenalty <\z@ |
| 490 |
\@largefloatcheck |
| 491 |
\@cons\@currlist\@currbox |
| 492 |
\ifnum\@floatpenalty <-\@Mii |
| 493 |
\penalty -\@Miv |
| 494 |
\@tempdima\prevdepth |
| 495 |
\vbox{}% |
| 496 |
\prevdepth\@tempdima |
| 497 |
\penalty\@floatpenalty |
| 498 |
\else |
| 499 |
\vadjust{\penalty -\@Miv \vbox{}\penalty\@floatpenalty}\@Esphack |
| 500 |
\UseTaggingSocket{float/hmode/end}% |
| 501 |
\fi |
| 502 |
\fi |
| 503 |
} |
| 504 |
% \end{macrocode} |
| 505 |
% and similar for double floats: |
| 506 |
% \begin{macrocode} |
| 507 |
\def\end@dblfloat{% |
| 508 |
\if@twocolumn |
| 509 |
\@endfloatbox |
| 510 |
\UseTaggingSocket{float/end}% |
| 511 |
\ifnum\@floatpenalty <\z@ |
| 512 |
\@largefloatcheck |
| 513 |
\global\dp\@currbox1sp % |
| 514 |
\@cons\@currlist\@currbox |
| 515 |
\ifnum\@floatpenalty <-\@Mii |
| 516 |
\penalty -\@Miv |
| 517 |
\@tempdima\prevdepth |
| 518 |
\vbox{}% |
| 519 |
\prevdepth\@tempdima |
| 520 |
\penalty\@floatpenalty |
| 521 |
\else |
| 522 |
\vadjust{\penalty -\@Miv \vbox{}\penalty\@floatpenalty}\@Esphack |
| 523 |
\UseTaggingSocket{float/hmode/end}% |
| 524 |
\fi |
| 525 |
\fi |
| 526 |
\else |
| 527 |
\end@float |
| 528 |
\fi |
| 529 |
}% |
| 530 |
\ExplSyntaxOn |
| 531 |
% \end{macrocode} |
| 532 |
% |
| 533 |
% \subsection{Handling captions} |
| 534 |
% |
| 535 |
% To avoid that hyperref interferes we disable its patches: |
| 536 |
% \begin{macrocode} |
| 537 |
\def\hyper@nopatch@caption{} |
| 538 |
% \end{macrocode} |
| 539 |
% |
| 540 |
% \subsubsection{(Tagging) sockets} |
| 541 |
% |
| 542 |
% First some temporary sockets. |
| 543 |
% These sockets are in lttagging. |
| 544 |
% \begin{macrocode} |
| 545 |
\socket_if_exist:nF {tagsupport/caption/begin} |
| 546 |
{ |
| 547 |
\NewTaggingSocket{caption/begin}{1} |
| 548 |
\NewTaggingSocket{caption/end}{0} |
| 549 |
\NewTaggingSocket{caption/label/begin}{0} |
| 550 |
\NewTaggingSocket{caption/label/end}{0} |
| 551 |
} |
| 552 |
% \end{macrocode} |
| 553 |
% These socket are currently defined in tagpdf. |
| 554 |
% \changes{v0.81g}{2024-11-21}{add missing argument to socket} |
| 555 |
% \begin{macrocode} |
| 556 |
\socket_if_exist:nF {tagsupport/para/begin} |
| 557 |
{ |
| 558 |
\NewTaggingSocket{para/begin}{0} |
| 559 |
\NewTaggingSocket{para/end}{0} |
| 560 |
} |
| 561 |
% \end{macrocode} |
| 562 |
% |
| 563 |
% \begin{socketdecl}{caption/label} |
| 564 |
% This socket is a lightweight start for |
| 565 |
% some interface to format the label or add a font command. |
| 566 |
% The argument is the label text. |
| 567 |
% The default plug \texttt{kernel} adds a colon |
| 568 |
% and a space. |
| 569 |
% TODO: revisit after checking float and caption packages |
| 570 |
% to identify which sockets and hooks are needed. |
| 571 |
% \begin{macrocode} |
| 572 |
\NewSocket{caption/label}{1} |
| 573 |
% \end{macrocode} |
| 574 |
% \end{socketdecl} |
| 575 |
% |
| 576 |
% \begin{plugdecl}{kernel (caption/label)} |
| 577 |
% The standard label formatting from the kernel. |
| 578 |
% \begin{macrocode} |
| 579 |
\NewSocketPlug{caption/label}{kernel} |
| 580 |
{ |
| 581 |
#1:~ |
| 582 |
} |
| 583 |
\AssignSocketPlug{caption/label}{kernel} |
| 584 |
% \end{macrocode} |
| 585 |
% \end{plugdecl} |
| 586 |
% \begin{plugdecl}{default} |
| 587 |
% The caption begin socket takes an argument: the structure number of |
| 588 |
% the parent float. If the argument is empty, the current structure is used. |
| 589 |
% TODO: a tagpdf key that moves a structure to the begin of the parent. |
| 590 |
% The caption is moved to the first position with the firstkid option. |
| 591 |
% \begin{macrocode} |
| 592 |
\NewTaggingSocketPlug{caption/begin}{default} |
| 593 |
{ |
| 594 |
\tl_if_empty:eTF {#1} |
| 595 |
{ |
| 596 |
\tag_struct_begin:n{tag=Caption,firstkid} |
| 597 |
} |
| 598 |
{ |
| 599 |
\tag_struct_begin:n{tag=Caption,parent=#1,firstkid} |
| 600 |
} |
| 601 |
\bool_set_true:N \l__tag_para_flattened_bool |
| 602 |
} |
| 603 |
\AssignTaggingSocketPlug{caption/begin}{default} |
| 604 |
% \end{macrocode} |
| 605 |
% \end{plugdecl} |
| 606 |
% \begin{plugdecl}{default} |
| 607 |
% \begin{macrocode} |
| 608 |
\NewTaggingSocketPlug{caption/end}{default} |
| 609 |
{ |
| 610 |
\tag_struct_end: |
| 611 |
} |
| 612 |
\AssignTaggingSocketPlug{caption/end}{default} |
| 613 |
% \end{macrocode} |
| 614 |
% \end{plugdecl} |
| 615 |
% |
| 616 |
% \begin{plugdecl}{default (tagsupport/caption/label/begin)} |
| 617 |
% \begin{macrocode} |
| 618 |
\NewTaggingSocketPlug{caption/label/begin}{default} |
| 619 |
{ |
| 620 |
% \end{macrocode} |
| 621 |
% suppress para tagging at the begin. |
| 622 |
% \begin{macrocode} |
| 623 |
\tagpdfparaOff |
| 624 |
\tag_struct_begin:n{tag=Lbl} |
| 625 |
\tag_mc_begin:n{} |
| 626 |
} |
| 627 |
\AssignTaggingSocketPlug{caption/label/begin}{default} |
| 628 |
% \end{macrocode} |
| 629 |
% \end{plugdecl} |
| 630 |
% |
| 631 |
% \begin{plugdecl}{default (tagsupport/caption/label/end)} |
| 632 |
% \begin{macrocode} |
| 633 |
\NewTaggingSocketPlug{caption/label/end}{default} |
| 634 |
{ |
| 635 |
\tag_mc_end: |
| 636 |
\tag_struct_end: |
| 637 |
\tagpdfparaOn |
| 638 |
} |
| 639 |
\AssignTaggingSocketPlug{caption/label/end}{default} |
| 640 |
% \end{macrocode} |
| 641 |
% \end{plugdecl} |
| 642 |
% |
| 643 |
% \subsubsection{Redefinitions} |
| 644 |
% |
| 645 |
% With hyperref that means that the \cs{refstepcounter} now can affect spacing so we |
| 646 |
% change that to the kernel refstepcounter: |
| 647 |
% \begin{macrocode} |
| 648 |
\def\caption{% |
| 649 |
\ifx\@captype\@undefined |
| 650 |
\@latex@error{\noexpand\caption\c_space_tl outside~float}\@ehd |
| 651 |
\expandafter\@gobble |
| 652 |
\else |
| 653 |
% \end{macrocode} |
| 654 |
% if a caption is used outside a float no |
| 655 |
% target has been set and \cs{@current@float@struct} is empty |
| 656 |
% \begin{macrocode} |
| 657 |
\tl_if_empty:NTF\@current@float@struct |
| 658 |
{ |
| 659 |
\refstepcounter\@captype |
| 660 |
} |
| 661 |
{ |
| 662 |
\@kernel@refstepcounter\@captype |
| 663 |
% \end{macrocode} |
| 664 |
% we need to reset the target for \cs{addcontentsline}. |
| 665 |
% We use \cs{@captype} to support autoref. |
| 666 |
% \begin{macrocode} |
| 667 |
\xdef\@currentHref{\@captype.struct.\@current@float@struct}% |
| 668 |
} |
| 669 |
\expandafter\@firstofone |
| 670 |
\fi |
| 671 |
{\@dblarg{\@caption\@captype}}% |
| 672 |
} |
| 673 |
% \end{macrocode} |
| 674 |
% |
| 675 |
% \begin{macro}{\@makecaption} |
| 676 |
% \cs{@makecaption} is defined by the classes so we overwrite it for now |
| 677 |
% at begin document. |
| 678 |
% \changes{0.81k}{2025-10-11}{Add command hook explicitly to avoid patching error, tagging issue 998} |
| 679 |
% \begin{macrocode} |
| 680 |
\NewHookWithArguments{cmd/@makecaption/before}{2} |
| 681 |
\AddToHook{begindocument} |
| 682 |
{ |
| 683 |
\long\def\@makecaption#1#2{% |
| 684 |
\UseHookWithArguments{cmd/@makecaption/before}{2}{#1}{#2}% |
| 685 |
\vskip\abovecaptionskip |
| 686 |
% \end{macrocode} |
| 687 |
% We don't want tagging when storing the caption for the singleline check. |
| 688 |
% \changes{0.81l}{2025-10-17}{Measure \texttt{caption/label} socket instead of hard-coded colon and space, tagging issue 935} |
| 689 |
% \begin{macrocode} |
| 690 |
\SuspendTagging{\@makecaption} |
| 691 |
\sbox\@tempboxa{\UseSocket{caption/label}{#1}#2}% |
| 692 |
\ResumeTagging{\@makecaption} |
| 693 |
% \end{macrocode} |
| 694 |
% We pass \cs{@current@float@struct} as parent structure |
| 695 |
% number. If that is empty the socket will use the parent structure and hope ... |
| 696 |
% \begin{macrocode} |
| 697 |
\UseTaggingSocket{caption/begin}{\@current@float@struct} |
| 698 |
\ifdim \wd\@tempboxa >\hsize |
| 699 |
\UseTaggingSocket{caption/label/begin} |
| 700 |
\UseSocket{caption/label}{#1} |
| 701 |
\UseTaggingSocket{caption/label/end} |
| 702 |
\UseTaggingSocket{para/begin} |
| 703 |
#2 |
| 704 |
\par |
| 705 |
\else |
| 706 |
% \end{macrocode} |
| 707 |
% we don't reuse the box as it doesn't contain tagging, but set the text explicitly. |
| 708 |
% \begin{macrocode} |
| 709 |
\global \@minipagefalse |
| 710 |
\hb@xt@\hsize{\hfil |
| 711 |
\UseTaggingSocket{caption/label/begin} |
| 712 |
\UseSocket{caption/label}{#1} |
| 713 |
\UseTaggingSocket{caption/label/end} |
| 714 |
\UseTaggingSocket{para/begin} |
| 715 |
#2 |
| 716 |
\UseTaggingSocket{para/end} |
| 717 |
\hfil}% |
| 718 |
\fi |
| 719 |
\UseTaggingSocket{caption/end} |
| 720 |
\vskip\belowcaptionskip} |
| 721 |
} |
| 722 |
% \end{macrocode} |
| 723 |
% \end{macro} |
| 724 |
% |
| 725 |
% \begin{macrocode} |
| 726 |
%</package> |
| 727 |
% \end{macrocode} |
| 728 |
|
| 729 |
% \begin{macrocode} |
| 730 |
%<*latex-lab> |
| 731 |
\ProvidesFile{float-latex-lab-testphase.ltx} |
| 732 |
[\ltlabfloatdate\space v\ltlabfloatversion\space latex-lab wrapper float] |
| 733 |
\RequirePackage{latex-lab-testphase-float} |
| 734 |
%</latex-lab> |
| 735 |
% \end{macrocode} |
| 736 |
% \end{implementation} |