summaryrefslogtreecommitdiff
path: root/macros/latex-dev/required/latex-lab/latex-lab-toc-hyperref-changes.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex-dev/required/latex-lab/latex-lab-toc-hyperref-changes.dtx')
-rw-r--r--macros/latex-dev/required/latex-lab/latex-lab-toc-hyperref-changes.dtx203
1 files changed, 203 insertions, 0 deletions
diff --git a/macros/latex-dev/required/latex-lab/latex-lab-toc-hyperref-changes.dtx b/macros/latex-dev/required/latex-lab/latex-lab-toc-hyperref-changes.dtx
new file mode 100644
index 0000000000..ea39e3a6a5
--- /dev/null
+++ b/macros/latex-dev/required/latex-lab/latex-lab-toc-hyperref-changes.dtx
@@ -0,0 +1,203 @@
+% \iffalse meta-comment
+%
+%% File: toc-hyperref-changes.dtx (C) Copyright 2022-2023 LaTeX Project
+%
+% It may be distributed and/or modified under the conditions of the
+% LaTeX Project Public License (LPPL), either version 1.3c of this
+% license or (at your option) any later version. The latest version
+% of this license is in the file
+%
+% https://www.latex-project.org/lppl.txt
+%
+%
+% The development version of the bundle can be found below
+%
+% https://github.com/latex3/latex2e/required/latex-lab
+%
+% for those people who are interested or want to report an issue.
+%
+%<*driver>
+\documentclass{l3doc}
+\EnableCrossrefs
+\CodelineIndex
+\begin{document}
+ \DocInput{latex-lab-toc-hyperref-changes.dtx}
+\end{document}
+%</driver>
+%
+% \fi
+% \title{The \textsf{toc-hyperref-changes} package\\
+% Changes and additions to hyperref related to toc entries}
+% \author{\LaTeX{} Project\thanks{Initial implementation done by Ulrike Fischer}}
+% \date{Version 0.81 2023-02-10}
+%
+% \maketitle
+%
+% \newcommand{\xt}[1]{\textsl{\textsf{#1}}}
+% \newcommand{\TODO}[1]{\textbf{[TODO:} #1\textbf{]}}
+% \newcommand{\docclass}{document class \marginpar{\raggedright document class
+% customizations}}
+%
+% \providecommand\hook[1]{\texttt{#1}}
+%
+% \begin{abstract}
+% \end{abstract}
+%
+% \section{Introduction}
+%
+% The followings contains various change needed for hyperref for the new toc tagging
+% code. They should be only loaded if hyperref is used!
+% \begin{macrocode}
+%<*package>
+% \end{macrocode}
+%
+% \section{Changes for hyperref}
+% \subsection{\cs{contentsline},\cs{addcontentsline}}
+% The standard \cs{contentsline} and \cs{addcontentsline}
+% should also be used with hyperref (together
+% with more changes below) so we have to disable the redefinition in hyperref (this
+% requires hyperref version 7.00v!
+% \begin{macrocode}
+\def\hyper@nopatch@toc{}
+\AddToHook{package/hyperref/after}
+ {
+ \@ifpackagelater{hyperref}{2023-02-07}{}
+ {\PackageWarning{latex-lab-testphase-toc-tagging}{hyperref too old}{}}
+ }
+% \end{macrocode}
+%
+% \subsection{Add links to toc entries}
+% \begin{macrocode}
+\ExplSyntaxOn
+\AddToHook{package/hyperref/after}
+ {
+ \AddToHook{contentsline/text/before}[hyp]
+ {
+ \tl_if_blank:VF \@contentsline@arg@two%text
+ {
+ \tl_if_blank:VF\@contentsline@arg@four%destination
+ {
+ \int_case:nnF {\Hy@linktoc}
+ {
+ {0}{} %none
+ {1}{\hyper@linkstart{link}{\@contentsline@arg@four}} %section
+ {2}{} %page
+ }
+ {\hyper@linkstart{link}{\@contentsline@arg@four}} %all
+ }
+ }
+ }
+ \AddToHook{contentsline/text/after}[hyp]
+ {
+ \tl_if_blank:VF \@contentsline@arg@two
+ {
+ \tl_if_blank:VF\@contentsline@arg@four
+ {
+ \int_case:nnF {\Hy@linktoc}
+ {
+ {0}{} %none
+ {1}{\hyper@linkend} %section
+ {2}{} %page
+ }
+ {\hyper@linkend} %all
+ } % none
+ }
+ }
+
+ \AddToHook{contentsline/page/before}[hyp]
+ {
+ \tl_if_blank:VF \@contentsline@arg@three
+ {
+ \tl_if_blank:VF\@contentsline@arg@two
+ {
+ \int_case:nnF {\Hy@linktoc}
+ {
+ {0}{} %none
+ {1}{} %section
+ {2}{\hyper@linkstart{link}{\@contentsline@arg@four}} %page
+ }
+ {\hyper@linkstart{link}{\@contentsline@arg@four}} %all
+ } % none
+ }
+ }
+ \AddToHook{contentsline/page/after}[hyp]
+ {
+ \tl_if_blank:VF \@contentsline@arg@three
+ {
+ \tl_if_blank:VF\@contentsline@arg@four
+ {
+ \int_case:nnF {\Hy@linktoc}
+ {
+ {0}{} %none
+ {1}{} %section
+ {2}{\hyper@linkend} %page
+ }
+ {\hyper@linkend} %all
+ } % none
+ }
+ }
+ \AddToHook{cmd/addcontentsline/before}[hyp]
+ {%
+ \ExpandArgs{ooo}
+ \Hy@addcontentsline@addbookmark
+ {\addcontentsline@arg@one}
+ {\addcontentsline@arg@two}
+ {\addcontentsline@arg@three}%
+ }
+ }
+\ExplSyntaxOff
+% \end{macrocode}
+% \subsection{Add bookmark code to \cs{addcontentsline}}
+%
+% \begin{macrocode}
+\newcommand\Hy@addcontentsline@addbookmark[3]%#1 toc type, #2 level, #3 content
+ {%
+ \ifx\@currentHref\@empty
+ \Hy@Warning{%
+ No destination for bookmark of \string\addcontentsline,%
+ \MessageBreak destination is added%
+ }%
+ \phantomsection
+ \fi
+ \begingroup
+ \expandafter\ifx\csname toclevel@#2\endcsname\relax
+ \begingroup
+ \def\Hy@tempa{#1}%
+ \ifx\Hy@tempa\Hy@bookmarkstype
+ \Hy@WarningNoLine{%
+ bookmark level for unknown #2 defaults to 0%
+ }%
+ \else
+ \Hy@Info{bookmark level for unknown #2 defaults to 0}%
+ \fi
+ \endgroup
+ \expandafter\gdef\csname toclevel@#2\endcsname{0}%
+ \fi
+ \edef\Hy@toclevel{\csname toclevel@#2\endcsname}%
+ \Hy@writebookmark{\csname the#2\endcsname}%
+ {#3}%
+ {\@currentHref}%
+ {\Hy@toclevel}%
+ {#1}%
+ \ifHy@verbose
+ \begingroup
+ \def\Hy@tempa{#3}%
+ \@onelevel@sanitize\Hy@tempa
+ \let\temp@online\on@line
+ \let\on@line\@empty
+ \Hy@Info{%
+ bookmark\temp@online:\MessageBreak
+ thecounter {\csname the#2\endcsname}\MessageBreak
+ text {\Hy@tempa}\MessageBreak
+ reference {\@currentHref}\MessageBreak
+ toclevel {\Hy@toclevel}\MessageBreak
+ type {#1}%
+ }%
+ \endgroup
+ \fi
+ \endgroup
+ }
+% \end{macrocode}
+% \begin{macrocode}
+%</package>
+% \end{macrocode}