Stabilizing characters like `< >`, `{ }` and `[ ]`

When the language layout is changed to a right to left language; in some standard editing places (e.g. the address bar of Google Chrome), characters like <, { and [ automatically become >, } and ] just by changing language layout.

Is there a way to prevent this and make these characters stable?


Solution 1:

I didn't get what you mean for the first time, because I got familiar with that. I think it will be OK, if you can expect results.

That behavior is a standard from Unicode Bidirectional Algorithm. So the dominant BiDi direction is taken from first strong character in the paragraph.

  • So what I think it happens in this case:

    1. First direction with empty textbox is taken from locale/language configuration. As you said Arabic is an RTL language. So cursor on the right.

      initial empty textbox, RTL direction

    2. Input < but it showed as >. It is a neutral char so no affects on direction. Why it is flipped? Short answer: Unicode standard, :) accept that anyway. Well its name is Less-than sign, So ... In RTL/Arabic, formula's start from right side, it should be flipped. What do you think...no?!!!

      textbox with bidi neutral character

    3. Input a Latin char g. It's a strong L (left) char, so this paragraph is detected as LTR.

      textbox with strong left character

    4. Backspace to delete g. But notice where the cursor.

      textbox with bidi neutral character after removing a strong left character

    Now, example [, it was wrongly named Left square bracket. It should be some thing like Open square bracket (It is BiDi neutral and flipped in RTL)

All developers try to follow standards. So noway they will force textbox to be RTL or LTR, Auto is the best for most users.

  • So for you, the best thing I can offer is to use Unicode BiDi Control Char's.

    U+200F right-to-left mark (RLM)
    
    1. In empty address bar, Ctrl+Shift+u, small underlined u shows up, enter 200f then Enter

      GTK/Gnome Unicode input

    2. See < did not flip as LTR.

      GTK/Gnome force RTL direction

    Ctrl+Shift+u is GTK/Gnome specific. KDE misses for such option and it seems not to be fixed, as this bug report mention the conflict between KDE/Qt/Xorg Need way to insert arbitrary Unicode characters in Kubuntu.

  • As it is just a matter of few characters, you could remap non needed keys or map non used ones. For example, I'm using US English (international AltGr dead keys)

    1. Open its xkb layout file for editing:

      sudo nano /usr/share/X11/xkb/symbols/us
      
    2. Look for the group definition that with same name:

      xkb_symbols "altgr-intl" {
      
          name[Group1]= "English (international AltGr dead keys)";
      
    3. Let's look as example for r (easy to remember),: AltGr+r → RLM, Shift+AltGr+r → LRM. Instead of ë & Ë. Replace:

      key <AD04> { [        r, R,           ediaeresis,   Ediaeresis      ] };
      

      With:

      key <AD04> { [        r, R,           U200F,        U200E           ] };
      
    4. Update xkb

      sudo dpkg-reconfigure xkb-data
      
    5. Switch to another layout then back, it will be active immediately.

    Notes:

    • Use same method to add them to Arabic layout, if you want to be able to use it from both layouts.

    • You may use U+061C ؜ ‭arabic letter mark (ALM) instead of RLM as you are an Arabic user.

    • xkb supports other Unicode code entry format, 0x100200f eq. U200F (ie 0x100 as prefix)

    • To avoid overwriting of the modified key map by xkb-data updates, the best is to create a new custom XKB map. See How to add a new keyboard layout (Custom keyboard layout definition) or What are the steps needed to create new keyboard layout on ubuntu?

    • It's possible add all other Unicode control characters. Some application has already an option in Popup Menu of the Multi-line Input Text Box. Example Poedit:

      poedit, bidi control characters menu

Nice to read for further understanding:

  • Wikipedia: Bi-directional text
  • Understanding Bidirectional (BIDI) Text in Unicode

References:

  • Unicode Bidirectional Algorithm
  • How to enter any Unicode not available on keyboard, see Cannot type “ć” on Hungarian layout

  • Howto: Custom keyboard layout definitions

  • Wikipedia: Unicode input
  • Reconfigure keyboard layout - 13.10, 14.04
  • Wikibooks: FOSS Localization/Annex B: Technical Aspects (Ref. for 0x100 prefix)