Text Directionality Draft

This is a preliminary draft of proposed sections for the TEI Guidelines, created by the Text Directionality Workgroup. Please see the associated Text Directionality Draft Questions document for some issues to think about before and after reading this draft, and feel free to respond there and to add new questions. There is also a talk page for more informal discussion.

Writing Modes
The scripts used for writing human languages vary not only in the glyphs they use, but also in the way (or ways) that those glyphs are arranged on the writing surface. For the majority of modern languages, writing is arranged as a series of lines which are to be read from top to bottom. Within each line, individual characters are frequently presented from left to right (English, Russian, Greek), but there are also several widely-used scripts which run right-to-left (Arabic, Hebrew). Writing in which the lines of glyphs are presented vertically and read from right to left is also often encountered, notably in older East Asian scripts (Sinitic characters, Japanese Kana, Korean Hangul, Vietnamese chữ nôm). In many cases, a language normally uses the same writing mode (that is, the orientation of individual glyphs within a line and reading order of the lines), but there are exceptions, such as Japanese or modern Chinese, in which the same language may appear in different modes, for example either vertically or horizontally. There are also comparatively rare cases of ancient scripts which are characteristically written with lines running left to right, each line being read top to bottom (Ancient Uighur, classical Mongolian and Manchu), or even (in the case of Ogham) from bottom to top.

When different languages are combined, it is probable that different writing modes will be needed: for example, in Hebrew text, running right to left, sequences of Latin digits still run left to right. When different writing modes are available for the same language, it may be that different glyphs will be preferred when the script is used in different modes. For example, when Japanese is written horizontally, the Unicode character U+3001, the "ideographic comma", is used in preference to Unicode character U+FE11, the vertical mode comma. This ensures that the comma appears in the correct position relative to the surrounding glyphs. Even for scripts which are usually written in exactly the same way, different writing modes may be encountered in particular contexts, for example when a language using Roman script is embedded within vertically organized Chinese text, it may sometimes be displayed in vertical and sometimes in horizontal writing mode. And the writing mode may also vary in response to layout constraints such as those imposed by a complex table, where column or row labels may be written vertically or diagonally to make the most effective use of available space, just as it may vary in response to the size and shape of the carrier in the case of a monumental inscription.

For many, perhaps most, TEI documents there may be no need to encode the writing mode explicitly, even in so-called "mixed mode" texts containing passages written in languages which use different writing modes. Modern printed texts in most European languages, for instance, may be expected to use left-to-right/top-to-bottom directionality; while Arabic or Hebrew texts are expected to run right-to-left/top-to-bottom. In a TEI document, language and script are explicitly stated in the markup using the attribute xml:lang (reference); this indication will imply a particular default writing mode. Even where this attribute is not used, passages in different scripts will use different Unicode characters, and will thus imply a particular default writing mode. Nevertheless, the W3C i18n Working Group recommends against reliance on language tags for encoding directionality information [per Richard Ishida, W3C; I need to find a formal reference for this] [if we cannot find substantial evidence to support this recommendation we should imho drop it. LB]).

Consider the case of an English text containing a few Arabic words :

A correct TEI encoding might read as follows:

We might assume that it is the presence of the xml:lang attribute with value "ar" that causes processing software to display the Arabic from right to left, but in fact, this is not the case. T he order in which the Arabic characters appear when rendered would be the same, even if the markup were not present:

This is because Arabic glyphs are always displayed right to left, even when they appear within a left-to-right English sentence. Like most other codepoints in the Unicode standard, they have a specific directionality setting which helps any rendering software determine how they should be ordered. The Latin glyph "a" has a strong left-to-right bidirectionality setting, as do the digits 0 to 9; the Hebrew א (alef) is strongly right-to-left. Of course, some glyphs (common punctuation marks such as the period or comma for example) have weak or neutral settings because they may appear in several contexts.

