Archive for the ‘XeTeX’ Category
Typesetting professional Islamic articles/books with XeTeX
Last edit: October 20, 2009. Note that this article is a work in progress. Feel free to comment.
Masha Allah, XeTeX has come a long way!
For those that don’t know, XeTeX is a TeX typesetting engine (i.e. software) supporting Unicode and modern font technologies such as OpenType or Apple Advanced Typography. Together with LaTeX, it lets you create beautiful and professional looking PDFs, with support for a lot of natural languages/scripts. And, you can get it for free, because it’s Free/Open Source software.
A typical XeTeX document contains plain text and looks something like this:
\documentclass{article}
\usepackage{xltxtra}
\newfontfamily{\arabicfont}[Script=Arabic,Scale=1.5]{Traditional Arabic}
\usepackage{arabxetex}
\begin{document}
\section{\textarab[utf]{العربية}}
\textarab[utf]{السلم عليكم و رحمت الله و بركته}
\section{Legacy syntax}
When he goes---``Salamun alaykum!''\\
She replies—“Wa alaykumus-salam, dear!”
\end{document}
Actually, the text above is a LaTeX document with XeTeX (i.e. Unicode) support. LaTeX is a full-fledged markup language for typesetting, built on top of TeX, which is a programming language for very low-level typesetting. A pretty rough analogy would be that LaTeX is the equivalent of barebone HTML/CSS, while TeX is like JavaScript, enabling you to fine-tune the visual appearance.
Being a programming language, TeX/LaTeX offers a lot of packages that extend its core functionality. Packages are written by ordinary users and uploaded to The Comprehensive TeX Archive Network (CTAN) or some other place, where anyone can download them.
The downside is that it takes time to get used to (La)TeX. Some parts of the syntax are very weird. Installing TeX and friends can be a real pain. Fortunately, there’s plenty of documentation online, as well as some mailing lists where you can get help from (Xe)TeX experts. Packages come with their own documentation, usually in a PDF file. This can be a problem when it comes to searching for what you need, because some PDFs generated with XeLaTeX can be unsearchable, even from within Adobe Acrobat Reader.
What’s wrong with MS Word?
Word (or the freely available equivalent OpenOffice) is OK for documents with a small number of pages, although even then the results are suboptimal. With larger documents it’s definitely better to switch to something more suited to professional typesetting. TeX and friends are one solution.
Installing XeTeX on Windows
Enough words, let’s do something useful. If you’re using Windows, I recommend installing MiKTeX. MiKTeX is a free TeX/LaTeX/XeTeX distribution for Microsoft Windows. It comes with a great package manager that automatically downloads and installs packages from CTAN. You can even update the packages when new versions come out. It adds the directory with all the executables (e.g., C:\Program Files\MiKTeX 2.8\miktex\bin) to the default search PATH for executables so you can invoke it directly from the command prompt (cmd.exe). There’s even a completely portable USB stick ready version of XeTeX. Really well done!
There are some screencasts out there that show you how to install and use MiKTeX. One even goes to explain ArabTeX which I don’t recommend using (there’s ArabXeTeX now). More on that later.
Text editors for Windows
When you install MiKTeX, it doesn’t come with a text editor. While you can use Notepad as your editor for LaTeX, it’s better to use something that has at least syntax highlithting for TeX.
Unfortunately, the problem with editors on Windows is Unicode support, which can be pretty bad. Notepad has decent Unicode support. When I say Unicode, I mean UTF-8 which is the only sane text encoding that should be used for writing multilanguage (plain text) documents. There’s also the problem of a good monospace font that supports Arabic.
After experimenting a bit, it seems that the best free LaTeX editor on Windows is Texmaker. It has to be tweaked a little – by default, it isn’t set-up to save files in UTF-8, and for generating PDFs with the “Quick Build” button, one should use xelatex, instead of pdflatex. You can also change the default Courier New font to Traditional Arabic.
When you click on “Quick build” inside Texmaker, especially the first time, it can take a while. This is even more so on Windows, where MiKTeX has to download the packages needed to build the document. It’s probably better to use the xelatex command from the command-line (cmd.exe) the first few times.
Here are some pics:



