mathlive icon indicating copy to clipboard operation
mathlive copied to clipboard

[Feature] RTL support

Open alexprey opened this issue 5 years ago • 4 comments

I'm want to use this library for arabic languages and it requires to use RTL text direction, but I can't find anything related with this in documentation. That is not supported? If that is a true my second question is do you have any plans to support that?

alexprey avatar Oct 27 '20 10:10 alexprey

RTL is not currently supported. Some of the things that would need to be addressed include:

  • adding configuration options to define the default text direction
  • implementation of a Bidi algorithm, including appropriate glyph shaping (ligatures) (this might be tricky because of the way the caret is implemented)
  • support for split caret (when on the boundary of a RTL/LTR area)
  • support of \RTL and \LTR commands
  • support for mirrored symbols (e.g. \sqrt, \sum, \int, etc...)
  • support for Arabic-Indic and Eastern-Arabic-Indic digits
  • support for different style of mathematical notations, including Maghreb (which flips symbols), Moroccan (which doesn't flip symbols), Machrek (which uses different symbols for \sum, etc...), Persian (special notation for limits)
  • support for additional glyph variants (e.g. fraktur) including tailed, looped, stretched

This represent some substantial amount of work, although a partial implementation might still be valuable. There are no specific plans to add this support at this time, but PR would be gladly considered.

arnog avatar Oct 27 '20 12:10 arnog

Thanks for response!

alexprey avatar Nov 06 '20 17:11 alexprey

I am keen to having RTL support as well. Would like to use mathlive in situations that require right to left languages!

m-hakkestad avatar Dec 03 '21 13:12 m-hakkestad

@m-hakkestad Could you provide some examples of expressions you'd like to be able to handle, preferably as Latex and as screenshot?

arnog avatar Dec 03 '21 15:12 arnog

There is some discussion of RTL in the MathML spec. Basically, most everything except (sometimes) numbers are mirrored (depends on the country). Unicode has a list of mirror chars and ones that the font needs to mirror: http://www.unicode.org/Public/UNIDATA/BidiMirroring.txt. I'm not sure what the state of character mirroring is in fonts these days but a quick search doesn't make me hopeful that font engines support it.

An alternative is to find a mirror font for math. I'm pretty sure there is one, but I couldn't find a link in a quick search. If someone is going to work on this, I'll look harder.

FYI: I implemented BIDI in MathPlayer years ago when it was an IE plug-in. It was surprisingly easier to implement than what I thought it would be. It didn't support shaping Arabic letters though.

@arnog is about an order of magnitude faster at writing code than I am, so I suspect it won't take him more than a day to implement (you can take that as a challenge :-)

NSoiffer avatar Nov 22 '22 01:11 NSoiffer

@NSoiffer thank you for your kind words, but I would suggest that implementing support for an editor is vastly more complicated than for a renderer. In particular the need to handle moving a cursor and a split cursor (i.e. a cursor that's at the boundary of a LTR/RTL zone) is non-trivial.

Furthermore, as you notice, displaying mirrored symbols is non-trivial and would typically require a custom math font. I'm not aware of an Arabic one. Furthermore, for some stretched symbols such as square root and integral, there's additional work to be done to make sure they line up correctly.

But as usual, if someone is willing to contribute, I'd be happy to integrate the required changes in MathLive.

arnog avatar Nov 22 '22 01:11 arnog

MathLive now supports RTL for Hebrew and Arabic. This is only for the UI, though. The math formulas themselves are still laid out LTR. If someone is interested in providing a layout engine for LTR I'll be happy to review a PR.

arnog avatar Dec 08 '23 23:12 arnog