I am trying to use the following chapter style for Arabic language. My following code works perfectly for English only, and produced the following output.
However, when I include polyglossia and enable Arabic language I receive errors:
- Package polyglossia Error: The current roman font does not contain the Arabic(polyglossia) Please define \arabicfont with \newfontfamily. \chapter{عنوان تجريبي}
- Package graphics Error: Division by 0. \chapter{عنوان تجريبي}
MWE:
\documentclass{memoir}
%------------- CHAPTER STYLE <START>
\usepackage{color,calc,graphicx,soul,fourier}
\definecolor{nicered}{rgb}{.647,.129,.149}
\makeatletter
\newlength\dlf@normtxtw
\setlength\dlf@normtxtw{\textwidth}
\def\myhelvetfont{\def\sfdefault{mdput}}
\newsavebox{\feline@chapter}
\newcommand\feline@chapter@marker[1][4cm]{%
\sbox\feline@chapter{%
\resizebox{!}{#1}{\fboxsep=1pt%
\colorbox{nicered}{\color{white}\bfseries\sffamily\thechapter}%
}}%
\rotatebox{90}{%
\resizebox{%
\heightof{\usebox{\feline@chapter}}+\depthof{\usebox{\feline@chapter}}}%
{!}{\scshape\so\@chapapp}}\quad%
\raisebox{\depthof{\usebox{\feline@chapter}}}{\usebox{\feline@chapter}}%
}
\newcommand\feline@chm[1][4cm]{%
\sbox\feline@chapter{\feline@chapter@marker[#1]}%
\makebox[0pt][l]{% aka \rlap
\makebox[1cm][r]{\usebox\feline@chapter}%
}}
\makechapterstyle{daleif1}{
\renewcommand\chapnamefont{\normalfont\Large\scshape\raggedleft\so}
\renewcommand\chaptitlefont{\normalfont\huge\bfseries\scshape\color{nicered}}
\renewcommand\chapternamenum{}
\renewcommand\printchaptername{}
\renewcommand\printchapternum{\null\hfill\feline@chm[2.5cm]\par}
\renewcommand\afterchapternum{\par\vskip\midchapskip}
\renewcommand\printchaptertitle[1]{\chaptitlefont\raggedleft ##1\par}
}
\makeatother
%------------- CHAPTER STYLE <END>
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage{arabic}
\setdefaultlanguage{arabic}
\setotherlanguage{english}
\newfontfamily\englishfont{Calibri}
\newfontfamily\arabicfont[Script=Arabic,Mapping=arabicdigits]{Simplified Arabic}
\begin{document}
\chapterstyle{daleif1}
%\chapter{A Test Chapter In English}
%It works for English (without polyglossia ). However, if I enable Arabic Language it will not work.
\chapter{عنوان تجريبي}
\end{document}
UPDATE:: I have tried an answer which made it show up. However, There are still two issues: 1. The spacing for the number in the red box is not the same as for English (I mean left right upper bottom margins) 2. When I add appendices the red box appear in different sizes.
Below is the new code and illustration of the new issues:
\documentclass{memoir}
%------------- CHAPTER STYLE <START>
\usepackage{color,calc,graphicx,soul,fourier}
\definecolor{nicered}{rgb}{.647,.129,.149}
\makeatletter
\newlength\dlf@normtxtw
\setlength\dlf@normtxtw{\textwidth}
\def\myhelvetfont{\def\sfdefault{mdput}}
\newsavebox{\feline@chapter}
\newcommand\feline@chapter@marker[1][4cm]{%
\sbox\feline@chapter{%
\resizebox{!}{#1}{\fboxsep=1pt%
\colorbox{nicered}{\color{white}\bfseries\sffamily\thechapter}%
}}%
\rotatebox{90}{%
\resizebox{%
\heightof{\usebox{\feline@chapter}}+\depthof{\usebox{\feline@chapter}}}%
{!}{\@chapapp}}\quad%
\raisebox{\depthof{\usebox{\feline@chapter}}}{\usebox{\feline@chapter}}%
}
\newcommand\feline@chm[1][4cm]{%
\sbox\feline@chapter{\feline@chapter@marker[#1]}%
\makebox[0pt][l]{% aka \rlap
\makebox[1cm][r]{\usebox\feline@chapter}%
}}
\makechapterstyle{daleif1}{
\renewcommand\chapnamefont{\normalfont\Large\scshape\raggedleft\so}
\renewcommand\chaptitlefont{\normalfont\huge\bfseries\scshape\color{nicered}}
\renewcommand\chapternamenum{}
\renewcommand\printchaptername{}
\renewcommand\printchapternum{\null\hfill\feline@chm[2.5cm]\par}
\renewcommand\afterchapternum{\par\vskip\midchapskip}
\renewcommand\printchaptertitle[1]{\chaptitlefont\raggedleft ##1\par}
}
\makeatother
%------------- CHAPTER STYLE <END>
\usepackage{fontspec}
\newfontfamily\englishfont{Calibri}
\newfontfamily\arabicfont[Script=Arabic,Mapping=arabicdigits]{Simplified Arabic}
\newfontfamily\arabicfontsf[Script=Arabic,Mapping=arabicdigits]{Simplified Arabic}
\usepackage{polyglossia}
\setmainlanguage{arabic}
\setdefaultlanguage{arabic}
\setotherlanguage{english}
\newcommand\letters[1]{\expandafter\xletters\csname c@#1\endcsname}
\def\xletters#1{\ifcase#1\or
أ\or
ب\or
ج\or
د\or
\else
أحتاج إلى المزيد من ترقيمات الأبواب بالحروف في ملف arbbook.cls\fi}
\def\thepage{\letters{page}}
\begin{document}
\chapterstyle{daleif1}
\mainmatter
\chapter{عنوان تجريبي}
\appendix
\renewcommand{\thechapter}{\letters{chapter}}
\chapter{تجريبي}
\chapter{تجريبي}
\chapter{تجريبي}
\end{document}
\setsansfont{<Some Arabic Font>}
after\usepackage{fontspec}