4

I'm facing a problem in writing Arabic words, letter, and numbers in TikZ figures. I'm using lualatex. Numbers are not typed in Arabic and words do not appear. Here is the code I'm using:

\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}
2
  • Welcome! I think TikZ is irrelevant and you would not get your text to show up anyway because you're not loading anything which can cope with Arabic text.
    – cfr
    May 10, 2016 at 23:59
  • Since you’re using luatex, you’ll want to look at the new package arabluatex.
    – Thérèse
    May 11, 2016 at 2:22

1 Answer 1

7

The first thing to note is that the problem really has nothing to do with TikZ. Consider

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

which produces a blank page when compiled with LuaLaTeX.

This is not surprising: the default configuration supports English and uses fonts with a limited range of characters, all Latin script.

To typeset Arabic, you need to configure support for it in your preamble.

So let's start with

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

Compilation fails with an error asking us to define a suitable font with \newfontfamily\arabicfont. So let's try that.

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

This goes better, but still not well. A warning message early in the transcript tells us that Arabic is not supported with LuaTeX. We need to use XeLaTeX rather than LuaLaTeX. Trying the compilation that way, we finally produce some output.

Arabic

Using Thérèse's suggestion we can improve this by adding [Script=Arabic] to the font definition for Arabic.

'shaped' Arabic

Since we want particular things in Arabic and not everything, let's set English as the main language and Arabic as a second language.

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

Arabic word

We could also use the Arabic environment for more extended passages of Arabic.

Minimising the original example a bit and integrating the configuration for Arabic, we can produce the required diagram. Obviously, this requires XeLaTeX to compile, as mentioned above.

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

Arabic in diagram

4
  • For correct Arabic shaping, add the option [Script=Arabic] to Amiri (or any other Arabic font you choose).
    – Thérèse
    May 11, 2016 at 2:20
  • @Thérèse Thanks. I wouldn't know. Isn't it odd that you need to do that? I realise the font supports Latin, too, but if that is always required for Arabic, why doesn't Polyglossia configure it?
    – cfr
    May 11, 2016 at 3:10
  • I don’t know — possibly because the same fonts can often be used for Urdu and other languages written with the same alphabet? But I’ve never looked at the inner workings of polyglossia.
    – Thérèse
    May 11, 2016 at 3:15
  • @Thérèse But you are specifying Arabic and it does configuration tailored to Arabic. If you were just loading fontspec, I could understand it. But, anyway, thanks for pointing it out. I know nothing about Arabic so no idea at all what it should look like.
    – cfr
    May 11, 2016 at 3:18

You must log in to answer this question.

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