| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
%% File: latex-lab-l3doc-tagging.dtx |
| 4 |
% Copyright (C) 2022-2026 The LaTeX Project |
| 5 |
% |
| 6 |
% It may be distributed and/or modified under the conditions of the |
| 7 |
% LaTeX Project Public License (LPPL), either version 1.3c of this |
| 8 |
% license or (at your option) any later version. The latest version |
| 9 |
% of this license is in the file |
| 10 |
% |
| 11 |
% https://www.latex-project.org/lppl.txt |
| 12 |
% |
| 13 |
% |
| 14 |
% The latex-lab bundle is developed in the LaTeX2e GitHub. |
| 15 |
% Issues may be reported at |
| 16 |
% |
| 17 |
% https://github.com/latex3/latex2e/issues |
| 18 |
% |
| 19 |
\def\ltlabdoctaggingdate{2026-04-28} |
| 20 |
\def\ltlabdoctaggingversion{0.80j} |
| 21 |
|
| 22 |
%<*driver> |
| 23 |
\DocumentMetadata |
| 24 |
{ |
| 25 |
lang=en, |
| 26 |
pdfstandard=ua-2, |
| 27 |
tagging=on |
| 28 |
} |
| 29 |
\tagpdfsetup{table/header-rows=1} |
| 30 |
\documentclass{l3in2edoc} |
| 31 |
|
| 32 |
\EnableCrossrefs |
| 33 |
\CodelineIndex |
| 34 |
\ProvideDocElement[envlike, idxtype=instance, idxgroup=instances, |
| 35 |
printtype=\textit{inst.}] {Instance}{instance} |
| 36 |
|
| 37 |
\begin{document} |
| 38 |
\DocInput{latex-lab-l3doc-tagging.dtx} |
| 39 |
\end{document} |
| 40 |
%</driver> |
| 41 |
% |
| 42 |
% \fi |
| 43 |
% |
| 44 |
% |
| 45 |
% \title{The \texttt{latex-lab-testphase-l3doc} package\thanks{}} |
| 46 |
% \author{Ulrike Fischer, \LaTeX{} Project} |
| 47 |
% |
| 48 |
% \maketitle |
| 49 |
% |
| 50 |
% \tableofcontents |
| 51 |
% |
| 52 |
% \begin{documentation} |
| 53 |
% \section{Introduction} |
| 54 |
% |
| 55 |
% This package provides tagging support for the l3doc class. |
| 56 |
% It is work in progress. It is neither guarantied that every element |
| 57 |
% is correctly tagged nor that the output looks identical to the untagged version. |
| 58 |
% |
| 59 |
% If a documentation is tagged with this code, it is important to check the log-file |
| 60 |
% for warnings, the tag structure for missing parts and the output for deviations! |
| 61 |
% |
| 62 |
% Feedback at \url{https://github.com/latex3/tagging-project} is welcome! |
| 63 |
% |
| 64 |
% TODO: Index? |
| 65 |
% |
| 66 |
% \end{documentation} |
| 67 |
% |
| 68 |
% \begin{implementation} |
| 69 |
% \section{implementation} |
| 70 |
% |
| 71 |
% \begin{macrocode} |
| 72 |
%<*package> |
| 73 |
% \end{macrocode} |
| 74 |
% |
| 75 |
% \subsection{Declaration} |
| 76 |
% |
| 77 |
% \begin{macrocode} |
| 78 |
\ProvidesExplPackage {latex-lab-testphase-l3doc} {\ltlabdoctaggingdate} {\ltlabdoctaggingversion} |
| 79 |
{ Tagging Support for the l3doc class } |
| 80 |
% \end{macrocode} |
| 81 |
% some minimal error checking |
| 82 |
% \begin{macrocode} |
| 83 |
\IfClassLoadedF{l3doc} |
| 84 |
{\PackageError{latex-lab-testphase-l3doc}{This~package~requires~the~l3doc~class!}{}} |
| 85 |
% \end{macrocode} |
| 86 |
% |
| 87 |
% \begin{macrocode} |
| 88 |
\IfDocumentMetadataF |
| 89 |
{\PackageError{latex-lab-testphase-l3doc}{This~package~requires~\textbackslash DocumentMetadata}{}} |
| 90 |
% \end{macrocode} |
| 91 |
% |
| 92 |
% \subsection{Tag and roles} |
| 93 |
% |
| 94 |
% The exact tagging structure is not yet clear. Especially for verbatim and |
| 95 |
% code material. So we define roles that we can exchange when needed. |
| 96 |
|
| 97 |
% \begin{macrocode} |
| 98 |
\tagpdfsetup |
| 99 |
{ |
| 100 |
role/new-tag=function/Sect, |
| 101 |
role/new-tag=functionnames/Caption, |
| 102 |
role/new-tag=functionname/Code, |
| 103 |
role/new-tag=functionnamepart/Span, |
| 104 |
role/new-tag=syntax/Sect, |
| 105 |
role/new-tag=function-description/Div, |
| 106 |
role/new-tag=macro/Sect, |
| 107 |
role/new-tag=macronames/Caption, |
| 108 |
role/new-tag=macroname/Span, |
| 109 |
role/new-tag=variable/Sect, |
| 110 |
role/new-tag=variablenames/Caption, |
| 111 |
role/new-tag=variablename/Span, |
| 112 |
role/new-tag=codelinenum/Span, |
| 113 |
% role/new-tag=part/H1 %??????? |
| 114 |
} |
| 115 |
|
| 116 |
\NewStructureName{doc/function} |
| 117 |
\AssignStructureRole{doc/function}{function} |
| 118 |
\NewStructureName{doc/functionnames} |
| 119 |
\AssignStructureRole{doc/functionnames}{functionnames} |
| 120 |
\NewStructureName{doc/functionname} |
| 121 |
\AssignStructureRole{doc/functionname}{functionname} |
| 122 |
\NewStructureName{doc/functionnamepart} |
| 123 |
\AssignStructureRole{doc/functionnamepart}{functionnamepart} |
| 124 |
\NewStructureName{doc/syntax} |
| 125 |
\AssignStructureRole{doc/syntax}{syntax} |
| 126 |
\NewStructureName{doc/function-description} |
| 127 |
\AssignStructureRole{doc/function-description}{function-description} |
| 128 |
\NewStructureName{doc/macro} |
| 129 |
\AssignStructureRole{doc/macro}{macro} |
| 130 |
\NewStructureName{doc/macronames} |
| 131 |
\AssignStructureRole{doc/macronames}{macronames} |
| 132 |
\NewStructureName{doc/macroname} |
| 133 |
\AssignStructureRole{doc/macroname}{macroname} |
| 134 |
\NewStructureName{doc/variable} |
| 135 |
\AssignStructureRole{doc/variable}{variable} |
| 136 |
\NewStructureName{doc/variablenames} |
| 137 |
\AssignStructureRole{doc/variablenames}{variablenames} |
| 138 |
\NewStructureName{doc/variablename} |
| 139 |
\AssignStructureRole{doc/variablename}{variablename} |
| 140 |
\NewStructureName{doc/codelinenum} |
| 141 |
\AssignStructureRole{doc/codelinenum}{codelinenum} |
| 142 |
\NewStructureName{doc/codeline} |
| 143 |
\AssignStructureRole{doc/codeline}{codeline} |
| 144 |
|
| 145 |
% \end{macrocode} |
| 146 |
% |
| 147 |
% \subsection{Variables} |
| 148 |
% |
| 149 |
% |
| 150 |
% \begin{variable}{\l__codedoc_current_names_struct_tl} |
| 151 |
% The structure around the command names in the margin must be moved around. |
| 152 |
% For this we define a variable that will hold the relevant current structure. |
| 153 |
% \begin{macrocode} |
| 154 |
\tl_new:N\l__codedoc_current_names_struct_tl |
| 155 |
% \end{macrocode} |
| 156 |
% \end{variable} |
| 157 |
% |
| 158 |
% \begin{variable}{\g__codedoc_macroname_structnum_seq} |
| 159 |
% This holds the structure numbers of the |
| 160 |
% structure around every command name in a macro environment. As the |
| 161 |
% structures are created inside a box this is a global variable, which is cleared |
| 162 |
% at the end of the outer macro environment. |
| 163 |
% \begin{macrocode} |
| 164 |
\seq_new:N\g__codedoc_macroname_structnum_seq |
| 165 |
% \end{macrocode} |
| 166 |
% \end{variable} |
| 167 |
% |
| 168 |
% |
| 169 |
% \subsection{The \env{function} enviroment} |
| 170 |
% |
| 171 |
% \begin{macro}{\__codedoc_function_typeset_start:} |
| 172 |
% This command starts the typesetting and opens the structure. |
| 173 |
% \begin{macrocode} |
| 174 |
\cs_set_protected:Npn \__codedoc_function_typeset_start: |
| 175 |
{ |
| 176 |
\par \bigskip |
| 177 |
\UseTaggingSocket{struct/begin}{tag=\UseStructureName{doc/function}} |
| 178 |
% \end{macrocode} |
| 179 |
% The paragraph structure should start after the building of the macronames. |
| 180 |
% TODO: check if we can simply move ... |
| 181 |
% \begin{macrocode} |
| 182 |
\tagpdfparaOff |
| 183 |
\noindent |
| 184 |
} |
| 185 |
% \end{macrocode} |
| 186 |
% \end{macro} |
| 187 |
% |
| 188 |
% |
| 189 |
% \begin{macro}{\__codedoc_typeset_functions:} |
| 190 |
% TODO: \cs{toprule} and \cs{bottomrule} should be artifacts with pdflatex |
| 191 |
% (they are already with lualatex). |
| 192 |
% \begin{macrocode} |
| 193 |
\cs_set_protected:Npn \__codedoc_typeset_functions: |
| 194 |
{ % |
| 195 |
\small\ttfamily |
| 196 |
\__codedoc_target: |
| 197 |
\Hy@MakeCurrentHref { HD. \int_use:N \c@HD@hypercount } |
| 198 |
% \end{macrocode} |
| 199 |
% The function names are typeset as a tabular. We use |
| 200 |
% the table code to add the tagging. |
| 201 |
% \begin{macrocode} |
| 202 |
\UseTaggingSocket{struct-mc}{tag=\UseStructureName{doc/functionnames}} |
| 203 |
{ |
| 204 |
\tagpdfsetup{table/tagging=div} |
| 205 |
\AssignStructureRole{table/row}{\UseStructureName{doc/functionname}} |
| 206 |
\AssignStructureRole{table/cell}{\UseStructureName{doc/functionnamepart}} |
| 207 |
\begin{tabular} [t] { @{} l @{} >{\hspace{\tabcolsep}} r @{} } |
| 208 |
\toprule |
| 209 |
\__codedoc_function_extra_labels: |
| 210 |
\__codedoc_names_typeset: |
| 211 |
\__codedoc_typeset_dates: |
| 212 |
\bottomrule |
| 213 |
\end{tabular} |
| 214 |
} |
| 215 |
\normalfont\normalsize\par |
| 216 |
} |
| 217 |
% \end{macrocode} |
| 218 |
% \end{macro} |
| 219 |
% |
| 220 |
% \begin{macro}{\__codedoc_function_descr_start:w} |
| 221 |
% The function environment is mainly a box. We store the structure |
| 222 |
% for the syntax environment. |
| 223 |
% \begin{macrocode} |
| 224 |
\cs_set_protected:Npn \__codedoc_function_descr_start:w |
| 225 |
{ |
| 226 |
\vcoffin_set:Nnw \l__codedoc_descr_coffin { \textwidth } |
| 227 |
\tagpdfparaOn |
| 228 |
\tagstructbegin{tag=\UseStructureName{doc/function-description}} |
| 229 |
\tl_set:Ne\l__codedoc_current_names_struct_tl{\tag_get:n{struct_num}} |
| 230 |
\noindent \ignorespaces |
| 231 |
} |
| 232 |
% \end{macrocode} |
| 233 |
% \end{macro} |
| 234 |
% |
| 235 |
% \begin{macro}{\__codedoc_function_typeset_stop:} |
| 236 |
% At the end we must close the two main structures. |
| 237 |
% \begin{macrocode} |
| 238 |
\cs_set_protected:Npn \__codedoc_function_typeset_stop: |
| 239 |
{ |
| 240 |
\par |
| 241 |
\UseTaggingSocket{struct/end}% function-description |
| 242 |
\UseTaggingSocket{struct/end} % function |
| 243 |
\dim_set:Nn \prevdepth { \coffin_dp:N \l__codedoc_descr_coffin } |
| 244 |
\allowbreak |
| 245 |
} |
| 246 |
% \end{macrocode} |
| 247 |
% \end{macro} |
| 248 |
% |
| 249 |
% \subsection{The \env{syntax} environment} |
| 250 |
% |
| 251 |
% These environments are full of boxes that are moved around. |
| 252 |
% Getting the mc-chunks right is not trivial. |
| 253 |
% |
| 254 |
% TODO: check if one should change/simplify the tagging of the inner minipage. |
| 255 |
% \begin{macro}{\__codedoc_syntax:w} |
| 256 |
% \begin{macrocode} |
| 257 |
\cs_set_protected:Npn \__codedoc_syntax:w |
| 258 |
{ |
| 259 |
\box_if_empty:NF \g__codedoc_syntax_box |
| 260 |
{ \msg_error:nn { l3doc } { multiple-syntax } } |
| 261 |
\dim_set:Nn \l__codedoc_syntax_dim |
| 262 |
{ |
| 263 |
\textwidth |
| 264 |
\bool_if:NT \l__codedoc_long_name_bool |
| 265 |
{ + \marginparwidth - \l__codedoc_trial_width_dim } |
| 266 |
} |
| 267 |
\tag_mc_end_push: |
| 268 |
\hbox_gset:Nw \g__codedoc_syntax_box |
| 269 |
\tl_if_empty:NTF\l__codedoc_current_names_struct_tl |
| 270 |
{ |
| 271 |
\UseTaggingSocket{struct/begin}{tag=\UseStructureName{doc/syntax}} |
| 272 |
} |
| 273 |
{ |
| 274 |
% \end{macrocode} |
| 275 |
% TODO: check if firstkid is the right thing. |
| 276 |
% \begin{macrocode} |
| 277 |
\UseTaggingSocket{struct/begin} |
| 278 |
{tag=\UseStructureName{doc/syntax},firstkid,parent=\l__codedoc_current_names_struct_tl} |
| 279 |
} |
| 280 |
\small \ttfamily |
| 281 |
\tagpdfsetup{table/tagging=false} |
| 282 |
\tagpdfparaOff |
| 283 |
\arrayrulecolor{white} |
| 284 |
\begin{tabular} { @{} p{\l__codedoc_syntax_dim} @{} } |
| 285 |
\toprule |
| 286 |
\begin{minipage}[t]{\l__codedoc_syntax_dim} |
| 287 |
\raggedright |
| 288 |
\obeyspaces |
| 289 |
\obeylines |
| 290 |
} |
| 291 |
% \end{macrocode} |
| 292 |
% \end{macro} |
| 293 |
% |
| 294 |
% |
| 295 |
% \begin{macro}{\__codedoc_syntax_end:} |
| 296 |
% \begin{macrocode} |
| 297 |
\cs_set_protected:Npn \__codedoc_syntax_end: |
| 298 |
{ |
| 299 |
\end{minipage} |
| 300 |
\end{tabular} |
| 301 |
\arrayrulecolor{black} |
| 302 |
\UseTaggingSocket{struct/end} |
| 303 |
\hbox_gset_end: |
| 304 |
\tag_mc_begin_pop:n{} |
| 305 |
\bool_if:NF \l__codedoc_in_function_bool |
| 306 |
{ |
| 307 |
\begin{quote} |
| 308 |
\mode_leave_vertical: |
| 309 |
\box_use_drop:N \g__codedoc_syntax_box |
| 310 |
\end{quote} |
| 311 |
} |
| 312 |
} |
| 313 |
% \end{macrocode} |
| 314 |
% \end{macro} |
| 315 |
% |
| 316 |
% \subsection{The \env{macro} environment} |
| 317 |
% The macro environment is difficult: It collects various content |
| 318 |
% in boxes and outputs everything at the end in \cs{__codedoc_macro_dump:}, |
| 319 |
% including the command names in the argument which are output in the margin. |
| 320 |
% A macro environment can have more than one name in |
| 321 |
% the argument and the environment be nested and the respective command names |
| 322 |
% are then combined with the outer names. |
| 323 |
% A command name can link to a \env{function} environment, |
| 324 |
% which mean that it isn't simple text but contains a structure. |
| 325 |
% This means that one has to collect structure numbers to insert them when needed. |
| 326 |
% |
| 327 |
% |
| 328 |
% \begin{macro}{\__codedoc_macro_dump:} |
| 329 |
% Here we have larger changes as we need also to replace the trivlist by a displayblock. |
| 330 |
% We setup a tagging socket which will create the container for the |
| 331 |
% macronames structure. The argument will contain the structure number. |
| 332 |
% \begin{macrocode} |
| 333 |
\NewTaggingSocket{doc/container/macronames}{1} |
| 334 |
\NewTaggingSocketPlug{doc/container/macronames}{default} |
| 335 |
{ |
| 336 |
\tagstructbegin{tag=\UseStructureName{doc/macronames}} |
| 337 |
\tl_set:Ne #1 {\tag_get:n{struct_num}} |
| 338 |
\seq_map_inline:Nn \g__codedoc_macroname_structnum_seq |
| 339 |
{\tag_struct_use_num:n {##1}} |
| 340 |
\seq_gclear:N \g__codedoc_macroname_structnum_seq |
| 341 |
\tagstructend |
| 342 |
} |
| 343 |
\AssignTaggingSocketPlug{doc/container/macronames}{default} |
| 344 |
|
| 345 |
\cs_set_protected:Npn \__codedoc_macro_dump: |
| 346 |
{ |
| 347 |
\int_compare:nNnF{\l__codedoc_nested_macro_int}>{1} |
| 348 |
{ |
| 349 |
\begin{displayblock} [tag-name=macro,begin-vspace=\MacroTopsep] |
| 350 |
% \end{macrocode} |
| 351 |
% we add here a container for the macronames which are built later and use |
| 352 |
% the structures from the list. |
| 353 |
% \begin{macrocode} |
| 354 |
\UseTaggingSocket{doc/container/macronames}{\l__codedoc_current_names_struct_tl} |
| 355 |
} |
| 356 |
\noindent\llap |
| 357 |
{ \tagmcend |
| 358 |
\hbox_unpack_drop:N \l__codedoc_macro_index_box |
| 359 |
\vtop to \baselineskip |
| 360 |
{ |
| 361 |
\vbox_unpack_drop:N \l__codedoc_macro_box |
| 362 |
\vss |
| 363 |
} |
| 364 |
\hspace{\labelsep} |
| 365 |
\tagmcbegin{} |
| 366 |
} |
| 367 |
} |
| 368 |
% \end{macrocode} |
| 369 |
% \end{macro} |
| 370 |
% |
| 371 |
% \begin{macro}{\__codedoc_macro_typeset_one:nN} |
| 372 |
% The \cs{__codedoc_macro_typeset_one:nN} command appends one macro name |
| 373 |
% to the \cs{l__codedoc_macro_box}. We have to add a structure. |
| 374 |
% If we are on the outer level we have to record the structure number. |
| 375 |
% In the inner level we can use the existing structure. |
| 376 |
% As the structures are used in another place, we have to push/pop the mc. |
| 377 |
% \begin{macrocode} |
| 378 |
\NewTaggingSocket{doc/macroname}{2} |
| 379 |
\NewTaggingSocketPlug{doc/macroname}{default} |
| 380 |
{ |
| 381 |
\int_compare:nNnTF { \l__codedoc_nested_macro_int } = { 1 } |
| 382 |
{ |
| 383 |
\tagstructbegin{tag=\UseStructureName{doc/macroname},stash} |
| 384 |
\seq_gput_right:Ne |
| 385 |
\g__codedoc_macroname_structnum_seq{\tag_get:n{struct_num}} |
| 386 |
} |
| 387 |
{ |
| 388 |
\tagstructbegin |
| 389 |
{tag=\UseStructureName{doc/macroname},parent=\l__codedoc_current_names_struct_tl} |
| 390 |
} |
| 391 |
\tagmcbegin{} |
| 392 |
#2 |
| 393 |
\tagmcend |
| 394 |
\tagstructend |
| 395 |
} |
| 396 |
\AssignTaggingSocketPlug{doc/macroname}{default} |
| 397 |
|
| 398 |
\cs_set_protected:Npn \__codedoc_macro_typeset_one:nN #1#2 |
| 399 |
{ |
| 400 |
\tag_mc_end_push: |
| 401 |
\vbox_set:Nn \l__codedoc_macro_box |
| 402 |
{ |
| 403 |
\vbox_unpack_drop:N \l__codedoc_macro_box |
| 404 |
\UseTaggingSocket{doc/macroname}{} |
| 405 |
{ |
| 406 |
\hbox { \llap { \__codedoc_print_macroname:nN {#1} #2 |
| 407 |
\MacroFont \ |
| 408 |
} } |
| 409 |
} |
| 410 |
} |
| 411 |
\tag_mc_begin_pop:n{} |
| 412 |
\int_incr:N \l__codedoc_macro_int |
| 413 |
} |
| 414 |
% \end{macrocode} |
| 415 |
% \end{macro} |
| 416 |
% |
| 417 |
% \begin{macro}{\__codedoc_macro_reset:} |
| 418 |
% As we have no nested lists, we need to ignore spaces explicitly |
| 419 |
% \begin{macrocode} |
| 420 |
\cs_set_protected:Npn \__codedoc_macro_reset: |
| 421 |
{ |
| 422 |
\tl_set:Nn \l__codedoc_override_module_tl { \q_no_value } |
| 423 |
\ignorespaces |
| 424 |
} |
| 425 |
% \end{macrocode} |
| 426 |
% \end{macro} |
| 427 |
% |
| 428 |
% \begin{macro}{\__codedoc_macro_end:} |
| 429 |
% \begin{macrocode} |
| 430 |
\cs_set_protected:Npn \__codedoc_macro_end: |
| 431 |
{ |
| 432 |
\__codedoc_macro_end_check_tested: |
| 433 |
\int_compare:nNnT \l__codedoc_nested_macro_int = 1 |
| 434 |
{ |
| 435 |
\par \__codedoc_macro_end_style:n { \__codedoc_print_end_definition: } |
| 436 |
\end{displayblock} |
| 437 |
% \end{macrocode} |
| 438 |
% Instead of a displayblock we should really use a block with a |
| 439 |
% standalone recipe and it should |
| 440 |
% combine two envs directly following each other within a single |
| 441 |
% text-unit, but for some reason that isn't happening and each macro |
| 442 |
% env acts as if it is standalone already. TODO: figure out why that |
| 443 |
% is the case. |
| 444 |
% \begin{macrocode} |
| 445 |
} |
| 446 |
} |
| 447 |
% \end{macrocode} |
| 448 |
% \end{macro} |
| 449 |
% |
| 450 |
% \subsection{The \env{macrocode} environment} |
| 451 |
% |
| 452 |
% |
| 453 |
% \begin{macro}[no-user-doc]{\legacymacrocodesetup} |
| 454 |
% We want to base the environment on the new template code. |
| 455 |
% This is a counterpart to the \cs{legacyverbatimsetup} |
| 456 |
% command in the latex-lab-block code. |
| 457 |
% \begin{macrocode} |
| 458 |
\def\legacymacrocodesetup{% |
| 459 |
\macro@font |
| 460 |
\blank@linefalse \def\par{\ifblank@line |
| 461 |
\leavevmode \else \fi |
| 462 |
% \end{macrocode} |
| 463 |
% Similar to the case for verbatim we must group the |
| 464 |
% \cs{@@par} so that we do not loose indentation on the first |
| 465 |
% line |
| 466 |
% \begin{macrocode} |
| 467 |
\blank@linetrue{\@@par} |
| 468 |
\penalty\interlinepenalty} |
| 469 |
\obeylines |
| 470 |
\@noligs |
| 471 |
\let\do\@makeother \dospecials |
| 472 |
\global\@newlistfalse |
| 473 |
\global\@minipagefalse |
| 474 |
\ifcodeline@index |
| 475 |
|
| 476 |
\everypar{\global\advance\c@CodelineNo\@ne |
| 477 |
\llap{\tagmcend\tagstructbegin{tag=\UseStructureName{doc/codelinenum}} |
| 478 |
\tagmcbegin{} |
| 479 |
\theCodelineNo\pdffakespace |
| 480 |
\tagmcend\tagstructend |
| 481 |
\tagmcbegin{}% |
| 482 |
\ }% |
| 483 |
\check@module}% |
| 484 |
\else \everypar{\check@module}% |
| 485 |
\fi |
| 486 |
\tagpdfsetup{para/tag=\UseStructureName{doc/codeline}}% check tagging |
| 487 |
} |
| 488 |
% \end{macrocode} |
| 489 |
% \end{macro} |
| 490 |
% \begin{instance}{blockenv macrocode} |
| 491 |
% \begin{macrocode} |
| 492 |
\DeclareInstance{blockenv}{macrocode}{std} |
| 493 |
{ |
| 494 |
name = macrocode, |
| 495 |
tag-name = \UseStructureName{block/verbatim}, |
| 496 |
tag-attr-class = , |
| 497 |
tagging-recipe = standard, |
| 498 |
inner-level-counter = , |
| 499 |
transparent-level = true, |
| 500 |
legacy-code = , |
| 501 |
block-instance = verbatim , |
| 502 |
inner-instance = , |
| 503 |
final-code = \legacymacrocodesetup , |
| 504 |
para-instance = justify, |
| 505 |
tagging-suppress-paras = true |
| 506 |
} |
| 507 |
% \end{macrocode} |
| 508 |
% \end{instance} |
| 509 |
% |
| 510 |
% \begin{environment}{macrocode} |
| 511 |
% \begin{macrocode} |
| 512 |
\RenewDocumentEnvironment{macrocode}{!O{}} |
| 513 |
{\SimpleBlockEnv{macrocode} |
| 514 |
{begin-penalty = \predisplaypenalty, |
| 515 |
begin-vspace = \MacrocodeTopsep, |
| 516 |
left-margin = \MacroIndent, |
| 517 |
para-indent =0pt,#1} |
| 518 |
\@setupverbinvisiblespace |
| 519 |
\init@crossref |
| 520 |
\frenchspacing \@vobeyspaces |
| 521 |
\xmacro@code |
| 522 |
} |
| 523 |
{ |
| 524 |
\ifpm@module \endgroup \pm@modulefalse \fi |
| 525 |
\everypar{} |
| 526 |
\BlockEnvEnd |
| 527 |
\close@crossref |
| 528 |
} |
| 529 |
% \end{macrocode} |
| 530 |
% \end{environment} |
| 531 |
% |
| 532 |
% \subsection{New doc elements} |
| 533 |
% Various documentation elements are declare with the \cs{NewDocElement} |
| 534 |
% command. Here we patch the relevant commands to get tagged versions. |
| 535 |
% |
| 536 |
% \begin{macro}[no-user-doc]{\@doc@env} |
| 537 |
% As \cs{@doc@env} maps over the keys in the argument is means, that there can be more |
| 538 |
% \cs{@doc@env@} at the begin as calls at the end, so we have to move the main structure |
| 539 |
% outside of \cs{@doc@env@} in to \cs{@doc@env@} |
| 540 |
% \begin{macrocode} |
| 541 |
\int_new:N\l__codedoc_nested_env_int |
| 542 |
\long\def\@doc@env#1#2#3{ |
| 543 |
\endgroup |
| 544 |
\int_incr:N\l__codedoc_nested_env_int |
| 545 |
% \end{macrocode} |
| 546 |
% we setup a new role: |
| 547 |
% \begin{macrocode} |
| 548 |
\tagpdfsetup{role/new-tag=#2/Sect} |
| 549 |
\int_compare:nNnF{\l__codedoc_nested_env_int}>{1} |
| 550 |
{\SimpleBlockEnv{displayblock} |
| 551 |
{transparent-level=true,tag-name=#2,begin-vspace=\MacroTopsep} |
| 552 |
% \end{macrocode} |
| 553 |
% A container for the function names. |
| 554 |
% \begin{macrocode} |
| 555 |
\tagstructbegin{tag=\UseStructureName{doc/macronames}} |
| 556 |
\tl_set:Ne \l__codedoc_current_names_struct_tl {\tag_get:n{struct_num}} |
| 557 |
\tagstructend |
| 558 |
} |
| 559 |
\clist_map_inline:nn {#3} { \@doc@env@{#1}{#2}{##1} }\ignorespaces |
| 560 |
} |
| 561 |
% \end{macrocode} |
| 562 |
% \end{macro} |
| 563 |
% \begin{macro}[no-user-doc]{\@doc@env@} |
| 564 |
% \begin{macrocode} |
| 565 |
\long\def\@doc@env@#1#2#3{% |
| 566 |
\edef\saved@macroname{\string#3}% |
| 567 |
\if #1% |
| 568 |
\edef\saved@indexname{\expandafter\@gobble\saved@macroname}% |
| 569 |
\expandafter\ifx |
| 570 |
\csname Code#2Index\endcsname |
| 571 |
\CodeMacroIndex |
| 572 |
\else |
| 573 |
\record@index@type@save |
| 574 |
{\saved@indexname}{#2}% |
| 575 |
\fi |
| 576 |
\else |
| 577 |
\let\saved@indexname\saved@macroname |
| 578 |
\fi |
| 579 |
\def\makelabel##1{\noindent\llap{ |
| 580 |
\UseTaggingSocket{inline/begin} |
| 581 |
{tag=\UseStructureName{doc/macroname},parent=\l__codedoc_current_names_struct_tl} |
| 582 |
##1\hspace{\itemsep} |
| 583 |
\UseTaggingSocket{inline/end} |
| 584 |
}}% |
| 585 |
% \int_compare:nNnTF{\l__codedoc_nested_env_int}>{1} |
| 586 |
% { |
| 587 |
\let\@tempa\@empty |
| 588 |
\count@\macro@cnt |
| 589 |
\loop\ifnum\count@>\z@ |
| 590 |
\edef\@tempa{\@tempa\hbox{\strut}}\advance\count@\m@ne |
| 591 |
\repeat |
| 592 |
\edef\makelabel##1{\noindent\llap{ |
| 593 |
\UseTaggingSocket{inline/begin} |
| 594 |
{tag=\UseStructureName{doc/macroname},parent=\l__codedoc_current_names_struct_tl} |
| 595 |
\vtop to\baselineskip{\@tempa\hbox{##1\kern\labelsep}\vss} |
| 596 |
\UseTaggingSocket{inline/end} |
| 597 |
}}% |
| 598 |
\advance\macro@cnt\@ne |
| 599 |
% } |
| 600 |
% { \macro@cnt\@ne } |
| 601 |
\ifdoc@noprint |
| 602 |
\else |
| 603 |
\edef\@tempa{% |
| 604 |
\noexpand\makelabel{ |
| 605 |
\noexpand\doc@providetarget |
| 606 |
\noexpand\strut |
| 607 |
\noexpand\@nameuse{Print#2Name}{\saved@macroname}}}% |
| 608 |
\@tempa |
| 609 |
\fi |
| 610 |
\ifdoc@noindex\else |
| 611 |
\global\advance\c@CodelineNo\@ne |
| 612 |
\csname SpecialMain#2Index\expandafter\endcsname |
| 613 |
\expandafter{\saved@macroname}\nobreak |
| 614 |
\global\advance\c@CodelineNo\m@ne |
| 615 |
\fi |
| 616 |
\if#1\expandafter\DoNotIndex \expandafter {\saved@macroname}\fi |
| 617 |
\ignorespaces} |
| 618 |
% \end{macrocode} |
| 619 |
% \end{macro} |
| 620 |
% |
| 621 |
% \begin{macro}[no-user-doc]{\doc@createenv} |
| 622 |
% We must use \cs{BlockEnvEnd}. |
| 623 |
% \begin{macrocode} |
| 624 |
\def\doc@createenv#1#2#3{% |
| 625 |
\@namedef{#3}{% |
| 626 |
\@ifnextchar[%] |
| 627 |
{\doc@env{#1}{#2}}{\doc@env{#1}{#2}[]}}% |
| 628 |
\@namedef{end#3} |
| 629 |
{ |
| 630 |
\int_compare:nNnF{\l__codedoc_nested_env_int}>{1}{\BlockEnvEnd} |
| 631 |
\int_decr:N\l__codedoc_nested_env_int |
| 632 |
}% |
| 633 |
%\@namedef{end#3}{\BlockEnvEnd}% |
| 634 |
} |
| 635 |
% \end{macrocode} |
| 636 |
% \end{macro} |
| 637 |
% |
| 638 |
% We must renew the environment doc element so that is uses the new code: |
| 639 |
% \begin{macrocode} |
| 640 |
\RenewDocElement[macrolike = false , |
| 641 |
idxtype = env. , |
| 642 |
idxgroup = environments , |
| 643 |
printtype = \textit{env.} |
| 644 |
]{Env}{environment} |
| 645 |
% \end{macrocode} |
| 646 |
% |
| 647 |
% |
| 648 |
% \subsection{\cs{maketitle}} |
| 649 |
% The \pkg{doc} package redefines \cs{maketitle}. So we have to reinstate the |
| 650 |
% version from the title module. |
| 651 |
% |
| 652 |
% \begin{macrocode} |
| 653 |
\cs_if_exist:NT \__tag_patch_maketitle: |
| 654 |
{ |
| 655 |
\cs_set_eq:NN \maketitle \__tag_patch_maketitle: |
| 656 |
} |
| 657 |
% \end{macrocode} |
| 658 |
% |
| 659 |
% \subsection{Sectioning commands and table of contents} |
| 660 |
% |
| 661 |
% \cs{l@section} must get the hooks: |
| 662 |
|
| 663 |
% \begin{macro}[no-user-doc]{\l@section} |
| 664 |
% \begin{macrocode} |
| 665 |
\cs_gset:Npn \l@section #1#2 |
| 666 |
{ |
| 667 |
\ifnum \c@tocdepth >\z@ |
| 668 |
\addpenalty\@secpenalty |
| 669 |
\addvspace{1.0em \@plus\p@} |
| 670 |
\setlength\@tempdima{2.5em} % was 1.5em |
| 671 |
\begingroup |
| 672 |
\parindent \z@ \rightskip \@pnumwidth |
| 673 |
\parfillskip -\@pnumwidth |
| 674 |
\leavevmode \bfseries |
| 675 |
\advance\leftskip\@tempdima |
| 676 |
\hskip -\leftskip |
| 677 |
\UseHookWithArguments{contentsline/text/before}{4} |
| 678 |
{\toclevel@section}{#1}{#2}{\@contentsline@destination}% |
| 679 |
\csname contentsline@text@1@format\endcsname{#1} |
| 680 |
\UseHookWithArguments{contentsline/text/after}{4} |
| 681 |
{\toclevel@chapter}{#1}{#2}{\@contentsline@destination}% |
| 682 |
\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss |
| 683 |
\UseHookWithArguments{contentsline/page/before}{4} |
| 684 |
{\toclevel@section}{#1}{#2}{\@contentsline@destination}% |
| 685 |
#2 |
| 686 |
\UseHookWithArguments{contentsline/page/after}{4} |
| 687 |
{\toclevel@section}{#1}{#2}{\@contentsline@destination}% |
| 688 |
}\par |
| 689 |
\endgroup |
| 690 |
\fi |
| 691 |
} |
| 692 |
% \end{macrocode} |
| 693 |
% \end{macro} |
| 694 |
% |
| 695 |
% \subsection{Support \pkg{fancyvrb}} |
| 696 |
% l3doc uses \pkg{fancyvrb}. |
| 697 |
% As the block code redefines \env{verbatim} at begin document, |
| 698 |
% we have to overwrite that again: |
| 699 |
% \begin{macrocode} |
| 700 |
\AtBeginDocument |
| 701 |
{ |
| 702 |
\cs_gset_eq:NN \verbatim \Verbatim |
| 703 |
\cs_gset_eq:NN \endverbatim \endVerbatim |
| 704 |
} |
| 705 |
% \end{macrocode} |
| 706 |
% |
| 707 |
% \begin{macrocode} |
| 708 |
%</package> |
| 709 |
% \end{macrocode} |
| 710 |
% \end{implementation} |
| 711 |
\endinput |