[Tex/LaTex] Numbers in multi-language document

bidilanguagesmath-mode

When I use two different languages like English and Arabic (one is written form left to right and the other is written from right to left), the equation numbers are written in Arabic, e.g. 14, but when I use \ref it returns 41. I tried \textRL, but the format of the number changes from Arabic to English. So I need all numbers in the document to be written in the same format (English or Arabic), any suggestion please?
I use this code.

\documentclass[]{article}
\usepackage[utf8]{inputenc}
\usepackage[english,arabic]{babel}
\usepackage[LAE]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\begin{document}
نبين فلتحكم الكلي يما يلي قانون
% here there are equations more than ten

\begin{equation}\label{eq:lyap_tot}
\color{blue}{\boxed{\color{black}u=u_\theta-u_x}}
\end{equation}

figure \ref{lyap_tot} shows ... % here the returned number is written in arabic 
% but from left to right ( the real number is 14 and the retunred number is 41)
\end{document}

Best Answer

Here your code with polyglossia which require XeLaTeX engine

  • First you set default language with \setdefaultlanguage[calendar=gregorian,numerals=maghrib]{arabic}, option numerals=maghrib for arabic form of numerals 1, 2, 3, .... in opposite to numerals=machriq for Indian form ٣ ٢ ١ .....
  • Define other languages on your document with \setotherlanguage{english}
  • Define font for arabic script with \newfontfamily\arabicfont[Script=Arabic]{Name_of_font}

Code

\documentclass{article}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{polyglossia}

\setdefaultlanguage[calendar=gregorian,numerals=maghrib]{arabic}
\setotherlanguage{english}
\newfontfamily\arabicfont[Script=Arabic]{Amiri}
\newfontfamily\englishfont{Amiri}
\parindent 0pt
\begin{document}
نبين فلتحكم الكلي يما يلي قانون

\setcounter{equation}{13}

\begin{equation}\label{eq:lyap_tot}
\color{blue}{\boxed{\color{black}u=u_\theta-u_x}}
\end{equation}

\begin{english}
equation \ref{eq:lyap_tot} shows .....
\end{english}

المعادلة 
\ref{eq:lyap_tot} 
تبين أن ......

\end{document}

Result

enter image description here