1

I would like to use polyglossia to be able to write in arabic and english on the following code beautiful section styles

It compiles without errors, but the output doesn't show any Arabic language.

enter image description here

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage[explicit]{titlesec}
\usepackage{soul}

\definecolor{titleblue}{HTML}{4a7aa4}

\title{Probability}
\author{Educ}
\date{\today}

\newbox\TitleUnderlineTestBox
\newcommand*\TitleUnderline[1]
  {%
    \bgroup
    \setbox\TitleUnderlineTestBox\hbox{\colorbox{titleblue}\strut}%
    \setul{\dimexpr\dp\TitleUnderlineTestBox-.3ex\relax}{.3ex}%
    \ul{#1}%
    \egroup
  }
\newcommand*\SectionNumberBox[1]
  {%
    \colorbox{titleblue}
      {%
        \makebox[2.5em][c]
          {%
            \color{white}%
            \strut
            \csname the#1\endcsname
          }%
      }%
    \TitleUnderline{\ \ \ }%
  }
\titleformat{\section}
  {\Large\bfseries\sffamily\color{titleblue}}
  {\SectionNumberBox{section}}
  {0pt}
  {\TitleUnderline{#1}}
\titleformat{\subsection}
  {\large\bfseries\sffamily\color{titleblue}}
  {\SectionNumberBox{subsection}}
  {0pt}
  {\TitleUnderline{#1}}

\usepackage{polyglossia}
\setmainlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}
\newfontfamily\arabicfont[Script=Arabic,Scale=1.2,AutoFakeSlant=-0.02]{Traditional Arabic}
\setsansfont[Script=Arabic,Scale=1.5]{Traditional Arabic}

\begin{document}

\maketitle

\newpage
\chapter{الاحتمالات}
\section{الاحتمالات الحزء الاول }
\subsection{الاحتمالات الحزء الاول}
\subsection{الاحتمالات الحزء الاول}
\section{الاحتمالات الحزء الاول الاحتمالات الحزء الاول}

\section
  {الاحتمالات الحزء الاول and text in English }

\end{document}
azetina
  • 28,884
Educ
  • 4,362
  • 3
    Doesn't work is a pretty bad description of your problem. Does it throw compile errors (if yes, which)? Or is the output unpleasant? – TeXnician Jul 04 '18 at 07:46
  • 1
    To maybe state the obvious, if you delete all the code for the fancy sectioning and then run it, the arabic appears in the sections. So the issue is in the section style code. – AML Jul 05 '18 at 14:47
  • The soul use a font which do not contain arabic script. – Salim Bou Jul 18 '18 at 12:40

1 Answers1

2

The incompatibility was with the soul package, which switches the font to a legacy 8-bit typewriter-style font. It also does not support Unicode. Here is an example that replaces it with ulem:

\documentclass{article}
% To fit within the allowed image size on TeX.SX:
\usepackage[margin=1in]{geometry}
\usepackage{xcolor}
\usepackage[explicit]{titlesec}
\usepackage{ulem}

\definecolor{titleblue}{HTML}{4a7aa4}

\title{\textenglish{Probability}}
\author{\textenglish{Educ}}
\date{\today}

\newbox\TitleUnderlineTestBox
\newcommand\TitleUnderline{\bgroup\markoverwith{%
  \textcolor{titleblue}{\rule[-1.3ex]{2pt}{1.0pt}}}\ULon}
\newcommand*\SectionNumberBox[1]
  {%
    \colorbox{titleblue}
      {%
        \makebox[2.5em][c]
          {%
            \color{white}%
            \strut
            \csname the#1\endcsname
          }%
      }%
    \TitleUnderline{\ \ \ }%
  }
\titleformat{\section}
  {\Large\bfseries\sffamily\color{titleblue}}
  {\SectionNumberBox{section}}
  {0pt}
  {\TitleUnderline{#1}}
\titleformat{\subsection}
  {\large\bfseries\sffamily\color{titleblue}}
  {\SectionNumberBox{subsection}}
  {0pt}
  {\TitleUnderline{#1}}

\usepackage{polyglossia}
\setmainlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}
\setmainfont{Latin Modern Roman}
\setsansfont{Latin Modern Sans}
\newfontfamily\arabicfont[Script=Arabic]{Noto Naskh Arabic}
\newfontfamily\arabicfontsf[Script=Arabic]{Noto Sans Arabic}

\begin{document}

\maketitle

\newpage
\chapter{الاحتمالات}
\section{الاحتمالات الحزء الاول }
\subsection{الاحتمالات الحزء الاول}
\subsection{الاحتمالات الحزء الاول}
\section{الاحتمالات الحزء الاول الاحتمالات الحزء الاول}

\section
الاحتمالات الحزء الاول \\
\textenglish{and text in English}

\end{document}

Noto Arabic sample

Davislor
  • 44,045