# [XeTeX] Numerals in Right-to-Left

Jonathan Kew jonathan_kew at sil.org
Wed Nov 17 15:32:20 CET 2004

On 17 Nov 2004, at 6:33 am, Bruno Voisin wrote:

> I think the answer comes to what Jonathan has mentioned in his
> preceding message:
>
>> Le 15 nov. 04, à 15:07, Jonathan Kew a écrit :
>>
>>> Note that "auto-generated" numbers from TeX macros (like \pageno,
>>> for example) will be the Latin digits 0030..0039, and this may be a
>>> problem when working with non-Latin fonts. It's possible to wrap
>>> such things in additional macro code to replace the Latin digits
>>> with the appropriate codes for a different script, but this requires
>>> extra TeX macro programming.
>
> This is exactly the situation you are faced with: \folio is defined in
> plain.tex based on the counter \pageno, and the primitive \number
> which return the value (a decimal number) of this counter:
>
> \def\folio{\ifnum\pageno<\z@ \romannumeral-\pageno \else\number\pageno
> \fi}
>
> So I think you can't avoid that bit of extra programming.

I suppose people might like an example of how this could be done.
Here's a possible approach:

% - - - - - convert numbers to different digit sets - - - - -
\font\x="Geeza Pro" at 12pt \x

\def\translitnumber#1#2{%
% #1 -> the number to transliterate
% #2 -> unicode value of "zero" in the desired digit set
\begingroup
\count255=#2
\uccode\1=\count255 \advance\count255 by 1
\uccode\3=\count255 \advance\count255 by 1
\uccode\5=\count255 \advance\count255 by 1
\uccode\7=\count255 \advance\count255 by 1
\uccode\9=\count255
\edef\thenumber{#1}%
\expandafter\uppercase\expandafter{\thenumber}%
\endgroup}

\def\arabicnumber#1{\translitnumber{#1}{"0660}}
\def\persiannumber#1{\translitnumber{#1}{"06F0}}

\pageno=12345

% with Geeza Pro, the number doesn't appear here (no support for Latin
numerals)
{\rm Default:} \folio

% now try the page number in Arabic and Persian digit sets
{\rm Arabic:} \arabicnumber{\folio}

{\rm Persian:} \persiannumber{\folio}

\end
% - - - - - end of example - - - - -

HTH,

Jonathan