summaryrefslogtreecommitdiff
path: root/doc/context/sources/general/magazines/mag-1105-mkiv.tex
blob: df1ec7e2ccbaf7c28b38992dc3f19622f1894b8a (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
175
176
177
178
179
180
181
182
183
184
185
186
% author    : Hans Hagen
% copyright : PRAGMA ADE & ConTeXt Development Team
% license   : Creative Commons Attribution ShareAlike 4.0 International
% reference : pragma-ade.nl | contextgarden.net | texlive (related) distributions
% origin    : the ConTeXt distribution
%
% comment   : Because this manual is distributed with TeX distributions it comes with a rather
%             liberal license. We try to adapt these documents to upgrades in the (sub)systems
%             that they describe. Using parts of the content otherwise can therefore conflict
%             with existing functionality and we cannot be held responsible for that. Many of
%             the manuals contain characteristic graphics and personal notes or examples that
%             make no sense when used out-of-context.

\ifdefined\parindentmode     \parindentmode    \plusone \fi % this will become default in lmtx
\ifdefined\normalizelinemode \normalizelinemode\plusone \fi % this will become default in lmtx

\usemodule[magazine-basic,abr-02]

\usemodule[scite]

\startbuffer[abstract]
    Here is yet another short example of a feature introduced in \CONTEXT\ \LMTX.
    It is mostly meant as teaser: maybe users have additional demands for this
    low level mechanisn.
\stopbuffer

\setuplayout
  [backspace=20mm,
   topspace=10mm]

\startdocument
  [title={Playing with boxes, a teaser},
   author={Hans Hagen},
  %affiliation=PRAGMA ADE,
   date=August 2020,
   number=1105 LMTX]

When a paragraph is typeset in a vertical box, we get a bunch of lines pasted
together. If you want to change something in the result, you can disassemble that
box in detailed ways (in \LUA) but maybe it's something simple that you like to
do. For that we have a an interface to the lines on such a box. We start with a
few settings:

\starttyping[option=TEX]
\parindentmode    \plusone
\normalizelinemode\plusone
\stoptyping

These two settings will become default in \CONTEXT\ \LMTX, but here we need them in
order to show some properties of boxes.

\startbuffer[sample]
\setbox0\ruledvbox \bgroup
    \leftskip         10pt
    \rightskip        20pt
    \hangindent       40pt
    \hangafter         2
    \parindent         5pt
    \parfillleftskip  80pt plus 1 fill
    \parfillrightskip 40pt plus 1 fill
    \input tufte
\egroup
\stopbuffer

\typebuffer[sample][option=TEX]

This box has a bit weird setup but we want to demonstrate something to it's okay:

\startlinecorrection
    \getbuffer[sample] \box0
\stoplinecorrection


In case you wonder, the left and right parskips are a \MKIV\ thing and supported
in \LMTX\ in a more advanced way. The left one can be used to push the last line
to the right.

\startbuffer[overview]
\dorecurse {\boxlines 0} {
    [#1] (%
        \the\boxlinewd 0 #1, \the\boxlineht 0 #1, \the\boxlinedp 0 #1,
        \the\boxlinels 0 #1, \the\boxliners 0 #1,
        \the\boxlinelh 0 #1, \the\boxlinerh 0 #1,
        \the\boxlinein 0 #1, \the\boxlinelp 0 #1, \the\boxlinerp 0 #1
    ) \par
}
\stopbuffer

\typebuffer[overview][option=TEX]

\getbuffer[sample]

\startpacked \tt \txx
    \getbuffer[overview]
\stoppacked

The properties of a line are: width, height and depth, left and right skip,
applied left and right hang, indentation (of the first line), left and right
filler of the last line. You can use the commands shown as other dimensions, so
\type {\the} is only needed when you serialize a property.

Some properties can be changed (others might follow later). Here we change the
width of line four (the equal sign is optional):

\startbuffer
\the\boxlinewd 0 4 \space& \boxlinewd 0 4 = 40pt \the\boxlinewd 0 4
\stopbuffer

\typebuffer[option=TEX]

We get: \inlinebuffer . We can detach a line from the box. Here we put two lines
in another box that gets assigned to a box register, and a third line is assigned
to a box register as|-|is:

\startbuffer
\setbox2\ruledhbox{\copyboxline 0 2}
\setbox4\ruledhbox{\boxline     0 4}
\setbox6           \boxline     0 6
\stopbuffer

\typebuffer[option=TEX] \getbuffer

The result is:

\startbuffer
[2] [\box2] \par
[4] [\box4] \par
[6] [\box6] \par
\stopbuffer

\typebuffer[option=TEX]

\startlinecorrection
    \startpacked
        \getbuffer
    \stoppacked
\stoplinecorrection

Next we replace an existing line by a new line:

\startbuffer
\setboxline 0 3 \hbox {\darkred \bold This is a replacement line!}
\stopbuffer

\typebuffer[option=TEX] \getbuffer

The original box is now:

\startlinecorrection
\box0
\stoplinecorrection

We can repack the box with the usual \TEX\ commands: \type {\vpack {\unvbox0}}
but here we just did a \type {\box0}.

An example of a more useful application is the following. First we fill a box:

\startbuffer
\setbox\scratchbox\ruledvbox \bgroup
    \input ward
\egroup
\stopbuffer

\typebuffer[option=TEX] \getbuffer

With little effort we can add line numbers:

\startbuffer
\ruledvbox \bgroup
    \dorecurse {\boxlines \scratchbox} {%
        \dontleavehmode
        \strut
        \llap{\hbox to 1.5em{\txx#1\hss}}\boxline \scratchbox #1\par
    }
}
\stopbuffer

\typebuffer[option=TEX]

The result is:

\startlinecorrection
    {\forgetall \getbuffer}
\stoplinecorrection

\stopdocument