summaryrefslogtreecommitdiff
path: root/doc/context/sources/general/manuals/hybrid/hybrid-bidi.tex
blob: c291d11eb34243f9f611536fa4b2a10af086ee2c (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
187
188
189
190
191
192
193
194
% language=uk

\startcomponent hybrid-inserts

\environment hybrid-environment

\startchapter[title={The Bidi Dilemma}]

Here I will introduce a few concepts of bidirectional typesetting. While \LUATEX\
does a lot automatically, this does not mean that you get a proper bidirectional
layout for free. We distinguish a few cases:

\startitemize [packed]
\startitem verbatim as used in manuals \stopitem
\startitem simulating a text editor \stopitem
\startitem typesetting of text \stopitem
\stopitemize

In addition to this we distinguish two document layouts:

\startitemize [packed]
\startitem predominantly left||to||right with some right||to||left snippets \stopitem
\startitem predominantly right||to||left with some left||to||right snippets \stopitem
\stopitemize

In both cases explicit choices have to be made when defining the layout,
programming the style, and coding the content. In this chapter I will stick to
verbatim.

In verbatim mode we normally use a monospaced font and no interference with
features is to be expected. You get what you've keyed in. Because verbatim is
used for illustrative purposes, we need to have predictable output. This is why
we have to control the position of the linenumbers as well as the alignment
explicitly.

\startbuffer[basics]
\definetyping [XXtyping] [numbering=line]
\definetyping [RLtyping] [align=r2l,numbering=line]
\definetyping [LRtyping] [align=l2r,numbering=line]
\stopbuffer

\typebuffer[basics] \getbuffer[basics]

We use these definitions in the following example:

\startbuffer[sample]
\startLRtyping
At the left!
At the left!
\stopLRtyping

\startRLtyping
At the right!
At the right!
\stopRLtyping

\startalignment[l2r]
\startXXtyping
At the left!
At the left!
\stopXXtyping
\stopalignment

\startalignment[r2l]
\startXXtyping
At the right!
At the right!
\stopXXtyping
\stopalignment
\stopbuffer

\typebuffer[sample]

However, we can have a bit more control over the position of the line numbers. As
linenumbers are added in a later stage we need to define additional line number
classes for this. We show four relevant positions of linenumbers. What setting
you use depends on the predominant direction of your document as well as what you
want to demonstrate.

\startbuffer
\definetyping [RLtypingLEFT] [align=r2l,numbering=line]
\definetyping [LRtypingLEFT] [align=l2r,numbering=line]

\setuplinenumbering [RLtypingLEFT] [location=left]
\setuplinenumbering [LRtypingLEFT] [location=left]

\startLRtypingLEFT
At the left!
At the left!
\stopLRtypingLEFT

\startRLtypingLEFT
At the right!
At the right!
\stopRLtypingLEFT
\stopbuffer

\typebuffer

When \type {location} is set to \type {left}, the line numbers will always be in
the left margin, no matter what the text direction is.

\getbuffer

\startbuffer
\definetyping [RLtypingRIGHT] [align=r2l,numbering=line]
\definetyping [LRtypingRIGHT] [align=l2r,numbering=line]

\setuplinenumbering [RLtypingRIGHT] [location=right]
\setuplinenumbering [LRtypingRIGHT] [location=right]

\startLRtypingRIGHT
At the left!
At the left!
\stopLRtypingRIGHT

\startRLtypingRIGHT
At the right!
At the right!
\stopRLtypingRIGHT
\stopbuffer

From this it follows that when \type {location} is set to \type {right}, the line
numbers will always be in the right margin.

\typebuffer

Again, the text direction is not influencing the placement.

\getbuffer

\startbuffer
\definetyping [RLtypingBEGIN] [align=r2l,numbering=line]
\definetyping [LRtypingBEGIN] [align=l2r,numbering=line]

\setuplinenumbering [RLtypingBEGIN] [location=begin]
\setuplinenumbering [LRtypingBEGIN] [location=begin]

\startLRtypingBEGIN
At the left!
At the left!
\stopLRtypingBEGIN

\startRLtypingBEGIN
At the right!
At the right!
\stopRLtypingBEGIN
\stopbuffer

The next two cases {\em do} obey to the text direction. When set to \type
{begin}, the location will be at the beginning of the line.

\typebuffer

When typesetting a paragraph from right to left, the beginning of the line is at
the right margin.

\getbuffer

\startbuffer
\definetyping [RLtypingEND] [align=r2l,numbering=line]
\definetyping [LRtypingEND] [align=l2r,numbering=line]

\setuplinenumbering [RLtypingEND] [location=end]
\setuplinenumbering [LRtypingEND] [location=end]

\startLRtypingEND
At the left!
At the left!
\stopLRtypingEND

\startRLtypingEND
At the right!
At the right!
\stopRLtypingEND
\stopbuffer

Consequently we get the opposite result when we set \type {location} to
\type {end}.

\typebuffer

This time we get complementary results:

\getbuffer

It will be clear that when we are writing a manual where we mix example code with
real right to left text some care goes into setting up the verbatim environments.
And this is just one of the aspects you have to deal with in a bidirectional
document layout.

\stopchapter

\stopcomponent