# mixing right-to-left and left-to-right scripts

**URL:** <https://forum.xojo.com/t/mixing-right-to-left-and-left-to-right-scripts/34082>\
**Category:** General\
**Created:** [October 22, 2016, 4:35am UTC](https://forum.xojo.com/t/mixing-right-to-left-and-left-to-right-scripts/34082 "2016-10-22T04:35:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carlo\_Rubini](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/94ad74/32.png) [@Carlo\_Rubini](https://forum.xojo.com/u/Carlo_Rubini)\
**Post date:** [October 22, 2016, 4:35am UTC](https://forum.xojo.com/t/mixing-right-to-left-and-left-to-right-scripts/34082/1 "2016-10-22T04:35:02Z")

</div>

Hello,  
I would appreciate some help in order to be able to write on the same line right-to-left and left-to-right words.  
Let us suppose I want to right the word “House” followed by “=” and its Hebrew counterpart Beth (using an Hebrew font);  
setting tectArea1.alignment = textarea.alignRight I’d expect the following result:  
beth = house//the reader, reading from the right, should understand that “House” is “Beth” in Hebrew.

But typing “house = beth” or typing “beth = house”, it always turns out  
house = beth

I also tried with TextEdit, getting the same result. So obviously I need some input. It will be appreciated.

BTW: since the app is cross-platform (Mac and Windows10), I opened in Windows (Microsoft Word) my TextEdit file, and I found that the rendering is different: with several Hebrew and Roman words on the same line, the Hebrew words change position, for instance, the third word becomes the first, etc. More reasons for me to get tutored.  
Thanks.

---

<div class="post-metadata">

**Author:** ![Richard\_Corlett](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/74df32/32.png) [@Richard\_Corlett](https://forum.xojo.com/u/Richard_Corlett)\
**Post date:** [October 22, 2016, 6:18pm UTC](https://forum.xojo.com/t/mixing-right-to-left-and-left-to-right-scripts/34082/2 "2016-10-22T18:18:43Z")

</div>

I assume that you are using Unicode as your text encoding. In Unicode, alphabetical characters and numerals are strongly directional but punctuation and other characters are weakly directional so in your case the equals sign is probably weakly directional and this causes the words to flip into the wrong positions. Alignment has no effect on this, it only causes the text to be aligned to the right, left or centre of the text area.

To get bidirectional text displaying correctly you will then need to make use of Unicode’s text direction characters to tell the text area which direction a particular part of your string is reading RTL or LTR:

`Chr(&h200E)` LEFT-TO-RIGHT MARK

`Chr(&h200F)` RIGHT-TO-LEFT MARK

`Chr(&h202A)` LEFT-TO-RIGHT EMBEDDING

`Chr(&h202B)` RIGHT-TO-LEFT EMBEDDING

`Chr(&h202C)` POP DIRECTIONAL FORMATTING (use with each occurrence of the previous two)

So in your example, you should find that adding the left-to-right mark will put things in their proper place:

```auto
myTextArea.Text=Chr(&h200E)+"???"+"=House"
```

It is worth noting that Windows does not handle these text direction marks exactly the same way as Mac, however what works on Windows always seems to be OK on Mac if not always vice versa.

---

<div class="post-metadata">

**Author:** ![Carlo\_Rubini](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/94ad74/32.png) [@Carlo\_Rubini](https://forum.xojo.com/u/Carlo_Rubini)\
**Post date:** [October 23, 2016, 1:59pm UTC](https://forum.xojo.com/t/mixing-right-to-left-and-left-to-right-scripts/34082/3 "2016-10-23T13:59:26Z")

</div>

Richard, do not mind for me being late in answering you. I have been struggling hours in order to put things right following your advice.  
In Windows, things went straight at once with Syriac texts, but with Hebrew texts I’m still getting inconsistent results, especially when a roman line starts with a square bracket.  
What baffles me is that if I create a new project, then I do not get any problem; therefore I have to find out where in the real app things go wrong.  
As for Mac, no problem.  
Again, thank you for your suggestions.

---

<div class="post-metadata">

**Author:** ![Richard\_Corlett](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/74df32/32.png) [@Richard\_Corlett](https://forum.xojo.com/u/Richard_Corlett)\
**Post date:** [October 23, 2016, 3:30pm UTC](https://forum.xojo.com/t/mixing-right-to-left-and-left-to-right-scripts/34082/4 "2016-10-23T15:30:04Z")

</div>

You’re most welcome, Carlo. Bidirectional text is great fun…

The square bracket is weakly directional so it will take its direction from its context, which means that it may jump to a different position in a bidirectional string. Maybe that is what you are seeing.

To prevent this, if for example you want to wrap the Hebrew in square brackets, then you can do something like this (although in this simple example it does actually display correctly without the direction mark):

```auto
myTextArea.Text="["+Chr(&h200E)+"???"+"]=House"
```

It is a matter of trial and error to see what works best for a particular pattern of RTL, LTR and weakly directional characters.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 6:31pm UTC](https://forum.xojo.com/t/mixing-right-to-left-and-left-to-right-scripts/34082/5 "2020-10-29T18:31:29Z")

</div>