The Unicode Bidirectional Algorithm (http://www.unicode.org/reports/tr9/) defines a number of rules enabling software to render sequences of characters which have differing directionality properties in a predictable and reliable way, using only those properties. . It should be remembered however that individual sequences of characters are always stored in a file in the order in which they should be read, irrespective of the order in which the characters making up a sequence should be displayed or rendered. For example, in a RTL language such as Hebrew, the first character in a file will be that which is displayed at the rightmost end of the first line of text.

An encoder wishing to document or to control the order in which sequences of characters in a TEI document are displayed will usually do so by segmenting the text into sequences presented in the desired order and specifying an appropriate language code for each. In situations where this approach may result in ambiguity or lack of precision, or if the encoder wishes to record directional information explicitly in their encoding, we recommend using the global @style attribute to supply detail about the writing mode applicable to the content of any element. The @style attribute (discussed in section [ref to #STGAre here] ) permits use of any formatting language; for these purposes however, we recommend use of CSS, which now includes a Writing Modes module which permits direct specification of a number of useful properties associated with writing modes, notably :

The global TEI @style attribute applies to the element on which it is specified (and in most cases, its descendants). Rather than specify it on every element, it will often be more efficient, to express sets of commonly-used styling rules as elements in the  and then point to them using the global @rendition attribute (see further the discussion in [ref to #HD57-1 here]). Although the CSS specifications are mainly used to provide instructions for software when rendering a digital text, they also provide a useful means of describing the visual properties of a pre-existing document in a formal and standardised way.

In the next section, we present some examples of how CSS can be used to describe a variety of writing modes. A full description of the appearance of a document will probably include many other properties of course.

Horizontal directionality
Returning to our previous simple example

we could use the  property to make directionality explicit:

The use of the  property to record the observed directionality of the text is unambiguous, even though it is (as we noted above) superfluous.

Mixed directionality is very common in languages such as Arabic and Hebrew, particularly when numbers (which are always given LTR) or phrases from other LTR languages are embedded, and it is quite unusual though not impossible for ambiguities to arise.

[Would it be helpful to have another example presenting ambiguity arising out of the use of a g element at the end of a text run?]

Vertical writing modes
As we noted above, there are many scripts and languages which are written vertically (mostly top-to-bottom, but with a few unusual examples running bottom-to-top). Another CSS property, called the writing mode, can be used to specify this:

The values for this property have two components: "horizontal" or "vertical" specifies the inline writing direction, while the second component specifies the direction in which lines in a block, and blocks in a sequence are arranged: from top to bottom (as in most European languages, in which lines and paragraphs are arranged from top to bottom on a page), from right to left (as in the case of some East Asian languages such as Japanese, which we will see below), or left-to-right (e.g. Mongolian). Both Chinese and Japanese can be written in different writing modes, and the ability to encode which has been used in a given document is therefore very useful.

The following example shows three versions of the same poem, first in Japanese, written top to bottom; next in Romaji (Japanese in Latin script), and finally in an English translation.



We might encode this as follows:

Note: for the sake of simplicity, the indenting of lines in the vertical Japanese and the central alignment of the other components have been ignored in this encoding, since this section focuses on language and writing mode issues. The Japanese transcription has, which is required because Japanese may be written either in this mode or horizontally. The transcription in Romaji has  (Japanese written in Latin script) and has a horizontal writing mode; this may seem superfluous, but vertically-written romaji is not unknown.

&#160;

Vertical text with embedded horizontal text
When Japanese is written vertically, the glyph orientation remains the same as when it is written horizontally. In other words, glyphs are not rotated (although as noted above some different glyphs may be used for some characters the two orientations; punctuation for instance needs to be positioned differently in vertical versus horizontal text). However, it is very common for languages written vertically to have embedded runs of text from languages normally written horizontally. This raises the issue of the orientation of the glyphs from the horizontal language. Are they written upright, as they would normally appear in horizontal text runs, or are they rotated? Consider this fragment from a Japanese article about the Indonesian language, which takes the form of a glossary list:



This might be transcribed as follows:

The rule  gives the expected orientation: "In vertical writing modes, characters from horizontal-only scripts are set sideways, i.e. 90° clockwise from their standard orientation in horizontal text. Characters from vertical scripts are set with their intrinsic orientation" (CSS Writing Modes). In actual fact, the default value for  is "mixed", so this rule is not strictly required, but if the Indonesian glyphs (which are roman characters) had been set vertically, like this:

&#160;



then the encoding would have to be explicit, and we could capture the orientation with.

&#160;

Vertical orientation in horizontal scripts
It is not unusual to see text from horizontal languages written vertically even where it is not embedded in a text run from a vertically-written script. This example is a fragment from a table of information about agricultural development on Vancouver Island, written in 1855:



Four subheading cells in this fragment contain English text, written vertically, bottom-to-top, to conserve space on the page. This is not a "native orientation" for English; readers would not find it easy to read this text, and might be inclined to rotate the page in order to read it in a more natural way. To describe this sort of phenomenon, we can use the text-orientation property again:

For full details on this property, we refer the reader to the CSS Writing Modes specification. For the present example, we will make use only of the "sideways-left" value, which "causes text to be set as if in a horizontal layout, but rotated 90° counter-clockwise." We might encode one of the four cells containing vertical text like this:

The  captures the fact that the script is written vertically, and its line/block flow is from left to right (so "of" is to the right of "Cash value"), while the   value encodes the orientation (rotated 90° counter-clockwise). We might also add  to the style, to express the fact that the text is centrally-aligned; alignment properties are mapped relative to the line flow, so the word "of" is visibly centred relative to the physical top and bottom of the box, which are the left and right from the point of view of the line flow.

Bottom-to-top writing
There are a very small number of scripts which appear to be written bottom-to-top; perhaps the most well-known is Ogham, an alphabet used mainly to write Archaic Irish. The CSS Writing Modes specification does not explicitly provide for the distinction between top-to-bottom and bottom-to-top in vertically-written scripts; it is argued that all instances of bottom-to-top scripts are actually left-to-right horizontal scripts, oriented vertically because of the constraints of the medium on which they are inscribed (as in the case of Ogham inscriptions on tombstones). In other words, the case of scripts like this is analogous to the vertical English text-runs in the table cells in the example above, and can be handled in exactly the same manner.

Summary
In this section, we have presented one approach to encoding text directionality features in TEI files, using the properties and values from the CSS Writing Modes module, encoded in the global TEI @style attribute (or in the TEI  element and linked with the @rendition attribute). For most texts, it will not be necessary to encode any information about text directionality, either because it follows unambiguously from  values, or because it can be expected to be handled unequivocally by the Unicode Bidi Algorithm. Where it is important to encode text directionality, we believe that most phenomena can be well described through the use of the CSS Writing Modes features; of those which cannot, other approaches based on the CSS Transforms module are presented below.

Rotation
In what follows, we examine a range of textual phenomena which in some ways appear very similar to those examined above, and even overlap with them. We can categorize these as text transformation features, and suggest some strategies for encoding them based on the properties detailed in the CSS Transforms specification. The CSS Transforms module provides a complex array of properties, values and functions which can be used to rotate, skew, translate and otherwise transform textual and graphical objects. We can borrow this vocabulary in order to describe textual phenomena in a precise manner.

We begin with a simple example of a rotational transform:



Here a block of text has been rotated around its z-axis. This is clearly not a "writing mode"; the writing mode for this text is horizontal, left to right. Furthermore, even if we wished to treat this as a writing mode, we could not do so, because there is no way to use writing modes properties to describe an text orientation which is angled at 45 degrees; no human languages are consistently written in this orientation. It is more appropriate to treat this as a rotational transformation. We can do this using two properties:  and. (Both of these properties have quite complex value sets, and we will not look at all of them here. See the specification for full details.)

The  property takes as its value one or more of the transform functions, one of which is the function  :

Any rotation must take place clockwise around an axis positioned relative to the element being rotated, and the  property can be used to specify the pivot point. By default, the value of  is "50% 50%", the point at the centre of the element, but these values can be changed to reflect rotation around a different origin point. (The TEI zone element also bears an attribute @rotate which can specify rotation in degrees around the z-axis, but it is not available for any other element.)

An element may also be rotated about either of its other axes. For example, this shows rotation around the Y (vertical) axis:



These are obviously trivial examples, but similar features do appear in historical texts. George Herbert's The Temple includes two stanzas headed "Easter Wings" which are both normally printed in a rotated form so that they represent a pair of wings:



This could be encoded thus:

but we might also argue that this is in fact a vertical writing mode, and express it with.

&#160;

Boustrophedon
We may also use rotation as a method of handling a true writing mode which is not covered by the CSS Writing Modes: boustrophedon. This is a writing mode common in inscriptions in Latin, Greek and other languages, in which alternate lines run from left to right and from right to left; its name derives from the path of an ox pulling a plough. Right-to-left lines in boustrophedon have another unexpected feature: their glyphs are reversed, so that these lines appear as "mirror writing". This example shows a transcription of a Greek inscription at Dodona:



This might be transcribed as follows (ignoring word boundaries for the moment):

The 180-degree rotation around the Y (vertical) axis here gives us exactly the effect of the RTL line in boustrophedon; the order of glyphs is reversed, and so is their individual orientation (in fact, we see them "from the back", as it were). elements have been used here because these are clearly not "lines" in the sense of poetic lines; the text is continuous prose, and linebreaks are incidental.

There are obviously some unsatisfactory aspects of this manner of encoding boustrophedon. In the inscription above, some words run across linebreaks, so if we wished to tag both words and the right-to-left phenomena, one hierarchy would have to be privileged over the other. By using a transform function rather than a writing mode property, we are apparently suggesting that boustrophedon is not in fact a writing mode, whereas it clearly is. But the CSS Writing Modes specification does not provide support for boustrophedon, because it is a rather obscure historical phenomenon; using a rotational transform is one practical alternative.

&#160;

Caveats
The effect and behaviour of CSS Transforms properties and values according to the specification are highly dependent on the computed Visual formatting model of an HTML document. TEI currently does not have an explicit processing or formatting model. That is, it is by no means clear whether any given TEI element should be interpreted, for instance, as a block-level or inline-level element; for many elements we may think we can assume block-level (, "anonymous block") or inline-level ( , "word") from the semantics, but even this is risky. As long as the properties and values from the CSS Transforms module are used as a convenient, well-specified descriptive language to capture features of a text, without any expectation of using them directly and reliably for rendering, this is not problematic; we are simply borrowing a useful vocabulary from an external source, and benefiting from the clarity of definition provided by the specification. However, if there is any expectation of using this information to render a text in a predictable and accurate way, it will be essential to provide enough styling information throughout the document hierarchy to resolve all ambiguities with regard to size, positioning, block status, etc. before any element undergoes a transform operation.