| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
%% File: latex-lab-firstaid.dtx (C) Copyright 2023-2025 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\ltlabfirstaiddate{2025-11-03} |
| 20 |
\def\ltlabfirstaidversion{0.85o} |
| 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-firstaid.dtx} |
| 29 |
\end{document} |
| 30 |
%</driver> |
| 31 |
% |
| 32 |
% \fi |
| 33 |
% |
| 34 |
% \title{The \textsf{latex-lab-firstaid} package\\ |
| 35 |
% Temporary patches to external packages needed for the tagging project} |
| 36 |
% \author{\LaTeX{} Project\thanks{Initial implementation done by Ulrike Fischer}} |
| 37 |
% \date{v\ltlabfirstaidversion\ \ltlabfirstaiddate} |
| 38 |
% |
| 39 |
% \maketitle |
| 40 |
% |
| 41 |
% \newcommand{\xt}[1]{\textsl{\textsf{#1}}} |
| 42 |
% \newcommand{\TODO}[1]{\textbf{[TODO:} #1\textbf{]}} |
| 43 |
% \newcommand{\docclass}{document class \marginpar{\raggedright document class |
| 44 |
% customizations}} |
| 45 |
% |
| 46 |
% \providecommand\hook[1]{\texttt{#1}} |
| 47 |
% |
| 48 |
% \begin{abstract} |
| 49 |
% \end{abstract} |
| 50 |
% |
| 51 |
% \section{Introduction} |
| 52 |
% |
| 53 |
% The followings contains small temporary changes to external packages to avoid |
| 54 |
% errors with the new tagging code. |
| 55 |
% |
| 56 |
% Similar to the main firstaid package the goal is to remove the |
| 57 |
% patches once the packages have been updated. |
| 58 |
% |
| 59 |
% \changes{v0.85g}{2024/10/04}{Removed firstaid for blindtext. No longer needed with new doenpe-code.} |
| 60 |
% \changes{v0.85g}{2024/10/04}{Added firstaid for fancyvrb.} |
| 61 |
% \changes{v0.85n}{2025-10-12}{Added firstaid for pgf.} |
| 62 |
% \section{Implementation} |
| 63 |
% |
| 64 |
% \begin{macrocode} |
| 65 |
%<*package> |
| 66 |
%<@@=tag> |
| 67 |
% \end{macrocode} |
| 68 |
% \begin{macrocode} |
| 69 |
\ProvidesPackage {latex-lab-testphase-firstaid} [% |
| 70 |
\ltlabfirstaiddate\space v\ltlabfirstaiddate\space |
| 71 |
Temporary patches to external packages needed for the tagging project] |
| 72 |
% \end{macrocode} |
| 73 |
% \begin{macro}[no-user-doc]{\FirstAidNeededT} |
| 74 |
% This is a very simple help to ensure that we only apply first aid |
| 75 |
% to an unmodified package or class. It only works in the case the |
| 76 |
% file has already been loaded and the csname \cs{ver@\#1.\#2} got |
| 77 |
% defined (holding the current date, version, and short description |
| 78 |
% info). We then compare its content to a frozen string and make |
| 79 |
% the modification \verb=#3= only if both agree. If they differ we |
| 80 |
% assume that the package/class in question got updated by its |
| 81 |
% maintainer. |
| 82 |
% \begin{macrocode} |
| 83 |
\ExplSyntaxOn |
| 84 |
\providecommand\FirstAidNeededT[3]{ |
| 85 |
\exp_args:Ncx\str_if_eq:onF{ver@#1.#2}{#3} |
| 86 |
{ \typeout{==>~ First~ Aid~ for~ #1.#2~ no~ longer~ applied!^^J |
| 87 |
\@spaces Expected:^^J |
| 88 |
\@spaces\@spaces #3^^J |
| 89 |
\@spaces but~ found:^^J |
| 90 |
\@spaces\@spaces \use:c{ver@#1.#2}^^J |
| 91 |
\@spaces so~ I'm~ assuming~ it~ got~ fixed. |
| 92 |
} } |
| 93 |
\exp_args:Ncx\str_if_eq:onT{ver@#1.#2}{#3} |
| 94 |
} |
| 95 |
% \end{macrocode} |
| 96 |
% \end{macro} |
| 97 |
% \subsection{tikz/pgf} |
| 98 |
% ti\textit{k}z inputs libraries with the primitive \cs{input} command. This means that |
| 99 |
% these libraries are not listed in the file list written by \cs{listfiles} and the new |
| 100 |
% tagging status report created with the \texttt{check-tagging-status} key. |
| 101 |
% |
| 102 |
% We therefore redefine one \texttt{pgf} command to use the \LaTeX{} \cs{input} command. |
| 103 |
% Check https://github.com/pgf-tikz/pgf/issues/1424 for changes. |
| 104 |
% \begin{macrocode} |
| 105 |
\AddToHook{package/pgfrcs/after} |
| 106 |
{\def\pgfutil@InputIfFileExists#1#2#3{\pgfutil@IfFileExists{#1}{\input{#1}\relax#2}{#3}}} |
| 107 |
% \end{macrocode} |
| 108 |
% |
| 109 |
% \subsection{ams classes} |
| 110 |
% The amsart, amsbook and amsproc classes do not use \cs{@author} to store the author list |
| 111 |
% but a command \cs{authors}. To be able to nevertheless use the authors in the |
| 112 |
% xmp-metadata we map \cs{@author} to this new command. |
| 113 |
% |
| 114 |
% \begin{macrocode} |
| 115 |
\AddToHook{class/amsart/after} |
| 116 |
{\def\@author{\authors}} |
| 117 |
\AddToHook{class/amsbook/after} |
| 118 |
{\def\@author{\authors}} |
| 119 |
\AddToHook{class/amsproc/after} |
| 120 |
{\def\@author{\authors}} |
| 121 |
% \end{macrocode} |
| 122 |
% |
| 123 |
% \subsection{ams classes and amsthm} |
| 124 |
% The amsart, amsbook and amsproc classes redefine the theorem code |
| 125 |
% and this breaks the tagging added by the block code. The following |
| 126 |
% reenables tagging. It does \emph{not} give a completly identical output |
| 127 |
% (similar to the new theorem code, |
| 128 |
% see \url{https://github.com/latex3/tagging-project/issues/715}). |
| 129 |
% The code also does not try to use sockets yet, as the theorem definitions |
| 130 |
% in the block code don't do that yet either. |
| 131 |
% \changes{0.85l}{2025-07-02}{Removed \cs{tag_if_active} test, this errors with tagging=off} |
| 132 |
% \begin{macrocode} |
| 133 |
\AddToHook{class/amsart/after}[latex-lab-testphase-firstaid/amsthm] |
| 134 |
{\@@_firstaid_amsthm:\@@_firstaid_ams_abstract:} |
| 135 |
\AddToHook{class/amsbook/after}[latex-lab-testphase-firstaid/amsthm] |
| 136 |
{\@@_firstaid_amsthm:\@@_firstaid_ams_abstract:} |
| 137 |
\AddToHook{class/amsproc/after}[latex-lab-testphase-firstaid/amsthm] |
| 138 |
{\@@_firstaid_amsthm:} |
| 139 |
\AddToHook{package/amsthm/after}[latex-lab-testphase-firstaid/amsthm] |
| 140 |
{\@@_firstaid_amsthm:} |
| 141 |
% \end{macrocode} |
| 142 |
% |
| 143 |
% \changes{v0.85i}{2025/01/26}{Add missing \cs{par} to abstract env (gh/1641)} |
| 144 |
% \begin{macrocode} |
| 145 |
\cs_new_protected:Npn \@@_firstaid_ams_abstract: |
| 146 |
{ |
| 147 |
\renewenvironment{abstract}{% |
| 148 |
\ifx\maketitle\relax |
| 149 |
\ClassWarning{\@classname}{Abstract~ should~ precede~ |
| 150 |
\protect\maketitle\space in~ AMS~ document~ classes;~ reported}% |
| 151 |
\fi |
| 152 |
\global\setbox\abstractbox=\vtop \bgroup |
| 153 |
\normalfont\Small |
| 154 |
\list{}{\labelwidth\z@ |
| 155 |
\leftmargin3pc \rightmargin\leftmargin |
| 156 |
\listparindent\normalparindent \itemindent\z@ |
| 157 |
\parsep\z@ \@plus\p@ |
| 158 |
\let\fullwidthdisplay\relax |
| 159 |
}% |
| 160 |
\item[\hskip\labelsep\scshape\abstractname.]% |
| 161 |
}{% |
| 162 |
\endlist |
| 163 |
\par % <--- added |
| 164 |
\egroup |
| 165 |
\ifx\@setabstract\relax \@setabstracta \fi |
| 166 |
} |
| 167 |
} |
| 168 |
% \end{macrocode} |
| 169 |
% \changes{v0.85h}{2024/10/16}{moved Caption tag into \@begintheorem, tagging issue\#733} |
| 170 |
% \changes{0.85l}{2025-07-02}{guard the \cs{tagpdfparaOn} commands.} |
| 171 |
% \begin{macrocode} |
| 172 |
\cs_new_protected:Npn \@@_firstaid_amsthm: |
| 173 |
{ |
| 174 |
% \end{macrocode} |
| 175 |
% \cs{@endtheorem} must use the endblock code |
| 176 |
% \begin{macrocode} |
| 177 |
\def\@endtheorem{\endblockenv} |
| 178 |
% \end{macrocode} |
| 179 |
% In \cs{@thm} we have to remove the \cs{trivlist} |
| 180 |
% \begin{macrocode} |
| 181 |
\RenewDocumentCommand\@thm{mmmO{}}{% |
| 182 |
\ifhmode\unskip\unskip\par\fi |
| 183 |
\normalfont |
| 184 |
\let\thmheadnl\relax |
| 185 |
\let\thm@swap\@gobble |
| 186 |
\thm@notefont{\fontseries\mddefault\upshape}% |
| 187 |
\thm@headpunct{.}% add period after heading |
| 188 |
\thm@headsep 5\p@ plus\p@ minus\p@\relax |
| 189 |
\thm@space@setup |
| 190 |
##1% style overrides |
| 191 |
\@topsep \thm@preskip % used by thm head |
| 192 |
\@topsepadd \thm@postskip % used by \@endparenv |
| 193 |
% \end{macrocode} |
| 194 |
% We store the counter name so that the anchor can make use of it. |
| 195 |
% \begin{macrocode} |
| 196 |
\tl_set:Nn \l__block_thm_current_counter_tl{##2} |
| 197 |
\tl_if_empty:nTF{##2} |
| 198 |
{ |
| 199 |
\@begintheorem{##3}{}[##4] |
| 200 |
} |
| 201 |
{ |
| 202 |
\@kernel@refstepcounter{##2} |
| 203 |
\@begintheorem{##3}{\csname the##2\endcsname}[##4] |
| 204 |
} |
| 205 |
} |
| 206 |
% \end{macrocode} |
| 207 |
% \cs{@begintheorem} has a larger number of changes |
| 208 |
% \begin{macrocode} |
| 209 |
\def\@begintheorem##1##2[##3]{% |
| 210 |
% \end{macrocode} |
| 211 |
% We use the theorem instance. |
| 212 |
% \changes{v0.85h}{2024/10/16}{Added pre and post skips tagging/733} |
| 213 |
% \begin{macrocode} |
| 214 |
\UseInstance{blockenv}{theorem}{begin-vspace=\thm@preskip} |
| 215 |
% \end{macrocode} |
| 216 |
% There is no working key to set the endskip, so we set the skip directly |
| 217 |
% similar to what amsthm is doing after the \cs{trivlist}. |
| 218 |
% \begin{macrocode} |
| 219 |
\skip_set:Nn\l__block_topsepadd_skip { \thm@postskip } |
| 220 |
% \end{macrocode} |
| 221 |
% While create the caption/label we disable para-tagging. |
| 222 |
% \changes{0.85m}{2025-07-27}{Use tagging sockets} |
| 223 |
% \begin{macrocode} |
| 224 |
\tag_socket_use:n {para/off} |
| 225 |
\group_begin: |
| 226 |
\normalfont |
| 227 |
\the\thm@headfont \thm@indent |
| 228 |
% \end{macrocode} |
| 229 |
% The anchor for links. It must be inserted when we have started hmode |
| 230 |
% (which happens with \cs{thm@indent}). \pkg{amsthm} allows for unnumbered |
| 231 |
% theorems so we have to test for an empty counter. |
| 232 |
% \changes{v0.85h}{2024/10/16}{add test if counter is empty |
| 233 |
% tagging/736} |
| 234 |
% \changes{v0.85i}{2024/11/23}{Do not use \cs{leavevmode} but wait |
| 235 |
% for hmode to add the link target} |
| 236 |
% \begin{macrocode} |
| 237 |
\tl_if_empty:NTF \l__block_thm_current_counter_tl |
| 238 |
{\MakeLinkTarget[theorem]{}} |
| 239 |
{\MakeLinkTarget{\l__block_thm_current_counter_tl}} |
| 240 |
\@ifempty{##1} |
| 241 |
{\let\thmname\@gobble} |
| 242 |
% \end{macrocode} |
| 243 |
% we insert the MC and the Lbl structure into \cs{thmname}, |
| 244 |
% \cs{thmnumber} and \cs{thmnote}. This will also work |
| 245 |
% with new theorem style as long as they use these command. |
| 246 |
% \begin{macrocode} |
| 247 |
{\def\thmname####1{\tag_socket_use:nnn {mc}{}{####1}}}% |
| 248 |
\@ifempty{##2} |
| 249 |
{\let\thmnumber\@gobble} |
| 250 |
{\def\thmnumber####1 |
| 251 |
{\tag_socket_use:nnn{struct-mc}{tag=Lbl}{####1}} |
| 252 |
}% |
| 253 |
\@ifempty{##3} |
| 254 |
{\let\thmnote\@gobble} |
| 255 |
{\def\thmnote####1{\tag_socket_use:nnn {mc}{}{####1}}}% |
| 256 |
\tag_socket_use:nnn{block/theorem/caption}{} |
| 257 |
{ |
| 258 |
\thm@swap\swappedhead\thmhead{##1}{##2}{##3}% |
| 259 |
\tag_socket_use:nnn {mc}{}{\the\thm@headpunct} |
| 260 |
} |
| 261 |
\thmheadnl % possibly a newline. |
| 262 |
\group_end: |
| 263 |
% \end{macrocode} |
| 264 |
% Now we restart para tagging and start a paragraph. |
| 265 |
% \changes{0.85m}{2025-07-27}{Use a tagging socket} |
| 266 |
% \changes{0.85m}{2025-07-27}{move \cs{thm@headsep}, tagging issue 835} |
| 267 |
% \begin{macrocode} |
| 268 |
\tag_socket_use:n {para/on} |
| 269 |
\tag_socket_use:n {para/begin} |
| 270 |
\hskip\thm@headsep |
| 271 |
\ignorespaces} |
| 272 |
% \end{macrocode} |
| 273 |
% This redefines the standard styles for the theorem heads. |
| 274 |
% \cs{thm@headpunct} has been moved into the head code |
| 275 |
% to make tagging more easier. |
| 276 |
% \begin{macrocode} |
| 277 |
\def\thmhead@plain##1##2##3{% |
| 278 |
\thmname{##1} |
| 279 |
\thmnumber{ |
| 280 |
\@ifnotempty{##1}{~}\@upn{##2} |
| 281 |
}% |
| 282 |
\thmnote{\pdffakespace\space{\the\thm@notefont(##3)}} |
| 283 |
} |
| 284 |
\let\thmhead\thmhead@plain |
| 285 |
\def\swappedhead##1##2##3{% |
| 286 |
\thmnumber{##2} |
| 287 |
\thmname{\@ifnotempty{##2}{\nobreakspace}##1} |
| 288 |
\thmnote{\pdffakespace\space{\the\thm@notefont(##3)}} |
| 289 |
} |
| 290 |
\let\swappedhead@plain=\swappedhead |
| 291 |
% \end{macrocode} |
| 292 |
% At last some adjustments for the proof environment. |
| 293 |
% The qed symbols use a drawn box by default. We add an actualtext. |
| 294 |
% \begin{macrocode} |
| 295 |
\renewcommand{\openbox}{\leavevmode |
| 296 |
\hbox to.77778em{\pdf_bdc:nn{Span}{/ActualText<FEFF220E>}% |
| 297 |
\pdffakespace\hfil\vrule |
| 298 |
\vbox to.675em{\hrule width.6em\vfil\hrule}% |
| 299 |
\vrule\hfil\pdf_emc:}} |
| 300 |
% \end{macrocode} |
| 301 |
% And redefine proof to no longer use a trivlist. |
| 302 |
% \begin{macrocode} |
| 303 |
\renewenvironment{proof}[1][\proofname]{\par |
| 304 |
\pushQED{\qed}% |
| 305 |
\UseInstance{blockenv}{theorem}{begin-vspace=6\p@\@plus6\p@} |
| 306 |
\normalfont |
| 307 |
% \end{macrocode} |
| 308 |
% \changes{0.85m}{2025-07-27}{Use a tagging socket} |
| 309 |
% \begin{macrocode} |
| 310 |
\tag_socket_use:n {para/off} |
| 311 |
\AddToHookNext{para/begin} |
| 312 |
{ |
| 313 |
\tag_socket_use:nnn{block/theorem/caption}{} |
| 314 |
{ |
| 315 |
\tag_socket_use:nnn {mc}{} |
| 316 |
{\textit{##1\@addpunct{.}}} |
| 317 |
} |
| 318 |
% \end{macrocode} |
| 319 |
% If tagging is not active, we avoid reenabling paratagging as this leads to warnings. |
| 320 |
% \changes{0.85m}{2025-07-27}{Use a tagging socket} |
| 321 |
% \begin{macrocode} |
| 322 |
\tag_socket_use:n {para/on} |
| 323 |
\tag_socket_use:n {para/begin} |
| 324 |
\pdffakespace\hspace{\labelsep}} |
| 325 |
\ignorespaces |
| 326 |
}{% |
| 327 |
\popQED\endblockenv\par |
| 328 |
} |
| 329 |
} |
| 330 |
\ExplSyntaxOff |
| 331 |
% \end{macrocode} |
| 332 |
% |
| 333 |
% \subsection{verse} |
| 334 |
% |
| 335 |
% The \pkg{verse} package has its own definition of the |
| 336 |
% \env{verse} environment, which would tag correctly, except that |
| 337 |
% it is overwritten by the block code in the hook |
| 338 |
% \texttt{begindocument/before}. So the simplest way to make |
| 339 |
% tagging work is to reinstall the package version afterwards, |
| 340 |
% which is what we are doing here. |
| 341 |
% \begin{macrocode} |
| 342 |
\AddToHook{package/verse/after}[latex-lab-firstaid]{% |
| 343 |
\FirstAidNeededT{verse}{sty}{2014/05/10 v2.4b verse typesetting}% |
| 344 |
{% |
| 345 |
\AtBeginDocument{% |
| 346 |
\renewenvironment{verse}[1][\linewidth]{% |
| 347 |
\stepcounter{verse@envctr}% |
| 348 |
\setcounter{poemline}{0}\refstepcounter{poemline}% |
| 349 |
\setcounter{vslineno}{1}% |
| 350 |
\let\\=\@vscentercr |
| 351 |
\list{}{\itemsep \z@ |
| 352 |
\itemindent -\vindent |
| 353 |
\listparindent\itemindent |
| 354 |
\parsep \stanzaskip |
| 355 |
\ifdim #1 < \linewidth |
| 356 |
\rightmargin \z@ |
| 357 |
\setlength{\leftmargin}{\linewidth}% |
| 358 |
\addtolength{\leftmargin}{-#1}% |
| 359 |
\addtolength{\leftmargin}{-0.5\leftmargin}% |
| 360 |
\else |
| 361 |
\rightmargin \leftmargin |
| 362 |
\fi |
| 363 |
\addtolength{\leftmargin}{\vindent}}% |
| 364 |
\item[]% |
| 365 |
}% |
| 366 |
{\endlist}% |
| 367 |
}% |
| 368 |
}% |
| 369 |
} |
| 370 |
% \end{macrocode} |
| 371 |
% Of course, this means that the |
| 372 |
% optional argument of the environment then only accepts a length |
| 373 |
% value and not any more a key value list for altering the |
| 374 |
% environment settings. |
| 375 |
% |
| 376 |
% A more elabroate version could be something like this that allows |
| 377 |
% key/val and legacy interface. Or one could extend the list |
| 378 |
% template to support a \texttt{list-width} key. |
| 379 |
%\begin{verbatim} |
| 380 |
% \ExplSyntaxOn |
| 381 |
% \cs_new_protected:Npn \ExtractAndDropKey #1#2#3#4#5 { |
| 382 |
% \tl_set_eq:NN #4 \c_novalue_tl % or empty? |
| 383 |
% \keys_define:nn { #1 } { #2 .code:n = \tl_set:Nn #4{##1} } |
| 384 |
% \keys_set_known:nnN { #1 } { #3 } #5 |
| 385 |
% } |
| 386 |
% \ExplSyntaxOff |
| 387 |
% |
| 388 |
% % Change the env definition for verse matching verse.sty |
| 389 |
% % This keeps the verse.sty interface as it is and only adjusts the |
| 390 |
% % main environment to use the basic list env with the verse.sty |
| 391 |
% % specific settings. |
| 392 |
% \makeatletter |
| 393 |
% |
| 394 |
% \AddToHook{package/verse/after}{% |
| 395 |
% \AtBeginDocument{% |
| 396 |
% \RenewDocumentEnvironment{verse}{={verse-width}!O{\linewidth}}% |
| 397 |
% {% |
| 398 |
% \stepcounter{verse@envctr}% |
| 399 |
% \setcounter{poemline}{0}\refstepcounter{poemline}% |
| 400 |
% \setcounter{vslineno}{1}% |
| 401 |
% \let\\=\@vscentercr |
| 402 |
% % |
| 403 |
% \ExtractAndDropKey{verse}{verse-width}{#1}\@vswidth\@vsremainingkvlist |
| 404 |
% % If other keys have been specified but not verse-width we have no |
| 405 |
% % default for \@vswidth and need to set it again |
| 406 |
% \ExpandArgs{o}\IfNoValueT \@vswidth |
| 407 |
% {\def\@vswidth{\linewidth}}% |
| 408 |
% % |
| 409 |
% % This is a bit ugly but we can't stick \cs{@vsremainingkvlist} into |
| 410 |
% % the instance argument as keys are expected to be visible on |
| 411 |
% % top-level not hidden inside a macro. The alternative is to push |
| 412 |
% % in \verb=#1= but then the key/value \verb/verse-width=.../ is |
| 413 |
% % passed into the instance which is not known there (not harmful as |
| 414 |
% % it will get ignored but noticeably more and unnecessary |
| 415 |
% % processing). |
| 416 |
% % |
| 417 |
% \def\next##1{% |
| 418 |
% \UseInstance{blockenv}{list}% |
| 419 |
% {% |
| 420 |
% item-indent = -\vindent,% |
| 421 |
% para-indent = -\vindent,% |
| 422 |
% para-vspace = \stanzaskip,% |
| 423 |
% item-skip = 0pt,% |
| 424 |
% left-margin = (\linewidth-\@vswidth)/2+\vindent,% |
| 425 |
% right-margin = \ifdim\@vswidth<\linewidth 0pt |
| 426 |
% \else (\linewidth-\@vswidth)/2\fi,% |
| 427 |
% ##1% |
| 428 |
% }}% |
| 429 |
% \ExpandArgs{o}\next\@vsremainingkvlist |
| 430 |
% \item\relax |
| 431 |
% }{\endblockenv}% |
| 432 |
% }% |
| 433 |
% } |
| 434 |
% \makeatother |
| 435 |
%\end{verbatim} |
| 436 |
% |
| 437 |
% |
| 438 |
% \subsection{cleveref} |
| 439 |
% |
| 440 |
% The cleveref package redefines \cs{@makefntext} and this means that the patches in |
| 441 |
% the new footnote code fails. We use a hook instead. |
| 442 |
% \changes{v0.85h}{2024/10/16}{Remove redefinition of refstepcounter. It no longer uses |
| 443 |
% the hook.} |
| 444 |
% \begin{macrocode} |
| 445 |
\AddToHook{package/cleveref/after} |
| 446 |
{ |
| 447 |
\let\@makefntext\cref@old@makefntext |
| 448 |
\AddToHook{cmd/@makefntext/before}{% |
| 449 |
\cref@constructprefix{footnote}{\cref@result}% |
| 450 |
\protected@edef\cref@currentlabel{% |
| 451 |
[footnote][\arabic{footnote}][\cref@result]% |
| 452 |
\p@footnote\@thefnmark}} |
| 453 |
} |
| 454 |
% \end{macrocode} |
| 455 |
% |
| 456 |
% \subsection{booktabs} |
| 457 |
% In some cases booktabs inserts a |
| 458 |
% \cs{multispan} into the table (through the commands \cs{@cmidruleb} |
| 459 |
% and \cs{@cmidrulea} and this then errors |
| 460 |
% with the tagging code. |
| 461 |
% This affects both tabular and longtable |
| 462 |
% (but longtable more as booktabs handles lines in longtable differently). |
| 463 |
% See also issue \url{https://github.com/latex3/tagging-project/issues/69} |
| 464 |
% |
| 465 |
% |
| 466 |
% \begin{macrocode} |
| 467 |
\ExplSyntaxOn |
| 468 |
\AddToHook{package/booktabs/after} |
| 469 |
{ |
| 470 |
\def\@cmidrulea{ |
| 471 |
\multispan\@cmidla |
| 472 |
&\multispan\@cmidlb |
| 473 |
\unskip\hskip\cmrkern@l |
| 474 |
{ |
| 475 |
\tag_mc_begin:n{artifact} |
| 476 |
\CT@arc@\leaders\hrule \@height\@thisrulewidth\hfill\kern\z@} |
| 477 |
\hskip\cmrkern@r |
| 478 |
\tag_mc_end: \int_gdecr:N \g__tbl_row_int |
| 479 |
\cr} |
| 480 |
|
| 481 |
\def\@cmidruleb{% |
| 482 |
\multispan\@cmidlb |
| 483 |
\unskip\hskip \cmrkern@l% |
| 484 |
{ |
| 485 |
\tag_mc_begin:n{artifact} |
| 486 |
\CT@arc@\leaders\hrule \@height\@thisrulewidth\hfill\kern\z@} |
| 487 |
\hskip\cmrkern@r |
| 488 |
\tag_mc_end: \int_gdecr:N \g__tbl_row_int |
| 489 |
\cr} |
| 490 |
} |
| 491 |
\ExplSyntaxOff |
| 492 |
% \end{macrocode} |
| 493 |
|
| 494 |
% |
| 495 |
% \subsection{fancyvrb} |
| 496 |
% The firstaid adds first partial tagging support to the environments |
| 497 |
% of fancyvrb (inline verbatim is untested). |
| 498 |
% This supports then also packages like minted which internally uses fancyvrb |
| 499 |
% and classes like l3doc (where currently the verbatim environment based on fancyvrb |
| 500 |
% is overwritten by the block code). |
| 501 |
% The environments are surrounded by a \texttt{verbatim} structure, |
| 502 |
% every line by a \texttt{codeline} |
| 503 |
% structure (this requires the block code, but firstaid should be used only with |
| 504 |
% phase-III anyway). Line numbers are tagged as Lbl, inside of the |
| 505 |
% \texttt{codeline} structure. The frame lines are marked as artifact. |
| 506 |
% |
| 507 |
% \begin{macro}[no-user-doc]{\FV@LeaveVMode} |
| 508 |
% If we are in vmode we have to open a text-unit structure, if we are |
| 509 |
% in hmode we have to set para mode to flattened before the fancyhdr code |
| 510 |
% issues the\cs{par}. The closing of the text-unit structure is handled by the |
| 511 |
% doendpe code in the block code. |
| 512 |
% \begin{macrocode} |
| 513 |
\ExplSyntaxOn |
| 514 |
\AddToHook{package/fancyvrb/after} |
| 515 |
{ |
| 516 |
\def\FV@LeaveVMode{% |
| 517 |
\if@noskipsec |
| 518 |
\leavevmode |
| 519 |
\else |
| 520 |
\if@FV@ResetMargins\if@inlabel\leavevmode\fi\fi |
| 521 |
\fi |
| 522 |
\ifvmode |
| 523 |
\@noparlisttrue |
| 524 |
\__tag_gincr_para_main_begin_int: |
| 525 |
\tag_struct_begin:n{tag=\l__tag_para_main_tag_tl} |
| 526 |
\else |
| 527 |
\bool_set_true:N\l__tag_para_flattened_bool |
| 528 |
\@noparlistfalse |
| 529 |
\unskip\par |
| 530 |
\fi |
| 531 |
} |
| 532 |
% \end{macrocode} |
| 533 |
% \end{macro} |
| 534 |
% |
| 535 |
% \begin{macro}[no-user-doc]{\FV@List} |
| 536 |
% At the begin of the list code we have to tag the frame as artifact |
| 537 |
% and start the \texttt{verbatim} structure |
| 538 |
% \begin{macrocode} |
| 539 |
\def\FV@List#1{% |
| 540 |
\begingroup |
| 541 |
\FV@UseKeyValues |
| 542 |
\FV@LeaveVMode |
| 543 |
\if@inlabel\else\setbox\@labels=\box\voidb@x\fi |
| 544 |
\FV@ListNesting{#1}% |
| 545 |
\FV@ListParameterHook |
| 546 |
\FV@ListVSpace |
| 547 |
\FV@SetLineWidth |
| 548 |
\FV@InterLinePenalty |
| 549 |
\let\FV@ProcessLine\FV@ListProcessLine@i |
| 550 |
\FV@CatCodes |
| 551 |
\FV@FormattingPrep |
| 552 |
\FV@ObeyTabsInit |
| 553 |
\cs_if_exist:NT \FV@BeginListFrame |
| 554 |
{ |
| 555 |
\tag_mc_begin:n{artifact} |
| 556 |
\FV@BeginListFrame |
| 557 |
\tag_mc_end: |
| 558 |
} |
| 559 |
\tag_struct_begin:n{tag=verbatim} |
| 560 |
} |
| 561 |
% \end{macrocode} |
| 562 |
% \end{macro} |
| 563 |
% \begin{macro}[no-user-doc]{\FV@EndList} |
| 564 |
% At the end of the list code we close the \texttt{verbatim} structure and |
| 565 |
% tag the frame as artifact. |
| 566 |
% \begin{macrocode} |
| 567 |
\def\FV@EndList{% |
| 568 |
\FV@ListProcessLastLine |
| 569 |
\tag_struct_end: |
| 570 |
\cs_if_exist:NT \FV@EndListFrame |
| 571 |
{ |
| 572 |
\tag_mc_begin:n{artifact} |
| 573 |
\FV@EndListFrame |
| 574 |
\tag_mc_end: |
| 575 |
} |
| 576 |
\@endparenv |
| 577 |
\endgroup |
| 578 |
\@endpetrue |
| 579 |
} |
| 580 |
% \end{macrocode} |
| 581 |
% \end{macro} |
| 582 |
% |
| 583 |
% \begin{macro}[no-user-doc]{\FV@ListProcessLine} |
| 584 |
% At last the tagging of the code lines. Here we have to tag also |
| 585 |
% numbers and frame parts if they exist. |
| 586 |
% \begin{macrocode} |
| 587 |
\def\FV@ListProcessLine#1{% |
| 588 |
\hbox to \hsize{% |
| 589 |
\kern\leftmargin |
| 590 |
\hbox to \linewidth{% |
| 591 |
\tag_struct_begin:n{tag=codeline} |
| 592 |
\cs_if_exist:NT \FV@LeftListNumber |
| 593 |
{ |
| 594 |
\tag_struct_begin:n{tag=Lbl} |
| 595 |
\tag_mc_begin:n{} |
| 596 |
\FV@LeftListNumber |
| 597 |
\tag_mc_end: |
| 598 |
\tag_struct_end: |
| 599 |
} |
| 600 |
\cs_if_exist:NT \FV@LeftListFrame |
| 601 |
{ |
| 602 |
\tag_mc_begin:n{artifact} |
| 603 |
\FV@LeftListFrame |
| 604 |
\tag_mc_end: |
| 605 |
} |
| 606 |
\tag_mc_begin:n{}% |
| 607 |
\FancyVerbFormatLine{#1}% |
| 608 |
\tag_mc_end: |
| 609 |
\tag_struct_end:\hss |
| 610 |
\cs_if_exist:NT \FV@RightListFrame |
| 611 |
{ |
| 612 |
\tag_mc_begin:n{artifact} |
| 613 |
\FV@RightListFrame |
| 614 |
\tag_mc_end: |
| 615 |
} |
| 616 |
\cs_if_exist:NT \FV@RightListNumber |
| 617 |
{ |
| 618 |
\tag_struct_begin:n{tag=Lbl} |
| 619 |
\tag_mc_begin:n{} |
| 620 |
\FV@RightListNumber |
| 621 |
\tag_mc_begin:n{} |
| 622 |
\tag_struct_end: |
| 623 |
} |
| 624 |
} |
| 625 |
\hss}} |
| 626 |
} |
| 627 |
\ExplSyntaxOff |
| 628 |
% \end{macrocode} |
| 629 |
% |
| 630 |
% \subsection{The \pkg{microtype} package first aid} |
| 631 |
% |
| 632 |
% The microtype package fails in kernel 2025/11 if tagging is active as due to the |
| 633 |
% change to \cs{partokencontext} para tagging is triggered and then is unbalanced in |
| 634 |
% an unwanted place. We disable the tagging in this command. |
| 635 |
% \changes{v0.85o}{2025/11/03}{Fix microtype to work with tagging 2025/11 kernel |
| 636 |
% https://github.com/schlcht/microtype/issues/59} |
| 637 |
% \begin{macrocode} |
| 638 |
\AddToHook{package/microtype/after}[firstaid]{% |
| 639 |
\FirstAidNeededT{microtype}{sty}{2025/07/09 v3.2b |
| 640 |
Micro-typographical refinements |
| 641 |
(RS)} |
| 642 |
{% |
| 643 |
\def\MT@get@prot#1#2{% |
| 644 |
\begingroup |
| 645 |
\SuspendTagging{\MT@get@prot}%%added by firstaid |
| 646 |
\setbox\MT@tempbox\vbox{% |
| 647 |
\everypar{}% |
| 648 |
\parfillskip=\z@skip |
| 649 |
\hbadness\@M |
| 650 |
\clubpenalty\z@ |
| 651 |
\widowpenalty\z@ |
| 652 |
\interlinepenalty\z@ |
| 653 |
\@newlistfalse |
| 654 |
\MT@prot@hook |
| 655 |
\begingroup |
| 656 |
\MT@noindent #1\relax\MT@csq@eqgroup |
| 657 |
\endgroup}% |
| 658 |
\vbadness=\@M |
| 659 |
\splittopskip=\z@ |
| 660 |
\vfuzz=\maxdimen |
| 661 |
\setbox\MT@tempbox\vbox{% |
| 662 |
\ifvbox\MT@tempbox |
| 663 |
\global\setbox\MT@tempbox=\vsplit\MT@tempbox to \normalbaselineskip |
| 664 |
\unvbox\MT@tempbox |
| 665 |
\global\setbox\MT@tempbox=\lastbox |
| 666 |
\fi |
| 667 |
}% |
| 668 |
\endgroup |
| 669 |
\ifhbox\MT@tempbox |
| 670 |
\@tempdima=\@nameuse{#2marginkern}\MT@tempbox\relax |
| 671 |
\expandafter\ifdim\@tempdima=\z@ \else |
| 672 |
\leavevmode |
| 673 |
\MT@vinfo{|<< adding #2 margin kern for `#1':\MessageBreak |
| 674 |
\the\@tempdima \on@line}% |
| 675 |
\kern\@tempdima |
| 676 |
\fi |
| 677 |
\fi |
| 678 |
}} |
| 679 |
} |
| 680 |
% \end{macrocode} |
| 681 |
% \end{macro} |
| 682 |
% \begin{macrocode} |
| 683 |
%</package> |
| 684 |
% \end{macrocode} |
| 685 |
% |
| 686 |
% |
| 687 |
% \begin{macrocode} |
| 688 |
%<*latex-lab> |
| 689 |
\ProvidesFile{firstaid-latex-lab-testphase.ltx} |
| 690 |
[\ltlabfirstaiddate\space v\ltlabfirstaidversion\space |
| 691 |
latex-lab wrapper firstaid] |
| 692 |
|
| 693 |
\RequirePackage{latex-lab-testphase-firstaid} |
| 694 |
|
| 695 |
%</latex-lab> |
| 696 |
% \end{macrocode} |