page-lin.mkvi /size: 21 Kb    last modification: 2021-10-28 13:50
1
%D \module
2
%D [ file=page-lin,
3
%D version=2007.11.29,
4
%D title=\CONTEXT\ Core Macros,
5
%D subtitle=Line Numbering,
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
% generic or not ... maybe not bother too much and simplify to mkiv only
15
% get rid of \mk* (left over from experimental times)
16
%
17
% to be redone (was experiment) .. can be hooked into margin code
18
% reshuffle arguments
19
%
20
% this is early luatex code, 2007 or even before that, and it shows ... we
21
% have better tricks now
22 23
\writestatus
{
loading
}
{
ConTeXt
Core
Macros
/
Line
Numbering
}
24 25
\unprotect
26 27
% todo: save settings
28
%
29
% low level interface
30
%
31
% we should use normal counters but then we need to sync settings
32 33
% some line
34
%
35
% \startlocallinenumbering
36
% some source code 1\par
37
% some source code 2\par
38
% some source code 3\par
39
% \stoplocallinenumbering
40
%
41
% some line
42 43
\registerctxluafile
{
page
-
lin
}
{
}
44 45
\definesystemattribute
[
linenumber
]
[
public
]
46
\definesystemattribute
[
linereference
]
[
public
]
47 48
\appendtoksonce
49
\c_attr_linenumber
\attributeunsetvalue
50
\to
\everyforgetall
51 52
\appendtoks
53
\c_attr_linenumber
\attributeunsetvalue
54
\to
\everyinsidefloat
55 56
\mutable
\let
\linenumber
\!!zerocount
57 58
\newbox
\b_page_lines_scratch
59
\newcount
\c_page_lines_reference
60
\newconstant
\c_page_lines_nesting
61 62
\newconditional
\tracelinenumbering
% we keep this for old times sake
63 64
\installtextracker
65
{
lines
.
numbers
.
show
}
66
{
\settrue
\tracelinenumbering
}
67
{
\setfalse
\tracelinenumbering
}
68 69
% id nr shift width leftskip dir
70 71
\installcorenamespace
{
linenumberinginstance
}
72 73
% tag skipflag s getfield(n,"shift") getfield(n,"width") leftmarginwidth(getlist(n)) getfield(n,"dir"))
74 75
\let
\makelinenumber
\gobblefivearguments
% used at lua end
76 77
\newconditional
\page_postprocessors_needed_box
78 79
\unexpanded
\def
\page_postprocessors_linenumbers_page_indeed
#
tag
{
\page_lines_add_numbers_to_box
{
#
tag
}
\plusone
\plusone
\zerocount
}
80
\unexpanded
\def
\page_postprocessors_linenumbers_box_indeed
#
tag
{
\page_lines_add_numbers_to_box
{
#
tag
}
\plusone
\plusone
\zerocount
}
81
\unexpanded
\def
\page_postprocessors_linenumbers_deepbox_indeed
#
tag
{
\page_lines_add_numbers_to_box
{
#
tag
}
\plusone
\plusone
\plusone
}
82
\unexpanded
\def
\page_postprocessors_linenumbers_column_indeed
#
tag
{
\page_lines_add_numbers_to_box
{
#
tag
}
\currentcolumn
\nofcolumns
\zerocount
}
83 84
\let
\page_postprocessors_linenumbers_page
\gobbleoneargument
85
\let
\page_postprocessors_linenumbers_box
\gobbleoneargument
86
\let
\page_postprocessors_linenumbers_deepbox
\gobbleoneargument
87
\let
\page_postprocessors_linenumbers_column
\gobbleoneargument
88 89
\unexpanded
\def
\page_postprocessors_linenumbers_check
90
{
\glet
\page_postprocessors_linenumbers_check
\relax
91
\glet
\page_postprocessors_linenumbers_page
\page_postprocessors_linenumbers_page_indeed
92
\glet
\page_postprocessors_linenumbers_box
\page_postprocessors_linenumbers_box_indeed
93
\glet
\page_postprocessors_linenumbers_deepbox
\page_postprocessors_linenumbers_deepbox_indeed
94
\glet
\page_postprocessors_linenumbers_column
\page_postprocessors_linenumbers_column_indeed
}
95 96
\def
\page_lines_start_define
97
{
\setxvalue
{
\??linenumberinginstance
\currentlinenumbering
}
%
98
{
\clf_registerlinenumbering
99
continue
{
\ifnum
\c_page_lines_mode
=
\zerocount
\v!yes
\else
\v!no
\fi
}
%
100
start
\linenumberingparameter
\c!start
101
step
\linenumberingparameter
\c!step
102
method
{
\linenumberingparameter
\c!method
}
%
103
tag
{
\currentlinenumbering
}
%
104
}
}
105 106
\def
\page_lines_start_update
107
{
\clf_setuplinenumbering
108
\csname
\??linenumberinginstance
\currentlinenumbering
\endcsname
109
{
%
110
continue
{
\ifnum
\c_page_lines_mode
=
\zerocount
\v!yes
\else
\v!no
\fi
}
%
111
}
%
112
\relax
}
113 114
\def
\page_lines_setup
115
{
\ifcsname
\??linenumberinginstance
\currentlinenumbering
\endcsname
116
\clf_setuplinenumbering
117
\lastnamedcs
118
{
%
119
continue
{
\ifnum
\c_page_lines_mode
=
\zerocount
\v!yes
\else
\v!no
\fi
}
%
120
start
\linenumberingparameter
\c!start
121
step
\linenumberingparameter
\c!step
122
method
{
\linenumberingparameter
\c!method
}
%
123
tag
{
\currentlinenumbering
}
%
124
}
%
125
\relax
126
\fi
}
127 128
% we could make this a bit more efficient by putting the end reference
129
% in the same table as the start one but why make things complex ...
130 131
\unexpanded
\def
\page_lines_some_reference
#
1
#
2
#
3
%
132
{
\dontleavehmode
\begingroup
133
\global
\advance
\c_page_lines_reference
\plusone
134
\c_attr_linereference
\c_page_lines_reference
135
#
3
% todo: #3{#1} as there is no need to pass #1 as part of #3
136
% for the moment we use a simple system i.e. no prefixes etc .. todo: store as number
137
\c_strc_references_bind_state
\zerocount
% we don't want the prewordbreak and manage it here
138
\normalexpanded
{
\strc_references_set_named_reference
{
line
}
{
#
2
}
{
conversion
=
\linenumberingparameter
\c!conversion
}
{
\the
\c_page_lines_reference
}
}
% kind labels userdata text
139
\endgroup
}
140 141
% \def\page_lines_reference_start#1{\page_lines_some_reference{#1}{lr:b:#1}{}} % reimplemented later
142
% \def\page_lines_reference_stop #1{\page_lines_some_reference{#1}{lr:e:#1}{}} % reimplemented later
143 144
% \def\mklinestartreference#1[#2]{\in{#1}[lr:b:#2]} % not interfaced/ not used
145
% \def\mklinestopreference #1[#2]{\in{#1}[lr:e:#2]} % not interfaced/ not used
146 147
\newif
\ifnumberinglines
% will change
148
\newif
\iftypesettinglines
% will change
149 150
\installcorenamespace
{
linenumbering
}
151 152
\installcommandhandler
\??linenumbering
{
linenumbering
}
\??linenumbering
153 154
\setnewconstant
\c_page_lines_mode
\plusone
% 0=continue, 1=restart
155
\setnewconstant
\c_page_lines_location
\plusone
% 0=middle, 1=left, 2=right, 3=inner, 4=outer, 5=text, 6=begin, 7=end
156
\setnewconstant
\c_page_lines_alignment
\plusfive
% 0=middle, 1=left, 2=right, 5=auto
157 158
\newdimen
\d_page_lines_width
159
\newdimen
\d_page_lines_distance
160 161
\newevery
\beforeeverylinenumbering
\relax
162
\newevery
\aftereverylinenumbering
\relax
163
\newevery
\everylinenumber
\relax
164 165
\appendtoks
166
\page_lines_setup
167
\to
\everysetuplinenumbering
168 169
\appendtoks
170
\page_lines_start_define
171
\to
\everydefinelinenumbering
172 173
\setuplinenumbering
174
[
\c!conversion
=
\v!numbers
,
175
\c!start
=
1
,
176
\c!step
=
1
,
177
\c!method
=
\v!first
,
178
\c!continue
=
\v!no
,
179
\c!style
=
,
180
\c!color
=
,
181
\c!width
=
2
\emwidth
,
182
\c!left
=
,
183
\c!right
=
,
184
\c!command
=
,
185
\c!margin
=
2
.
5
\emwidth
,
186
\c!distance
=
\zeropoint
,
187
\c!location
=
\v!default
,
% depends on direction, columns etc
188
\c!align
=
\v!auto
]
189 190
\definelinenumbering
191
[
]
192 193
% \startlinenumbering[<startvalue>|continue|settings|name]
194
% \startlinenumbering[name][<startvalue>|continue|settings]
195 196
\unexpanded
\def
\startlinenumbering
197
{
\begingroup
198
\page_postprocessors_linenumbers_check
199
\dodoubleempty
\page_lines_start
}
200 201
\newcount
\c_pages_lines_nesting
202 203
\def
\page_lines_start
% we stay downward compatible
204
{
\advance
\c_pages_lines_nesting
\plusone
205
\ifnum
\c_pages_lines_nesting
>
\plusone
206
\expandafter
\dodoubleempty
\expandafter
\gobbletwooptionals
207
\else
208
\expandafter
\page_lines_start_indeed
209
\fi
}
210 211
\def
\page_lines_start_indeed
212
{
\ifsecondargument
213
\expandafter
\page_lines_start_two
214
\else
\iffirstargument
215
\doubleexpandafter
\page_lines_start_one
216
\else
217
\doubleexpandafter
\page_lines_start_zero
218
\fi
\fi
}
219 220
\def
\page_lines_start_zero
[
#
1
]
[
#
2
]
%
221
{
\edef
\m_argument
{
\linenumberingparameter
\c!continue
}
%
222
\ifx
\m_argument
\v!yes
223
\c_page_lines_mode
\zerocount
224
\else
225
\c_page_lines_mode
\plusone
226
\fi
227
\page_lines_start_followup
}
228 229
\def
\page_lines_start_one
[
#
1
]
[
#
2
]
% [continue|<number>|settings] % historic
230
{
\edef
\m_argument
{
#
1
}
%
231
\ifx
\m_argument
\v!continue
232
\c_page_lines_mode
\zerocount
233
\let
\currentlinenumbering
\empty
234
\else
235
\c_page_lines_mode
\plusone
236
\ifx
\m_argument
\v!empty
237
\let
\currentlinenumbering
\empty
238
\else
239
\doifelseassignment
{
#
1
}
240
{
\let
\currentlinenumbering
\empty
241
\setupcurrentlinenumbering
[
#
1
]
}
242
{
\doifelsenumber
\m_argument
243
{
\let
\currentlinenumbering
\empty
244
\letlinenumberingparameter
\c!start
\m_argument
}
245
{
\let
\currentlinenumbering
\m_argument
}
}
%
246
\fi
247
\edef
\p_continue
{
\linenumberingparameter
\c!continue
}
%
248
\ifx
\p_continue
\v!yes
249
\c_page_lines_mode
\zerocount
250
\fi
251
\fi
252
\page_lines_start_followup
}
253 254
\def
\page_lines_start_two
[
#
1
]
[
#
2
]
% [tag][continue|<number>|settings]
255
{
\edef
\currentlinenumbering
{
#
1
}
%
256
\edef
\m_argument
{
#
2
}
%
257
\ifx
\m_argument
\v!continue
258
\c_page_lines_mode
\zerocount
259
\else
260
\c_page_lines_mode
\plusone
261
\ifx
\m_argument
\v!empty
\else
262
\doifelseassignment
{
#
2
}
263
{
\setupcurrentlinenumbering
[
#
2
]
}
264
{
\doifnumber
\m_argument
265
{
\letlinenumberingparameter
\c!start
\m_argument
}
}
%
266
\fi
267
\edef
\p_continue
{
\linenumberingparameter
\c!continue
}
%
268
\ifx
\p_continue
\v!yes
269
\c_page_lines_mode
\zerocount
270
\fi
271
\fi
272
\page_lines_start_followup
}
273 274
\newconditional
\c_page_lines_auto_narrow
275
%\newconditional\c_page_lines_enabled
276 277
\appendtoks
278
\ifconditional
\page_postprocessors_needed_box
279
\page_postprocessors_linenumbers_page
\b_page_postprocessor
280
\fi
281
\to
\t_page_postprocessors_page
282 283
\appendtoks
284
\ifconditional
\page_postprocessors_needed_box
285
\page_postprocessors_linenumbers_column
\b_page_postprocessor
286
\fi
287
\to
\t_page_postprocessors_column
288 289
\def
\page_lines_start_followup
290
{
\numberinglinestrue
291
\edef
\p_location
{
\linenumberingparameter
\c!location
}
%
292
\setfalse
\c_page_lines_auto_narrow
293
\ifhmode
\else
294
\ifx
\p_location
\v!text
295
\ifdim
\leftskip
>
\zeropoint
\else
296
\advance
\leftskip
\linenumberingparameter
\c!margin
297
\settrue
\c_page_lines_auto_narrow
298
\fi
299
\else
\ifx
\p_location
\v!begin
300
\ifdim
\leftskip
>
\zeropoint
\else
301
\advance
\leftskip
\linenumberingparameter
\c!margin
302
\settrue
\c_page_lines_auto_narrow
303
\fi
304
\else
\ifx
\p_location
\v!end
305
\ifdim
\leftskip
>
\zeropoint
\else
306
\advance
\rightskip
\linenumberingparameter
\c!margin
307
\settrue
\c_page_lines_auto_narrow
308
\fi
309
\fi
\fi
\fi
310
\fi
311
\the
\beforeeverylinenumbering
312
%\global\settrue\c_page_lines_enabled %
313
\global
\settrue
\page_postprocessors_needed_box
% see core-rul.mkiv
314
\ifcase
\c_page_lines_mode
\relax
315
\page_lines_start_update
% continue
316
\or
317
\page_lines_start_define
% only when assignment
318
\fi
319
\c_attr_linenumber
\csname
\??linenumberinginstance
\currentlinenumbering
\endcsname
\relax
}
320 321
\unexpanded
\def
\stoplinenumbering
322
{
\ifconditional
\c_pages_lines_nesting
=
\plusone
323
\c_attr_linenumber
\attributeunsetvalue
324
\the
\aftereverylinenumbering
325
\ifconditional
\c_page_lines_auto_narrow
\par
\fi
326
\fi
327
\endgroup
}
328 329
% number placement .. will change into (the new) margin code
330 331
\newconditional
\c_page_lines_fake_number
332
\newconstant
\b_page_lines_number
333
\newconstant
\c_page_lines_column
334
\newconstant
\c_page_lines_last_column
335
\newdimen
\d_page_lines_line_width
336
\settrue
\c_page_lines_dir_left_to_right
337 338
\installcorenamespace
{
linenumberinghandler
}
339 340
\def
\page_line_swap_align
% can become a helper
341
{
\ifx
\p_align
\v!inner
\let
\p_align
\v!outer
\else
342
\ifx
\p_align
\v!outer
\let
\p_align
\v!inner
\else
343
\ifx
\p_align
\v!flushleft
\let
\p_align
\v!flushright
\else
344
\ifx
\p_align
\v!flushright
\let
\p_align
\v!flushleft
\else
345
\ifx
\p_align
\v!left
\let
\p_align
\v!right
\else
346
\ifx
\p_align
\v!right
\let
\p_align
\v!left
\fi
\fi
\fi
\fi
\fi
\fi
}
347 348
\let
\page_lines_make_number_indeed
\relax
349 350
% \def\page_lines_rlap{\ifconditional\c_page_lines_dir_left_to_right\expandafter\rlap\else\expandafter\llap\fi}
351
% \def\page_lines_llap{\ifconditional\c_page_lines_dir_left_to_right\expandafter\llap\else\expandafter\rlap\fi}
352 353
\def
\page_lines_add_numbers_to_box
#
box
#
column
#
max
#
nesting
%
354
{
\bgroup
355
\ifconditional
\c_strc_tags_enabled
356
\strc_tags_enable_indeed
357
\fi
358
\b_page_lines_number
#
box
\relax
359
\c_page_lines_column
#
column
\relax
360
\c_page_lines_last_column
#
max
\relax
361
\fullrestoreglobalbodyfont
362
\let
\makelinenumber
\page_lines_make_number
% used at lua end
363
\setbox
\b_page_lines_scratch
\vbox
364
{
\forgetall
365
\offinterlineskip
366
\clf_linenumbersstageone
367
\b_page_lines_number
368
#
nesting
%
369
\relax
}
%
370
\clf_linenumbersstagetwo
371
\b_page_lines_number
372
\b_page_lines_scratch
373
\relax
374
\egroup
}
375 376
\def
\page_lines_make_number
#
tag
#
mode
#
linenumber
#
width
#
dir
% with hang and parindent and skips we have to compensate for \hsize
377
{
\naturalhbox
to
\zeropoint
\bgroup
378
\ifcase
#
mode
\relax
379
% \settrue \c_page_lines_fake_number
380
\else
381
% \setfalse\c_page_lines_fake_number
382
\edef
\currentlinenumbering
{
#
tag
}
%
383
\def
\linenumber
{
#
linenumber
}
% unsafe
384
\d_page_lines_line_width
#
width
\scaledpoint
\relax
385
\d_page_lines_distance
\linenumberingparameter
\c!distance
\relax
386
\edef
\p_align
{
\linenumberingparameter
\c!align
}
%
387
\edef
\p_location
{
\linenumberingparameter
\c!location
}
%
388
\ifcase
#
dir
\relax
389
\settrue
\c_page_lines_dir_left_to_right
390
\else
391
\setfalse
\c_page_lines_dir_left_to_right
392
\fi
393
%
394
% maybe we also need an option to ignore columns, so that we renumber
395
% once but on the other hand this assumes aligned lines
396
%
397
\ifcase
\c_page_lines_last_column
\relax
398
\settrue
\c_page_lines_fake_number
% why
399
\or
400
% one column
401
\or
402
% two columns
403
\ifx
\p_location
\v!default
% or just margin
404
\ifcase
\c_page_lines_column
\relax
405
\settrue
\c_page_lines_fake_number
% why
406
\or
407
% one
408
\let
\p_location
\v!left
409
\else
410
% two
411
\let
\p_location
\v!right
412
% can become a helper
413
\page_line_swap_align
414
\fi
415
\fi
416
\else
417
% too fuzzy
418
\fi
419
\ifx
\p_location
\v!default
420
\ifconditional
\c_page_lines_dir_left_to_right
421
\let
\p_location
\v!left
422
\else
423
\let
\p_location
\v!right
424
\page_line_swap_align
% yes or no
425
\fi
426
\fi
427
%
428
\begincsname
\??linenumberinghandler
\p_location
\endcsname
429
\fi
430
\egroup
}
431 432
\def
\page_lines_number_inject
#
align
#
width
%
433
{
\edef
\p_width
{
\linenumberingparameter
\c!width
}
%
434
\ifx
\p_width
\v!margin
435
\d_page_lines_width
#
width
%
436
\else
437
\d_page_lines_width
\p_width
438
\fi
439
\relax
440
\ifdim
\d_page_lines_width
>
\zeropoint
441
% \ifconditional\c_page_lines_dir_left_to_right\else
442
% \let\simplealignedbox\simplereversealignedbox
443
% \fi
444
\ifconditional
\tracelinenumbering
445
\ruledhbox
{
\simplealignedbox
\d_page_lines_width
#
align
{
\page_lines_number_inject_indeed
}
}
%
446
\else
447
\simplealignedbox
\d_page_lines_width
#
align
{
\page_lines_number_inject_indeed
}
%
448
\fi
449
\else
450
\ifconditional
\tracelinenumbering
451
\ruledhbox
452
\else
453
% \hbox
454
\fi
455
{
\page_lines_number_inject_indeed
}
%
456
\fi
}
457 458
\def
\page_lines_number_inject_indeed
459
{
\uselinenumberingstyleandcolor
\c!style
\c!color
460
\linenumberingparameter
\c!command
461
{
\linenumberingparameter
\c!left
462
\convertnumber
{
\linenumberingparameter
\c!conversion
}
\linenumber
463
\linenumberingparameter
\c!right
}
}
464 465
% \def\dodorlap{\hbox to \zeropoint{\box\nextbox\normalhss}\endgroup}
466
% \def\dodollap{\hbox to \zeropoint{\normalhss\box\nextbox}\endgroup}
467 468
\def
\page_line_handle_left
#
align
#
width
#
distance
%
469
{
\dostarttagged
\t!linenumber
\empty
470
\llap
471
{
\page_lines_number_inject
#
align
#
width
%
472
\dostarttagged
\t!ignore
\empty
473
\kern
\dimexpr
474
#
distance
+
\d_page_lines_distance
475
\ifconditional
\c_page_lines_dir_left_to_right
\else
+
\d_page_lines_line_width
\fi
476
\relax
477
\the
\everylinenumber
478
\hss
479
\dostoptagged
}
%
480
\dostoptagged
}
481 482
\def
\page_line_handle_right
#
align
#
width
#
distance
%
483
{
\dostarttagged
\t!linenumber
\empty
484
\rlap
485
{
\dostarttagged
\t!ignore
\empty
486
\kern
\dimexpr
487
#
distance
+
\d_page_lines_distance
488
\ifconditional
\c_page_lines_dir_left_to_right
+
\d_page_lines_line_width
\fi
489
\relax
490
\dostoptagged
491
\page_lines_number_inject
#
align
#
width
%
492
\dostarttagged
\t!ignore
\empty
493
\the
\everylinenumber
494
\hss
495
\dostoptagged
}
%
496
\dostoptagged
}
497 498
\setuvalue
{
\??linenumberinghandler
\v!left
}
%
499
{
\page_line_handle_left
\p_align
\leftmarginwidth
\leftmargindistance
}
500 501
\setuvalue
{
\??linenumberinghandler
\v!right
}
%
502
{
\page_line_handle_right
\p_align
\rightmarginwidth
\rightmargindistance
}
503 504
\setuvalue
{
\??linenumberinghandler
\v!inner
}
%
505
{
\ifodd
\realpageno
506
\ifx
\p_align
\v!inner
507
\page_line_handle_left
\v!flushleft
\leftmarginwidth
\leftmargindistance
508
\else
\ifx
\p_align
\v!outer
509
\page_line_handle_left
\v!flushright
\leftmarginwidth
\leftmargindistance
510
\else
511
\page_line_handle_left
\p_align
\leftmarginwidth
\leftmargindistance
512
\fi
\fi
513
\else
514
\ifx
\p_align
\v!inner
515
\page_line_handle_right
\v!flushright
\rightmarginwidth
\rightmargindistance
516
\else
\ifx
\p_align
\v!outer
517
\page_line_handle_right
\v!flushleft
\rightmarginwidth
\rightmargindistance
518
\else
519
\page_line_handle_right
\p_align
\rightmarginwidth
\rightmargindistance
520
\fi
\fi
521
\fi
}
522 523
\setuvalue
{
\??linenumberinghandler
\v!outer
}
%
524
{
\ifodd
\realpageno
525
\ifx
\p_align
\v!inner
526
\page_line_handle_right
\v!flushleft
\leftmarginwidth
\leftmargindistance
527
\else
\ifx
\p_align
\v!outer
528
\page_line_handle_right
\v!flushright
\leftmarginwidth
\leftmargindistance
529
\else
530
\page_line_handle_right
\p_align
\leftmarginwidth
\leftmargindistance
531
\fi
\fi
532
\else
533
\ifx
\p_align
\v!inner
534
\page_line_handle_left
\v!flushright
\rightmarginwidth
\rightmargindistance
535
\else
\ifx
\p_align
\v!outer
536
\page_line_handle_left
\v!flushleft
\rightmarginwidth
\rightmargindistance
537
\else
538
\page_line_handle_left
\p_align
\rightmarginwidth
\rightmargindistance
539
\fi
\fi
540
\fi
}
541 542
\def
\page_line_handle_begin
#
align
%
543
{
\rlap
544
{
\kern
\d_page_lines_distance
545
\page_lines_number_inject
#
align
\zeropoint
546
\the
\everylinenumber
}
}
547 548
\def
\page_line_handle_end
#
align
%
549
{
\rlap
550
{
\kern
\d_page_lines_line_width
\relax
551
\llap
552
{
\page_lines_number_inject
#
align
\zeropoint
553
\kern
\d_page_lines_distance
554
\the
\everylinenumber
}
}
}
555 556
\setuvalue
{
\??linenumberinghandler
\v!begin
}
{
\page_line_handle_begin
\p_align
}
557
\setuvalue
{
\??linenumberinghandler
\v!end
}
{
\page_line_handle_end
\p_align
}
558
\setuvalue
{
\??linenumberinghandler
\v!text
}
{
\page_line_handle_begin
\p_align
}
559 560
\expandafter
\let
\csname
\??linenumberinghandler
\v!inleft
\expandafter
\endcsname
\csname
\??linenumberinghandler
\v!left
\endcsname
561
\expandafter
\let
\csname
\??linenumberinghandler
\v!inmargin
\expandafter
\endcsname
\csname
\??linenumberinghandler
\v!left
\endcsname
562
\expandafter
\let
\csname
\??linenumberinghandler
\v!margin
\expandafter
\endcsname
\csname
\??linenumberinghandler
\v!left
\endcsname
563
\expandafter
\let
\csname
\??linenumberinghandler
\v!inright
\expandafter
\endcsname
\csname
\??linenumberinghandler
\v!right
\endcsname
564 565
% referencing: \permithyphenation, also removes leading spaces (new per 29-11-2013)
566 567
\unexpanded
\def
\someline
[
#
1
]
{
\page_lines_reference_start
{
#
1
}
\page_lines_reference_stop
{
#
1
}
}
% was just a def
568
%unexpanded\def\startline[#1]{\page_lines_reference_start{#1}\ignorespaces}
569
\unexpanded
\def
\startline
[
#
1
]
{
\page_lines_reference_start
{
#
1
}
\permithyphenation
\ignorespaces
}
%okay?
570
\unexpanded
\def
\stopline
[
#
1
]
{
\removeunwantedspaces
\permithyphenation
\page_lines_reference_stop
{
#
1
}
}
571 572
\def
\page_lines_reference_show_start
573
{
\ifconditional
\tracelinenumbering
574
\expandafter
\page_lines_reference_show_start_indeed
575
\else
576
\expandafter
\gobbleoneargument
577
\fi
}
578 579
\def
\page_lines_reference_show_stop
580
{
\ifconditional
\tracelinenumbering
581
\expandafter
\page_lines_reference_show_stop_indeed
582
\else
583
\expandafter
\gobbleoneargument
584
\fi
}
585 586
\def
\page_lines_reference_show_start_indeed
#
1
%
587
{
\setbox
\scratchbox
\hpack
{
\llap
588
{
\vrule
\s!width
\onepoint
\s!depth
\strutdp
\s!height
.
8
\strutht
\raise
.
8
5
\strutht
\hpack
{
\llap
{
\tt
\txx
#
1
}
}
}
}
%
589
\smashbox
\scratchbox
590
\box
\scratchbox
}
591 592
\def
\page_lines_reference_show_stop_indeed
#
1
%
593
{
\setbox
\scratchbox
\hpack
{
\rlap
594
{
\raise
.
8
5
\strutht
\hpack
{
\rlap
{
\tt
\txx
#
1
}
}
\vrule
\s!width
\onepoint
\s!depth
\strutdp
\s!height
.
8
\strutht
}
}
%
595
\smashbox
\scratchbox
596
\box
\scratchbox
}
597 598
\def
\page_lines_reference_start
#
1
{
\page_lines_some_reference
{
#
1
}
{
lr
:
b
:
#
1
}
{
\page_lines_reference_show_start
{
#
1
}
}
}
599
\def
\page_lines_reference_stop
#
1
{
\page_lines_some_reference
{
#
1
}
{
lr
:
e
:
#
1
}
{
\page_lines_reference_show_stop
{
#
1
}
}
}
600 601
% eventually we will do this in lua
602 603
\def
\currentreferencelinenumber
{
\clf_filterreference
{
linenumber
}
}
604 605
\let
\m_page_lines_from
\empty
606
\let
\m_page_lines_to
\empty
607 608
\unexpanded
\def
\doifelsesamelinereference
#
1
#
2
#
3
%
609
{
\doifelsereferencefound
{
lr
:
b
:
#
1
}
610
{
\edef
\m_page_lines_from
{
\currentreferencelinenumber
}
%
611
\doifelsereferencefound
{
lr
:
e
:
#
1
}
612
{
\edef
\m_page_lines_to
{
\currentreferencelinenumber
}
%
613
%[\m_page_lines_from,\m_page_lines_to]
614
\ifx
\m_page_lines_from
\m_page_lines_to
#
2
\else
#
3
\fi
}
615
{
#
2
}
}
616
{
#
2
}
}
617 618
\let
\doifsamelinereferenceelse
\doifelsesamelinereference
619 620
\unexpanded
\def
\inline
#
1
[
#
2
]
%
621
{
\doifelsenothing
{
#
1
}
622
{
\doifelsesamelinereference
{
#
2
}
623
{
\in
{
\leftlabeltext
\v!line
}
{
\rightlabeltext
\v!line
}
[
lr
:
b
:
#
2
]
}
624
{
\in
{
\leftlabeltext
\v!lines
}
{
}
[
lr
:
b
:
#
2
]
-
-
\in
{
}
{
\rightlabeltext
\v!lines
}
[
lr
:
e
:
#
2
]
}
}
625
{
\doifelsesamelinereference
{
#
2
}
626
{
\in
{
#
1
}
[
lr
:
b
:
#
2
]
}
627
{
\in
{
#
1
}
[
lr
:
b
:
#
2
]
-
-
\in
[
lr
:
e
:
#
2
]
}
}
}
628 629
\unexpanded
\def
\inlinerange
[
#
1
]
%
630
{
\doifelsesamelinereference
{
#
1
}
631
{
\in
[
lr
:
b
:
#
1
]
}
632
{
\in
[
lr
:
b
:
#
1
]
\endash
\in
[
lr
:
e
:
#
1
]
}
}
633 634
\protect
\endinput
635