summaryrefslogtreecommitdiff
path: root/tex/context/base/strc-bkm.mkiv
blob: 8ddf0a6dff99f11484ef1e422c9bda39e6c73f1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
%D \module
%D   [       file=strc-bkm,
%D        version=2009.04.01,
%D          title=\CONTEXT\ Structure Macros,
%D       subtitle=Bookmarks,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

%D This might become scrn-bkm.mkiv.

\writestatus{loading}{ConTeXt Structure Macros / Bookmarks}

\registerctxluafile{strc-bkm}{1.001}

\unprotect

%D Due to requests I finally decided to support bookmarks, a
%D driver dependant way of showing tables of content. The most
%D simple way of support is hooking bookmark generation into
%D the existing list mechanisms. That way users can generate
%D bookmarks automatically, although its entirely valid to add
%D bookmarks by defining alternative ones. These will be added
%D at the appropriate place in the list.

% \hoofdstuk{het eerste hoofdstuk}
%
% \bookmark {de eerste bookmark} % optional overruled hoofdstuk
%
% .... text ....
%
% \placebookmarks [hoofdstuk,paragraaf,subparagraaf,subsubparagraaf,mylist]
%                 [open list]
%
% \bookmark[mylist]{whatever}

%D This will go away.

\let\flushpostponedbookmark\relax

%D We have better ways now.

\unexpanded\def\bookmark
  {\dosingleempty\dobookmark}

\def\dobookmark[#1]#2%
  {\begingroup
   \simplifycommands
   \ctxcommand{overloadbookmark("#1",\!!bs\detokenize\expandafter{\normalexpanded{#2}}\!!es)}%
   \endgroup}

%D Placement \unknown\ look how simple compared to \MKII:

\newtoks \everysetupbookmarks

\def\bookmarkparameter#1{\ifcsname\??bm#1\endcsname\csname\??bm#1\endcsname\fi}

\unexpanded\def\setupbookmarks[#1]%
  {\getparameters[\??bm][#1]%
    \the\everysetupbookmarks}

\unexpanded\def\placebookmarks
  {\dotripleempty\doplacebookmarks}

% Use force to get titles in the bookmarklist. This is somewhat tricky as one
% does not want "Contents" in a table of contents but it has to be in the
% bookmark list.

\def\doplacebookmarks[#1][#2][#3]%
  {\iflocation
     \begingroup
     \edef\askednames{#1}%
     \edef\askedopened{#2}%
     \ifx\askednames\empty
       \edef\askednames{\getvalue{\??ih\v!content\c!list}}%
     \fi
     \ifx\askednames\empty
       \let\askednames\v!all
     \fi
     \ifthirdargument
       \getparameters[\??bm][#3]%
     \else\ifsecondargument
       \doifassignmentelse{#2}{\let\askedopened\empty\getparameters[\??bm][#2]}\donothing
     \fi\fi
     \ctxcommand{registerbookmark {
        names  = "\askednames",
        opened = "\askedopened",
        force  = "\bookmarkparameter\c!force",
        number = "\bookmarkparameter\c!number",
      }}%
     \endgroup
   \fi}

\setupbookmarks
  [\c!force=\v!no,    % it's easier to force that to inhibit
   \c!number=\v!yes]  % might become v!no

\appendtoks
    \ctxcommand{setupbookmarks {
        separatorset  = "\bookmarkparameter\c!numberseparatorset",
        conversionset = "\bookmarkparameter\c!numberconversionset",
        starter       = \!!bs\bookmarkparameter\c!numberstarter\!!es,
        stopper       = \!!bs\bookmarkparameter\c!numberstopper\!!es,
        segments      = "\bookmarkparameter\c!numbersegments",
    }}%
\to \everysetupbookmarks

\protect \endinput

% \starttext
% \setupinteraction[state=start]\setupinteractionscreen[option=bookmark]
% \placebookmarks[chapter,section,subsection][chapter]
% \chapter{First}
% \bookmark{The First Indeed}
% \section{alpha}
% \bookmark[chapter]{The First Indeed Again}
% \section{beta}
% \chapter{Second}
% \bookmark{The Second Indeed}
% \section{gamma \tex{radiation}}
% \subsection{a}
% \subsection{b}
% \section{delta}
% \section{epsilon}
% \chapter{Third \relax}
% \chapter{我〈能吞下玻璃而不傷身〉體。} % whatever that means
% \chapter{Idris Samawi Hamid ادريس سماوي حامد}
% \stoptext