hybrid-bidi.tex /size: 4796 b    last modification: 2023-12-21 09:43
1% language=us
2
3\startcomponent hybrid-inserts
4
5\environment hybrid-environment
6
7\startchapter[title={The Bidi Dilemma}]
8
9Here I will introduce a few concepts of bidirectional typesetting. While \LUATEX\
10does a lot automatically, this does not mean that you get a proper bidirectional
11layout for free. We distinguish a few cases:
12
13\startitemize [packed]
14\startitem verbatim as used in manuals \stopitem
15\startitem simulating a text editor \stopitem
16\startitem typesetting of text \stopitem
17\stopitemize
18
19In addition to this we distinguish two document layouts:
20
21\startitemize [packed]
22\startitem predominantly left||to||right with some right||to||left snippets \stopitem
23\startitem predominantly right||to||left with some left||to||right snippets \stopitem
24\stopitemize
25
26In both cases explicit choices have to be made when defining the layout,
27programming the style, and coding the content. In this chapter I will stick to
28verbatim.
29
30In verbatim mode we normally use a monospaced font and no interference with
31features is to be expected. You get what you've keyed in. Because verbatim is
32used for illustrative purposes, we need to have predictable output. This is why
33we have to control the position of the linenumbers as well as the alignment
34explicitly.
35
36\startbuffer[basics]
37\definetyping [XXtyping] [numbering=line]
38\definetyping [RLtyping] [align=r2l,numbering=line]
39\definetyping [LRtyping] [align=l2r,numbering=line]
40\stopbuffer
41
42\typebuffer[basics] \getbuffer[basics]
43
44We use these definitions in the following example:
45
46\startbuffer[sample]
47\startLRtyping
48At the left!
49At the left!
50\stopLRtyping
51
52\startRLtyping
53At the right!
54At the right!
55\stopRLtyping
56
57\startalignment[l2r]
58\startXXtyping
59At the left!
60At the left!
61\stopXXtyping
62\stopalignment
63
64\startalignment[r2l]
65\startXXtyping
66At the right!
67At the right!
68\stopXXtyping
69\stopalignment
70\stopbuffer
71
72\typebuffer[sample]
73
74However, we can have a bit more control over the position of the line numbers. As
75linenumbers are added in a later stage we need to define additional line number
76classes for this. We show four relevant positions of linenumbers. What setting
77you use depends on the predominant direction of your document as well as what you
78want to demonstrate.
79
80\startbuffer
81\definetyping [RLtypingLEFT] [align=r2l,numbering=line]
82\definetyping [LRtypingLEFT] [align=l2r,numbering=line]
83
84\setuplinenumbering [RLtypingLEFT] [location=left]
85\setuplinenumbering [LRtypingLEFT] [location=left]
86
87\startLRtypingLEFT
88At the left!
89At the left!
90\stopLRtypingLEFT
91
92\startRLtypingLEFT
93At the right!
94At the right!
95\stopRLtypingLEFT
96\stopbuffer
97
98\typebuffer
99
100When \type {location} is set to \type {left}, the line numbers will always be in
101the left margin, no matter what the text direction is.
102
103\getbuffer
104
105\startbuffer
106\definetyping [RLtypingRIGHT] [align=r2l,numbering=line]
107\definetyping [LRtypingRIGHT] [align=l2r,numbering=line]
108
109\setuplinenumbering [RLtypingRIGHT] [location=right]
110\setuplinenumbering [LRtypingRIGHT] [location=right]
111
112\startLRtypingRIGHT
113At the left!
114At the left!
115\stopLRtypingRIGHT
116
117\startRLtypingRIGHT
118At the right!
119At the right!
120\stopRLtypingRIGHT
121\stopbuffer
122
123From this it follows that when \type {location} is set to \type {right}, the line
124numbers will always be in the right margin.
125
126\typebuffer
127
128Again, the text direction is not influencing the placement.
129
130\getbuffer
131
132\startbuffer
133\definetyping [RLtypingBEGIN] [align=r2l,numbering=line]
134\definetyping [LRtypingBEGIN] [align=l2r,numbering=line]
135
136\setuplinenumbering [RLtypingBEGIN] [location=begin]
137\setuplinenumbering [LRtypingBEGIN] [location=begin]
138
139\startLRtypingBEGIN
140At the left!
141At the left!
142\stopLRtypingBEGIN
143
144\startRLtypingBEGIN
145At the right!
146At the right!
147\stopRLtypingBEGIN
148\stopbuffer
149
150The next two cases {\em do} obey to the text direction. When set to \type
151{begin}, the location will be at the beginning of the line.
152
153\typebuffer
154
155When typesetting a paragraph from right to left, the beginning of the line is at
156the right margin.
157
158\getbuffer
159
160\startbuffer
161\definetyping [RLtypingEND] [align=r2l,numbering=line]
162\definetyping [LRtypingEND] [align=l2r,numbering=line]
163
164\setuplinenumbering [RLtypingEND] [location=end]
165\setuplinenumbering [LRtypingEND] [location=end]
166
167\startLRtypingEND
168At the left!
169At the left!
170\stopLRtypingEND
171
172\startRLtypingEND
173At the right!
174At the right!
175\stopRLtypingEND
176\stopbuffer
177
178Consequently we get the opposite result when we set \type {location} to
179\type {end}.
180
181\typebuffer
182
183This time we get complementary results:
184
185\getbuffer
186
187It will be clear that when we are writing a manual where we mix example code with
188real right to left text some care goes into setting up the verbatim environments.
189And this is just one of the aspects you have to deal with in a bidirectional
190document layout.
191
192\stopchapter
193
194\stopcomponent
195