Update: now I think that on Windows Gedit is the best choice for the average user. Still, I prefer to use Emacs (my text editor of choice) even on Windows (see also EmacsW32). Emacs currently doesn’t display correctly Right-to-Left (RTL) languages (work is under way), so I don’t recommend it for texts with lots of Arabic.
Related to TeX(t) editing is the process of viewing the generated PDF. Just recently, Evince, a GNU/Linux document viewer has been ported to Windows. Evince has a very useful feature of automatically reloading the PDF every time it’s changed, and that’s why I recommend it.
Installing it on GNU/Linux – Ubuntu
You can install XeTeX on Ubuntu with:
sudo apt-get install texlive-xetex
ArabXeTeX isn’t packaged for Ubuntu, but you can add it to your home texmf dir. There are a lot of editors available on GNU/Linux systems, Texmaker included.
Note that, at the time of writing, Ubuntu is is still supporting only the TeX Live 2007 version. TeX Live 2008 is the latest stable version, while the 2009 version is in pretest stage. You can easily install them on your local system, even as a non-root user. In fact, I removed the original Ubuntu package(s) completely. I have installed TeX Live 2008 to /home/edin/texlive2008 and created a shell script (~/bin/texlive2008.sh) with the following content:
export PATH=~/texlive2008/2008/bin/i386-linux:$PATH
It can be invoked with bash --rcfile ~/bin/texlive2008.sh
Installing it on Mac OS
I don’t have a Mac, but XeTeX was initially developed for the Mac platform so you should have no problems installing it.
Arabic support for LaTeX
XeTeX enables you to use Unicode fonts in your LaTeX documents, but for smooth Arabic (i.e. RTL) experience you have to install the bidi package. I suggest you also install ArabXeTeX. ArabXeTeX is the XeTeX compliant successor of ArabTeX, which works without XeTeX, i.e. with plain TeX. ArabTeX doesn’t allow you to use your OTF/AAT fonts and there are rumors that the code underlying it is ugly.
In addition, ArabXeTeX provides a nice plain ASCII transliteration mechanism, so you can write Arabic using an English keyboard.
Update: I have been working a bit with ArabXeTeX and it has had a problem with positioning of harakats on the lam-elif ligature. Now I’m sticking to plain XeTeX with \newcommand{\ar}[1]{\RL{\arabicfont#1}}.
There’s a video from TUG 2009 entitled “Arabic typography: Past, present, and TeX”. There are also some other Arabic related packages: arabi, alqalam. As far as I know, alqalam is packaged only for Debian-like GNU/Linux distributions and isn’t uploaded to CTAN. There’s also FarsiTeX.
Fonts
For some nice free Arabic fonts, I suggest you visit the SIL page dedicated to Scheherazade and Lateef fonts.
Khaled Hosny is working on a fork of Scheherazade as part of his raqm project. He plans to add many ligatures to the font, and could use your help. With the freely available FontForge this shouldn’t be difficult. There’s also an easy to install (i.e. unpack) Windows version of FontForge.
There are also some free fonts that contain calligraphic symbols/sentences: Allah, bismilla etc. We could use some more.
For some other fonts see the (whole) thread: List of free Unicode fonts in the XeTeX ML archive, the somewhat old WAZU JAPAN’s Gallery of Unicode Fonts, and the ArabEyes font page.
An example
There’s a mercurial repository of the XeTeX version of the ongoing discontinued? series of articles by Al-Kakazai: “Sharh Aqidah al-Awam of Sayyid al-Maliki”.
You can download the resulting PDF files here:
The sharh of the aqidah, The aqidah without the commentary