Debian Codegraph @

texmf-dist/source/latex-dev/latex-lab/latex-lab-sec.dtx

raw
1 % \iffalse meta-comment
2 %
3 %% File: latex-lab-sec.dtx (C) Copyright 2022-2026 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 latex-lab bundle is developed in the LaTeX2e GitHub.
14 % Issues may be reported at
15 %
16 % https://github.com/latex3/latex2e/issues
17 %
18 \def\ltlabsecdate{2026-04-28}
19 \def\ltlabsecversion{0.84o}
20
21 %<*driver>
22 \DocumentMetadata{tagging=on,pdfstandard=ua-2}
23 \documentclass[kernel]{l3in2edoc}
24
25 \EnableCrossrefs
26 \CodelineIndex
27 \begin{document}
28 \DocInput{latex-lab-sec.dtx}
29 \end{document}
30 %</driver>
31 %
32 % \fi
33 %
34 %
35 % \title{The \textsf{latex-lab-sec} package\\
36 % Changes related to the tagging of sectioning commands}
37 % \author{\LaTeX{} Project\thanks{Initial implementation done by Ulrike Fischer}}
38 % \date{v\ltlabsecversion\ \ltlabsecdate}
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 %
49 % \begin{abstract}
50 % The following code implements a first draft for the tagging of heading commands.
51 % \end{abstract}
52 %
53 % \section{New implementation with templates}
54 %
55 % Various parts of this module are obsolete as the commands have been reimplemented
56 % in the module \texttt{latex-lab-sec-template} with templates. The tagging sockets
57 % are still relevant.
58 %
59 % In a later step both files will be merged.
60 %
61 % \section{Limitations}
62 %
63 % Heading commands are in general not defined by the format but by the classes.
64 % Their implementation vary: some are defined with the help of \cs{@startsection},
65 % some are like \cs{chapter} handcrafted,
66 % some built with the help of extension packages or as in the KOMA classes
67 % with class code that extends the \cs{@startsection} functionality.
68 %
69 % The following code can therefore currently be used \emph{only} with the standard classes
70 % or with classes which do not overwrite the changed definitions.
71 %
72 %
73 %
74 % \section{Introduction}
75 %
76 % Tagging of heading commands consist of two parts:
77 %
78 % \begin{itemize}
79 % \item The \emph{title text} of the heading should be surrounded by a structure with
80 % a \emph{heading tag}, typically \texttt{Hn} with some value of \texttt{n}.
81 % In theory, one could/should put the number of the heading in an \texttt{Lbl} structure.
82 % However, current AT doesn't handle this well, so
83 % we use a tag \texttt{section-number} that is role-mapped to \texttt{Span}.
84 % The number of the \texttt{Hn} tag should reflect the \enquote{natural} level.
85 % So in an article \cs{section} will use \texttt{H1}, in a book \cs{chapter} will use
86 % \texttt{H1} and \cs{section} \texttt{H2}.
87 % Titles of \cs{part} are a bit out of this system as they are normally
88 % not part of the hierarchy: often only some chapters are grouped under a part.
89 % Their title is therefore tagged as \texttt{Title}.
90 % \item
91 % The whole section (title and all the text body) should normally be surrounded by
92 % a \texttt{Sect} tag. Parts (started with the \cs{part} command)
93 % are surrounded currently by \texttt{Part} until the next \cs{part} or a command like
94 % \cs{backmatter}.
95 % It is a bit unclear if the headings should be inside or outside of these
96 % structures---the best practice guide puts them outside---but on the whole
97 % it seems more logical to group the heading together with the text inside the \texttt{Sect}.
98 % For \cs{part} this is actually required, as there can be only one \texttt{Title}
99 % in a structure, so the part title can't be at the same level as the
100 % document \texttt{Title}.
101 %
102 % Starting such an enclosing \texttt{Sect} structure is rather easy,
103 % but closing it requires code in various place,
104 % for example, the commands \cs{mainmatter}, \cs{backmatter},
105 % \cs{frontmatter} and \cs{appendix} should typically close everything.
106 % Following heading commands should close all previous structures
107 % with a level equal or higher than their own level.
108 % \end{itemize}
109 %
110 % \section{Technical details and problems}
111 %
112 % The implementation has to take care of various details.
113 %
114 % \begin{itemize}
115 %
116 % \item As heading commands in \LaTeX{} are not environments, the
117 % \texttt{<Sect>} structures can be wrongly nested with other structures. For example
118 % if a document puts a heading command into a list or a trivlist or
119 % a minipage then it can no longer close previous \texttt{<Sect>} structures correctly.
120 % The problem can be detected by checking the structure stack
121 % and a warning can be issued, but the author then has to close the structures
122 % manually before the list or minipage.
123 %
124 % Thus there have to be user interfaces to handle such cases.
125 % It should also be possible not to create all the \texttt{<Sect>} structures
126 % automatically but to tag only the headings so that the author can handle special
127 % cases manually.
128 %
129 % \item If hyperref is used, targets for links should be inserted, either with
130 % \cs{refstepcounter} or manually with \cs{MakeLinkTarget}. These targets must be
131 % in the correct structure for the structure destinations. They replace some
132 % of the current patches in hyperref.
133 %
134 % \end{itemize}
135 %
136 % \subsection{TODO}
137 %
138 % \begin{itemize}
139 % \item A dedicated command to close a \texttt{Sect} unit should be provided.
140 %
141 % \item A dedicated command to open a \texttt{Sect} unit should be provided too.
142 %
143 % \item It should also be possible to put an epigraph or similar in front of a heading command,
144 % that is still inside the \texttt{Sect} unit.
145 %
146 % \item The number in \cs{part} and \cs{chapter} is currently not correctly
147 % tagged as a \texttt{section-number} as this requires to redefine the internal (class dependent)
148 % commands too.
149 %
150 % \end{itemize}
151 %
152 % \begin{macrocode}
153 %<*package>
154 % \end{macrocode}
155 %
156 % \section{Implementation}
157 % \begin{macrocode}
158 \ProvidesExplPackage {latex-lab-testphase-sec} {\ltlabsecdate} {\ltlabsecversion}
159 {Code related to the tagging of heading commands}
160 % \end{macrocode}
161 % \changes{0.84k}{2025-10-20}{Switched to tagging sockets and various corrections}.
162 %
163 % \subsection{Surrounding by \texttt{Sect} structures}
164 % We use a stack to record the levels of the open \texttt{Sect}. The first item
165 % has level $-100$. A heading command will take a record from the stack. If its level is
166 % greater or equal it closes this structure and takes the next record from the stack.
167 % If the record has a smaller level then it puts it back and stops.
168 % The stack is compared with the main structure stack, if they don't match
169 % it means we can't safely close the \texttt{Sect} and so we issue a warning
170 % and do nothing.
171 %
172 % \begin{macrocode}
173 %</package>
174 % \end{macrocode}
175 % \changes{0.84m}{2026-02-25}{Removed glyphtounicode definitions}
176 % \begin{macrocode}
177 %<*package>
178 %<@@=tag>
179 % \end{macrocode}
180 %
181 % \subsubsection{Tagging commands}
182 %
183 %
184 % \begin{variable}{\g_@@_sec_stack_seq}
185 % The stack holds the tag, the level and the structure number.
186 % \begin{macrocode}
187 \seq_new:N \g_@@_sec_stack_seq
188 \seq_gpush:Nn\g_@@_sec_stack_seq {{Document}{-100}{2}}
189 % \end{macrocode}
190 % \end{variable}
191 %
192 % \begin{macro}{\@@_get_data_current_Sect:}
193 % This allows to retrieve the number of the current Sect structure (or
194 % Document if we are outside any Sect) with |\tag_get:n{current_Sect}|
195 % \begin{macrocode}
196 \cs_new:Npn \@@_get_data_current_Sect:
197 {
198 \exp_last_unbraced:Ne\use_iii:nnn{\seq_item:Nn\g_@@_sec_stack_seq{1}}
199 }
200 % \end{macrocode}
201 % \end{macro}
202 % \begin{variable}{\l_@@_sec_Sect_bool}
203 % This boolean controls if a Sect structure is opened.
204 % \begin{macrocode}
205 \bool_new:N \l_@@_sec_Sect_bool
206 \bool_set_true:N\l_@@_sec_Sect_bool
207 % \end{macrocode}
208 % \end{variable}
209 % \begin{variable}{\l_@@_sec_tmpa_tl}
210 % a temp variable
211 % \begin{macrocode}
212 \tl_new:N \l_@@_sec_tmpa_tl
213 % \end{macrocode}
214 % \end{variable}
215 % \begin{macro}{\@@_sec_begin:nn}
216 % This starts a \texttt{Sect} unit structure (the „Sect environment“).
217 % Currently the default tag is either Sect or Part, depending on the level,
218 % but this can be changed by adapting the symbolic structure names which are
219 % built from the level.
220 % The second argument allows to add more options but is currently unused.
221 % \begin{macrocode}
222 \cs_new_protected:Npn\@@_sec_begin:nn #1 #2 %#1 level #2 keyval
223 {
224 \tag_struct_begin:n
225 {
226 tag= \UseStructureName{sec/#1}
227 ,#2
228 }
229 \seq_gpush:Ne \g_@@_sec_stack_seq
230 {{\g_@@_struct_tag_tl}{\int_eval:n{#1}}{\g_@@_struct_stack_current_tl}}
231 }
232 \cs_generate_variant:Nn \@@_sec_begin:nn {en}
233 % \end{macrocode}
234 % \end{macro}
235 %
236 % \begin{macro}{\@@_sec_end:n}
237 % \begin{macrocode}
238 \msg_new:nnn { tag } {wrong-sect-nesting}
239 {
240 The~structure~#1~can~not~be~closed.\\
241 It~is~not~equal~to~the~current~structure~#2~on~the~main~stack
242 }
243
244 \cs_new_protected:Npn\@@_sec_end:n #1 % #1 level
245 {
246 \seq_get:NN \g_@@_sec_stack_seq \l_@@_tmpa_tl
247 \int_compare:nNnT {#1}<{\exp_last_unbraced:NV\use_ii:nnn\l_@@_tmpa_tl+1}
248 {
249 \seq_get:NN\g_@@_struct_tag_stack_seq \l_@@_tmpb_tl
250 \exp_args:Nee
251 \tl_if_eq:nnTF
252 {\exp_last_unbraced:NV\use_i:nnn\l_@@_tmpa_tl}
253 {\exp_last_unbraced:NV\use_i:nn\l_@@_tmpb_tl}
254 {
255 \seq_gpop:NN \g_@@_sec_stack_seq \l_@@_tmpa_tl
256 \tag_struct_end:
257 \@@_sec_end:n {#1}
258 }
259 {
260 \msg_warning:nnee {tag}{wrong-sect-nesting}
261 { \exp_last_unbraced:NV\use_i:nnn \l_@@_tmpa_tl }
262 { \exp_last_unbraced:NV\use_i:nn \l_@@_tmpb_tl }
263 }
264 }
265 }
266 % \end{macrocode}
267 % \end{macro}
268
269 % \begin{macro}{\@@_sec_title_split:,\@@_sec_restore_para:}
270 % A runin-heading command must separate the heading title from the following text.
271 % The code is in an \cs{everypar} which is perhaps executed in a group (e.g. when
272 % a list follows), we have to ensure that the restoring of the para can escape.
273 % \begin{macrocode}
274 \cs_new_protected:Npn\@@_sec_restore_para:
275 {
276 \UseTaggingSocket {para/restore}
277 \if_int_compare:w \tex_currentgrouptype:D =14 % semi-simple group
278 \group_insert_after:N \@@_sec_restore_para:
279 \else:
280 \if_int_compare:w \tex_currentgrouptype:D =\c_one_int % simple group
281 \group_insert_after:N \@@_sec_restore_para:
282 \fi:
283 \fi:
284 }
285 \cs_new_protected:Npn \@@_sec_title_split:
286 {
287 % \end{macrocode}
288 % This ends the title structure. As the begin is from the
289 % automatic (flattened) para-tagging we have to increase the counter.
290 % \begin{macrocode}
291 \tag_mc_end:
292 \tag_struct_end:
293 \@@_gincr_para_end_int:
294 % \end{macrocode}
295 % In case something (e.g. a list) did reset the boolean we need to close also a semantic
296 % paragraph.
297 % \begin{macrocode}
298 \bool_if:NF\l__tag_para_flattened_bool
299 {\UseTaggingSocket{para/semantic/end}{}}
300 % \end{macrocode}
301 % Now restore the para-tagging and start a normal paragraph:
302 % \begin{macrocode}
303 \@@_sec_restore_para:
304 \UseTaggingSocket{para/begin}
305 }
306 % \end{macrocode}
307 % \end{macro}
308 %
309 % \begin{macro}{\@@_sec_title_begin:nn}
310 % This command is used in the socket at the begin of display heading commands
311 % like part and chapter. It takes two arguments: the level and the title.
312 % \begin{macrocode}
313 \cs_new_protected:Npn \@@_sec_title_begin:nn #1 #2 %level, title
314 {
315 \pdf_purify:nN{#2}\l_@@_sec_tmpa_tl
316 \tag_struct_begin:n{tag=\UseStructureName{sec/#1/title},title-o={\l_@@_sec_tmpa_tl}}
317 \bool_set_true:N\l_@@_para_flattened_bool
318 \tl_set:Nn\l_@@_para_tag_tl {\UseStructureName{sec/#1/titleline}}
319 }
320 % \end{macrocode}
321 % \end{macro}
322
323 % \begin{macro}{\@@_sec_title_end:}
324 % \begin{macrocode}
325 \cs_new_protected:Npn \@@_sec_title_end:
326 {
327 \tag_struct_end: %P = Hn
328 \UseTaggingSocket{para/restore}
329 }
330 % \end{macrocode}
331 % \end{macro}
332 %
333 % \begin{macro}{\@@_set_title_hang:nnn}
334 % To be able to correctly tag the number and insert the link target in the
335 % title of a sectioning command created with \cs{@startsection}
336 % we need a special\cs{@hangfrom} variant. This is a bit tricky:
337 % The argument contains the link target and for a correct structure
338 % destination it should be typeset \emph{after} the structure has been opened.
339 % But to measure the hangindent it must be typeset \emph{before} the paragraph is started.
340 % This means that we have to open the title structure manually
341 % and then have to suppress the para-tagging.
342 % Additionally there is an engine difference: with pdftex the literals for the mc are inserted
343 % with the box after the paragraph has started but luatex sets the attributes before
344 % and we have to reset them. Hiding all this in a tagging socket is non-trivial.
345 % The code assumes that we are in vmode!
346 % Attention: The code opens a structure that it doesn't close (it is closed by the \cs{par}).
347 % It therefore does not handle the full tagging of the title. In a new implementation
348 % of the sectioning command this will perhaps have to change.
349 %
350 % \begin{macrocode}
351 \cs_new_protected:Npn \@@_set_title_hang:nNnn #1 #2 #3 #4
352 %#1 level,
353 %#2 boolean: nonumber? (will be later \l__head_nonumber_bool)
354 %#3 formated number /hang space
355 %#4 title
356 % \end{macrocode}
357 % The handling of the title is not perfect. It would be better to pass it through
358 % something like \cs{GetTitleString}. TODO.
359 % \changes{0.84l}{2026-01-07}{use \cs{protected@edef} to avoid problem with conditionals}
360 % \changes{0.84o}{2026-04-28}{use \cs{pdf_purify:nN} for the title of the structure}
361 % \begin{macrocode}
362 {
363 \pdf_purify:nN {#4}\l_@@_sec_tmpa_tl
364 \tagstructbegin{tag=\UseStructureName{sec/#1/title},title-o={\l_@@_sec_tmpa_tl}}
365 \cs_if_exist_use:N \@@_gincr_para_begin_int:
366 \bool_if:NF #2
367 { \tagstructbegin{tag=\UseStructureName{sec/#1/number}} }
368 \setbox\@tempboxa\hbox{{#3}}
369 % \end{macrocode}
370 % We stop paratagging now, to avoid that the \cs{noindent} creates a structure.
371 % \begin{macrocode}
372 \bool_set_false:N \l_@@_para_bool
373 \hangindent \wd\@tempboxa\noindent
374 % \end{macrocode}
375 % Restart paratagging and insert the box. If the box has a real content (if there is a
376 % number) we have to add mc-chunks and reset the attribute of the box.
377 % \begin{macrocode}
378 \bool_set_true:N \l_@@_para_bool
379 \bool_if:NTF #2
380 {
381 \box\@tempboxa
382 }
383 {
384 \tagmcbegin{}
385 % \end{macrocode}
386 % In lua mode we have to reset the attributes inside the box!
387 % \begin{macrocode}
388 \tag_mc_reset_box:N\@tempboxa
389 \box\@tempboxa
390 \tagmcend
391 \tagstructend
392 }
393 \tagmcbegin{}
394 }
395 % \end{macrocode}
396 % \end{macro}
397 %
398 %
399 % \begin{macro}{\@@_sec_title_runin_number:nn}
400 % \begin{macrocode}
401 \cs_new_protected:Npn \@@_sec_title_runin_number:nNn #1 #2 #3 %#1 level, #2 boolean no number, #3 content
402 {
403 \bool_if:NTF #2
404 { #3 }
405 {
406 \tag_mc_end_push:
407 \tag_struct_begin:n{tag=\UseStructureName{sec/#1/number}}
408 \tag_mc_begin:n{}
409 #3
410 \tag_mc_end:
411 \tag_struct_end:
412 \tag_mc_begin_pop:n{}
413 }
414 }
415 % \end{macrocode}
416 % \end{macro}
417 % Open sec structures should be closed at the end of the document. This should
418 % be done before tagpdf closes the Document structure.
419 % \begin{macrocode}
420 \hook_gput_code:nnn
421 {tagpdf/finish/before}
422 {tagpdf/sec}
423 {\AssignTaggingSocketPlug{sec/end}{kernel}\UseTaggingSocket{sec/end}{-10}}
424 \hook_gset_rule:nnnn {tagpdf/finish/before}{tagpdf/sec}{before}{tagpdf}
425 % \end{macrocode}
426 %
427 % The commands \cs{mainmatter}, \cs{backmatter}, \cs{frontmatter} and
428 % \cs{appendix} close all \texttt{Sect} and \texttt{Part} structures.
429 % \changes{v0.84g}{2025/01/05}{ensure that paragraph is ended (tagging/777)}
430 % \begin{macrocode}
431 \AddToHook{cmd/frontmatter/before}{\par\UseTaggingSocket{sec/end}{-10}}
432 \AddToHook{cmd/mainmatter/before} {\par\UseTaggingSocket{sec/end}{-10}}
433 \AddToHook{cmd/backmatter/before} {\par\UseTaggingSocket{sec/end}{-10}}
434 \AddToHook{cmd/appendix/before} {\par\UseTaggingSocket{sec/end}{-10}}
435 % \end{macrocode}
436 %
437 % \subsection{Tagging Sockets}
438 % First the sockets that handle the Sect structures.
439 %
440 % The argument of the begin socket consists of two brace groups,
441 % in the first brace is the level, in the second the keys for the structure.
442 % \begin{macrocode}
443 \NewTaggingSocketPlug{sec/begin}{kernel}
444 {
445 \@@_sec_begin:en #1
446 }
447 \AssignTaggingSocketPlug{sec/begin}{kernel}
448 % \end{macrocode}
449 % The end socket takes as argument only the level to close.
450 % \begin{macrocode}
451 \NewTaggingSocketPlug{sec/end}{kernel}
452 {
453 \@@_sec_end:n {#1}
454 }
455 \AssignTaggingSocketPlug{sec/end}{kernel}
456 % \end{macrocode}
457 %
458 % These two sockets handle the tagging of headings titles with special formatting
459 % like part and chapter.
460 % The argument of the begin socket is two brace groups containing the level and
461 % the title.
462 % \begin{macrocode}
463 \NewTaggingSocketPlug{sec/title/begin}{kernel}
464 {
465 \@@_sec_title_begin:nn #1
466 }
467 \AssignTaggingSocketPlug{sec/title/begin}{kernel}
468 % \end{macrocode}
469 % The end socket does not take an argument. It only closes the structures
470 % and restores the para settings.
471 % \begin{macrocode}
472
473 \NewTaggingSocketPlug{sec/title/end}{kernel}
474 {
475 \@@_sec_title_end:
476 }
477 \AssignTaggingSocketPlug{sec/title/end}{kernel}
478 % \end{macrocode}
479 %
480 %
481 % The \texttt{sec/title/hang} socket is used to typeset a heading title using \cs{@hangfrom}.
482 % It is the most tricky one. It takes two arguments.
483 % The second argument of this socket will pass the normal \cs{@hangfrom} command
484 % if tagging is not active. It is not used with tagging.
485 % The first argument passes four brace groups:
486 % the level, a boolean for \enquote{nonumber},
487 % the actual content of the number and the title.
488 %
489 % Attention: The socket opens a structure that it doesn't close (it is closed by the \cs{par}).
490 % It therefore does not handle the full tagging of the title. In a new implementation
491 % of the heading command this will perhaps have to change.
492 % \begin{macrocode}
493 \NewTaggingSocketPlug{sec/title/hang}{kernel}
494 {
495 \@@_set_title_hang:nNnn #1
496 }
497 \AssignTaggingSocketPlug{sec/title/hang}{kernel}
498 % \end{macrocode}
499 %
500 % The \texttt{sec/title/init} socket is used to do some initialization
501 % for heading commands that are set up with \cs{@startsection}. It sets
502 % the tag name and flattens the para-tagging. It is mostly needed for run-in
503 % headings which set the heading inside \cs{everypar}.
504 % It takes 1 argument, the level.
505 % \begin{macrocode}
506 \NewTaggingSocketPlug{sec/title/init}{kernel}
507 {
508 \tl_set:Ne\l_@@_para_tag_tl{\UseStructureName{sec/#1/title}}
509 \bool_set_true:N \l_@@_para_flattened_bool
510 }
511 \AssignTaggingSocketPlug{sec/title/init}{kernel}
512 % \end{macrocode}
513 %
514 % This socket handles the tagging between a run-in heading and the following text.
515 % It takes no argument.
516 % \begin{macrocode}
517 \NewTaggingSocketPlug{sec/title/split}{kernel}
518 {
519 \@@_sec_title_split:
520 }
521 \AssignTaggingSocketPlug{sec/title/split}{kernel}
522 % \end{macrocode}
523 %
524 % The following tagging socket command is used to handle the tagging
525 % of the number in the title of run-in headings. Similar to the hang variant it does not
526 % handle the full structure but relies in part on the paragraph
527 % tagging. This again can change if sectioning commands are reimplemented.
528 % It takes as first argument the level and a boolean for the numbering.
529 % The second argument contains the formatted number (if numbered) and the destination.
530 % \begin{macrocode}
531 \NewTaggingSocketPlug{sec/title/runin/number}{kernel}
532 {
533 \@@_sec_title_runin_number:nNn #1 {#2}
534 }
535 \AssignTaggingSocketPlug{sec/title/runin/number}{kernel}
536 % \end{macrocode}
537 %
538 % The following tagging socket command simply tags a number.
539 % It is not used here, as the legacy code needs a more complicated setup.
540 %
541 % It takes the level as first argument.
542 % The second argument contains the formatted number.
543 % \begin{macrocode}
544 \NewTaggingSocketPlug{sec/title/number}{kernel}
545 {
546 \tag_mc_end_push:
547 \tag_struct_begin:n{tag=\UseStructureName{sec/#1/number}}
548 \tag_mc_begin:n{}
549 #2
550 \tag_mc_end:
551 \tag_struct_end:
552 \tag_mc_begin_pop:n{}
553 }
554 \AssignTaggingSocketPlug{sec/title/number}{kernel}
555 % \end{macrocode}
556 %
557 % \section{Heading commands}
558 %
559 % \subsection{\cs{part} and \cs{chapter}}
560 %
561 % \cs{part} and \cs{chapter} are defined by the classes.
562 % To tag them we redefine the user commands.
563 % This will probably break with various classes and with titlesec.
564 % The tagging inside relies on the para tagging.
565 % We do not yet use keyval in the optional argument, as this requires latex-dev
566 % and the naming of the keys and their key family is unclear.
567 % \changes{v0.84f}{2024/10/04}{Added braces around optional arg (tagging/725)}
568 % \changes{v0.84l}{2026/01/06}{Removed redefinition of \cs{chapter} and \cs{part}. Now done with templates.}
569 %
570 %
571 % \subsubsection{Hyperref code}
572 % Package \pkg{hyperref} has to insert anchors. If the heading is numbered this is done by
573 % \cs{refstepcounter} (and so in vmode). For unnumbered headings hyperref
574 % injects the anchor in hmode before the text, it also inserts a
575 % kern to compensate the indent.
576 %
577 % This means that the target of numbered and unnumbered sectioning commands
578 % differ, both regarding the location and in relation to the
579 % tagging structure: The anchor from the \cs{refstepcounter} is outside of
580 % the structure created by the heading title if the para tags are used,
581 % while the other anchors are inside and so the structure destinations are different.
582 %
583 %
584 % \changes{0.84n}{2026-04-24}{Removed the suppressing of hyperref patches, it is done by hyperref now.}
585 % \changes{0.84n}{2026-04-24}{Removed the hyperref code, this is done in the template implementation.}
586 %
587 % \subsection{Adaption of the heading commands}
588 %
589 % \changes{0.84n}{2026-04-24}{Removed the code, as it is now superseded
590 % by the new implementation in latex-lab-sec-template}
591 %
592 % \subsection{Keys for \cs{tagpdfsetup}}
593 % We need to provide user and package level commands
594 % \changes{0.84k}{2025/04/09}{Add braces around key values, tagging issue \#830}
595 % \changes{0.84j}{2025-10-11}{add \cs{tagpdfsetup} keys for two user facing keys}
596 %
597 % \begin{macrocode}
598 \keys_define:nn{__tag / setup}
599 {
600 ,sec/end .code:n =
601 {
602 \par
603 \UseTaggingSocket{sec/end}{\int_eval:n{\cs_if_exist_use:c{toclevel@#1}+0}}
604 }
605 ,sec/end .value_required:n = true
606 ,sec/grouping .choice:,
607 ,sec/grouping / true .code:n =
608 {
609 \AssignTaggingSocketPlug{sec/begin}{kernel}
610 \AssignTaggingSocketPlug{sec/end}{kernel}
611 }
612 ,sec/grouping / false .code:n =
613 {
614 \AssignTaggingSocketPlug{sec/begin}{noop}
615 \AssignTaggingSocketPlug{sec/end}{noop}
616 }
617 ,sec/grouping .default:n = true
618 }
619 % \end{macrocode}
620 % \begin{macrocode}
621 %</package>
622 % \end{macrocode}