1%D \module 2%D [ file=strc-bkm, 3%D version=2009.04.01, 4%D title=\CONTEXT\ Structure Macros, 5%D subtitle=Bookmarks, 6%D author=Hans Hagen, 7%D date=\currentdate, 8%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] 9%C 10%C This module is part of the \CONTEXT\ macro||package and is 11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for 12%C details. 13 14\writestatus{loading}{ConTeXt Structure Macros / Bookmarks} 15 16\registerctxluafile{strc-bkm}{} 17 18% \enabledirectives[references.bookmarks.preroll] 19 20\unprotect 21 22%D Bookmarks are a very viewer dependent feature. They are mostly used 23%D as additional table of contents and therefore relate directly to lists. 24%D 25%D A bookmark list is added to the document only when interaction is 26%D enabled. The given lists are bookmarked and a second argument specifies 27%D the opened bookmark trees. 28%D 29%D \starttyping 30%D \placebookmarks 31%D [chapter,section,subsection,mylist] 32%D [chapter] 33%D \stoptyping 34%D 35%D You can overloads the last set bookmark in a sectioning command: 36%D 37%D \starttyping 38%D \chapter {the first chapter} 39%D \bookmark {the first bookmark} 40%D \stoptyping 41%D 42%D However, in practice you can better use \type {\startchapter} and set the 43%D \type {bookmark} parameter. 44%D 45%D You can add entries to the bookmarklist: 46%D 47%D \starttyping 48%D \bookmark[mylist]{whatever} 49%D \stoptyping 50%D 51%D Use force to get titles in the bookmarklist. This is somewhat tricky as 52%D one does not want "Contents" in a table of contents but it has to be in 53%D the bookmark list. 54 55\installcorenamespace{bookmark} 56 57\installsetuponlycommandhandler \??bookmark {bookmark} % installdirectparametersethandler 58 59\setupbookmark 60 [\c!force=\v!no, % it's easier to force that to inhibit 61 \c!number=\v!yes, % might become v!no 62 \c!sectionblock=\v!no] % show sectionblock level + title 63 64\let\setupbookmarks\setupbookmark 65 66\unexpanded\def\bookmark 67 {\dosingleempty\strc_bookmarks_bookmark} 68 69\def\strc_bookmarks_bookmark 70 {\iflocation 71 \expandafter\strc_bookmarks_bookmark_yes 72 \else 73 \expandafter\strc_bookmarks_bookmark_nop 74 \fi} 75 76\def\strc_bookmarks_bookmark_yes[#1]#2% 77 {\begingroup 78 \simplifycommands 79 \ifnum\thenamedheadlevel{#1}>\zerocount 80 {#1}{\detokenize\expandafter{\normalexpanded{#2}}}% 81 \else 82 \strc_lists_write_to[#1][]{#2}{}% todo: a dedicated bookmark writer 83 \fi 84 \endgroup} 85 86\def\strc_bookmarks_bookmark_nop[#1]#2% 87 {} 88 89\unexpanded\def\placebookmarks 90 {\dotripleempty\strc_bookmarks_place} 91 92\def\strc_bookmarks_place 93 {\iflocation 94 \expandafter\strc_bookmarks_place_yes 95 \else 96 \expandafter\gobblethreeoptionals 97 \fi} 98 99\let\m_bookmarks_names \empty 100\let\m_bookmarks_opened\empty 101 102\def\strc_bookmarks_place_yes[#1][#2][#3]% 103 {\begingroup 104 \edef\m_bookmarks_names{#1}% 105 \edef\m_bookmarks_opened{#2}% 106 \ifx\m_bookmarks_names\empty 107 \edef\m_bookmarks_names{\namedlistparameter\v!content\c!list}% 108 \fi 109 \ifx\m_bookmarks_names\empty 110 \let\m_bookmarks_names\v!all 111 \fi 112 \ifthirdargument 113 \setupcurrentbookmark[#3]% no every so not all possible 114 \else\ifsecondargument 115 \doifelseassignment{#2}{\let\m_bookmarks_opened\empty\setupcurrentbookmark[#2]}\donothing 116 \fi\fi 117 118 names {\m_bookmarks_names}% 119 opened {\m_bookmarks_opened}% 120 force {\bookmarkparameter\c!force}% 121 number {\bookmarkparameter\c!number}% 122 \relax 123 \endgroup} 124 125\appendtoks 126 127 separatorset {\bookmarkparameter\c!numberseparatorset}% 128 conversionset {\bookmarkparameter\c!numberconversionset}% 129 starter {\bookmarkparameter\c!numberstarter}% 130 stopper {\bookmarkparameter\c!numberstopper}% 131 segments {\bookmarkparameter\c!numbersegments}% 132 showblocktitle {\bookmarkparameter\c!sectionblock}% 133 \relax 134\to \everysetupbookmark 135 136%D There is a plugin mechanism but this is for experts only. The intermediate 137%D data structures are stable. 138%D 139%D \starttyping 140%D \startluacode 141%D structures.bookmarks.installhandler("check before","before",function(levels) 142%D logs.report("extra bookmarks","before (normal bookmarks)") 143%D inspect(levels) 144%D logs.report("extra bookmarks","before (extra bookmarks)") 145%D inspect(structures.bookmarks.extras.get()) 146%D return levels 147%D end) 148%D structures.bookmarks.installhandler("check after", "after", function(levels) 149%D logs.report("extra bookmarks","after (merged bookmarks)") 150%D inspect(levels) 151%D return levels 152%D end) 153%D \stopluacode 154%D \starttyping 155%D 156%D This mechanism was added when bookmark inclusion became (optional) part of graphic 157%D inclusion (which is needed by Taco). 158%D 159%D \starttyping 160%D \getfiguredimensions[somefile.pdf] 161%D \dorecurse {\noffigurepages} { 162%D \startTEXpage 163%D \externalfigure[somefile.pdf][interaction=bookmark,page=\recurselevel] 164%D \stopTEXpage 165%D } 166%D \starttyping 167 168\protect \endinput 169 170% \starttext 171% \setupinteraction[state=start]\setupinteractionscreen[option=bookmark] 172% \placebookmarks[chapter,section,subsection][chapter] 173% \chapter{First} 174% \bookmark{The First Indeed} 175% \section{alpha} 176% \bookmark[chapter]{The First Indeed Again} 177% \section{beta} 178% \chapter{Second} 179% \bookmark{The Second Indeed} 180% \section{gamma \tex{radiation}} 181% \subsection{a} 182% \subsection{b} 183% \section{delta} 184% \section{epsilon} 185% \chapter{Third \relax} 186% \chapter{我〈能吞下玻璃而不傷身〉體。} % whatever that means 187% \chapter{Idris Samawi Hamid ادريس سماوي حامد} 188% \stoptext 189 |