| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
%% File: l3pdfoutline.dtx |
| 4 |
% |
| 5 |
% Copyright (C) 2026 The LaTeX Project |
| 6 |
% |
| 7 |
% It may be distributed and/or modified under the conditions of the |
| 8 |
% LaTeX Project Public License (LPPL), either version 1.3c of this |
| 9 |
% license or (at your option) any later version. The latest version |
| 10 |
% of this license is in the file |
| 11 |
% |
| 12 |
% http://www.latex-project.org/lppl.txt |
| 13 |
% |
| 14 |
% This file is part of the "LaTeX PDF management testphase bundle" (The Work in LPPL) |
| 15 |
% and all files in that bundle must be distributed together. |
| 16 |
% |
| 17 |
% ----------------------------------------------------------------------- |
| 18 |
% |
| 19 |
% The development version of the bundle can be found at |
| 20 |
% |
| 21 |
% https://github.com/latex3/pdfresources |
| 22 |
% |
| 23 |
% for those people who are interested. |
| 24 |
% |
| 25 |
%<*driver> |
| 26 |
\DocumentMetadata{tagging=on,pdfstandard=ua-2,testphase=bookmark} |
| 27 |
\documentclass[kernel]{l3in2edoc} |
| 28 |
\usepackage{booktabs} |
| 29 |
\hypersetup{pdfauthor=The LaTeX Project, |
| 30 |
pdftitle=l3pdfoutline (LaTeX PDF management bundle)} |
| 31 |
\begin{document} |
| 32 |
\DocInput{\jobname.dtx} |
| 33 |
\end{document} |
| 34 |
%</driver> |
| 35 |
% \fi |
| 36 |
% \providecommand\hook[1]{\texttt{#1}} |
| 37 |
% \title{^^A |
| 38 |
% The \pkg{l3pdfoutline} module\\ Commands for PDF bookmarks ^^A |
| 39 |
% \\ \LaTeX{} PDF management bundle |
| 40 |
% } |
| 41 |
% |
| 42 |
% \author{^^A |
| 43 |
% The \LaTeX{} Project\thanks |
| 44 |
% {^^A |
| 45 |
% E-mail: |
| 46 |
% \href{mailto:[email protected]} |
| 47 |
% {[email protected]}^^A |
| 48 |
% }^^A |
| 49 |
% } |
| 50 |
% |
| 51 |
% \date{Version 0.97c, released 2026-05-26} |
| 52 |
% |
| 53 |
% \maketitle |
| 54 |
% \begin{documentation} |
| 55 |
% |
| 56 |
% \section{\pkg{l3pdfoutline} documentation} |
| 57 |
% \subsection{Introduction} |
| 58 |
% This module contains a number of commands to create the PDF outline, also |
| 59 |
% called bookmarks. |
| 60 |
% |
| 61 |
% \emph{Attention:} There can be only one outline in a PDF and |
| 62 |
% the commands of this module should not be mixed |
| 63 |
% with other code that creates outline items, this would mess up the tree! |
| 64 |
% |
| 65 |
% A reference implementation that shows the use of the command is in \texttt{latex-lab-bookmark.dtx}, |
| 66 |
% a package that can replace the package \pkg{bookmark}. |
| 67 |
% |
| 68 |
% The outline is a tree build with a set of objects. |
| 69 |
% The root is the \emph{outline dictionary} |
| 70 |
% which is referenced from the catalog with the \texttt{/Outline} key. The other objects |
| 71 |
% are called \emph{outline items}. |
| 72 |
% |
| 73 |
% The dictionaries of the \emph{outline items} contain |
| 74 |
% keys which can be divided into three classes: |
| 75 |
% \begin{description} |
| 76 |
% \item[\enquote{Management}] |
| 77 |
% The connection between the root, the items and their children |
| 78 |
% are described with keys \texttt{/Parent}, \texttt{/Next}, \texttt{/Prev}, \texttt{/First}, |
| 79 |
% \texttt{/Last}. The \texttt{/Count} key describes how many subitems are visible (open). |
| 80 |
% |
| 81 |
% \item[\enquote{Attributes}] |
| 82 |
% The \texttt{/Title} key contains the text shown in the bookmarks, |
| 83 |
% \texttt{/C} sets its color, the flag \texttt{/F} sets the font type (italic and/or bold). |
| 84 |
% There is a \texttt{/SE} key which can reference a structure, but |
| 85 |
% its function is unclear (the note in the reference says, that it is not meant for |
| 86 |
% navigation, but does not say what it is for). |
| 87 |
% |
| 88 |
% |
| 89 |
% \item[\enquote{Action}] |
| 90 |
% The action that should be executed can be set either with an \texttt{/A} or a |
| 91 |
% \texttt{/Dest} key. \LaTeX{} typically uses only the first option and adds an action, |
| 92 |
% e.g., for a simple link to a destination something like |
| 93 |
% |<< /S /GoTo /D (section.1) /SD 19 0 R >>| |
| 94 |
% (the \texttt{SD} key is used when there are structures). |
| 95 |
% |
| 96 |
% While in most cases the outline is used with a \texttt{GoTo} action and more or less mirrors |
| 97 |
% the table of contents, other actions are possible too, an outline item |
| 98 |
% can, e.g., open an external url or another file. The PDF reference lists in total |
| 99 |
% 17 different, theoretically usable actions\footnote{Sound and Movie are deprecated in PDF~2.0}: |
| 100 |
% GoTo, GoToR, GoToE, GoToDp (PDF~2.0), Launch, Thread, URI, Sound, Movie, |
| 101 |
% Hide, Named, SetOCGState, Rendition, Trans, GoTo3DView, JavaScript, RichMediaExecute. |
| 102 |
% |
| 103 |
% An action dictionary typically looks like this: |
| 104 |
% \begin{verbatim} |
| 105 |
% /A << /Type /Action %optional |
| 106 |
% /S ... % type name, e.g. /URI or /GoTo |
| 107 |
% /Next ... % optional, next action |
| 108 |
% ... ... % more keys |
| 109 |
% >> |
| 110 |
% \end{verbatim} |
| 111 |
% |
| 112 |
% The |/Next| key allows to chain actions. The value can be a reference to a |
| 113 |
% single action, or an array of actions. |
| 114 |
% It depends on the action type which other keys should be used. |
| 115 |
% |
| 116 |
% From all these action types the \pkg{bookmark} package supports |GoTo| (through the |
| 117 |
% |dest| and |page| keys), |GoToR| (through the |gotor| key together |
| 118 |
% with the |dest| and |page| keys), |
| 119 |
% |Named| (through the |named| key) and |URI| (through the |uri| key). |
| 120 |
% These standard types looks like this: |
| 121 |
% \begin{description} |
| 122 |
% \item[GoTo link to a named destination] e.g. |
| 123 |
% |/S /GoTo /D (section.1) /SD 19 0 R|, this can be handled with |\pdfoutline_goto:nnn|. |
| 124 |
% |
| 125 |
% \item[GoTo link to a page] |/S /GoTo /D [5 0 R /FitH 0]| |
| 126 |
% |
| 127 |
% \item[Named] e.g. |/S/Named/N/FirstPage|, values are \texttt{FirstPage}, |
| 128 |
% \texttt{NextPage}, \texttt{PrevPage}, \texttt{LastPage}. |
| 129 |
% |
| 130 |
% \item[URI] e.g.|/S/URI/URI(https://blub.de)| |
| 131 |
% |
| 132 |
% \item[GoToR] |/S/GoToR/F(blub.pdf)/D[0/Fit]|, |/S/GoToR/F(blub.pdf)/D[3/FitH 0]|, |
| 133 |
% |/S/GoToR/F(blub.pdf)/D(duck)| |
| 134 |
% \end{description} |
| 135 |
% All other actions (and also chained actions) are not |
| 136 |
% directly supported by \pkg{bookmark} but can be |
| 137 |
% implemented by using the |rawaction| key. |
| 138 |
% \end{description} |
| 139 |
% |
| 140 |
% Theoretically all needed objects described above could be created manually, |
| 141 |
% but getting all the management keys right wouldn't be trivial. |
| 142 |
% For \texttt{/Count} e.g. one would have to track recursively |
| 143 |
% the number of visible subitems. Luckily all backends have |
| 144 |
% dedicated primitives or \verb+\special+'s to create outline items which take |
| 145 |
% care of the management keys. Not quite so lucky is that the |
| 146 |
% backends use different methods to decide if |
| 147 |
% an outline item is a sibling or a child or some great-uncle of the previous item. |
| 148 |
% |
| 149 |
% The \texttt{(x)dvipdfmx} backend has the easiest implementation: |
| 150 |
% The general syntax is \verb+\special{pdf:out [-]number << attr>>}+ |
| 151 |
% where the parameter \emph{number} is an integer representing |
| 152 |
% the level of the outline entry. The first item |
| 153 |
% has to start with the level 1 and one can't skip levels, so one can't |
| 154 |
% simply use a fixed number for the various headings; instead one has to keep track of |
| 155 |
% which level has been used previously. This is a bit awkward, nevertheless with this backend |
| 156 |
% it is possible to build the outline directly while compiling the document and |
| 157 |
% one doesn't have to use the \texttt{aux} or to delay code until the end of the document. |
| 158 |
% |
| 159 |
% When using \pdfTeX{}, lua\TeX{} or the \texttt{dvips} backend, a count must be given |
| 160 |
% in the primitive which describes the number of direct children of the outline. |
| 161 |
% The backend then collects (recursively) following items until all children are found |
| 162 |
% and then goes up a level again. |
| 163 |
% To get this number the code has to obviously look ahead |
| 164 |
% to count all subsections below the current section. \pkg{hyperref} solved |
| 165 |
% this problem by writing everything into the \texttt{.out} file and to |
| 166 |
% process it at begin of the next compilation to get the correct count. |
| 167 |
% The \pkg{bookmark} package writes |
| 168 |
% the content and attributes (hex encoded) into the \texttt{.aux}-file. |
| 169 |
% Additionally it keeps track of the number of children during the compilation and |
| 170 |
% stores it for every bookmark in a command. When the |
| 171 |
% \texttt{.aux} file is read in again at the end of the document, it decodes |
| 172 |
% content and attributes again and writes out all the outline objects. In |
| 173 |
% this way it can produce the outline tree |
| 174 |
% for \pdfTeX{} and lua\TeX{} directly in the |
| 175 |
% first compilation. With the \texttt{dvips} backend it creates a \texttt{.ps} file |
| 176 |
% which is then read in at the next compilation. |
| 177 |
% |
| 178 |
% The new implementation in this module doesn't use external files but keeps all |
| 179 |
% bookmarks in memory and outputs them at the end of the document (for the |
| 180 |
% dvi based engines in the shipout/lastpage hook, this can require a second compilation if the |
| 181 |
% page numbers change). |
| 182 |
% |
| 183 |
% \subsection{The commands} |
| 184 |
% |
| 185 |
% \subsection{Creating an outline item} |
| 186 |
% \begin{function} |
| 187 |
% {\pdfoutline_action:nnn,\pdfoutline_action:neo,\pdfoutline_action:nee} |
| 188 |
% \begin{syntax} |
| 189 |
% \cs{pdfoutline_action:nnn}\Arg{level}\Arg{action}\Arg{title} |
| 190 |
% \end{syntax} |
| 191 |
% This creates an outline item. \meta{level} is an integer expression |
| 192 |
% and sets the (relative) level: A positive |
| 193 |
% number creates a child of the current outline item, 0 creates a sibling, |
| 194 |
% and negative numbers go back. |
| 195 |
% \meta{action} should be a list of dictionary keys and its values |
| 196 |
% that can be used within the |/A| key, e.g. the output from |\pdfdict_use:n|\footnote{It can |
| 197 |
% not be an object reference as this doesn't work with most backends.}\footnote{This is not completely |
| 198 |
% accurate: the dvips backend expects in some cases special names, e.g. a color must be given |
| 199 |
% with \texttt{/Color} and not \texttt{/C}. Complex actions must therefore be tested |
| 200 |
% and if needed one must add backend abstractions.}. |
| 201 |
% \meta{title} is the title, it should be |
| 202 |
% correctly escaped and encoded for use as a literal string |
| 203 |
% (but without the outer parentheses), such a representation can for example be created |
| 204 |
% with |\pdfstringdef| or with a combination of |\pdf_purify:nN| and |
| 205 |
% |\pdf_string_from_unicode:nnN| from the \texttt{l3pdftools} module. |
| 206 |
% The command can be used for general outline item, for the special case of |
| 207 |
% a GoTo link to a named destination see the following command. |
| 208 |
% \end{function} |
| 209 |
% |
| 210 |
% \begin{function} |
| 211 |
% {\pdfoutline_goto:nnn,\pdfoutline_goto:neo,\pdfoutline_goto:nee} |
| 212 |
% \begin{syntax} |
| 213 |
% \cs{pdfoutline_goto:nnn}\Arg{level}\Arg{destination}\Arg{title} |
| 214 |
% \end{syntax} |
| 215 |
% This creates an outline which creates a link to a named destination. |
| 216 |
% While such a GoTo link can also be created with \cs{pdfoutline_action:nnn} |
| 217 |
% the use of this command is recommended as it will also create a reference to a |
| 218 |
% structure destination if tagging is activated. |
| 219 |
% \meta{level} is an integer expression |
| 220 |
% and sets the (relative) level: A positive |
| 221 |
% number creates a child of the current outline, 0 creates a sibling, and negative numbers |
| 222 |
% go back. \meta{destination} is a destination name. |
| 223 |
% \meta{title} is the title, it should be |
| 224 |
% correctly escaped and encoded for a use as a literal string |
| 225 |
% (but without the outer parentheses), such a representation can for example be created |
| 226 |
% with |\pdfstringdef| with a combination of |\pdf_purify:nN| and |
| 227 |
% |\pdf_string_from_unicode:nnN| from the \texttt{l3pdftools} module. |
| 228 |
% \end{function} |
| 229 |
% |
| 230 |
% \begin{variable} |
| 231 |
% {\l_pdfoutline_active_bool} |
| 232 |
% This boolean decides if bookmarks are shown |
| 233 |
% at all. |
| 234 |
% \end{variable} |
| 235 |
% |
| 236 |
% \begin{variable} |
| 237 |
% {\l_pdfoutline_open_bool} |
| 238 |
% This boolean decides if bookmarks are shown |
| 239 |
% \enquote{open}, so show their children or not. |
| 240 |
% \end{variable} |
| 241 |
% |
| 242 |
% \begin{variable} |
| 243 |
% {\l_pdfoutline_open_int} |
| 244 |
% With this integer you can set the number of |
| 245 |
% visible levels. Bookmarks with a level above the value of this integer are |
| 246 |
% always closed. So if it is set to 1, everything is closed and so |
| 247 |
% only the top level bookmarks are shown |
| 248 |
% if its value is 2, the first level will show its children, |
| 249 |
% etc. By default this integer is set to |\c_max_int| and |
| 250 |
% so everything is open. |
| 251 |
% \end{variable} |
| 252 |
% |
| 253 |
% \begin{variable} |
| 254 |
% {\l_pdfoutline_F_bitset} |
| 255 |
% This bitset is used to set the flag for the font in bookmarks. |
| 256 |
% It knows the two values \texttt{italic} and \texttt{bold}, so after |
| 257 |
% \begin{verbatim} |
| 258 |
% \bitset_set_true:Nn \l_pdfoutline_F_bitset {italic} |
| 259 |
% \end{verbatim} |
| 260 |
% italic will be enabled. |
| 261 |
% \end{variable} |
| 262 |
% |
| 263 |
% \begin{variable} |
| 264 |
% {\l_pdfoutline_color_tl,\l_pdfoutline_color_model_tl} |
| 265 |
% \cs{l_pdfoutline_color_tl} can be empty or hold a color expression to set the color of |
| 266 |
% the outline(s). It then should have either the format |[model]{value}| |
| 267 |
% or be a color expression. For examples: |[rgb]{1,0,.5}| or |red!50!blue|. |
| 268 |
% \cs{l_pdfoutline_color_model_tl} should be |rgb| or |cmyk|. The first is |
| 269 |
% the normal one, the option to use also |cmyk| is only offered for the |
| 270 |
% case that some PDF/A validator complains. |
| 271 |
% \end{variable} |
| 272 |
% |
| 273 |
% \subsection{References} |
| 274 |
% A user package that uses these commands to create a tree must be able |
| 275 |
% to retrieve parents and level data. |
| 276 |
% \begin{function}[EXP] |
| 277 |
% {\pdfoutline_id_ref_last:,\pdfoutline_level_ref_last:} |
| 278 |
% \begin{syntax} |
| 279 |
% \cs{pdfoutline_id_ref_last:} \\ |
| 280 |
% \cs{pdfoutline_level_ref_last:} |
| 281 |
% \end{syntax} |
| 282 |
% These expandable functions give back the id and the level |
| 283 |
% of the last bookmark created. |
| 284 |
% \end{function} |
| 285 |
% |
| 286 |
% \begin{function}[EXP]{\pdfoutline_parent_ref:n} |
| 287 |
% \begin{syntax} |
| 288 |
% \cs{pdfoutline_parent_ref:n}\Arg{id} |
| 289 |
% \end{syntax} |
| 290 |
% This retrieves the parent of the bookmark with id \meta{id}. |
| 291 |
% If the bookmark is at the root level the value is 1. |
| 292 |
% \end{function} |
| 293 |
% \end{documentation} |
| 294 |
% |
| 295 |
% \begin{implementation} |
| 296 |
% |
| 297 |
% \section{\pkg{l3pdfoutline} implementation} |
| 298 |
% \subsection{Package declaration} |
| 299 |
% \begin{macrocode} |
| 300 |
%<@@=pdfoutline> |
| 301 |
%<*header> |
| 302 |
\ProvidesExplPackage{l3pdfoutline}{2026-05-26}{0.97c} |
| 303 |
{PDF outlines} |
| 304 |
%</header> |
| 305 |
% \end{macrocode} |
| 306 |
% \begin{macrocode} |
| 307 |
%<*package> |
| 308 |
% \end{macrocode} |
| 309 |
% |
| 310 |
% \subsection{Public variables} |
| 311 |
% \begin{variable}{\l_pdfoutline_active_bool,\l_pdfoutline_open_bool} |
| 312 |
% The state of the first boolean decides |
| 313 |
% if a bookmark is created at all, this allows to disable bookmarks |
| 314 |
% fully or in parts. |
| 315 |
% The second boolean decides if a bookmark is open (so shows its children) |
| 316 |
% or not. |
| 317 |
% \begin{macrocode} |
| 318 |
\bool_new:N \l_pdfoutline_active_bool |
| 319 |
\bool_set_true:N \l_pdfoutline_active_bool |
| 320 |
\bool_new:N \l_pdfoutline_open_bool |
| 321 |
\bool_set_true:N \l_pdfoutline_open_bool |
| 322 |
% \end{macrocode} |
| 323 |
% \end{variable} |
| 324 |
% |
| 325 |
% \begin{variable}{\l_pdfoutline_open_int} |
| 326 |
% This is the level up to which a bookmark is opened. By default the maximum |
| 327 |
% integer value is used and everything is open. |
| 328 |
% |
| 329 |
% \begin{macrocode} |
| 330 |
\int_new:N \l_pdfoutline_open_int |
| 331 |
\int_set:Nn \l_pdfoutline_open_int { \c_max_int } |
| 332 |
% \end{macrocode} |
| 333 |
% \end{variable} |
| 334 |
% |
| 335 |
% \begin{variable}{\l_pdfoutline_F_bitset} |
| 336 |
% Outlines have a /F flag, we provide a public |
| 337 |
% bitset for it. |
| 338 |
% \begin{macrocode} |
| 339 |
\bitset_new:Nn \l_pdfoutline_F_bitset |
| 340 |
{ |
| 341 |
Italic = 1, |
| 342 |
italic = 1, |
| 343 |
Bold = 2, |
| 344 |
bold = 2 |
| 345 |
} |
| 346 |
% \end{macrocode} |
| 347 |
% \end{variable} |
| 348 |
% |
| 349 |
% \begin{variable}{\l_pdfoutline_color_tl,\l_pdfoutline_color_model_tl} |
| 350 |
% The variable for the color expression. |
| 351 |
% \begin{macrocode} |
| 352 |
\tl_new:N \l_pdfoutline_color_tl |
| 353 |
\tl_new:N \l_pdfoutline_color_model_tl |
| 354 |
\tl_set:Nn \l_pdfoutline_color_model_tl {rgb} |
| 355 |
% \end{macrocode} |
| 356 |
% \end{variable} |
| 357 |
% |
| 358 |
% \subsection{Data structure for the Count} |
| 359 |
% |
| 360 |
% \begin{variable}{\l_@@_tmpa_tl} |
| 361 |
% \begin{macrocode} |
| 362 |
\tl_new:N\l_@@_tmpa_tl |
| 363 |
% \end{macrocode} |
| 364 |
% \end{variable} |
| 365 |
|
| 366 |
% \begin{variable}{\g_@@_id_int} |
| 367 |
% This integer is used to track the bookmarks. |
| 368 |
% id 1 is the root, the first \enquote{real} bookmark |
| 369 |
% has id 2. |
| 370 |
% \begin{macrocode} |
| 371 |
\int_new:N \g_@@_id_int |
| 372 |
\int_gincr:N \g_@@_id_int |
| 373 |
% \end{macrocode} |
| 374 |
% \end{variable} |
| 375 |
% |
| 376 |
% \begin{variable}{\g_@@_current_parent_id_tl} |
| 377 |
% This holds the id of the current parent |
| 378 |
% so that we do not have to retrieve it all the time. |
| 379 |
% \begin{macrocode} |
| 380 |
\tl_new:N \g_@@_current_parent_id_tl |
| 381 |
\tl_gset:Nn \g_@@_current_parent_id_tl {1} |
| 382 |
% \end{macrocode} |
| 383 |
% \end{variable} |
| 384 |
% |
| 385 |
% \begin{variable}{\g_@@_current_level_int} |
| 386 |
% This holds the (relative) level. It starts at 1 as dvipdfmx counts this way. |
| 387 |
% \begin{macrocode} |
| 388 |
\int_new:N \g_@@_current_level_int |
| 389 |
\int_gincr:N \g_@@_current_level_int |
| 390 |
% \end{macrocode} |
| 391 |
% \end{variable} |
| 392 |
% |
| 393 |
% We do not assume that we will ever have more than 2000 bookmarks, but we set a block |
| 394 |
% size so that we can make the range dynamic if needed like in the object code. |
| 395 |
% |
| 396 |
% \begin{variable}{\c_@@_block_size_int} |
| 397 |
% Sets the block size used for managing outlines. |
| 398 |
% \begin{macrocode} |
| 399 |
\int_const:Nn \c_@@_block_size_int { 2000 } |
| 400 |
% \end{macrocode} |
| 401 |
% \end{variable} |
| 402 |
% |
| 403 |
% For some backends we must know for every outline |
| 404 |
% the numbers of direct children, and |
| 405 |
% we must know the id of the parent to be able to go |
| 406 |
% up the tree again. For this we use two intarray variables. |
| 407 |
% \begin{variable}{\g_@@_kid_count_intarray,\g_@@_parent_id_intarray} |
| 408 |
% The first contains for every id the number of (direct) kids. |
| 409 |
% The second contains the id of the parent. |
| 410 |
% \begin{macrocode} |
| 411 |
\intarray_new:Nn \g_@@_kid_count_intarray { \c_@@_block_size_int } |
| 412 |
\intarray_new:Nn \g_@@_parent_id_intarray { \c_@@_block_size_int } |
| 413 |
\intarray_gset:Nnn \g_@@_parent_id_intarray {1}{1} |
| 414 |
% \end{macrocode} |
| 415 |
% \end{variable} |
| 416 |
% |
| 417 |
% Unlike \pkg{bookmark} we do not use an external file but keep all content in memory |
| 418 |
% in one large tl var. |
| 419 |
% \begin{variable}{\g_@@_collect_build_tl} |
| 420 |
% \begin{macrocode} |
| 421 |
\tl_new:N \g_@@_collect_build_tl |
| 422 |
% \end{macrocode} |
| 423 |
% \end{variable} |
| 424 |
% |
| 425 |
% The main commands |
| 426 |
% \begin{macro}{\pdfoutline_action:nnn} |
| 427 |
% \begin{macrocode} |
| 428 |
\cs_new_protected:Npn \pdfoutline_action:nnn #1 #2 #3 |
| 429 |
% #1 level, #2 action, #3 title |
| 430 |
{ |
| 431 |
\bool_if:NT \l_pdfoutline_active_bool |
| 432 |
{ |
| 433 |
\int_compare:nNnTF {\g_@@_id_int}={1} |
| 434 |
{ |
| 435 |
\tl_build_gbegin:N \g_@@_collect_build_tl |
| 436 |
\@@_item:nnnn {0}{#2}{#3}{action} |
| 437 |
\tl_gput_right:Nn \g__kernel_pdfmanagement_end_run_code_tl |
| 438 |
{ |
| 439 |
\tl_build_gend:N \g_@@_collect_build_tl |
| 440 |
\tl_use:N \g_@@_collect_build_tl |
| 441 |
} |
| 442 |
} |
| 443 |
{ |
| 444 |
\@@_item:nnnn {#1}{#2}{#3}{action} |
| 445 |
} |
| 446 |
\cs_gset_protected:Npn \pdfoutline_action:nnn ##1 ##2 ##3 |
| 447 |
{ |
| 448 |
\bool_if:NT \l_pdfoutline_active_bool |
| 449 |
{\@@_item:nnnn {##1}{##2}{##3}{action}} |
| 450 |
} |
| 451 |
} |
| 452 |
} |
| 453 |
\cs_generate_variant:Nn \pdfoutline_action:nnn {nee} |
| 454 |
% \end{macrocode} |
| 455 |
% \end{macro} |
| 456 |
% |
| 457 |
% \begin{macro}{\pdfoutline_goto:nnn} |
| 458 |
% \begin{macrocode} |
| 459 |
\cs_new_protected:Npn \pdfoutline_goto:nnn #1 #2 #3 |
| 460 |
% #1 level, #2 destination, #3 title |
| 461 |
{ |
| 462 |
\bool_if:NT \l_pdfoutline_active_bool |
| 463 |
{ |
| 464 |
\int_compare:nNnTF {\g_@@_id_int}={1} |
| 465 |
{ |
| 466 |
\tl_build_gbegin:N \g_@@_collect_build_tl |
| 467 |
\@@_item:nnnn {0}{#2}{#3}{goto} |
| 468 |
\tl_gput_right:Nn \g__kernel_pdfmanagement_end_run_code_tl |
| 469 |
{ |
| 470 |
\tl_build_gend:N \g_@@_collect_build_tl |
| 471 |
\tl_use:N \g_@@_collect_build_tl |
| 472 |
} |
| 473 |
} |
| 474 |
{ |
| 475 |
\@@_item:nnnn {#1}{#2}{#3}{goto} |
| 476 |
} |
| 477 |
\cs_gset_protected:Npn \pdfoutline_goto:nnn ##1 ##2 ##3 |
| 478 |
{ |
| 479 |
\bool_if:NT \l_pdfoutline_active_bool |
| 480 |
{\@@_item:nnnn {##1}{##2}{##3}{goto}} |
| 481 |
} |
| 482 |
} |
| 483 |
} |
| 484 |
\cs_generate_variant:Nn \pdfoutline_goto:nnn {nee} |
| 485 |
% \end{macrocode} |
| 486 |
% \end{macro} |
| 487 |
% |
| 488 |
% \begin{macro}{\@@_item:nnnn} |
| 489 |
% \begin{macrocode} |
| 490 |
\cs_new_protected:Npn \@@_item:nnnn #1 #2 #3 #4 |
| 491 |
% #1 level, #2 action, #3 title, #4 keyword action or goto |
| 492 |
{ |
| 493 |
\int_gincr:N \g_@@_id_int |
| 494 |
% \end{macrocode} |
| 495 |
% Follow up bookmarks. At first siblings. |
| 496 |
% The parent doesn't change. |
| 497 |
% \begin{macrocode} |
| 498 |
\int_compare:nNnTF {#1}={0} |
| 499 |
{ |
| 500 |
\intarray_gset:Nnn |
| 501 |
\g_@@_parent_id_intarray |
| 502 |
{ \g_@@_id_int } |
| 503 |
{ \g_@@_current_parent_id_tl } |
| 504 |
\intarray_gset:Nnn |
| 505 |
\g_@@_kid_count_intarray |
| 506 |
{ \g_@@_current_parent_id_tl } |
| 507 |
{ \intarray_item:Nn \g_@@_kid_count_intarray { \g_@@_current_parent_id_tl } + 1 } |
| 508 |
} |
| 509 |
{ |
| 510 |
% \end{macrocode} |
| 511 |
% The first child of the previous bookmark |
| 512 |
% \begin{macrocode} |
| 513 |
\int_compare:nNnTF {#1} > {0} |
| 514 |
{ |
| 515 |
\int_gincr:N \g_@@_current_level_int |
| 516 |
\tl_gset:Ne \g_@@_current_parent_id_tl |
| 517 |
{ \int_eval:n { \g_@@_id_int -1 } } |
| 518 |
\intarray_gset:Nnn |
| 519 |
\g_@@_parent_id_intarray |
| 520 |
{ \g_@@_id_int } |
| 521 |
{ \g_@@_current_parent_id_tl } |
| 522 |
\intarray_gset:Nnn |
| 523 |
\g_@@_kid_count_intarray |
| 524 |
{ \g_@@_current_parent_id_tl } |
| 525 |
{ 1 } |
| 526 |
} |
| 527 |
% \end{macrocode} |
| 528 |
% The most complicated case: going up the hierarchy. |
| 529 |
% The root level is 1, so we can go up at most current level minus 1 |
| 530 |
% steps. If we are already at the root level, the current parent is 1. |
| 531 |
% \begin{macrocode} |
| 532 |
{ |
| 533 |
\int_compare:nNnTF { \g_@@_current_level_int } = {1} |
| 534 |
{ |
| 535 |
\tl_gset:Ne \g_@@_current_parent_id_tl {1} |
| 536 |
} |
| 537 |
{ |
| 538 |
\int_step_inline:nn |
| 539 |
{ \int_min:nn { \int_abs:n {#1} } { \g_@@_current_level_int -1 } } |
| 540 |
{ |
| 541 |
% \end{macrocode} |
| 542 |
% Get recursively the parent of the current parent and decrease the level. |
| 543 |
% \begin{macrocode} |
| 544 |
\tl_gset:Ne \g_@@_current_parent_id_tl |
| 545 |
{ \intarray_item:Nn \g_@@_parent_id_intarray { \g_@@_current_parent_id_tl } } |
| 546 |
\int_gdecr:N \g_@@_current_level_int |
| 547 |
} |
| 548 |
} |
| 549 |
% \end{macrocode} |
| 550 |
% Store the parent and |
| 551 |
% increase the kid count of the finally found parent (if this is the root level, |
| 552 |
% the id is 1) |
| 553 |
% \begin{macrocode} |
| 554 |
\intarray_gset:Nnn |
| 555 |
\g_@@_parent_id_intarray |
| 556 |
{ \g_@@_id_int } |
| 557 |
{ \g_@@_current_parent_id_tl } |
| 558 |
\intarray_gset:Nnn |
| 559 |
\g_@@_kid_count_intarray |
| 560 |
{ \g_@@_current_parent_id_tl } |
| 561 |
{ |
| 562 |
\intarray_item:Nn |
| 563 |
\g_@@_kid_count_intarray |
| 564 |
{ \g_@@_current_parent_id_tl } + 1 |
| 565 |
} |
| 566 |
} |
| 567 |
} |
| 568 |
% \end{macrocode} |
| 569 |
% Now we store the collected data into the tl var. |
| 570 |
% \begin{macrocode} |
| 571 |
\@@_store:nnn {#2}{#3}{#4} |
| 572 |
} |
| 573 |
% \end{macrocode} |
| 574 |
% \end{macro} |
| 575 |
% |
| 576 |
% \begin{macro}{\@@_color_export:nnN} |
| 577 |
% This exports space separated values from a color expression or a |[model]{values}| |
| 578 |
% expression. It is used in the next command. |
| 579 |
% \begin{macrocode} |
| 580 |
\cs_new_protected:Npn \@@_color_export_aux:wnnN [#1] #2 #3 #4 |
| 581 |
{ |
| 582 |
\color_export:nnnN {#1}{#2}{ space-sep-#3 }#4 |
| 583 |
} |
| 584 |
\cs_new_protected:Npn \@@_color_export:nnN #1 #2 #3 %#1 color, #2 target model, #3 command |
| 585 |
{ |
| 586 |
\tl_if_blank:nTF { #1 } |
| 587 |
{ \tl_clear:N #3 } |
| 588 |
{ |
| 589 |
\tl_if_head_eq_charcode:nNTF {#1} [ %] |
| 590 |
{ |
| 591 |
\@@_color_export_aux:wnnN #1 { #2 } #3 |
| 592 |
} |
| 593 |
{ |
| 594 |
\color_export:nnN { #1 } { space-sep-#2 } #3 |
| 595 |
} |
| 596 |
} |
| 597 |
} |
| 598 |
\cs_generate_variant:Nn \@@_color_export:nnN {ee} |
| 599 |
% \end{macrocode} |
| 600 |
% \end{macro} |
| 601 |
% |
| 602 |
% \begin{macro}{\@@_store:nnn} |
| 603 |
% This command stores the data into the tl var. The backends have different requirements |
| 604 |
% regarding the handling, so we keep arguments separate and generic to stay flexible. |
| 605 |
% \begin{macrocode} |
| 606 |
\cs_new_protected:Npn \@@_store:nnn #1 #2 #3 |
| 607 |
% #1: action or destination, #2: title, #3: keyword action or goto |
| 608 |
{ |
| 609 |
\int_compare:nNnF { \g_@@_current_level_int } < { \l_pdfoutline_open_int } |
| 610 |
{ \bool_set_false:N \l_pdfoutline_open_bool } |
| 611 |
\@@_color_export:eeN {\l_pdfoutline_color_tl}{\l_pdfoutline_color_model_tl}\l_@@_tmpa_tl |
| 612 |
\tl_build_gput_right:Ne \g_@@_collect_build_tl |
| 613 |
{ |
| 614 |
\exp_not:N \use:c { __pdf_backend_#3:nnnnnnn } |
| 615 |
% #1 level, #2 kid count, #3 open? #4 color, #5 flag, #6 action/destination, #7 title, |
| 616 |
{ |
| 617 |
\int_use:N \g_@@_current_level_int |
| 618 |
} |
| 619 |
{ |
| 620 |
\exp_not:N \intarray_item:Nn |
| 621 |
\exp_not:N \g_@@_kid_count_intarray |
| 622 |
{ \int_use:N \g_@@_id_int } |
| 623 |
} |
| 624 |
{ |
| 625 |
\bool_if:NTF\l_pdfoutline_open_bool {\exp_not:N \c_true_bool }{ \exp_not:N \c_false_bool} |
| 626 |
} |
| 627 |
{ |
| 628 |
\l_@@_tmpa_tl |
| 629 |
} |
| 630 |
{ |
| 631 |
\bitset_to_arabic:N \l_pdfoutline_F_bitset |
| 632 |
} |
| 633 |
{ |
| 634 |
\exp_not:n {#1} % action/destination, or expand?? |
| 635 |
} |
| 636 |
{ |
| 637 |
\exp_not:n {#2} % title, or expand?? |
| 638 |
} |
| 639 |
} |
| 640 |
} |
| 641 |
% \end{macrocode} |
| 642 |
% \end{macro} |
| 643 |
% |
| 644 |
% \subsection{References} |
| 645 |
% \begin{macro}{\pdfoutline_id_ref_last:,} |
| 646 |
% \begin{macrocode} |
| 647 |
\cs_new:Npn \pdfoutline_id_ref_last: {\int_use:N\g_@@_id_int} |
| 648 |
% \end{macrocode} |
| 649 |
% \end{macro} |
| 650 |
% \begin{macro}{\pdfoutline_level_ref_last:} |
| 651 |
% \begin{macrocode} |
| 652 |
\cs_new:Npn \pdfoutline_level_ref_last: {\int_use:N\g_@@_current_level_int} |
| 653 |
% \end{macrocode} |
| 654 |
% \end{macro} |
| 655 |
% \begin{macro}{\pdfoutline_parent_ref:n} |
| 656 |
% \begin{macrocode} |
| 657 |
\cs_new:Npn \pdfoutline_parent_ref:n #1 { \intarray_item:Nn\g_@@_parent_id_intarray{#1} } |
| 658 |
%</package> |
| 659 |
% \end{macrocode} |
| 660 |
% \end{macro} |
| 661 |
% |
| 662 |
% \end{implementation} |
| 663 |
% |
| 664 |
% \PrintIndex |