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

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.

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(&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:


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.

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.

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):


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