Debian Codegraph @

texmf-dist/source/latex/latex-lab/latex-lab-toc-hyperref-changes.dtx

raw
1 % \iffalse meta-comment
2 %
3 %% File: latex-lab-toc-hyperref-changes.dtx (C) Copyright 2022-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\ltlabtochyperdate{2025-05-10}
20 \def\ltlabtochyperversion{0.85b}
21 %<*driver>
22 \DocumentMetadata{tagging=on,pdfstandard=ua-2}
23 \documentclass[kernel]{l3doc}
24 \usepackage{latex-lab-testphase-l3doc}
25 \EnableCrossrefs
26 \CodelineIndex
27 \begin{document}
28 \DocInput{latex-lab-toc-hyperref-changes.dtx}
29 \end{document}
30 %</driver>
31 %
32 % \fi
33 % \title{The \textsf{latex-lab-toc-hyperref-changes} package\\
34 % Changes and additions to hyperref related to toc entries}
35 % \author{\LaTeX{} Project\thanks{Initial implementation done by Ulrike Fischer}}
36 % \date{v\ltlabtochyperversion\ \ltlabtochyperdate}
37 %
38 % \maketitle
39 %
40 % \newcommand{\xt}[1]{\textsl{\textsf{#1}}}
41 % \newcommand{\TODO}[1]{\textbf{[TODO:} #1\textbf{]}}
42 % \newcommand{\docclass}{document class \marginpar{\raggedright document class
43 % customizations}}
44 %
45 % \providecommand\hook[1]{\texttt{#1}}
46 %
47 % \begin{abstract}
48 % \end{abstract}
49 %
50 % \section{Introduction}
51 %
52 % The followings contains various change needed for hyperref for the new toc tagging
53 % code. They should be only loaded if hyperref is used!
54 % \begin{macrocode}
55 %<*package>
56 % \end{macrocode}
57 %
58 % \section{Changes for hyperref}
59 % \subsection{\cs{contentsline},\cs{addcontentsline}}
60 % The standard \cs{contentsline} and \cs{addcontentsline}
61 % should also be used with hyperref (together
62 % with more changes below) so we have to disable the redefinition in hyperref (this
63 % requires hyperref version 7.00v!
64 % \begin{macrocode}
65 \def\hyper@nopatch@toc{}
66 \AddToHook{package/hyperref/after}
67 {
68 \@ifpackagelater{hyperref}{2023-02-07}{}
69 {\PackageWarning{latex-lab-testphase-toc-tagging}{hyperref too old}{}}
70 }
71 % \end{macrocode}
72 %
73 % \subsection{Add links to toc entries}
74 % \begin{macrocode}
75 \ExplSyntaxOn
76 \AddToHook{package/hyperref/after}
77 {
78 \AddToHookWithArguments{contentsline/text/before}[hyp]
79 {
80 \tl_if_blank:nF {#2}%text
81 {
82 \tl_if_blank:nF {#4}%destination
83 {
84 \int_case:nnF {\Hy@linktoc}
85 {
86 {0}{} %none
87 {1}{\hyper@linkstart{link}{#4}} %section
88 {2}{} %page
89 }
90 {\hyper@linkstart{link}{#4}} %all
91 }
92 }
93 }
94 \AddToHookWithArguments{contentsline/text/after}[hyp]
95 {
96 \tl_if_blank:nF {#2}
97 {
98 \tl_if_blank:nF {#4}
99 {
100 \int_case:nnF {\Hy@linktoc}
101 {
102 {0}{} %none
103 {1}{\hyper@linkend} %section
104 {2}{} %page
105 }
106 {\hyper@linkend} %all
107 } % none
108 }
109 }
110
111 \AddToHookWithArguments{contentsline/page/before}[hyp]
112 {
113 \tl_if_blank:nF {#3}
114 {
115 \tl_if_blank:nF {#4} %
116 {
117 \int_case:nnF {\Hy@linktoc}
118 {
119 {0}{} %none
120 {1}{} %section
121 {2}{\hyper@linkstart{link}{#4}} %page
122 }
123 {\hyper@linkstart{link}{#4}} %all
124 } % none
125 }
126 }
127 \AddToHookWithArguments{contentsline/page/after}[hyp]
128 {
129 \tl_if_blank:nF {#3}
130 {
131 \tl_if_blank:nF {#4}
132 {
133 \int_case:nnF {\Hy@linktoc}
134 {
135 {0}{} %none
136 {1}{} %section
137 {2}{\hyper@linkend} %page
138 }
139 {\hyper@linkend} %all
140 } % none
141 }
142 }
143 \AddToHookWithArguments{cmd/addcontentsline/before}[hyp]
144 {%
145 \Hy@addcontentsline@addbookmark
146 {#1}
147 {#2}
148 {#3}%
149 }
150 }
151 \ExplSyntaxOff
152 % \end{macrocode}
153 % \subsection{Add bookmark code to \cs{addcontentsline}}
154 %
155 % \begin{macrocode}
156 \newcommand\Hy@addcontentsline@addbookmark[3]%#1 toc type, #2 level, #3 content
157 {%
158 \ifx\@currentHref\@empty
159 \Hy@Warning{%
160 No destination for bookmark of \string\addcontentsline,%
161 \MessageBreak destination is added%
162 }%
163 \phantomsection
164 \fi
165 \begingroup
166 \expandafter\ifx\csname toclevel@#2\endcsname\relax
167 \begingroup
168 \def\Hy@tempa{#1}%
169 \ifx\Hy@tempa\Hy@bookmarkstype
170 \Hy@WarningNoLine{%
171 bookmark level for unknown #2 defaults to 0%
172 }%
173 \else
174 \Hy@Info{bookmark level for unknown #2 defaults to 0}%
175 \fi
176 \endgroup
177 \expandafter\gdef\csname toclevel@#2\endcsname{0}%
178 \fi
179 \edef\Hy@toclevel{\csname toclevel@#2\endcsname}%
180 \Hy@writebookmark{\csname the#2\endcsname}%
181 {#3}%
182 {\@currentHref}%
183 {\Hy@toclevel}%
184 {#1}%
185 \ifHy@verbose
186 \begingroup
187 \def\Hy@tempa{#3}%
188 \@onelevel@sanitize\Hy@tempa
189 \let\temp@online\on@line
190 \let\on@line\@empty
191 \Hy@Info{%
192 bookmark\temp@online:\MessageBreak
193 thecounter {\csname the#2\endcsname}\MessageBreak
194 text {\Hy@tempa}\MessageBreak
195 reference {\@currentHref}\MessageBreak
196 toclevel {\Hy@toclevel}\MessageBreak
197 type {#1}%
198 }%
199 \endgroup
200 \fi
201 \endgroup
202 }
203 % \end{macrocode}
204 % \begin{macrocode}
205 %</package>
206 % \end{macrocode}