3

My code

\documentclass{exam}

\pagestyle{headandfoot}
\firstpageheader{\bfseries\large رياضيات\\مأمون }{\includegraphics{example-image}}{\bfseries\large الإمتحان الأول }

\begin{document}
مرحبا كيف حالكم, جزاكم الله كل خير 

\begin{table}
    \begin{tabular}{lllll}
        الوحدة & فصول الوحدة & عدد الحصص & الفترة الزمنية & الوسائل المقترحة\\
    \end{tabular} 
\end{table}

\end{document}

All these codes didn't work.

\usepackage{polyglossia}
\setmainlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}
\newfontfamily\arabicfont[Script=Arabic,Scale=1.1,AutoFakeSlant=-0.03]{Amiri}
\setsansfont[Script=Arabic,Scale=1.1]{Amiri}
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{arabic}
\newfontfamily\arabicfont[Script = Arabic]{Simplified Arabic}
\usepackage{sexam} % wexam & sexam package
%\setdefaultlanguage[calendar=gregorian,,locale=algeria]{arabic} % on sexam.sty
%\newfontfamily\arabicfont[Script=Arabic,Scale=1.1]{Amiri}% on sexam.sty
%\newfontfamily\arabicfontsf[Script=Arabic,Scale=1.2]{Aljazeera}% on sexam.sty
%\newfontfamily\arabicfonttt[Script=Arabic,Scale=1.1]{Simplified Arabic} % on sexam.sty

2 Answers 2

3

LuaLaTeX requires the HarfBuzz renderer to show complex scripts with combining characters, but selects the old renderer by default. This appeared to work for me (although I don’t know Arabic and apologize if the text is wrong)

\documentclass{exam}
\usepackage{polyglossia}
\setmainlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}
\newfontfamily\arabicfont{Amiri}[
  Script=Arabic,
  Scale=MatchLowercase,
  AutoFakeSlant=-0.03, % Are you sure?
  Renderer=HarfBuzz ]

\pagestyle{headandfoot}
\firstpageheader{\bfseries\large رياضيات\\مأمون }{}{\bfseries\large الإمتحان الأول }

\begin{document}
مرحبا كيف حالكم, جزاكم الله كل خير 
\end{document}

It would also be possible to use babel. This MWE loads Khaled Hosny’s Libertinus fonts, including Libertinus Math, as companions for his Amiri font.

\documentclass{exam}
\usepackage[bidi=basic,layout=sectioning.tabular,english]{babel}
\usepackage{unicode-math}

\babelprovide[import,main]{arabic} % You might select a variant here.

\defaultfontfeatures{ Scale=MatchLowercase, Ligatures=TeX, Renderer=Harfbuzz }
\babelfont{rm}
          [Scale=1.0, Ligatures={Common,Discretionary}]{Libertinus Serif}
\babelfont[arabic]{rm}
          {Amiri} % Might want to load a stylistic set or activate font features.
\babelfont{sf}
          [Ligatures={Common,Discretionary}]{Libertinus Sans}
% Load a sans-serif Arabic font here if needed, for example Noto Sans Arabic.
\babelfont{tt}
          {Libertinus Mono}
\babelfont[arabic]{tt}
          {ALM Fixed}
\setmathfont{Libertinus Math}

\babeltags{Arabic=arabic} % Enable \Arabic, \textArabic, etc.
\babeltags{english=english}

\pagestyle{headandfoot}
\firstpageheader{\bfseries\large رياضيات\\مأمون }{}{\bfseries\large الإمتحان الأول }

\begin{document}
    \begin{tabular}{lllll}
    الوحدة & فصول الوحدة & عدد الحصص & الفترة الزمنية & الوسائل المقترحة
    \end{tabular}  
\end{document}

If you only use English for short phrases within an Arabic document, you could remove the english option from babel and add \babelprovide[onchar=ids fonts]{english} to auto-detect the language being used and switch fonts automatically.

14
  • 1
    thanks first of all. in the second code, I couldn't write inside a table environment . Oct 20, 2020 at 21:16
  • 1
    @MamounMohammed Does explicit tagging with \textenglish and \textArabic help?
    – Davislor
    Oct 20, 2020 at 22:24
  • 1
    I got it by this code, to change columns order \newcommand{\abcdresults}[5]{ #1 & #2 & #3 & #4 & #5 \\} \begin{tabular}{lllll} \abcdresults{a}{b}{c}{d}{f} \abcdresults{2.33}{4.55}{5.66}{7.88}{4} \abcdresults{3.44}{5.66}{6.77}{9.00}{4} \end{tabular} Oct 22, 2020 at 14:46
  • 1
    @MamounMohammed This would be good as a new question.
    – Davislor
    Oct 22, 2020 at 15:11
  • 2
    @MamounMohammed You may need layout=sectioning.tabular instead of just layout=sectioning. Oct 27, 2020 at 8:12
2

One way to do it would be to use fontspec and polyglossia as you did in some of your code snippets. (Since you tried those already, I am guessing you are building the document with LuaLaTeX, not pdfLaTeX.)

If you want to know in detail how you can use polyglossia to activate multiple languages and switch between them, I recommend you have a look in the polyglossia manual. Here is one example (I just used Amiri as an arabic font because I had it installed already):

\documentclass{exam}
\usepackage{fontspec}
\usepackage{polyglossia}

\setdefaultlanguage{english}
\setotherlanguage{arabic}

\newfontfamily\arabicfont{Amiri}

\usepackage{graphicx}

\pagestyle{headandfoot}
\firstpageheader{\bfseries\large \textarabic{رياضيات\\مأمون}}{\includegraphics{example-image}}{\bfseries\large \textarabic{الإمتحان الأول}}

\begin{document}
\textarabic{مرحبا كيف حالكم, جزاكم الله كل خير }
\end{document}

Which gives this output:

enter image description here

If you want to mainly use arabic in your document, you should probably use \setdefaultlanguage{arabic}. Then you don't need to put \textarabic{...} around every arabic text.

You must log in to answer this question.

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