bidi-mixed.tex /size: 7148 b    last modification: 2021-10-28 13:50
1% language=us runpath=texruns:manuals/bidi
2
3\startcomponent bidi-mixed
4
5\environment bidi-style
6
7\startchapter[title=A mixed layout]
8
9The typesetting engine normally works from left to right and top to bottom. Going
10from right to left actually involved two decisions:
11
12\startitemize[packed]
13\startitem the direction of the display elements, the paragraphs \stopitem
14\startitem the direction of the inline text, the lines \stopitem
15\stopitemize
16
17The first one is kept track of in a state variable. Every paragraph starts with
18a node that carries, among other information, that state. This node is added
19automatically and does not interfere with the typesetting. The inline direction
20is more intrusive as it is marked by nodes that indicate the beginning and end
21of a reversed strip. This mechanism is rather reliable and normally works out
22well. Take this:
23
24\startbuffer
25left {\righttoleft right} left
26left{ \righttoleft right} left
27left {\righttoleft right }left
28left{ \righttoleft right }left
29\stopbuffer
30
31\typebuffer
32
33You can see that we need to be careful with spaces as they can end up inside or
34outside a substream and by swapping next to each other:
35
36\startlines
37\getbuffer
38\stoplines
39
40We can wrap the lines in boxes as in:
41
42\startbuffer
43\hbox{left\space{\bf\righttoleft right}\space left}
44\hbox{left{\bf\space \righttoleft right}\space left}
45\hbox{left\space{\bf\righttoleft right\space}left}
46\hbox{left{\bf\space\righttoleft right\space}left}
47\stopbuffer
48
49\typebuffer
50
51\definecolor[ShineThrough][s=0,a=1,t=.2]
52
53When visualize the spaces we get this:
54
55\startlines\ShineThrough
56\showmakeup[space,hbox]\getbuffer
57\stoplines
58
59The space of a normal and bold font in the same family normally is the same but
60let's mix with a larger size:
61
62\startbuffer
63\hbox{left {\bfa\righttoleft right} left}
64\hbox{left{\bfa\space \righttoleft right} left}
65\hbox{left {\bfa\righttoleft right }left}
66\hbox{left{\bfa\space\righttoleft right }left}
67\stopbuffer
68
69\typebuffer
70
71Now we get the following. As you can see, it really matters where we put the
72braces.
73
74\startlines
75\ShineThrough\showmakeup[space,hbox]\getbuffer
76\stoplines
77
78Once you are accustomed to tagging and \TEX\ you will probably not fall into
79these traps. In \in {figure} [fig:spaces] we show a large version.
80
81\startplacefigure[location=top,title={Watch your spaces!},reference=fig:spaces]
82    \scale
83      [width=\hsize]
84      {\vbox{\ShineThrough\showmakeup[space,hbox]\getbuffer}}
85\stopplacefigure
86
87The \type {\righttoleft} command actually has two meanings. This can best be seen
88from an example.
89
90\startbuffer
91\righttoleft \bf How will this come out?
92\stopbuffer
93
94\typebuffer
95
96\start \getbuffer \par \stop
97
98\startbuffer
99And \righttoleft \bf how will this come out?
100\stopbuffer
101
102\typebuffer
103
104\start \getbuffer \par \stop
105
106When we start a paragraph (or in \TEX\ speak: when we are still in vertical mode)
107the paragraph direction as well as the inline direction is set. Otherwise only
108the inline direction is set. There are low level \TEX\ commands (primitives) to
109set the direction but you can best {\em not} use these because we need to do a
110bit more than that.
111
112There are quite some low level commands related to changing directions. Some deal
113with the layout, some with boxes. We might provide more in the future.
114
115\starttabulate[|l|p|]
116\FL
117\NC \type {\lefttoright}                  \NC l2r dir node or paragraph property \NC \NR
118\NC \type {\righttoleft}                  \NC r2l dir node or paragraph property \NC \NR
119\NC \type {\checkedlefttoright}           \NC l2r dir node or paragraph property (unless already set) \NC \NR
120\NC \type {\checkedrighttoleft}           \NC r2l dir node or paragraph property (unless already set) \NC \NR
121\ML
122\NC \type {\synchronizeinlinedirection}   \NC pickup a (possibly) reset state \NC \NR
123\NC \type {\synchronizelayoutdirection}   \NC pickup a (possibly) reset state \NC \NR
124\NC \type {\synchronizedisplaydirection}  \NC pickup a (possibly) reset state \NC \NR
125\ML
126\NC \type {\righttolefthbox}              \NC r2l \type {\hbox} \NC \NR
127\NC \type {\lefttorighthbox}              \NC l2r \type {\hbox} \NC \NR
128\NC \type {\righttoleftvbox}              \NC r2l \type {\vbox} \NC \NR
129\NC \type {\lefttorightvbox}              \NC l2r \type {\vbox} \NC \NR
130\NC \type {\righttoleftvtop}              \NC r2l \type {\vtop} \NC \NR
131\NC \type {\lefttorightvtop}              \NC l2r \type {\vtop} \NC \NR
132\ML
133\NC \type {\leftorrighthbox}              \NC l2r or r2l \type {\hbox} \NC \NR
134\NC \type {\leftorrightvbox}              \NC l2r or r2l \type {\vbox} \NC \NR
135\NC \type {\leftorrightvtop}              \NC l2r or r2l \type {\vtop} \NC \NR
136\ML
137\NC \type {\autodirhbox}                  \NC l2r or r2l \type {\hbox} (a bit more clever) \NC \NR
138\NC \type {\autodirvbox}                  \NC l2r or r2l \type {\vbox} (a bit more clever) \NC \NR
139\NC \type {\autodirvtop}                  \NC l2r or r2l \type {\vtop} (a bit more clever) \NC \NR
140\ML
141\NC \type {\bidilre}                      \NC character \type {U+202A}, enforce l2r state    \NC \NR
142\NC \type {\bidirle}                      \NC character \type {U+202B}, enforce r2l state    \NC \NR
143\NC \type {\bidipop}                      \NC character \type {U+202C}, return to last state \NC \NR
144\NC \type {\bidilro}                      \NC character \type {U+202D}, override l2r state   \NC \NR
145\NC \type {\bidirlo}                      \NC character \type {U+202E}, override r2l state   \NC \NR
146\NC \type {\lefttorightmark} \type {\lrm} \NC character \type {U+200E}, l2r indicator        \NC \NR
147\NC \type {\righttoleftmark} \type {\rlm} \NC character \type {U+200F}, r2l indicator        \NC \NR
148\ML
149\NC \type {\dirlre}                       \NC switch to l2r mode using \type {\bidilre} or \lefttoright \NC \NR
150\NC \type {\dirrle}                       \NC switch to r2l mode using \type {\bidirle} or \righttoleft \NC \NR
151\NC \type {\dirlro}                       \NC enforce l2r mode   using \type {\bidilro} or \lefttoright \NC \NR
152\NC \type {\dirrlo}                       \NC enforce r2l mode   using \type {\bidirlo} or \righttoleft \NC \NR
153\ML
154\NC \type {\naturalhbox}                  \NC a normal l2r \type {hbox}  \NC \NR
155\NC \type {\naturalvbox}                  \NC a normal l2r \type {vbox}  \NC \NR
156\NC \type {\naturalvtop}                  \NC a normal l2r \type {vtop}  \NC \NR
157\NC \type {\naturalhpack}                 \NC a normal l2r \type {hpack} \NC \NR
158\NC \type {\naturalvpack}                 \NC a normal l2r \type {vpack} \NC \NR
159\LL
160\stoptabulate
161
162When we talk about layout, we mean the overall layout, concerning the document as
163a whole. We can have a dominantly l2r, dominantly r2l or mixed setup. In a next
164chapter we will give more details on the dominant setup. Here we stick to
165mentioning that the document flow direction is set with
166
167\starttyping
168\setupalign[r2l] % or r2l
169\stoptyping
170
171When a command to setup an environment has a \type {align} parameter, the same
172keywords can be uses as part of the specification. \footnote {We haven't tested
173all situations and possible interferences. Just report anomalies to the mailing
174list.}
175
176\stopchapter
177
178\stopcomponent
179