1

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. enter image description here

However, when I include polyglossia and enable Arabic language I receive errors:

  1. Package polyglossia Error: The current roman font does not contain the Arabic(polyglossia) Please define \arabicfont with \newfontfamily. \chapter{عنوان تجريبي}
  2. 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}

ISSUE 1: enter image description here

ISSUE 2: enter image description here

2
  • try to add \setsansfont{<Some Arabic Font>} after \usepackage{fontspec}
    – touhami
    Mar 26, 2018 at 17:36
  • I tried it and it did not work Mar 26, 2018 at 17:52

1 Answer 1

2
+50

You have to define a serif and a non-serif font before you invoke polyglossia. Further, you want to get rid of \scshape\so in the chapterstyle since it doesn't have any meaning in Arabic.

Then it compiles like a charm.

\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}


\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}

Compiled document


Update

To the first issue: You have to align the chapter number in the middle with the fboxsep set to zero for the colorbox and an adjustbox with a cframe around.

\documentclass{memoir}

%------------- CHAPTER STYLE <START>
\usepackage{color,calc,graphicx,soul,fourier,adjustbox}  
\definecolor{nicered}{rgb}{.647,.129,.149}  
\makeatletter  
\newlength\dlf@normtxtw  
\setlength\dlf@normtxtw{\textwidth}  
\newsavebox{\feline@chapter}  
\newcommand\feline@chapter@marker[1][4cm]{%  
    \sbox\feline@chapter{%  
        \setlength{\fboxsep}{0pt}\adjustbox{cframe=nicered 10pt 0pt}{\resizebox{!}{#1}{\colorbox{nicered}{\color{white}\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\raggedleft\so}  
    \renewcommand\chaptitlefont{\normalfont\huge\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}
\usepackage{polyglossia}
\setmainlanguage{arabic}
\setdefaultlanguage{arabic}
%\setotherlanguage{english}

\begin{document}

\chapterstyle{daleif1}                          
\mainmatter

\chapter{عنوان تجريبي}

\end{document}

Compiled document

For the second "issue": it is not an issue actually, it is perfecly normal. The red box is around the chapter number, if the chapter number is more long than large, so will be the box and vice versa. In latin scripts, numbers and capital characters have regular sizes, this is not the case in arabic. This chapter style is for latin script and was not designed for arabic script: it is totally normal, that it looks weird then. You should consider switching to a chapter style designed for arabic script or write your own.

5
  • Thank you for your answer, I tried your answer it works but still there are two issues, I have updated it in the question. Mar 27, 2018 at 19:48
  • You should consider writing a new question for your new issues. Mar 27, 2018 at 21:08
  • An answer is considered an answer if it provided a correct output. Mar 27, 2018 at 22:39
  • Thanks for the update, I have accepted the answer and rewarded the bounty. However, you think it is possible to make all red boxes the same size? Mar 28, 2018 at 13:49
  • It is possible, but you have to consider that in order for TeX to fit the character in the box, it will have to scale it to the size of the box (which will look weird: ١ , ج and ب will be huge, أ and any higher number bigger than 9 pretty small). Alternatively, you could make a big box that could fit the biggest character and don't scale, but then the boxe would look empty when only a small ١ is in it. Mar 28, 2018 at 16:04

You must log in to answer this question.

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