Aller au contenu

Introduction

In this article we explain how to typeset Arabic using the arabtex package with pdfLaTeX. However, the underlying pdfTeX engine (software), which typesets/processes your pdfLaTeX document, has relatively limited support for typesetting complex-script languages such as Arabic, Hebrew, Devanagari or Malayalam. Typesetting such languages requires more complete support of Unicode-based text input, the use of OpenType fonts and other capabilities which are not present in pdf(La)TeX.

Many authors are mandated to use pdfLaTeX due to requirements of their workflow, but if you are able to choose the LaTeX compiler, the modern approach to typesetting Arabic is to use XeLaTeX (XeTeX engine) or LuaLaTeX (LuaHBTeX engine). LuaLaTeX, via LuaHBTeX, provides the most advanced and complete TeX-based solutions for complex-script language typesetting. See these pages about polyglossia and babel.

Notes on the arabtex package

Klaus Lagally started work on the arabtex package in 1991, primarily as a personal project—see Appendix B of the package documentation. Its genesis and early development predates the advent of pdfTeX by around 5 years and LuaHBTeX and XeTeX by more than a decade—and long before the rise of Unicode and OpenType fonts. The arabtex package is a tour-de-force of complex TeX programming, but many core component files now date from circa 2003, meaning that the age of the arabtex package can give rise to incompatibilities with current versions of LaTeX or LaTeX packages.

A first arabtex example

The following basic example uses the arabtex package to typeset a single word in Arabic:

\documentclass[a4paper,10pt]{article}
\usepackage{arabtex}
\usepackage{utf8}
\setcode{utf8}
\begin{document}
Here is the word ``Arabic'' written in Arabic:  \<اَلْعَرَبِيَّةُ>. You can also use the command \verb|\RL{arabic text}| like this: \RL{اَلْعَرَبيَّةُ}.
\end{document}

 Open this pdfLaTeX and arabtex example in Overleaf.

This example produces the following output:

Example of Arabic typeset by arabtex

Note that the arabic text used with command \RL{arabic text} should not contain more than a single paragraph of right-to-left text.

arabtex: transliteration or UTF-8 input

The arabtex package supports the ability to typeset Arabic text by writing it using a particular form of transliteration: representing Arabic text using the Latin script. Here's a fragment from an example in the arabtex documentation—note how the Arabic text is represented in Latin text, which is converted to Arabic:

\documentclass[12pt]{article}
\usepackage{arabtex}
\begin{document}
\setarab % choose the language specific conventions
\vocalize % switch diacritics for short vowels on
%\transtrue % display the transliteration
\arabtrue % print arabic text (on by default)
\centerline {\RL{^gu.hA wa-.himAruhu}} % typeset a centred line of Arabic text
\begin{RLtext}
fa-qAla lahu ^gu.hA:

.garIbuN 'amruka yA .sadIqI!
'a-tu.saddiqu al-.himAra wa-tuka_d_dibunI?
\end{RLtext}
\end{document}

 Open this pdfLaTeX and arabtex example in Overleaf.

This example produces the following output:

Example of Arabic typeset by arabtex

If we want arabtex to use actual Arabic text as input, not transliterated Latin text, we have to tell arabtex to use UTF-8 input instead, by writing

\usepackage{utf8}
\setcode{utf8}

The utf8 package is part of the arabtex package.

A second arabtex example

The following example contains a more substantial piece of Arabic text which also contains some words in English:

\documentclass[a4paper,10pt]{article}
\usepackage{arabtex}
\usepackage{utf8}
\begin{document}
\setcode{utf8}
Here is the word ``Arabic'' written in Arabic:  \<اَلْعَرَبِيَّةُ>. You can also use the command \verb|\RL{arabic text}| like this: \RL{اَلْعَرَبيَّةُ}. 

\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}

 Open this pdfLaTeX and arabtex example in Overleaf.


An arabtex example also using babel

The following examples uses arabtex together with the babel and inputenc packages, for reasons that will be noted below.

\documentclass[11pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage{arabtex}
%\usepackage[LAE]{fontenc} %Not needed due to [arabic] option of the babel package
\usepackage[arabic]{babel}
\title{
    \Huge\textsc{اللغة العربية}
}
\author{سالم البوزيدي}
\begin{document}
\maketitle
\tableofcontents
\chapter{علوم الحاسوب}
\section{تاريخ}
\begin{otherlanguage}{arabic}
يعود تاريخ علوم الحاسوب إلى اختراع أول حاسوب رقمي حديث. فقبل العشرينات من القرن العشرين، كان مصطلح حاسوب \textLR{Computer} يشير إلى أي أداة بشرية تقوم بعملية الحسابات. ما هي القضايا أو الأشياء التي يمكن لآلة أن تحسبها باتباع قائمة من التعليمات مع ورقة وقلم، دون تحديد للزمن اللازم ودون أي مهارات أو بصيرة (ذكاء)؟ وكان أحد دوافع هذه الدراسات هو تطوير آلات حاسبة \textLR{computing machines} يمكنها إتمام الأعمال الروتينية والعرضة للخطأ البشري عند إجراء حسابات بشرية.
خلال الأربعينات، مع تطوير آلات حاسبة أكثر قوة وقدرة حسابية، تتطور مصطلح حاسوب ليشير إلى الآلات بدلا من الأشخاص الذين يقومون بالحسابات. وأصبح من الواضح أن الحواسيب يمكنها أن تقوم بأكثر من مجرد عمليات حسابية وبالتالي انتقلوا لدراسة تحسيب أو التحسيب بشكل عام. بدأت المعلوماتية وعلوم الحاسب تأخذ استقلالها كفرع أكاديمي مستقل في الستينات، مع إيجاد أوائل أقسام علوم الحاسب في الجامعات وبدأت الجامعات تعطي إجازات في هذه العلوم [1]. 
\end{otherlanguage}
\end{document}

 Open this Arabic text example in Overleaf


LanguageEx2.png

Input encoding

To support a variety of input encodings for different groups of languages and/or on different computer platforms LaTeX employs the inputenc package. Prior to the release of TeX Live 2018, using UTF-8 encoded text with pdfLaTeX required the inputenc package by writing

\usepackage[utf8]{inputenc}

in your document's preamble.

As noted in the Overleaf blog post TeX Live upgrade—September 2019, LaTeX has switched to UTF-8 as the default input encoding; consequently, it is now not usually necessary to explicitly write \usepackage[utf8]{inputenc} if you are using a post-2018 release of TeX Live. However, for the above example writing \usepackage[utf8]{inputenc} is still required.

Language-specific document elements

The arabic option of the babel package provides support for the Arabic language:

\usepackage[arabic]{babel}

which includes bidirectional typesetting and use of Arabic names for document elements. If you need to insert some Latin text inside your Arabic document, you use the \textLR{...} command; for example, by writing

\textLR{Latin text}

Font encoding

In addition to using the correct input encoding, typesetting a LaTeX document, containing Arabic text, requires fonts with the appropriate correct output encoding to provide the glyphs (shapes) which represent typeset Arabic. Typesetting the example above needs the equivalent of writing

\usepackage[LAE]{fontenc}

but, as noted in this reply on tex.stackexchange, using the arabic option of babel results in loading the required LAE encoding files laeenc.def and laeenc.dfu.

Further reading

For more information see

Overleaf guides

LaTeX Basics

Mathematics

Figures and tables

References and Citations

Languages

Document structure

Formatting

Fonts

Presentations

Commands

Field specific

Class files

Advanced TeX/LaTeX