Bidirectional text


A bidirectional text contains two text directionalities, right-to-left and left-to-right. It generally involves text containing different types of alphabets, but may also refer to boustrophedon, which is changing text direction in each row.
Some writing systems including the Arabic and Hebrew scripts or derived systems such as the Persian, Urdu, and Yiddish scripts, are written in a form known as right-to-left, in which writing begins at the right-hand side of a page and concludes at the left-hand side. This is different from the left-to-right direction used by the dominant Latin script. When LTR text is mixed with RTL in the same paragraph, each type of text is written in its own direction, which is known as bidirectional text. This can get rather complex when multiple levels of quotation are used.
Many computer programs fail to display bidirectional text correctly. For example, the Hebrew name Sarah is spelled: sin , then resh , and finally heh .
Note: Some web browsers may display the Hebrew text in this article in the opposite direction.

Bidirectional script support

Bidirectional script support is the capability of a computer system to correctly display bidirectional text. The term is often shortened to "BiDi" or "bidi".
Early computer installations were designed only to support a single writing system, typically for left-to-right scripts based on the Latin alphabet only. Adding new character sets and character encodings enabled a number of other left-to-right scripts to be supported, but did not easily support right-to-left scripts such as Arabic or Hebrew, and mixing the two was not practical. Right-to-left scripts were introduced through encodings like ISO/IEC 8859-6 and ISO/IEC 8859-8, storing the letters in writing and reading order. It is possible to simply flip the left-to-right display order to a right-to-left display order, but doing this sacrifices the ability to correctly display left-to-right scripts. With bidirectional script support, it is possible to mix characters from different scripts on the same page, regardless of writing direction.
In particular, the Unicode standard provides foundations for complete BiDi support, with detailed rules as to how mixtures of left-to-right and right-to-left scripts are to be encoded and displayed.

Unicode bidi support

The Unicode standard calls for characters to be ordered 'logically', i.e. in the sequence they are intended to be interpreted, as opposed to 'visually', the sequence they appear. This distinction is relevant for bidi support because at any bidi transition, the visual presentation ceases to be the 'logical' one. Thus, in order to offer bidi support, Unicode prescribes an algorithm for how to convert the logical sequence of characters into the correct visual presentation. For this purpose, the Unicode encoding standard divides all its characters into one of four types: 'strong', 'weak', 'neutral', and 'explicit formatting'.

Strong characters

Strong characters are those with a definite direction. Examples of this type of character include most alphabetic characters, syllabic characters, Han ideographs, non-European or non-Arabic digits, and punctuation characters that are specific to only those scripts.

Weak characters

Weak characters are those with vague direction. Examples of this type of character include European digits, Eastern Arabic-Indic digits, arithmetic symbols, and currency symbols.

Numbers

Unless a directional override is present numbers are always encoded big-endian, and the numerals rendered LTR. The weak directionality only applies to the placement of the number in its entirety.

Neutral characters

Neutral characters have direction indeterminable without context. Examples include paragraph separators, tabs, and most other whitespace characters. Punctuation symbols that are common to many scripts, such as the colon, comma, full-stop, and the no-break-space also fall within this category.

Explicit formatting

Explicit formatting characters, also referred to as "directional formatting characters", are special Unicode sequences that direct the algorithm to modify its default behavior. These characters are subdivided into "marks", "embeddings", "isolates", and "overrides". Their effects continue until the occurrence of either a paragraph separator, or a "pop" character.

Marks

If a "weak" character is followed by another "weak" character, the algorithm will look at the first neighbouring "strong" character. Sometimes this leads to unintentional display errors. These errors are corrected or prevented with "pseudo-strong" characters. Such Unicode control characters are called marks. The mark is to be inserted into a location to make an enclosed weak character inherit its writing direction.
For example, to correctly display the for an English name brand in an Arabic passage, an LRM mark is inserted after the trademark symbol if the symbol is not followed by LTR text. If the LRM mark is not added, the weak character ™ will be neighbored by a strong LTR character and a strong RTL character. Hence, in an RTL context, it will be considered to be RTL, and displayed in an incorrect order.

Embeddings

The "embedding" directional formatting characters are the classical Unicode method of explicit formatting, and as of Unicode 6.3, are being discouraged in favor of "isolates". An "embedding" signals that a piece of text is to be treated as directionally distinct. The text within the scope of the embedding formatting characters is not independent of the surrounding text. Also, characters within an embedding can affect the ordering of characters outside. Unicode 6.3 recognized that directional embeddings usually have too strong an effect on their surroundings and are thus unnecessarily difficult to use.

Isolates

The "isolate" directional formatting characters signal that a piece of text is to be treated as directionally isolated from its surroundings. As of Unicode 6.3, these are the formatting characters that are being encouraged in new documents – once target platforms are known to support them. These formatting characters were introduced after it became apparent that directional embeddings usually have too strong an effect on their surroundings and are thus unnecessarily difficult to use. Unlike the legacy 'embedding' directional formatting characters, 'isolate' characters have no effect on the ordering of the text outside their scope. Isolates can be nested, and may be placed within embeddings and overrides.

Overrides

The "override" directional formatting characters allow for special cases, such as for part numbers, and are recommended to be avoided wherever possible. As is true of the other directional formatting characters, "overrides" can be nested one inside another, and in embeddings and isolates.

Pops

The "pop" directional formatting characters terminate the scope of the most recent "embedding", "override", or "isolate".

Runs

In the algorithm, each sequence of concatenated strong characters is called a "run". A "weak" character that is located between two "strong" characters with the same orientation will inherit their orientation. A "weak" character that is located between two "strong" characters with a different writing direction, will inherit the main context's writing direction.

Table of possible BiDi character types

Scripts using bidirectional text

Egyptian hieroglyphs

can be written bidirectionally, where the signs had a distinct "head" that faced the beginning of a line and "tail" that faced the end.

Chinese characters and other CJK scripts

can be written in either direction as well as vertically, especially in signs, but the orientation of the individual characters is never changed. This can often be seen on tour buses in China, where the company name customarily runs from the front of the vehicle to its rear — that is, from right to left on the right side of the bus, and from left to right on the left side of the bus. English texts on the right side of the vehicle are also quite commonly written in reverse order.
Likewise, other CJK scripts made up of the same square characters, such as the Japanese writing system and Korean writing system, can also be written in any direction, although left-to-right, top-to-bottom and, right-to-left are most common.

Boustrophedon

is a writing style found in ancient Greek inscriptions and in Hungarian runes. This method of writing alternates direction, and usually reverses the individual characters, on each successive line.

Moon type

is an embossed adaptation of the Latin alphabet invented as a tactile alphabet for the blind.
Initially the text changed direction at the end of the lines.
Special embossed lines connected the end of a line and the beginning of the next.
Around 1990, it changed to a left-to-right orientation.