Page MenuHomePhabricator

Add Support for Farsi Digits and Scripts in LaTeX Mathematical Formulae
Closed, ResolvedPublic

Description

Author: vahid.ghasemian

Description:
I'm one of the users of Farsi Wikipedia. I've been wondering to add
thesupporting of Farsi Digits and Scripts in Math Extension of MediaWiki (in
LaTeX mode).

Arabi, is a good package under LaTeX that supports Arabic or Persian
digits and scripts. this pacakge is available in MiKTeX 2.5 and newer pacakges
of LaTeX. For more information about this package, please read these links:

http://www.mail-archive.com/ctan-ann@dante.de/msg00778.html

http://www.tug.org/texlive/Contents/live/texmf-dist/doc/latex/arabi/user_guide.pdf

For testing a sample file, please go to

http://sciencesoft.at/index.jsp?link=latex&js=0&lang=en

and copy-paste this code to the blank Area and click the "Start LaTeX" button:

% Start of the Code
\documentclass{article}
\usepackage[T1,LFE,LAE]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[farsi,arabic,english]{babel}
\TOCLanguage{farsi}

\makeatletter
%due to a bug in ARABI in which the command \textRL is not
%changed to write Farsi though the main TOC language is Farsi.
\def\textRL#1{{\expandafter\@farsi at R{#1}}}

%due to a bug in ARABI in which the quotaion marks are not
%assigned to their counterpart font-glyphs in lfeenc.def
\DeclareTextSymbol{\guillemotright}{LFE}{62}
\DeclareTextSymbol{\guillemotleft}{LFE}{60}
\makeatother

\begin{document}
\selectlanguage{farsi}
%a paragraph in Farsi
%to write a number use \I{NUMBER}
%to write some phrases in English use \textLR{English phrase}
سلام. بالاخره یک سرور \textLR{On Line} پیدا شد که از فارسی نویسی در
\textLR{ \LaTeX\ } حمایت کند!

$$\sum^{+ \infty}_{i=1} \frac{1}{i^2} = \frac{\pi^2}{6}$$

\end{document}
% End of the code

by the help of this sample code, is it possible for you to add
supporting farsi digits and scripts to the MediaWiki Math Extension in
LaTeX mode to use it in Farsi Wikipedia?

Best Regards


Version: unspecified
Severity: enhancement

Details

Reference
bz30463

Related Objects

Event Timeline

bzimport raised the priority of this task from to Normal.Nov 21 2014, 11:47 PM
bzimport added projects: Math, I18n.
bzimport set Reference to bz30463.
bzimport created this task.Aug 19 2011, 1:57 PM

vgssbs66 wrote:

Please Edit texutils.ml as follows and define a farsi mode to choose by farsi wikipedia users:

Index: texutil.ml

  • texutil.ml (revision 115660)

+++ texutil.ml (working copy)
@@ -48,6 +48,7 @@
let modules_color = ref false
let modules_teubner = ref false
let modules_euro = ref false
+let modules_farsi = ref false

