summaryrefslogtreecommitdiff
path: root/tex/context/base/strc-lnt.mkiv
blob: 442a9378fb61784651512b08f5f0a60f16dcae31 (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
%D \module
%D   [       file=strc-lnt,
%D        version=2002.05.10,
%D          title=\CONTEXT\ Structure Macros,
%D       subtitle=Line Notes,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Structure Macros / Line Notes}

%D This module loads on top of the footnote and line numbering macros.

\unprotect

\newcount\noflinenotes \newif\iftracelinenotes % will be tracker

\def\dohandlelinenote#1#2#3%
  {\bgroup
   \def\linenotelinenumber##1{\inlinerange[#2]}% ##1 == order
   \setupnote[#1][\c!numbercommand=\linenotelinenumber,\c!textcommand=\gobbleoneargument]% todo: deep hook
   \getvalue{\??vn:ln:#1}{#3}%
   \egroup}

\def\dotracedlinenote#1%
  {\iftracelinenotes
     \hbox to \zeropoint
       {\forgetall
        \hsize\zeropoint
        \hss
        \vbox to \strutheight{\llap{\red\infofont\setstrut\the\noflinenotes}\vss}%
        {\color[blue]{\vl}}%
        \vbox to \strutheight{\rlap{\red\infofont\setstrut#1}\vss}%
        \hss}%
      \prewordbreak
   \fi}

\def\dolinenote#1#2%
  {\global\advance\noflinenotes\plusone
   \dohandlelinenote{#1}{\the\noflinenotes}{#2}%
   \dotracedlinenote\empty
   \normalexpanded{\someline[\the\noflinenotes]}}

\def\dostartlinenote#1[#2]#3%
  {\global\advance\noflinenotes\plusone
   \dohandlelinenote{#1}{#2}{#3}%
   \dotracedlinenote{#2}%
   \startline[#2]}

\def\dostoplinenote#1[#2]%
  {\stopline[#2]}

\unexpanded\def\definelinenote
  {\dotripleempty\dodefinelinenote}

\def\dodefinelinenote[#1][#2][#3]%
  {\dodefinenote[#1][#2][#3]% do as we need to test for arguments
   \expandafter\let\csname\??vn:ln:#1\expandafter\endcsname\csname#1\endcsname % use copy command
   \setuvalue        {#1}{\dolinenote     {#1}}%
   \setuvalue{\e!start#1}{\dostartlinenote{#1}}%
   \setuvalue{\e!stop #1}{\dostoplinenote {#1}}}

\let\setuplinenote\setupnote

% We predefine one, namely \type {\linenote} cum suis.

\definelinenote[\v!linenote]

% beware: line numbers are added later on so grouping setups is a bad idea
%
% \startbuffer[test]
% \startlinenumbering[100]
% test \linenote {oeps 1} test test test test test test
% test \startlinenote [well] {oeps X} test test test test test test
% test \linenote {oeps 2} test test test test test test
% test \linenote {oeps 3} test test test test test test
% test \linenote {oeps 4} test test test test test test
% test \linenote {oeps 5} test test test test test test
% test \stoplinenote [well] test test test test test test
% \stoplinenumbering
% \stopbuffer
%
% \typebuffer[test] \getbuffer[test] \page
%
% \startbuffer[setup]
% \setuplinenumbering
%   [align=flushleft]
% \stopbuffer
%
% \typebuffer[setup] \getbuffer[setup,test] \page
%
% \startbuffer[setup]
% \setuplinenumbering
%   [width=4em,
%    distance=1em,
%    align=flushright]
% \stopbuffer
%
% \typebuffer[setup] \getbuffer[setup,test] \page
%
% \startbuffer[setup]
% \setuplinenumbering
%   [width=4em,
%    align=flushleft]
% \stopbuffer
%
% \typebuffer[setup] \getbuffer[setup,test] \page
%
% \startbuffer[setup]
% \setuplinenumbering
%   [width=2em,
%    distance=.5em,
%    align=middle]
% \stopbuffer
%
% \typebuffer[setup] \getbuffer[setup,test] \page
%
% \startbuffer[setup]
% \setuplinenumbering
%   [conversion=romannumerals,
%    start=1,
%    step=1,
%    location=text,
%    style=slanted,
%    color=blue,
%    width=1.5em]
% \stopbuffer
%
% \typebuffer[setup] \getbuffer[setup] \startnarrower\getbuffer[test]\stopnarrower \page
%
% \startbuffer[setup]
% \setuplinenumbering
%   [width=4em,
%    left=--,
%    right=--,
%    align=middle]
% \stopbuffer
%
% \typebuffer[setup] \getbuffer[setup,test] \page
%
% \startbuffer[setup-1]
% \setuplinenumbering
%   [style=\bfxx,
%    command=\WatchThis]
% \stopbuffer
%
% \startbuffer[setup-2]
% \def\WatchThis#1%
%   {\ifodd\linenumber
%      \definecolor[linecolor][red]%
%    \else
%      \definecolor[linecolor][green]%
%    \fi
%    \inframed
%      [offset=1pt,frame=off,background=color,backgroundcolor=linecolor]
%      {#1}}
% \stopbuffer
%
% \typebuffer[setup-1,setup-2] \getbuffer[setup-1,setup-2,test] \page
%
% \startbuffer[setup-1]
% \setuplinenumbering
%   [location=inright,
%    style=\bfxx,
%    command=\WatchThis]
% \stopbuffer
%
% \typebuffer[setup-1] \getbuffer[setup-1,setup-2,test] \page

\protect \endinput