3

I have a document where I need to write in both english and arabic, in the preamble I added:

 \usepackage{arabtex}
 \usepackage[utf8]{inputenc}
 \usepackage[LFE,LAE]{fontenc}
 \usepackage[arabic,english]{babel}

I am using the Latex arabic example in overleaf. Just added english.

The full corresponding source code is bellow:

\documentclass[11pt,a4paper]{report}

\usepackage{arabtex}
\usepackage[utf8]{inputenc}
\usepackage[LFE,LAE]{fontenc}
\usepackage[arabic,english]{babel}

\title{
\Huge\textsc{اللغة العربية}
}
\author{سالم البوزيدي} 

\begin{document}
\maketitle
\tableofcontents
\chapter{علوم الحاسوب}
\section{تاريخ}

    ...يعود تاريخ علوم الحاسوب إلى اختراع أول حاسوب رقمي حديث. فقبل العشرينات من القرن العشرين                                                   


\section{English section}
Trying to type in English but it doesn't work.

\end{document}

I couldn't compile the document and got this error:

LaTeX Error: Command \ayn unavailable in encoding OT1.

3

1 Answer 1

7

[Disclaimer/Disclosure: I'm a support personnel at Overleaf.]

If you need to compile your project using pdflatex (perhaps due to a journal publisher requirement), then your code just needs a few more changes:

Assuming that you want to typeset your document in mainly Arabic with some English sections, you should load arabic as the last option for babel, or mark it explicitly as main:

\usepackage[main=arabic,english]{babel}

Then mark the English text as "otherlanguage":

\begin{otherlanguage}{english}
\section{English section}
Trying to type in English, it works now.
\end{otherlanguage}

If you need to keep the main language as English: then it's the Arabic text portions that need to be wrapped in \begin{otherlanguage}{arabic}...\end{otherlanguage}. fontenc also needs an extra T1 option explicitly. Complete reworked example of your code:

\documentclass[11pt,a4paper]{report}

\usepackage[utf8]{inputenc}
\usepackage[LFE,LAE,T1]{fontenc}
\usepackage[arabic,main=english]{babel}

\title{
\Huge\textsc{اللغة العربية}
}
\author{سالم البوزيدي} 

\begin{document}
\begin{otherlanguage}{arabic}
\maketitle
\end{otherlanguage}

\tableofcontents

\begin{otherlanguage}{arabic}
\chapter{علوم الحاسوب}
\section{تاريخ}

    ...يعود تاريخ علوم الحاسوب إلى اختراع أول حاسوب رقمي حديث. فقبل العشرينات من القرن العشرين                                                 
\end{otherlanguage}

\section{English section}
Trying to type in English; it works now.

\end{document}

If you are allowed to use XeLaTeX or LuaLaTeX, then see these help pages on Overleaf on using fontspec to choose fonts. XeLaTeX/LuaLaTeX are more robust at handling unicode input. You can use polyglossia or babel.

2
  • Thanks for your answer. It works when Arabic is the main language, however, I am trying to do the opposite (I put english as main and arabic as other language), the arabic display is correct in this case , but it doesnt work for the english part which is displayed in arabic characters. I am using pdflatex
    – safo
    Jun 26, 2020 at 17:56
  • I've updated the answer with an example for when English is the babel main language.
    – imnothere
    Jul 1, 2020 at 15:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .