Erik Skare

The Microsoft ecosystem suffers from a number of inadequacies when typesetting Arabic script in general and intertwining Latin and Arabic scripts in particular. Having transitioned away from Microsoft — and, in particular, Microsoft Office — I began drafting documents using Markdown and Pandoc. Yet, although Markdown and Pandoc are excellent tools for handling Latin script and offer a relatively user-friendly experience, they presented significant challenges when integrating both Latin and Arabic scripts. While some colleagues managed to combine these scripts using tools like Babelfont and manipulating the YAML code, I found that altering font for Arabic compromised the aesthetic appeal that I so admired in Markdown. My journey was further marred by numerous error messages, pushing me to the brink of giving up and just relying on good old fashioned transcription of Arabic text.

LaTeX, a high-quality typesetting system commonly used for producing technical and scientific documents, offers a robust solution for several Arabic typographical challenges. LaTeX can, for example, seamlessly incorporate Arabic margin notes alongside Latin text, craft tables that intermix both scripts, create stretchable كَشَائِد/تطاويل, and format traditional Arabic poetry with its unique meter and rhyme schemes, mentioning just some. Here, I hope to offer some resources — either produced by other academics or by myself. These resources below will contain minimal narrative text and focus on the code itself. So feel free to contact me should you have any comments or questions.

Using the arabtex package

Typesetting single Arabic words is pretty straightforward using the arabtex package. Many of its component files date back to 2003 and may cause some incompatibility issues, although I have not personally experienced any.

The code:


  \documentclass[a4paper,10pt]{article}
  \usepackage{arabtex}
  \usepackage{utf8}
  \setcode{utf8}
  \begin{document}
    
  Here is the word "Arabic" written in Arabic:  \<اَلْعَرَبِيَّةُ>.
    
  \end{document}
  

The output would then look like this:

The package can also be used to feature extensive sections of Arabic text with interspersed Latin script. The \begin{RLtext} command tells LaTeX to typeset the content from the right to the left (as one does in Arabic) while the \LR{computer} command does the opposite.

The code:


  \documentclass[a4paper,10pt]{article}
  \usepackage{arabtex}
  \usepackage{utf8}
  \begin{document}
  \setcode{utf8}
  \vspace{10pt}
  
  Here is a larger section of Arabic, containing some words in English within the \verb|\LR| command:

  \vspace{10pt}
  \begin{RLtext}
  
  يعود تاريخ علوم الحاسوب إلى اختراع أول حاسوب رقمي حديث. فقبل العشرينات من القرن العشرين، كان مصطلح حاسوب \LR{Computer} يشير إلى أي أداة بشرية تقوم بعملية الحسابات. ما هي القضايا أو الأشياء التي يمكن لآلة أن تحسبها باتباع قائمة من التعليمات مع ورقة وقلم، دون تحديد للزمن اللازم ودون أي مهارات أو بصيرة (ذكاء)؟ وكان أحد دوافع هذه الدراسات هو تطوير آلات حاسبة \LR{computing machines} يمكنها إتمام الأعمال الروتينية والعرضة للخطأ البشري عند إجراء حسابات بشرية.
  خلال الأربعينات، مع تطوير آلات حاسبة أكثر قوة وقدرة حسابية، تتطور مصطلح حاسوب ليشير إلى الآلات بدلا من الأشخاص الذين يقومون بالحسابات. وأصبح من الواضح أن الحواسيب يمكنها أن تقوم بأكثر من مجرد عمليات حسابية وبالتالي انتقلوا لدراسة تحسيب أو التحسيب بشكل عام. بدأت المعلوماتية وعلوم الحاسب تأخذ استقلالها كفرع أكاديمي مستقل في الستينات، مع إيجاد أوائل أقسام علوم الحاسب في الجامعات وبدأت الجامعات تعطي إجازات في هذه العلوم [1]. 
  
  \end{RLtext}
  \end{document}
  

The output:

Using the quran package

The quran package makes LaTeX a great tool if you need to typeset the Qur'an as a part of your scholarly documents. This package requires a little bit effort, but I have tried to provide a short tutorial to make it work. As always, I have used Overleaf when creating documents with LaTeX; I highly recommend you do the same.

As opposed to the arabtex package, the quran package requires a number of dependencies in order to work. These dependencies are mainly the Quranic text data, which are not contained in the package itself. You will simply have to download the dependencies from here and add them to your working directory. That is pretty much it. I will briefly explain the code at the end of this section.

The code:


  \documentclass{article}
  \usepackage{quran,polyglossia}
  \setotherlanguage{arabic}
  \setmainfont{Amiri}
  \usepackage{bidi}


  \begin{document}
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed pulvinar, justo a luctus varius, tortor quam tristique ex, sit amet dapibus sem justo a tellus. Proin consectetur, nisl non bibendum blandit, arcu quam convallis tellus, sed volutpat mi libero et urna. In hac habitasse platea dictumst. Vivamus non lectus nec urna viverra facilisis.

  \vspace{0.4cm}
  \setRTL
  \textarabic{\quransurah[1]}
  \vspace{0.4cm}
  \setLTR

  Nullam vel metus sit amet elit ultrices malesuada. Fusce hendrerit, leo in tincidunt tempus, libero purus feugiat purus, in feugiat dolor dolor eget odio. Sed ullamcorper massa vitae leo ultrices, vel mattis massa fermentum. Vestibulum viverra massa id pharetra fermentum. Donec gravida, urna at tempus feugiat, velit velit fermentum purus, eget facilisis metus dolor vel arcu. Vivamus et urna odio.

  \end{document}

The output:

As you can see, there is not much to it. You use three packages: 1) quran, 2) polyglossia, and 3) bidi (the latter two used to typeset documents that contain text in bidirectional scripts). You set Arabic as "other language" and set Amiri as the main font. The \vspace{0.4cm} command is purely for aesthetic reasons and adds a 0.4cm vertical space in the document. The \setRTL command makes you write from Right To Left and the \setLTR command does the opposite.

When using the quran package, you essentially use the command \quransurah[] and add the preferred surah number. In our case, we used the number one, which obviously adds surah al-fatiha. If you want to add more than one surah then you add your preferred numbers separated by a dash (-). As there are 114 surahs, you will need to provide an integer between 1 and 114.

You can also use the command \quranayah[] to add a "verse" from the Quran. The logic is the same as when you typeset a surah, so when you provide the command \quranayah[33][33], then it means that you want to typeset the 33rd ayah in the 33rd surah.

Typesetting Arabic poetry

LaTeX is also highly efficient for typesetting Arabic poetry and the two columns known as "shatr" (شطْر) and "bayt" (بيْت). Shatr is the first line and sets the rhythmic tone for the entire line, while bayt is the second part, follows shatr, and completes the imagery or thought introduced. Naturally, this can be quite messy in other office programs — especially in a document combining Latin and Arabic scripts. Luckily, Ameer Taweel has developed a template, which I have tweaked a little bit:

The code typesetting a poem by Antara ibn Shaddad:


\documentclass{article}
\usepackage[colorlinks, urlcolor = blue]{hyperref}
\usepackage[
    bidi     = basic, 
    headfoot = arabic,
    layout   = counters.tabular
]{babel}
\usepackage{bidipoem}
\usepackage{lipsum}
\babelprovide[
    import,
    main,
    justification = kashida,
    transforms    = kashida.plain
]{arabic}
\babelfont{rm}{Amiri}
\usepackage{ragged2e}

\begin{document}

\begin{otherlanguage}{english}
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed pulvinar, justo a luctus varius, tortor quam tristique ex, sit amet dapibus sem justo a tellus. Proin consectetur, nisl non bibendum blandit, arcu quam convallis tellus, sed volutpat mi libero et urna. In hac habitasse platea dictumst. Vivamus non lectus nec urna viverra facilisis.
\end{otherlanguage}

\vspace{0.5cm}
\centering

  \begin{traditionalpoem*}
    سلي يا عبلةَ الجبلينِ عنَّا & وما لاقتْ بنو الأعجام منَّا 
    أَبَدْنَا جَمْعَهُمْ لما أَتوْنا & تموجُ مواكبٌ إنساً وجنا 
    وراموا أكلنا من غير جوع & فأشبعناهم ضرباً وطعنا 
    ضربناهم ببيضٍ مرهفاتٍ & تَقُدُّ جُسُومَهُمْ ظهْراً وَبَطْنا 
    وفرقنا المواكبَ عن نساءٍ & يزدْنَ على نساءِ الأَرْض حُسنا 
    وكم منْ سيدٍ أضحى بسيفي & خضيبَ الراحتين بغير حنا 
    وكم بطلٍ تركتُ نساهُ تبكى & يردّدنَ النُّواحَ عليه حزنا 
    وحجَّارٌ رأى طعني فنادى & تأَنى يا بنَ شدَّادِ تأَنى 
    خلقتُ من الجبالِ أشدَّ قلباً & وقد تفنى الجبالُ ولستُ أفنى 
    أنا الحصنُ المشيدُ لآلِ عبسٍ & إذا ما شادتِ الأبطالُ حصنا 
    شبيهُ اللّيلِ لوني غيرَ أَنّي & بفعلي منْ بياض الصُّبح أَسنى 
   جوادي نسبتي وأبي وأمي & حُسامي والسنانُ إذا انْتسبْنا 
  \end{traditionalpoem*}


\end{document}

The output:

Arabic margin notes and stretchable kashida

Andreas Hallberg at the University of Gothenburg has a wonderful blog about Arabic linguistics. He also shares code on Arabic typesetting, which is incredibly helpful. Check it out:

The code is a bit more complex than what I have presented above, but it works quite nicely.