TikZ 图形中书写阿拉伯语单词和字母的问题

TikZ 图形中书写阿拉伯语单词和字母的问题

我在 TikZ 图形中输入阿拉伯语单词、字母和数字时遇到问题。我正在使用 lualatex。阿拉伯语中没有输入数字,也没有出现单词。这是我使用的代码:

\documentclass[tikz, border=12]{standalone}
\usepackage{stix, tikz, tkz-euclide}
\usetikzlibrary
    {
     decorations.markings, arrows, arrows.meta, angles,
     quotes
    }
\usetkzobj{all}
%%
%%Define style's
\tikzstyle{generic} = [thick,>={Stealth[scale=1.2]}]
\newcommand*{\TickSize}{2pt}%
%Colors
\definecolor{red}{RGB}{255,0,0}
\definecolor{blue}{RGB}{0,51,255}
\definecolor{green}{RGB}{0,153,0}

\begin{document}
\begin{tikzpicture}[generic]

\draw[gray!50,thin] ({-1*(8)},{-1*(8)}) grid ({8},{8});
\draw [<->] ({-1*(8)},0) -- ({8},0);% x-axis
\draw [<->] (0,{-1*(8)}) -- (0,{8});% y-axis
%%% x-axis numbers%%%%
\foreach \x in {-7,-6,...,-1} {%
    \draw   ($(\x,0) + (0,\TickSize)$)--($(\x,0) + (0,-\TickSize)$)
        node [below] {$\x$};
}
\foreach \x in {1,2,...,7} {%
     \draw   ($(\x,0) + (0,\TickSize)$)--($(\x,0) + (0,-\TickSize)$)
        node [below] {$\x$};
}
%%%%%%
%%% y-axis numbers%%%%
\foreach \y in {-7,-6,...,-1} {%
    \draw  ($(0,\y) + (\TickSize,0)$)--($(0,\y) + (-\TickSize,0)$)
        node [left] {$\y$};
}
\foreach \y in {1,2,...,7} {%
    \draw  ($(0,\y) + (\TickSize,0)$)--($(0,\y) + (-\TickSize,0)$)
        node [left] {$\y$};
}
%%%%%%%

\path (7,0)--(8,0) node[midway,above,above=2mm,font=\large]{س};
\path (0,7)--(0,8) node[midway,right, right=2mm,font=\large]{ص};

\coordinate (a) at (-6, -2); 
\coordinate (b) at (-3, 5); 
\coordinate (c) at (4, 2); 

\coordinate (x) at  ($(a)!0.5!(b)$);
\node at  ($(c)!-0.3cm!(x)$){المنزل};

\coordinate (y) at  ($(b)!0.5!(c)$);
\node at  ($(a)!-0.3cm!(y)$){العمل};

\coordinate (z) at  ($(c)!0.5!(a)$);
\node at  ($(b)!-0.3cm!(z)$){العائلة};
\draw[ thick, blue] (a)--(b)--(c)--cycle;

\end{tikzpicture}
\end{document}

答案1

首先要注意的是,这个问题实际上与 TikZ 无关。考虑

\documentclass{article}
\begin{document}
  العائلة
\end{document}

使用 LuaLaTeX 编译时会产生空白页。

这并不奇怪:默认配置支持英语并使用字符范围有限的字体,全部是拉丁文字。

要排版阿拉伯语,您需要在序言中配置对它的支持。

那么让我们开始吧

\documentclass{article}
\usepackage{polyglossia}
\setmainlanguage{arabic}
\begin{document}
  العائلة
\end{document}

编译失败,并出现错误,要求我们用 定义合适的字体\newfontfamily\arabicfont。所以让我们尝试一下。

\documentclass{article}
\usepackage{polyglossia}
\setmainlanguage{arabic}
\newfontfamily\arabicfont{Amiri}
\begin{document}
  العائلة
\end{document}

情况有所好转,但仍然不够好。转录文本开头的一条警告消息告诉我们,LuaTeX 不支持阿拉伯语。我们需要使用 XeLaTeX 而不是 LuaLaTeX。尝试以这种方式进行编译,我们最终得到了一些输出。

阿拉伯

使用特蕾莎的建议我们可以通过添加[Script=Arabic]阿拉伯语的字体定义来改进这一点。

‘形’阿拉伯语

因为我们想要阿拉伯语中的特定内容而不是所有内容,所以我们将英语设置为主要语言,将阿拉伯语设置为第二语言。

\documentclass{article}
\usepackage{polyglossia}
\setmainlanguage[variant=british]{english}
\setotherlanguage{arabic}
\newfontfamily\arabicfont{Amiri}[Script=Arabic]
\begin{document}
  \textarabic{العائلة}
\end{document}

阿拉伯语单词

我们还可以利用这个Arabic环境来扩展阿拉伯语的段落。

将原始示例稍微简化一下,并整合阿拉伯语的配置,我们可以生成所需的图表。显然,这需要 XeLaTeX 进行编译,如上所述。

\documentclass[tikz, border=5pt, multi]{standalone}
\usepackage{polyglossia}
\setmainlanguage[variant=british]{english}
\setotherlanguage{arabic}
\newfontfamily\arabicfont{Amiri}[Script=Arabic]
\usetikzlibrary{arrows.meta,calc}
\tikzset{% \tikzstyle is deprecated
  generic/.style = {thick, >={Stealth[scale=1.2]}},
}
\newcommand*{\TickSize}{2pt}
% don't overwrite the standard colour
\definecolor{myblue}{RGB}{0,51,255}
\begin{document}
\begin{tikzpicture}[generic]
  \draw [gray!50, thin] ({-1*(8)},{-1*(8)}) grid ({8},{8});
  \draw [<->] ({-1*(8)},0) -- ({8},0);
  \draw [<->] (0,{-1*(8)}) -- (0,{8});
  \foreach \i in {-7,...,-1,1,2,...,7} {%
    \draw   ($(\i,0) + (0,\TickSize)$)--($(\i,0) + (0,-\TickSize)$) node [below] {$\i$};
    \draw  ($(0,\i) + (\TickSize,0)$)--($(0,\i) + (-\TickSize,0)$) node [left] {$\i$};
  }
  \path (7,0)--(8,0) node [midway,above,above=2mm,font=\large] {\textarabic{س}};
  \path (0,7)--(0,8) node [midway,right, right=2mm,font=\large] {\textarabic{ص}};
  \coordinate (a) at (-6, -2);
  \coordinate (b) at (-3, 5);
  \coordinate (c) at (4, 2);
  \coordinate (x) at  ($(a)!0.5!(b)$);
  \node at  ($(c)!-0.3cm!(x)$) {\textarabic{المنزل}};
  \coordinate (y) at  ($(b)!0.5!(c)$);
  \node at  ($(a)!-0.3cm!(y)$) {\textarabic{العمل}};
  \coordinate (z) at  ($(c)!0.5!(a)$);
  \node at  ($(b)!-0.3cm!(z)$) {\textarabic{العائلة}};
  \draw [ thick, myblue] (a)--(b)--(c)--cycle;
\end{tikzpicture}
\end{document}

图中阿拉伯语

相关内容