Results 1 to 10 of 44

Thread: Sanskrit input (Devanagari and transliteration)

Threaded View

  1. #1
    Join Date
    May 2006
    Ubuntu 11.04 Natty Narwhal

    Sanskrit input (Devanagari and transliteration)

    Update: In the new releases since this post was written, Ubuntu has come a very long way with preconfiguring the input method editor, now ibus (formerly SCIM), for us. It is now ready to go practically out of the box and setting up phonetic देवनागरी and Transliteration inputs is a trivial affair. For phonetic Devanāgarī, all you need to do is:
    1. Go to System > Administration > Language Support, and in the Language Tab select ibus for your "Keyboard Input Method System"
    2. Then click the button Install / Remove Languages..., click Hindi and Apply Changes

    That's it -- too simple! You may need to log out and log back in (i.e., restart X) for ibus to work. Once you hit ctrl-space, the ibus daemon should start up and you can begin typing in Devanagari by adding the Hindi Itrans input to your keyboard switcher. I'll leave the now-obsolete steps previously required for SCIM configuration in a quote below for those on older versions of Ubuntu (or other varieties of Debian), for the sake of reference. Scroll down below the quote for specific instructions on my recommendations for better Sanskrit input.

    For anyone having difficulty setting up their system to handle Sanskrit input, I'd like to point you to the relevant documentation and provide a few tips to save you a few hours of googling and trial and error. General disclaimer: I am still a linux beginner and I've never written an official "tips and tricks" post before, so 1. caveat emptor and 2. all suggestions / feedback / improvements welcome!

    Devanagari - देवनागरी

    This has worked well in Ubuntu for some time now, it just requires a little system configuration (less now than previously). Before beginning, you might want to check out the SCIM documentation for Ubuntu here and here.

    1. Go to: System > Administration > Language Support, check the box for Hindi, click Apply and then the select box for Enable support to enter complex characters. Proceed to Step 2.

      1. That should have pulled in both the Scim input method editor and the Devanagari fonts packages necessary for unicode input. For those on other Debian systems, who lack the helpful Ubuntu menu mentioned above, you can manually install the packages with the following:
        sudo aptitude install ttf-devanagari-fonts scim-qtimm scim-tables-additional scim-bridge scim-m17n m17n-lib-bin m17n-db scim-bridge-client-qt4 skim im-switch
    2. Configure your system by entering the following commands in a terminal (for those not in the US, enter the appropriate language / country codes in place of "en_US"):
      im-switch -z en_US -s scim
      export XMODIFIERS=@im=SCIM
      export GTK_IM_MODULE=scim
      export QT_IM_MODULE=scim
      Note: A more general alternative to the first command is simply "im-switch -z all_ALL -s scim" which may be preferable depending on your language setup. Also, it should no longer be necessary, but if in the end SCIM does not work properly at startup, you could also add the last three lines of code above to the .bashrc file in your home directory and restart X.
    3. Set up SCIM to run at startup by going to System > Preferences > Sessions > Startup Program > + Add > Command and enter
      scim -d
    That should be it for the basic set up. If you were to restart X or reboot at this point, you should be able to type in Devanagari with ease using ibus / m17n. However, I would recommend first tweaking your input method, because although the hi-itrans transliteration scheme is by far the most user-friendly of those available (in being relatively phonetic), it has a few problems. One is that the combination "rh" is designed to yield ऱ् rather than र्ह् . Similarly there is no transliteration for the double daṇḍa (used at the end of stanzas, etc., i.e. — ॥ — requiring that one use the less elegant combination of two daṇḍas — ।। . Also, there are several keystroke combinations in the Itrans scheme which to me at least seem either unintuitive or a little unwieldy: e.g., "R^i" for ऋ .

    1. Exit ibus (if you've already rebooted) and save a backup of your original input file (in your home directory):
      cp /usr/share/m17n/hi-itrans.mim ~/
    2. then open that file for editing: type in a terminal
      sudo gedit /usr/share/m17n/hi-itrans.mim
    3. Overwrite the contents of the file with the quote below. Select all (Ctrl-a) in that file and copy / paste the following quote into the hi-itrans file:

      ;; hi-itrans.mim -- Hindi input method with ITRANS method
      ;; Copyright (C) 2003, 2004, 2005
      ;; National Institute of Advanced Industrial Science and Technology (AIST)
      ;; Registration Number H15PRO112

      ;; This file is part of the m17n database; a sub-part of the m17n
      ;; library.

      ;; The m17n library is free software; you can redistribute it and/or
      ;; modify it under the terms of the GNU Lesser General Public License
      ;; as published by the Free Software Foundation; either version 2.1 of
      ;; the License, or (at your option) any later version.

      ;; The m17n library is distributed in the hope that it will be useful,
      ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
      ;; Lesser General Public License for more details.

      ;; You should have received a copy of the GNU Lesser General Public
      ;; License along with the m17n library; if not, write to the Free
      ;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
      ;; 02111-1307, USA.

      (input-method hi itrans)

      (description "Hindi input method by ITRANS transliteration.
      For the detail of ITRANS, see the page:

      (title "क")

      (".") ("~") ("#") ("$") ("^") ("*") ((S-\ )) ((C-@))
      ("0") ("1") ("2") ("3") ("4")
      ("5") ("6") ("7") ("8") ("9")
      ("A") ("C") ("D") ("G") ("H") ("I") ("J") ("K") ("L")
      ("M") ("N") ("O") ("R") ("S") ("T") ("U") ("Y")
      ("a") ("b") ("c") ("d") ("e") ("f") ("g") ("h") ("i")
      ("j") ("k") ("l") ("m") ("n") ("o") ("p") ("q") ("r")
      ("s") ("t") ("u") ("v") ("w") ("x") ("y") ("z"))

      ("k" "क्")
      ("kh" "ख्")
      ("g" "ग्")
      ("gh" "घ्")
      ("~N" "ङ्")
      ("c" "च्")
      ("ch" "छ्")
      ("j" "ज्")
      ("jh" "झ्")
      ("~n" "ञ्")
      (".t" "ट्")
      ("T" "ट्")
      (".th" "ठ्")
      ("Th" "ठ्")
      (".d" "ड्")
      ("D" "ड्")
      (".dh" "ढ्")
      ("Dh" "ढ्")
      (".n" "ण्")
      ("N" "ण्")
      ("t" "त्")
      ("th" "थ्")
      ("d" "द्")
      ("dh" "ध्")
      ("n" "न्")
      ("xn" "ऩ्")
      ("p" "प्")
      ("ph" "फ्")
      ("b" "ब्")
      ("bh" "भ्")
      ("m" "म्")
      ("y" "य्")
      ("r" "र्")
      ("xr" "ऱ्")
      ("l" "ल्")
      ("L" "ळ्")
      ("ld" "ळ्")
      ("v" "व्")
      ("w" "व्")
      ("sh" "श्")
      ("Sh" "ष्")
      (".s" "ष्")
      ("s" "स्")
      ("h" "ह्")
      ("q" "क़्")
      ("K" "ख़्")
      ("xg" "ग़्")
      ("xj" "ज़्")
      ("z" "ज़्")
      (".D" "ड़्")
      (".Dh" "ढ़्")
      ("f" "फ़्")
      ("Y" "य़्")
      ("yh" "य़्")
      ("GY" "ज्ञ्")
      ("dny" "ज्ञ्"))

      ("a" "अ")
      ("aa" "आ")
      ("A" "आ")
      ("i" "इ")
      ("ii" "ई")
      ("I" "ई")
      ("u" "उ")
      ("uu" "ऊ")
      ("U" "ऊ")
      (".r" "ऋ")
      ("RRi" "ऋ")
      ("R^i" "ऋ")
      ("LLi" "ऌ")
      ("L^i" "ऌ")
      (".l" "ऌ")
      (".c" "ऍ")
      ("e.c" "ऍ")
      ("E" "ऎ")
      ("e" "ए")
      ("ai" "ऐ")
      ("o.c" "ऑ")
      ("O" "ऒ")
      ("o" "ओ")
      ("au" "औ")
      ("RRI" "ॠ")
      ("R^I" "ॠ")
      (".R" "ॠ")
      ("LLI" "ॡ")
      ("L^I" "ॡ")
      (".L" "ॡ")
      (".N" "ँ")
      (".m" "ं")
      ("M" "ं")
      ("H" "ः")
      (".a" "ऽ")
      (".h" "्")
      ("AUM" "ॐ")
      ("OM" "ॐ")
      (".." "।")
      (".," "॥")
      ("0" "०")
      ("1" "१")
      ("2" "२")
      ("3" "३")
      ("4" "४")
      ("5" "५")
      ("6" "६")
      ("7" "७")
      ("8" "८")
      ("9" "९")
      ("#" "्र")
      ("$" "र्")
      ("^" "त्र")
      ("*" "श्र")
      ("]" "़")
      ((S-\ ) "*")
      ((C-@) "*"))

      ("a" (delete @-) "")
      ("aa" (delete @-) "ा")
      ("A" (delete @-) "ा")
      ("i" (delete @-) "ि")
      ("ii" (delete @-) "ी")
      ("I" (delete @-) "ी")
      ("u" (delete @-) "ु")
      ("uu" (delete @-) "ू")
      ("U" (delete @-) "ू")
      ("RRi" (delete @-) "ृ")
      ("R^i" (delete @-) "ृ")
      (".r" (delete @-) "ृ")
      ("LLi" (delete @-) "ॢ")
      ("L^i" (delete @-) "ॢ")
      (".l" (delete @-) "ॢ")
      (".c" (delete @-) "ॅ")
      ("e.c" (delete @-) "ॅ")
      ("E" (delete @-) "ॆ")
      ("e" (delete @-) "े")
      ("ai" (delete @-) "ै")
      ("o.c" (delete @-) "ॉ")
      ("O" (delete @-) "ॊ")
      ("o" (delete @-) "ो")
      ("au" (delete @-) "ौ")
      ("RRI" (delete @-) "ॄ")
      ("R^I" (delete @-) "ॄ")
      (".R" (delete @-) "ॄ")
      ("LLI" (delete @-) "ॣ")
      (".L" (delete @-) "ॣ")
      ("L^I" (delete @-) "ॣ"))


      ((BackSpace) (undo))))

      (starter (pushback 1) (shift intermediate)))

      (consonant (shift second))
      (independent (shift finish))
      (return (shift init)))

      (dependent (shift finish))
      (return (shift init)))

      (t (shift init))))

      ;; Local Variables:
      ;; coding: utf-8
      ;; mode: lisp
      ;; End:
    4. Hold back m17n-db. One neat trick is to hold back the m17n library package so that it won't update and overwrite your edits (you'll be warned first before dist-upgrades). To do that, enter in a terminal:
      echo "libm17n-0 hold" | sudo dpkg --set-selections
      and upgrades will bypass m17n, thus preserving your edits. If you opt not to hold that file, you'll just need to repeat the two steps above after updates to m17n to restore a more phonetic input in hi-itrans. For more information on holding and releasing packages, see here.
    5. You should feel free, btw, to tweak the above keyboard map to your tastes, just be sure not to create any conflicts in the process!

    Reboot for your changes to take effect and then configure ibus as necessary using "ibus Preferences" and select "hi-itrans" for phonetic Devanagari input. You can then select from among your newly installed Devanagari fonts (AksharYogini, Chandas, Gargi, Kalimati, Nakula, Sahadeva, Samanata and Sarai). For a very readable font with a decent set of ligatures, I like Kalimati, though for Sanskrit I tend to use Chandas/Uttara because of its unparalleled ligature set.


    Unlike Devanagari, there seems to be a relative dearth of information available for an intuitive system-wide Sanskrit transliteration input method. I have now found several different ways of going about this, two of which are listed below: ibus/m17n or Xmodmap. I highly recommend the first alternative.

    1st Alternative: ibus/m17n

    The best way to enable an inutitive Sanskrit transliteration input method is to create a new one using ibus/m17n. The pdf referred to above has the necessary documentation. I will describe my setup below, by way of example. Update: I have updated this transliteration scheme to include the diacritics necessary for easy inputting of French and German as well. The hotkeys for those, as well as for the Sanskrit diacritics, may be easily gleaned by referring to the keymap in the quote below.

    1. Exit ibus.
    2. Create a new input method file, e.g.,
      sudo gedit /usr/share/m17n/sa-translit.mim
      and enter the appropriate file preamble and desired keystroke combinations. The following is the complete content of my file which can be easily copied and pasted and tweaked according to your taste. Save it, before closing the file:
      ;;; <li> ;;; <li> sa-translit.mim
      ;;; Input method for Sanskrit transliteration using the ITRANS scheme.

      (title "sa-translit")


      ("aa" "ā")
      ("AA" "Ā")
      ("ii" "ī")
      ("$e" "ē")
      ("$o" "ō")
      ("II" "Ī")
      ("uu" "ū")
      ("UU" "Ū")
      ("$E" "Ē")
      ("$O" "Ō")
      (".r" "ṛ")
      (".R" "Ṛ")
      (".rr" "ṝ")
      (".RR" "Ṝ")
      (".l" "ḷ")
      (".L" "Ḷ")
      (".ll" "ḹ")
      (".LL" "Ḹ")
      (".M" "ṁ")
      (".m" "ṃ")
      (".h" "ḥ")
      (".H" "Ḥ")
      (";n" "ṅ")
      (";N" "Ṅ")
      ("~n" "")
      ("~N" "")
      (".t" "ṭ")
      (".T" "Ṭ")
      (".d" "ḍ")
      (".D" "Ḍ")
      (".n" "ṇ")
      (".N" "Ṇ")
      (";s" "ś")
      (";S" "Ś")
      (".s" "ṣ")
      (".S" "Ṣ")
      ("!a" "")
      ("!e" "")
      ("!i" "")
      ("!o" "")
      ("!u" "")
      ("!A" "")
      ("!E" "")
      ("!I" "")
      ("!O" "")
      ("!U" "")
      ("?a" "")
      ("?e" "")
      ("?i" "")
      ("?o" "")
      ("?u" "")
      ("?A" "")
      ("?E" "")
      ("?I" "")
      ("?O" "")
      ("?U" "")
      ("^a" "")
      ("^e" "")
      ("^i" "")
      ("^o" "")
      ("^u" "")
      ("^A" "")
      ("^E" "")
      ("^I" "")
      ("^O" "")
      ("^U" "")
      ("#a" "")
      ("#e" "")
      ("#i" "")
      ("#o" "")
      ("#u" "")
      ("#A" "")
      ("#E" "")
      ("#I" "")
      ("#O" "")
      ("#U" "")
      ("%a" "ă")
      ("%i" "ĭ")
      ("%u" "ŭ")
      ("%e" "ĕ")
      ("%o" "ŏ")
      ("%A" "Ă")
      ("%I" "Ĭ")
      ("%U" "Ŭ")
      ("%E" "Ĕ")
      ("%O" "Ŏ")
      ("~a" "")
      ("~i" "ĩ")
      ("~u" "ũ")
      ("~e" "ẽ")
      ("~o" "")
      ("~A" "")
      ("~I" "Ĩ")
      ("~U" "Ũ")
      ("~E" "Ẽ")
      ("~O" "")
      ("-ae" "")
      ("-Ae" "")
      ("-AE" "")
      ("-oe" "œ")
      ("-Oe" "Œ")
      ("-OE" "Œ")
      (",c" "")
      (",C" "")

    3. Enter the name of our new input file in the m17n database file.
      1. In a terminal enter
        sudo gedit /usr/share/m17n/mdb.dir
      2. change the following lines
        (input-method * "*.mim")
        ;;; </ul>
        to read
        (input-method * "*.mim")
        (input-method t sa-translit "sa-translit.mim")
        ;;; </ul>
      3. Save and exit.

    Simply restart ibus or if that fails, restart X or reboot. Your new transliteration input method should be available under the "Other" category of ibus' drop-down menu.

    2nd Alternative: XModmap

    If for whatever reason, you need another method for transliteration, you can use XModmap. I've given instructions for that here. This method uses less convenient dead keys, however, and is not convienently switchable, unlike m17n.

    I hope this post is of use to others in need of Devanagari and transliterated input on linux.

    शुभं भवतु । śubhaṃ bhavatu |
    Last edited by amerikkanu; May 9th, 2013 at 05:45 PM. Reason: altered ē/ō input to prevent conflicts when also used for English input


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts