RIGHT-TO-LEFT RENDERING WITH TROFF

TEXT DIRECTION IN TROFF

The dir branches of neatroff and my linux port of plan9 troff support right-to-left text rendering. In this page, I briefly describe how to use it.

The following troff commands and requests specify text direction:

So for instance one can write:

.<<
This is a paragraph in a right-to-left language
with some embedded \>left-to-right words\< in it.
.>>

The value of number registers \&.td and \&.cd indicate the current text and temporary directions respectively; zero means left-to-right and one means right-to-left.

Note that this patch does not implement the bidi algorithm inside troff itself. One can write a preprocessor to insert \> and \< requests where necessary. However, I think indicating the change in text direction with these requests explicitly is both cleaner and more predictable.

Note that many of the default ms macros won't work for r2l text. You can change ms macro package for that or write your own little macro package (I prefer the latter).

FARSI AND ARABIC

Typesetting Farsi and Arabic is a bit more involved. The characters need to be shaped too (most letters have distinct shapes based on their location in a word, something like ligatures). I wrote a preprocessor called shape for that, which can be used as a preprocessor of troff:

# cat src.tr | shape | [other preprocessors |] neatroff | neatpost

For creating troff font description files, you can use mktrfn. For Farsi fonts without Farsi special glyphs, like Farsi Yeh, you can pipe the output of mktrfn to this script.