Difference between revisions of "RTL"

From Wiki
Jump to navigation Jump to search
(added a list of TODOs)
Line 24: Line 24:
 
\stoptext
 
\stoptext
 
</context>
 
</context>
 +
 +
=== LTR paragraph in RTL document ===
 +
In addition to short LTR text pieces, sometimes one needs an LTR paragraph in a mainly RTL document.  Using {{code|\righttoleft}} at the beginning of a paragraph (i.e., in vertical mode) achieves this.  This command needs to be placed inside a group to limit its scope.  I use the following.
 +
 +
<texcode>
 +
\startstopLTR [before={\begingroup\lefttoright},after=\endgroup]
 +
</texcode>
 +
 +
This can be used either as {{code|\LTR{some English text}}} for short pieces (for example, inside an RTL paragraph) or as a start/stop construct to produce LTR paragraphs.
  
 
== TODO ==
 
== TODO ==

Revision as of 12:27, 28 April 2016

Here we collect several tips and tricks for dealing with right-to-left (RTL) texts as well as BiDi (bidirectional) texts. The large number of hooks in different commands makes it possible to use CONTEXT's support for such documents. However, there are limitations and/or bugs, as well. Everything here is tested in MkIV and we recommend that you try one of the most recent versions since certain bugs are fixed and features are added only in the beta.

Basics

Use \setupalign to change the text direction to RTL. This command sets the page, paragraph and text directions.

\setupalign[r2l]
\starttext
\input knuth
\stoptext

This produces:

BiDi text

To work with documents with mixed RTL and LTR text, we need the bidi algorithm implemented in \setupdirections. Since numbers are LTR elements in Arabic, Persian and other RTL languages, we almost always need this.

% mode=mkiv
\usemodule[simplefonts]
\setmainfont[ALM Fixed][features=arabic,range=arabic]
\setcharacterstripping[1]  % don't show ZWNJ, etc.
\setupdirections[bidi=global,method=one]
\setupalign[r2l]
\starttext
 این نمونه ساده از متنی فارسی است که در \CONTEXT\ تهیه شده است.
توجه کنید که عدد ۱۰۰۰ به صورت صحیح نمایش داده می‌شود.
\stoptext

This produces:

internal error: copy error zRVJNq/cropped.pdf

LTR paragraph in RTL document

In addition to short LTR text pieces, sometimes one needs an LTR paragraph in a mainly RTL document. Using \righttoleft at the beginning of a paragraph (i.e., in vertical mode) achieves this. This command needs to be placed inside a group to limit its scope. I use the following.

\startstopLTR [before={\begingroup\lefttoright},after=\endgroup]

This can be used either as \LTR{some English text} for short pieces (for example, inside an RTL paragraph) or as a start/stop construct to produce LTR paragraphs.

TODO

Here are some of the things to be added:

  • LTR paragraphs inside (mostly) RTL document.
  • Change numbers to Hindi numerals
    • Handling the LTR/RTL issues
    • Math mode Hindi digits
  • Footnotes: rule, bidi
  • RTL tables
  • RTL columns
  • Section/float numbers
  • Enumerations
  • Descriptions
  • Margin notes
  • Dates and time