(* wrappers to easily set / reset module properties *)
let tex_use_ams () = modules_ams := true
@@ -55,13 +56,15 @@
let tex_use_color () = modules_color := true
let tex_use_teubner () = modules_teubner := true
let tex_use_euro () = modules_euro := true
-let tex_mod_reset () = (
+let tex_use_farsi () = modules_farsi := true
+ let tex_mod_reset () = (

modules_ams := false;
modules_nonascii := false;
modules_encoding := UTF8;
modules_color := false;
modules_teubner := false;
modules_euro := false;

+ modules_farsi := false;

)

(* Return TeX fragment for one of the encodings in (UTF8,LATIN1,LATIN2) *)
@@ -77,8 +80,27 @@

(if !modules_color then "\\usepackage[dvips,usenames]{color}\n" else "") ^
(if !modules_teubner then "\\usepackage[greek]{babel}\n\\usepackage{teubner}\n" else "") ^
(if !modules_euro then "\\usepackage{eurosym}\n" else "") ^
  • "\\usepackage{cancel}\n\\pagestyle{empty}\n\\begin{document}\n$$\n"

+ (if !modules_farsi then
+ "\\usepackage[T1,LFE,LAE]{fontenc}
+\\usepackage[utf8]{inputenc}
+\\usepackage[farsi,arabic,english]{babel}
+\\TOCLanguage{farsi}

+\\makeatletter
+%due to a bug in ARABI in which the command \\textRL is not
+%changed to write Farsi though the main TOC language is Farsi.
+\\def\\textRL#1{{\\expandafter\\@farsi@R{#1}}}
+
+%due to a bug in ARABI in which the quotaion marks are not
+%assigned to their counterpart font-glyphs in lfeenc.def
+\\DeclareTextSymbol{\\guillemotright}{LFE}{62}
+\\DeclareTextSymbol{\\guillemotleft}{LFE}{60}
+\\makeatother"
+ else "") ^
+ "\\usepackage{cancel}\n\\pagestyle{empty}\n\\begin{document}\n" ^
+ (if !modules_farsi then "\\selectlanguage{farsi}\n" else "") ^
+ "$$\n"
+
(* TeX fragment appended after the content *)
let get_footer () = "\n$$\n\\end{document}\n"

@@ -748,4 +770,5 @@

| "\\color"            -> (tex_use_color (); LITERAL (TEX_ONLY "\\color"))
| "\\pagecolor"        -> (tex_use_color (); LITERAL (TEX_ONLY "\\pagecolor"))
| "\\definecolor"      -> (tex_use_color (); LITERAL (TEX_ONLY "\\definecolor"))

+ | "\\farsi" -> (tex_use_farsi (); LITERAL (TEX_ONLY "\\selectlanguage{farsi}")) (* Redundant but we need to make the hash different *)

| s                    -> raise (Illegal_tex_function s)

would you please test this code to see whether it works or not?

Best Regards

Vahid Ghasemian

Hi Vahid,

you are very welcome to use Developer access

https://www.mediawiki.org/wiki/Developer_access

to submit your patch from comment 1 as a Git branch directly into Gerrit:

https://www.mediawiki.org/wiki/Git/Tutorial

Putting your branch in Git makes it easier to review it quickly.
Thanks again! We appreciate your contribution.

Vahid:

Note that there is a MathJax option to replace PNG images, but AFAIK MathJax does not support the farsi command either. I guess \I and \textLR could be easy implement. I don't see these commands in the $$ of your example. Are the letters/digits supposed to be translated automatically, when one uses \selectlanguage{farsi}? Also, Farsi is written left to right, right?

Huji added a comment.Feb 13 2013, 2:32 PM

Farsi is written right to left, but digits and formulas are written left to right in farsi.

fredw added a comment.Feb 13 2013, 2:41 PM

Thanks, yes I meant the formulas are written left to right (MathJax does not support MathML "overall directionality of formulas" at the moment, so I wanted to be sure that this was not needed for this bug).

vahid.ghasemian wrote:

(In reply to comment #3)

Vahid:
Note that there is a MathJax option to replace PNG images, but AFAIK MathJax
does not support the farsi command either. I guess \I and \textLR could be
easy
implement. I don't see these commands in the $$ of your example. Are the
letters/digits supposed to be translated automatically, when one uses
\selectlanguage{farsi}? Also, Farsi is written left to right, right?

Dear Fredric: I don't know MathJax programming, but I put an example of code to run Arabi package in LaTeX, as I said before, it seems that by putting theses preamble LaTeX codes in appropriate places of texutils.ml, we can load Arabi package to use it's capabilities to write LaTeX formulas with Arabic digits.

Related URL: https://gerrit.wikimedia.org/r/58302 (Gerrit Change I960e39353f814d1f283c12f7161f30c5c3dac9a4)

physik wrote:

I would recommend to use a construct like
<math>
a^\text{ه از فارسی نوی}
</math>
this will work for future versions of the math extension.
The text is then passed as normal text to the browser without to be modified by the math extension.
Is that acceptable.

physik wrote:

*** This bug has been marked as a duplicate of bug 48032 ***

Change 58302 abandoned by Jforrester:
Added Support for Farsi Digits and Scripts in LaTeX Mathematical Formulae( bug 30463 )

Reason:
Untouched in over a year. Please re-instate if you want to work on this some more.

https://gerrit.wikimedia.org/r/58302