Arabic Fonts in Emacs

If you are like Ammar or me and use Emacs to write in both Arabic and English, you might have encountered the problem of using some Arabic font in Emacs and wished that you could use that font but you can't because the English text looks terrible, or vice versa. Well, I found a little trick in Emacs that allows you to assign a font for Arabic text and another font for English text.

There's a function in Emacs called set-fontset-font that allows us to specify a range of characters to have a specific font. To assign the Arabic range to have Noto Sans Arabic UI font, for example. All you have to do is to add the following somewhere in your init.el if you are using Emacs, or in dotspacemacs/user-init in your .spacemacs file if you are using spacemacs:

(let ((ar-font "Noto Sans Arabic UI")
      (range '(#x000600 . #x0006FF)))
  (set-fontset-font "fontset-startup"  range ar-font)
  (set-fontset-font "fontset-default"  range ar-font)
  (set-fontset-font "fontset-standard" range ar-font))

or for a shorter solution:

(set-fontset-font t 'arabic "Noto Sans Arabic UI")
Comments powered by Disqus