我希望能够用polyglossia
阿拉伯语和英语书写以下代码漂亮的部分样式
它编译时没有错误,但输出没有显示任何阿拉伯语。
\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}
答案1
不兼容问题出在soul
软件包上,软件包会将字体切换为传统的 8 位打字机字体。它也不支持 Unicode。下面是一个将其替换为的示例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}