Bug 134193 - Support right-to-left math layout in Formula Editor
Summary: Support right-to-left math layout in Formula Editor
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Formula Editor (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: low enhancement
Assignee: ⁨خالد حسني⁩
URL:
Whiteboard: target:24.2.0 inReleaseNotes:24.2 tar...
Keywords:
Depends on:
Blocks: Formula-Editor RTL
  Show dependency treegraph
 
Reported: 2020-06-21 13:46 UTC by libre officer
Modified: 2024-10-18 13:46 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:


Attachments
Arabic formula test (5.56 KB, application/vnd.oasis.opendocument.formula)
2020-06-21 13:46 UTC, libre officer
Details
RTL problem (24.09 KB, image/png)
2020-06-21 13:47 UTC, libre officer
Details
RTL formula displayed vs. Expected (86.28 KB, image/jpeg)
2022-01-04 19:45 UTC, libre officer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description libre officer 2020-06-21 13:46:24 UTC
Description:
When I type a formula using Arabic, the command and the output is displayed as if it is a left-to-right writing system.

Steps to Reproduce:
1. Open attached file
2. Check out the formula (d = v × t)

Actual Results:
Command window:

المدة times السرعة = المسافة

Output window:

المدة × السرعة = المسافة


Expected Results:
Command window:

المسافة = السرعة times المدة

Output window:

المسافة = السرعة × المدة



Reproducible: Always


User Profile Reset: No



Additional Info:
Version: 7.0.0.0.beta1 (x64)
Build ID: 94f789cbb33335b4a511c319542c7bdc31ff3b3c
CPU threads: 4; OS: Windows 10.0 Build 17763; UI render: Skia/Raster; VCL: win
Locale: fr-CH (fr_FR); UI: en-GB
Calc: threaded


Note: left-to-right and right-to-left toolbar buttons are both disabled (see picture attachment)
Comment 1 libre officer 2020-06-21 13:46:49 UTC
Created attachment 162253 [details]
Arabic formula test
Comment 2 libre officer 2020-06-21 13:47:20 UTC
Created attachment 162254 [details]
RTL problem
Comment 3 V Stuart Foote 2020-06-21 17:15:45 UTC
Our native StarMath, and MathML in general, provide limited support for Presentation Markup of Arabic mathematical notation. Only the Content Markup needed for standard mathematical notation.

ICU libs Unicode bidi is functional for literal strings, but literal formulas as in OP simply need to be entered in line with text in the module in use.

Would require dev effort to refactor the sm Formula editor to provide logic needed to handle localized literal formula input and localized Presentation martup of formulas.

=-ref-=

https://www.w3.org/TR/2006/NOTE-arabic-math-20060131/
Comment 4 libre officer 2020-06-22 13:38:48 UTC
(In reply to V Stuart Foote from comment #3)
> Our native StarMath, and MathML in general, provide limited support for
> Presentation Markup of Arabic mathematical notation. Only the Content Markup
> needed for standard mathematical notation.
> 
> ICU libs Unicode bidi is functional for literal strings, but literal
> formulas as in OP simply need to be entered in line with text in the module
> in use.
> 
> Would require dev effort to refactor the sm Formula editor to provide logic
> needed to handle localized literal formula input and localized Presentation
> martup of formulas.
> 
> =-ref-=
> 
> https://www.w3.org/TR/2006/NOTE-arabic-math-20060131/

I see that the complex formula are difficult to reimplement, but at least for primary and secondary schools, you mostly need the ability to be able to render the unicode bidirectional characters (specially: LRE, RLE, PDF, RLM, LRM, etc.) in the output window.

At this moment, this is ignored in the output window, but supported in the command window (however, it should have the right/left alignment).
Comment 5 V Stuart Foote 2020-06-22 14:04:20 UTC
Yes, probably a valid enhancement that the Formula pane, and inline OLE provide more than simple bidi response to entered strings--and support minimal Presentation markup needs.

But IIUC that is not supported in any fashion by current sm command logic and node generators which were implemented to produce normalized mathematical formula content.
Comment 6 V Stuart Foote 2020-06-22 17:37:58 UTC
Due to poor direction handling of formula parsers, RTL formulas were specifically suppressed for OpenOffice.org i62413 in 2006.

https://opengrok.libreoffice.org/xref/core/starmath/source/edit.cxx?a=true&r=be53f326#87
Comment 7 libre officer 2020-06-24 10:57:43 UTC
(In reply to V Stuart Foote from comment #6)
> Due to poor direction handling of formula parsers, RTL formulas were
> specifically suppressed for OpenOffice.org i62413 in 2006.
> 
> https://opengrok.libreoffice.org/xref/core/starmath/source/edit.
> cxx?a=true&r=be53f326#87

2006 is considered antiquity era in 2020 !

However, I strongly disagree with Rüdiger Timm's `Even RTL languages don't use RTL for math` !! That's completely wrong, many countries still uses Arabic letters in math formula.

People forgot that Math formula could be written in other languages to teach kids in school basic geometry rules. For example, how can somebody type this 5th grade formula without inducing kids in error:


مساحة شبه المنحرف = (القاعدة الكبرى + القاعدة الصغرى) × الارتفاع ÷ 2

(  Trapezoid Area = (smaller side + bigger side) × height ÷ 2  )


Making exercises or lessons for kids in school would be impractical in LibreOffice :(


I hope in the future that at least the text direction control characters will be supported in math formula output..
Comment 8 V Stuart Foote 2020-06-24 13:51:30 UTC
(In reply to libre officer from comment #7)

> ... 
> 2006 is considered antiquity era in 2020 !
> 
> However, I strongly disagree with Rüdiger Timm's `Even RTL languages don't
> use RTL for math` !! That's completely wrong, many countries still uses
> Arabic letters in math formula.

Actually believe the commit author was Alan Yaniger, working with Thomas Lang.

https://bz.apache.org/ooo/attachment.cgi?id=39273&action=diff 

> 
> People forgot that Math formula could be written in other languages to teach
> kids in school basic geometry rules. For example, how can somebody type this
> 5th grade formula without inducing kids in error:
> 
> 
> مساحة شبه المنحرف = (القاعدة الكبرى + القاعدة الصغرى) × الارتفاع ÷ 2
> 
> (  Trapezoid Area = (smaller side + bigger side) × height ÷ 2  )
> 
> 
> Making exercises or lessons for kids in school would be impractical in
> LibreOffice :(
> 
> 
> I hope in the future that at least the text direction control characters
> will be supported in math formula output..


+1, and it could be as simple as enabling RTL for the sm edit shell to allow Command windows input RTL in addition to the Bidi handling--but more likely the sm node creation logic is coded only for standard mathematical formulas.

Getting reasonable RTL Presentation syntax may require sm logic specific to handle:

U+200E LEFT-TO-RIGHT MARK (LRM)
U+200F RIGHT-TO-LEFT-MARK (RLM)

U+202A LEFT-TO-RIGHT EMBEDDING (LRE)
U+202B RIGHT-TO-LEFT EMBEDDING (RLE)
U+202C POP DIRECTIONAL FORMATTING (PDF)
U+202D LEFT-TO-RIGHT OVERRIDE (LRO)
U+202E RIGHT-TO-LEFT OVERRIDE (RLO)

U+2066 LEFT-TO-RIGHT ISOLATE (LRI)
U+2067 RIGHT-TO-LEFT ISOLATE (RLI)
Comment 9 Eyal Rozenberg 2021-02-26 20:51:06 UTC
The text rendering here on bugzilla may be confusing us regarding the actual and expected results. Can you explain, in words, what order should the parts of the equation appear in? e.g. "From left to write, the words you should see are FOO, then BAR, then BAZ"

Also, are you complaining about what's in the output window, the edit window or both?
Comment 10 libre officer 2022-01-04 19:45:19 UTC
Created attachment 177313 [details]
RTL formula displayed vs. Expected
Comment 11 libre officer 2022-01-04 19:51:57 UTC
(In reply to Eyal Rozenberg from comment #9)
> The text rendering here on bugzilla may be confusing us regarding the actual
> and expected results. Can you explain, in words, what order should the parts
> of the equation appear in? e.g. "From left to write, the words you should
> see are FOO, then BAR, then BAZ"
> 
> Also, are you complaining about what's in the output window, the edit window
> or both?

Hello Eyal,

Please check the picture that I just uploaded, titled ` RTL formula displayed vs. Expected`.

The problem is that the formula in the text mode letters are ordered correctly, from right-to-left.

However, in the display window on top of it, you can see that the order of the letters is incorrect : This will be a problem if letters are words in a sentence, because reading it will be confusing.

In a short summary: the formula of the top should look exactly like the one in the bottom.
Comment 12 Commit Notification 2023-09-04 16:16:23 UTC
Khaled Hosny committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/5c5c71266ff14493975f20ff5807f31565a3f909

tdf#134193: Add the ability to set RTL math direction

It will be available in 24.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 13 Commit Notification 2023-09-04 16:17:25 UTC
Khaled Hosny committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/fb43c497f2cc71c988a967fa0126c27561f8c16d

tdf#134193: Support rendering math in RTL mode

It will be available in 24.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 14 Commit Notification 2023-09-04 16:18:28 UTC
Khaled Hosny committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/b6c30b3d35eb01205acf0271d0192921c60eb73b

tdf#134193: Allow setting math direction

It will be available in 24.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 15 Commit Notification 2023-09-04 16:18:30 UTC
Khaled Hosny committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/fe3098b4c4b5b8099e43279044db9ae7a1e0999d

tdf#134193: Fix RTL selection and cursor handling

It will be available in 24.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 16 Commit Notification 2023-09-04 16:19:33 UTC
Khaled Hosny committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/f80c2c70756e3620daed6675c8546caca4153d4b

tdf#134193: Fix inline editing with RTL direction

It will be available in 24.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 17 Stéphane Guillou (stragu) 2023-12-18 10:12:11 UTC
Thanks Khaled!

In release notes: https://wiki.documentfoundation.org/index.php?title=ReleaseNotes%2F24.2&type=revision&diff=715802&oldid=715801

A screenshot and a better description would be welcome!
Comment 18 Commit Notification 2024-06-10 07:57:06 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/71e905b62b02f28e6eca728f763a845509bf5a1a

Related tdf#134193: declare right-to-left in Math.xcs

It will be available in 24.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.