使用 Polyglossia 软件包处理阿拉伯语时出现章节样式错误

使用 Polyglossia 软件包处理阿拉伯语时出现章节样式错误

我正在尝试将以下章节样式用于阿拉伯语。我的以下代码仅适用于英语,并产生以下输出。 在此处输入图片描述

但是,当我包含多语言并启用阿拉伯语时,我收到错误:

  1. 软件包 polyglossia 错误:当前罗马字体不包含阿拉伯语(polyglossia) 请使用 \newfontfamily 定义 \arabicfont。\chapter{عنوان تجريبي}
  2. 包图形错误:除以 0。\chapter{عنوان تجريبي}

梅威瑟:

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

更新:我尝试了一个让它显示的答案。但是,仍然有两个问题:1. 红框中的数字间距与英语不同(我的意思是左右上下边距)2. 当我添加附录时,红框显示的大小不同。

以下是新代码及新问题的说明:

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

问题 1: 在此处输入图片描述

问题 2: 在此处输入图片描述

答案1

你必须定义一个衬线无衬线字体您调用了多语制。此外,您想要在章节样式中删除它,\scshape\so因为它在阿拉伯语中没有任何意义。

然后它就像魔法一样编译完成。

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

编译文件


更新

对于第一期:您必须将中间的章节号与fboxsep设置为零的对齐colorbox,并将周围adjustbox对齐cframe

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

编译文件

对于第二个“问题”:这实际上不是一个问题,这是完全正常的。红色框围绕着章节号,如果章节号较长,框也会较长,反之亦然。在拉丁文中,数字和大写字母具有常规大小,但在阿拉伯文中并非如此。此章节样式适用于拉丁文,并非为阿拉伯文设计:因此看起来很奇怪是完全正常的。您应该考虑切换到为阿拉伯文设计的章节样式或编写自己的样式。

相关内容