%% %% This is file `latex-lab-testphase-bookmark.sty', %% generated with the docstrip utility. %% %% The original source files were: %% %% latex-lab-bookmark.dtx (with options: `package') %% %% Copyright (C) 2019-2026 The 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 %% %% This file is part of the "LaTeX PDF management bundle" (The Work in LPPL) %% and all files in that bundle must be distributed together. %% %% File: latex-lab-bookmark.dtx (C) Copyright 2026 LaTeX Project \def\ltlabbookmarkdate{2026-02-18} \def\ltlabbookmarkversion{0.95} \ProvidesExplPackage{latex-lab-testphase-bookmark}{2026-05-26}{0.97c} {PDF bookmarks with kernel methods}% \int_new:N \g__hyp_outline_currentlevel_int \int_new:N \l__hyp_outline_level_int \intarray_new:Nn \g__hyp_outline_level_intarray {2000} %TODO size?? \intarray_gset:Nnn \g__hyp_outline_level_intarray {1}{0} \int_new:N \l__hyp_outline_depth_int \tl_new:N \l__hyp_outline_title_tl \tl_new:N \l__hyp_outline_action_data_tl \tl_new:N \l__hyp_outline_action_dest_data_tl \tl_new:N \l__hyp_outline_action_view_tl \bool_new:N \l__hyp_outline_keeplevel_bool \seq_new:N \l__hyp_outline_type_seq \bitset_new:Nn \l__hyp_outline_action_bitset { goto = 1, gotor = 2, named = 3, uri = 4, raw = 5, namedest = 6, pagedest = 7 } \bitset_set_true:Nn \l__hyp_outline_action_bitset { goto } \int_new:N \l__hyp_outline_tmpa_int \int_new:N \l__hyp_outline_rellevel_tmpa_int \tl_new:N \l__hyp_outline_parent_tmpa_tl \seq_new:N \l__hyp_outline_tmpa_seq \tl_new:N \l__hyp_outline_tmpa_tl \str_new:N \g__hyp_outline_tmpa_str \socket_new:nn {hyp/outline/title}{2} \socket_new_plug:nnn {hyp/outline/title}{pdfstringdef} { \pdfstringdef#2{#1} } \socket_new_plug:nnn {hyp/outline/title}{default} { \pdf_purify:nN {#1}#2 \pdf_string_from_unicode:nVN {utf16/string-raw} #2 #2 } \socket_assign_plug:nn {hyp/outline/title}{default} \regex_const:Nn \c__hyp_outline_dest_startview_regex { \A\ * (?: (?:XYZ (?:\ +(?:(?:\d+|\d*\.\d+)|null)){3}\ ) | (?:Fit\b|FitB\b) | (?:(?:FitH|FitV|FitBH|FitBV)(?:\ +(?:\d+|\d*\.\d+)|\ +null){1}) | (?:FitR (?:\ +\d+|\ +\d*\.\d+){4}\ ) ) } \msg_new:nnn { hyp /outline } { invalid-view-value } { Invalid~value~'#1'~of~'#2' \\ is~replaced~by~'Fit'~\msg_line_context:. } \msg_new:nnn {hyp/outline}{no-action} { bookmark~action~missing!\\ Use~one~of~'dest',~'gotor',~'named',~'uri',~or~'rawaction' } \socket_new:nn {hyp/outline/numberformat}{0} \socket_new_plug:nnn {hyp/outline/numberformat}{false} { \text_declare_purify_equivalent:Nn\numberline\use_none:n \text_declare_purify_equivalent:Nn\booknumberline\use_none:n \text_declare_purify_equivalent:Nn\partnumberline\use_none:n \text_declare_purify_equivalent:Nn\chapternumberline\use_none:n \cs_set_eq:NN\numberline\use_none:n \cs_set_eq:NN\booknumberline\use_none:n \cs_set_eq:NN\partnumberline\use_none:n \cs_set_eq:NN\chapternumberline\use_none:n } \cs_new:Npn \__hyp_outline_use_numberline:n #1 {#1\c_space_tl} \socket_new_plug:nnn {hyp/outline/numberformat}{true} { \text_declare_purify_equivalent:Nn\numberline \__hyp_outline_use_numberline:n \text_declare_purify_equivalent:Nn\booknumberline \__hyp_outline_use_numberline:n \text_declare_purify_equivalent:Nn\partnumberline \__hyp_outline_use_numberline:n \text_declare_purify_equivalent:Nn\chapternumberline\__hyp_outline_use_numberline:n \cs_set_eq:NN \numberline \__hyp_outline_use_numberline:n \cs_set_eq:NN\booknumberline \__hyp_outline_use_numberline:n \cs_set_eq:NN\partnumberline \__hyp_outline_use_numberline:n \cs_set_eq:NN\chapternumberline\__hyp_outline_use_numberline:n } \keys_define:nn {hyp/outline} { ,bold .choice: ,bold / true .code:n = \bitset_set_true:Nn \l_pdfoutline_F_bitset {Bold} ,bold /false .code:n = \bitset_set_false:Nn\l_pdfoutline_F_bitset {Bold} ,bold .default:n = true ,italic .choice: ,italic / true .code:n = \bitset_set_true:Nn\l_pdfoutline_F_bitset {Italic} ,italic /false .code:n = \bitset_set_false:Nn\l_pdfoutline_F_bitset {Italic} ,italic .default:n = true ,numbered .code:n = { \socket_assign_plug:nn { hyp/outline/numberformat } {#1}} ,numbered .default:n = true ,numbered .initial:n = false ,bookmarksnumbered .meta:n = {numbered} ,color .tl_set:N = \l_pdfoutline_color_tl ,open .bool_set:N = \l_pdfoutline_open_bool ,depth .code:n = { \cs_if_exist:cTF {toclevel@#1} { \int_set:Nn \l__hyp_outline_depth_int { \use:c {toclevel@#1} } } { \int_set:Nn \l__hyp_outline_depth_int { #1 } } } ,bookmarksdepth .meta:n = { depth = #1 } ,depth .initial:n = {\int_use:N \c_max_int} ,openlevel .int_set:N = \l_pdfoutline_open_int ,bookmarksopenlevel .meta:n = { openlevel = #1 } ,level .code:n = { \cs_if_exist:cTF {toclevel@#1} { \int_set:Nn \l__hyp_outline_level_int { \use:c {toclevel@#1} } } { \int_set:Nn \l__hyp_outline_level_int { #1 } } } ,rellevel .code:n = { \int_set:Nn \l__hyp_outline_level_int { \g__hyp_outline_currentlevel_int + #1 } } ,keeplevel .bool_set:N = \l__hyp_outline_keeplevel_bool ,startatroot .code:n = { \int_set:Nn \l__hyp_outline_level_int { -1000 } \bool_if:NF \l__hyp_outline_keeplevel_bool { \int_gset:Nn \g__hyp_outline_currentlevel_int {#1} \bool_set_true:NF \l__hyp_outline_keeplevel_bool } } ,startatroot .default:n = 0 ,dest .code:n = { \int_compare:nNnTF { \bitset_item:Nn \l__hyp_outline_action_bitset {gotor} } = {1} { \bitset_clear:N \l__hyp_outline_action_bitset \bitset_set_true:Nn \l__hyp_outline_action_bitset { gotor } } { \bitset_clear:N \l__hyp_outline_action_bitset \bitset_set_true:Nn \l__hyp_outline_action_bitset { goto } } \bitset_set_true:Nn \l__hyp_outline_action_bitset { namedest } \tl_set:Nn\l__hyp_outline_action_dest_data_tl {#1} } ,dest .default:n = Doc-Start ,goto .code:n = { \bitset_clear:N \l__hyp_outline_action_bitset \bitset_set_true:Nn \l__hyp_outline_action_bitset { goto } \bitset_set_true:Nn \l__hyp_outline_action_bitset { namedest } \tl_set:Nn\l__hyp_outline_action_dest_data_tl {#1} } ,gotor .code:n = { \int_compare:nNnTF { \bitset_item:Nn \l__hyp_outline_action_bitset {pagedest} } = {1} { \bitset_clear:N \l__hyp_outline_action_bitset \bitset_set_true:Nn \l__hyp_outline_action_bitset { pagedest } } { \bitset_clear:N \l__hyp_outline_action_bitset \bitset_set_true:Nn \l__hyp_outline_action_bitset { namedest } } \bitset_set_true:Nn \l__hyp_outline_action_bitset { gotor } \tl_set:Nn\l__hyp_outline_action_data_tl {#1} } ,named .choices:nn = {FirstPage, NextPage, PrevPage, LastPage} { \bitset_clear:N \l__hyp_outline_action_bitset \bitset_set_true:Nn \l__hyp_outline_action_bitset { named } \tl_set:Nn \l__hyp_outline_action_data_tl {/#1} } ,page .code:n = { \int_compare:nNnTF { \bitset_item:Nn \l__hyp_outline_action_bitset {gotor} } = {1} { \bitset_clear:N \l__hyp_outline_action_bitset \bitset_set_true:Nn \l__hyp_outline_action_bitset { gotor } } { \bitset_clear:N \l__hyp_outline_action_bitset \bitset_set_true:Nn \l__hyp_outline_action_bitset { goto } } \bitset_set_true:Nn \l__hyp_outline_action_bitset { pagedest } \tl_set:Nn \l__hyp_outline_action_dest_data_tl {#1} } ,page .default:n = 1 ,rawaction .code:n = { \bitset_clear:N \l__hyp_outline_action_bitset \bitset_set_true:Nn \l__hyp_outline_action_bitset { uri } \tl_set:Nn\l__hyp_outline_action_data_tl {#1} } ,view .code:n = { \tl_set:Ne \l__hyp_outline_tmpa_tl {#1~null~null~null~} \exp_args:NNV \regex_extract_once:NnNTF \c__hyp_outline_dest_startview_regex \l__hyp_outline_tmpa_tl \l__hyp_outline_tmpa_seq { \tl_set:Ne \l__hyp_outline_action_view_tl {/\seq_item:Nn \l__hyp_outline_tmpa_seq {1}} } { \msg_warning:nnnn {hyp/outline}{invalid-view-value}{#1}{view} \tl_set:Nn \l__hyp_outline_action_view_tl {Fit} } } ,uri .code:n = { \bitset_clear:N \l__hyp_outline_action_bitset \bitset_set_true:Nn \l__hyp_outline_action_bitset { uri } \pdf_purify:nN{#1}\l__hyp_outline_action_data_tl \pdf_string_from_unicode:nVN { utf8/URI } \l__hyp_outline_action_data_tl \l__hyp_outline_action_data_tl } ,lists .code:n = { \seq_set_from_clist:Nn \l__hyp_outline_type_seq { #1 } } ,lists .initial:n = toc ,bookmarkstype .meta:n = {lists={#1}} } \NewDocumentCommand\bookmarksetup{m}{\keys_set:nn{hyp/outline}{#1}} \NewHook{bookmark} \NewDocumentCommand\bookmarksetupnext{m}{\AddToHookNext{bookmark}{\bookmarksetup{#1}}} \cs_new:Npn\bookmarkget #1 {\use:c{__hyp_bookmarkget_#1:}} \cs_new:Npn\__hyp_bookmarkget_level:{\int_use:N\l__hyp_outline_level_int} \NewDocumentCommand\bookmark{O{}m} { \bool_if:NT \l_pdfoutline_active_bool { \group_begin: \keys_set:nn {hyp/outline} { #1 } \UseHook{bookmark} \socket_use:nnn{hyp/outline/title}{#2}\l__hyp_outline_title_tl \int_compare:nNnF {\l__hyp_outline_level_int} > {\l__hyp_outline_depth_int} { \__hyp_outline_bookmark_aux: } \group_end: } } \cs_new_protected:Npn \__hyp_outline_bookmark_aux: { \__hyp_outline_calc_rellevel:NN \l__hyp_outline_level_int \l__hyp_outline_rellevel_tmpa_int \bool_if:NF\l__hyp_outline_keeplevel_bool { \int_gset:Nn \g__hyp_outline_currentlevel_int { \l__hyp_outline_level_int } } \int_compare:nNnTF { \bitset_item:Nn \l__hyp_outline_action_bitset {goto} * \bitset_item:Nn \l__hyp_outline_action_bitset {namedest} } = {1} { \pdfoutline_goto:nee { \l__hyp_outline_rellevel_tmpa_int } %level { \l__hyp_outline_action_dest_data_tl } { \l__hyp_outline_title_tl } } { \int_case:nnF { \bitset_to_arabic:N \l__hyp_outline_action_bitset } { { 65 } % goto (1) + pagedest (65) { \pdfoutline_action:nee { \l__hyp_outline_rellevel_tmpa_int } { /S/GoTo~ /D [ \pdf_pageobject_ref:n { \l__hyp_outline_action_dest_data_tl }~ \l__hyp_outline_action_view_tl ] } { \l__hyp_outline_title_tl } } { 34 } % gotor (2) + namedest (32) { \pdfoutline_action:nee { \l__hyp_outline_rellevel_tmpa_int } { /S/GoToR~ /F ( \l__hyp_outline_action_data_tl ) %Todo check format /D ( \l__hyp_outline_action_dest_data_tl ) %Todo check format } { \l__hyp_outline_title_tl } } { 66 } % gotor (2) + pagedest (64) { \pdfoutline_action:nee { \l__hyp_outline_rellevel_tmpa_int } { /S/GoToR~ /F ( \l__hyp_outline_action_data_tl ) %Todo check format /D [ \pdf_pageobject_ref:n { \l__hyp_outline_action_dest_data_tl }~ \l__hyp_outline_action_view_tl ] } { \l__hyp_outline_title_tl } } { 4 } % named (4) { \pdfoutline_action:nee { \l__hyp_outline_rellevel_tmpa_int } { /S/Named~ /N \l__hyp_outline_action_data_tl %TODO check formt } { \l__hyp_outline_title_tl } } { 8 } % uri (8) { \pdfoutline_action:nee { \l__hyp_outline_rellevel_tmpa_int } { /S/URI~ /URI \l__hyp_outline_action_data_tl %TODO check formt } { \l__hyp_outline_title_tl } } { 16 } % raw (16) { \pdfoutline_action:nee { \l__hyp_outline_rellevel_tmpa_int } { \l__hyp_outline_action_data_tl %TODO check formt } { \l__hyp_outline_title_tl } } } { \msg_error:nn {hyp/outline}{no-action} } } \intarray_gset:Nnn \g__hyp_outline_level_intarray { \pdfoutline_id_ref_last: } { \g__hyp_outline_currentlevel_int } } % \cs_new_protected:Npn\__hyp_outline_calc_rellevel:NN #1 #2 % #1 the requested level, #2 the return value { \int_compare:nNnTF { #1 } < { \g__hyp_outline_currentlevel_int } { \int_set:Nn #2 { 0 } \tl_set:Ne \l__hyp_outline_parent_tmpa_tl { \pdfoutline_parent_ref:n { \pdfoutline_id_ref_last: } } \int_compare:nNnTF { \l__hyp_outline_parent_tmpa_tl } > { 0 } { \int_set:Nn \l__hyp_outline_tmpa_int { \intarray_item:Nn \g__hyp_outline_level_intarray { \l__hyp_outline_parent_tmpa_tl } } } { \int_set_eq:NN \l__hyp_outline_tmpa_int #1 } \int_do_while:nNnn { \l__hyp_outline_tmpa_int } > { #1 } { \int_case:nn { \int_sign:n { \l__hyp_outline_tmpa_int-#1 } } { { 0 } { \int_decr:N #2 } { 1 } { \int_decr:N #2 \tl_set:Ne \l__hyp_outline_parent_tmpa_tl { \pdfoutline_parent_ref:n { \l__hyp_outline_parent_tmpa_tl } } \int_compare:nNnTF { \l__hyp_outline_parent_tmpa_tl } > { 1 } { \int_set:Nn \l__hyp_outline_tmpa_int { \intarray_item:Nn \g__hyp_outline_level_intarray { \l__hyp_outline_parent_tmpa_tl } } } { % root \int_set_eq:NN \l__hyp_outline_tmpa_int #1 } } } } \int_if_zero:nT {\l__hyp_outline_tmpa_int-#1}{\int_decr:N #2} } { \int_set:Nn #2 { #1 - \g__hyp_outline_currentlevel_int } } } \disable@package@load{bookmark}{\RequirePackage{hyperref}} \DeclareHookRule{package/hyperref/after}% {latex-lab-testphase-bookmark}{voids}{latex-lab-testphase-sec-template} \DeclareHookRule{package/hyperref/after}% {latex-lab-testphase-bookmark}{voids}{latex-lab-testphase-sec} \DeclareHookRule{package/hyperref/after}% {latex-lab-testphase-bookmark}{voids}{latex-lab-testphase-toc} \AddToHook{package/hyperref/after} { \RemoveFromHook{cmd/addcontentsline/before}[hyp] \AddToHookWithArguments{cmd/addcontentsline/before}[hyp/outline] { \__hyp_addcontentsline_bookmark:nnn {#1}{#2}{#3} } \providecommand\addcontentslinebookmark{} \providecommand\addcontentslinebookmarkOff{} \RenewCommandCopy\addcontentslinebookmark\__hyp_addcontentsline_bookmark:nnn \renewcommand\addcontentslinebookmarkOff { \bool_if:NTF \l_pdfoutline_active_bool { \def\addcontentslinebookmarkReset{\bool_set_true:N\l_pdfoutline_active_bool} } { \let\addcontentslinebookmarkReset\relax } \bool_set_false:N\l_pdfoutline_active_bool } \legacy_if:nF{Hy@bookmarks}{\bool_set_false:N\l_pdfoutline_active_bool} \renewcommand*{\pdfbookmark}[3][0]{% \bookmark[level=#1,dest={#3.#1}]{#2}% \hyper@anchorstart{#3.#1}\hyper@anchorend} \def\currentpdfbookmark#1#2#3{% \bookmark[rellevel=0,dest={#3.#1}]{#2}% \hyper@anchorstart{#3.#1}\hyper@anchorend} \def\subpdfbookmark#1#2#3{% \bookmark[rellevel=1,dest={#3.#1}]{#2}% \hyper@anchorstart{#3.#1}\hyper@anchorend} \def\belopdfbookmark#1#2#3{% \bookmark[keeplevel,rellevel=1,dest={#3.#1}]{#2}% \hyper@anchorstart{#3.#1}\hyper@anchorend} \keys_define:nn{hyp} {bookmarksdepth .meta:nn = {hyp/outline}{depth=#1}, bookmarksopen .meta:nn = {hyp/outline}{open}, bookmarksopenlevel .meta:nn = {hyp/outline}{openlevel=#1}, bookmarksnumbered .meta:nn = {hyp/outline}{numbered}} } \DeclareHookRule{package/hyperref/after}{latex-lab-testphase-bookmark}{after}{latex-lab-testphase-toc} \cs_new_protected:Npn \__hyp_addcontentsline_bookmark:nnn #1 #2 #3 %%#1 toc type, #2 level, #3 content { \seq_if_in:NeT \l__hyp_outline_type_seq { #1 } { \tl_if_empty:NT\@currentHref { \MakeLinkTarget[page] {} } \tl_if_exist:cF { toclevel@#2 } { \tl_new:c { toclevel@#2 } \tl_gset:cn { toclevel@#2 } { 0 } % message } \group_begin: \socket_use:n{hyp/outline/numberformat} \bookmark[level=#2,dest={\HyperDestNameFilter{\@currentHref}}]{#3} \group_end: } } %% %% %% End of file `latex-lab-testphase-bookmark.sty'.