4

I write a document with mixed languages having different writing direction. The main language is in left to right direction. I want to write a tree diagram in another language having right to left direction.

Firstly I try this:

\documentclass[a4paper,12pt,fleqn]{article}
\usepackage[no-math,quiet]{fontspec}
\setmainfont[Ligatures=TeX]{Linux Libertine O}
\newfontfamily\arabicfont[Script=Arabic,Mapping=arabicdigits]{Amiri}
\usepackage{tikz}
\usepackage[quiet]{polyglossia}
\setmainlanguage{bahasai} % Indonesian Language, Left to Right Direction
\setotherlanguage{arabic} % Arabic Language, Right to Left Direction
\begin{document}

\begin{Arabic}
لَاحِظِ الصُّوۡرَةَ الشَّجَرِيَّةَ التَّالِيَةَ:
\end{Arabic}

\begin{Arabic}
\begin{tikzpicture}
    [parent anchor=west,child anchor=east,grow=west,
     sibling distance=15mm, level distance=35mm
    ]
    \node {الۡأَصۡلُ}
        child {node {الۡفَرۡعُ الۡأَوَّلُ}}
        child {node {الۡفَرۡعُ الثَّانِيۡ}
            child {node {فَرۡعُ الۡفَرۡعِ الۡأَوَّلِ الۡأَوَّلُ}}
            child {node {فَرۡعُ الۡفَرۡعِ الۡأَوَّلِ الثَّانِيۡ}}
    };
\end{tikzpicture}
\end{Arabic}

\end{document}

and I get the text displayed in incorrect direction and the tikzpicture displayed in left to right direction. enter image description here

Secondly I try this

\documentclass[a4paper,12pt,fleqn]{article}
\usepackage[no-math,quiet]{fontspec}
\setmainfont[Ligatures=TeX]{Linux Libertine O}
\newfontfamily\arabicfont[Script=Arabic,Mapping=arabicdigits]{Amiri}
\usepackage{tikz}
\usepackage[quiet]{polyglossia}
\setmainlanguage{bahasai} % Indonesian Language, Left to Right Direction
\setotherlanguage{arabic} % Arabic Language, Right to Left Direction
\begin{document}

\begin{Arabic}
لَاحِظِ الصُّوۡرَةَ الشَّجَرِيَّةَ التَّالِيَةَ:
\end{Arabic}

\begin{tikzpicture}
    [parent anchor=west,child anchor=east,grow=west,
     sibling distance=15mm, level distance=35mm
    ]
\begin{Arabic}
    \node {الۡأَصۡلُ}
        child {node {الۡفَرۡعُ الۡأَوَّلُ}}
        child {node {الۡفَرۡعُ الثَّانِيۡ}
            child {node {فَرۡعُ الۡفَرۡعِ الۡأَوَّلِ الۡأَوَّلُ}}
            child {node {فَرۡعُ الۡفَرۡعِ الۡأَوَّلِ الثَّانِيۡ}}
    };
\end{Arabic}
\end{tikzpicture}

\end{document}

and I get the same result as above.

Thirdly I try this

\documentclass[a4paper,12pt,fleqn]{article}
\usepackage[no-math,quiet]{fontspec}
\setmainfont[Ligatures=TeX]{Linux Libertine O}
\newfontfamily\arabicfont[Script=Arabic,Mapping=arabicdigits]{Amiri}
\usepackage{tikz}
\usepackage[quiet]{polyglossia}
\setmainlanguage{bahasai} % Indonesian Language, Left to Right Direction
\setotherlanguage{arabic} % Arabic Language, Right to Left Direction
\begin{document}

\begin{Arabic}
لَاحِظِ الصُّوۡرَةَ الشَّجَرِيَّةَ التَّالِيَةَ:
\end{Arabic}

\begin{Arabic}
\begin{tikzpicture}
    [parent anchor=west,child anchor=east,grow=west,
     sibling distance=15mm, level distance=35mm
    ]
    \node {\RL{الۡأَصۡلُ}}
        child {node {\RL{الۡفَرۡعُ الۡأَوَّلُ}}}
        child {node {\RL{الۡفَرۡعُ الثَّانِيۡ}}
            child {node {\RL{فَرۡعُ الۡفَرۡعِ الۡأَوَّلِ الۡأَوَّلُ}}}
            child {node {\RL{فَرۡعُ الۡفَرۡعِ الۡأَوَّلِ الثَّانِيۡ}}}
    };
\end{tikzpicture}
\end{Arabic}

\end{document}

I get the text displayed in correct direction but the tikzpicture is still displayed in left to right direction. enter image description here

Lastly I try just for a testing to change the default language the language with Right to Left Direction:

\documentclass[a4paper,12pt,fleqn]{article}
\usepackage[no-math,quiet]{fontspec}
\setmainfont[Ligatures=TeX]{Linux Libertine O}
\newfontfamily\arabicfont[Script=Arabic,Mapping=arabicdigits]{Amiri}
\usepackage{tikz}
\usepackage[quiet]{polyglossia}
\setmainlanguage{arabic} % Arabic Language, Right to Left Direction
\setotherlanguage{bahasai} % Indonesian Language, Left to Right Direction
\begin{document}

لَاحِظِ الصُّوۡرَةَ الشَّجَرِيَّةَ التَّالِيَةَ:

\begin{tikzpicture}
    [parent anchor=west,child anchor=east,grow=west,
     sibling distance=15mm, level distance=35mm
    ]
    \node {الۡأَصۡلُ}
        child {node {الۡفَرۡعُ الۡأَوَّلُ}}
        child {node {الۡفَرۡعُ الثَّانِيۡ}
            child {node {فَرۡعُ الۡفَرۡعِ الۡأَوَّلِ الۡأَوَّلُ}}
            child {node {فَرۡعُ الۡفَرۡعِ الۡأَوَّلِ الثَّانِيۡ}}
    };
\end{tikzpicture}

\end{document}

and I get surprisedly the text and the tikzpicture environment both are displayed incorectly similar with the result of the first and second testing.

Is there any solution so I can get both of the text and the tikzpicture environment displayed in Right to Left Direction? Thanks.

2
  • 1
    Perhaps: \begin{tikzpicture}[xscale=-1] ... \end{tikzpicture}.
    – AlexG
    Oct 27 '15 at 11:11
  • I try to implement it in the third test, but the tree become from the top to bottom (vertical tree?). I want to get the list from right to the left (horizontal tree?). Anyway thanks. Oct 28 '15 at 8:50
4

Arabic nodes in TikZ picture

You may define a arabic node TikZ style:

\tikzset{
  arabic node/.style={
    execute at begin node={\Arabic},
    execute at end node={\endArabic},
  },
}

Completed example:

\documentclass[a4paper,12pt,fleqn]{article}
\usepackage[no-math,quiet]{fontspec}
\setmainfont[Ligatures=TeX]{Linux Libertine O}
\newfontfamily\arabicfont[Script=Arabic,Mapping=arabicdigits]{Amiri}
\usepackage{tikz}
\usepackage[quiet]{polyglossia}
\setmainlanguage{bahasai} % Indonesian Language, Left to Right Direction
\setotherlanguage{arabic} % Arabic Language, Right to Left Direction

\tikzset{
  arabic node/.style={
    execute at begin node={\Arabic},
    execute at end node={\endArabic},
  },
}

\begin{document}

\begin{Arabic}
لَاحِظِ الصُّوۡرَةَ الشَّجَرِيَّةَ التَّالِيَةَ:
\end{Arabic}

\begin{tikzpicture}
    [parent anchor=west,child anchor=east,grow=west,
     sibling distance=15mm, level distance=35mm
    ]
    \node[arabic node] {الۡأَصۡلُ}
        child {node[arabic node] {الۡفَرۡعُ الۡأَوَّلُ}}
        child {node[arabic node] {الۡفَرۡعُ الثَّانِيۡ}
            child {node[arabic node] {فَرۡعُ الۡفَرۡعِ الۡأَوَّلِ الۡأَوَّلُ}}
            child {node[arabic node] {فَرۡعُ الۡفَرۡعِ الۡأَوَّلِ الثَّانِيۡ}}
    };
\end{tikzpicture}

\end{document}

Bug with tikzpicture in RTL/LTR environment

About the tikzpicture environment displayed in right to left direction, it seems that the RTL/LTR mechanisms of XeTeX breaks the tikzpicture environment (a kind of bug...). The following document changes when you uncomment the arabic other language:

\documentclass[11pt,a4paper]{article}
\usepackage[no-math,quiet]{fontspec}
\setmainfont[Ligatures=TeX]{Linux Libertine O}
\newfontfamily\arabicfont[Script=Arabic,Mapping=arabicdigits]{Amiri}
\usepackage{tikz}
\usepackage[quiet]{polyglossia}
\setmainlanguage{english}
%\setotherlanguage{arabic} % Arabic Language, Right to Left Direction
\begin{document}
A
\begin{tikzpicture}
\fill[cyan] (0,0) rectangle (2,1);
\end{tikzpicture}
B
\end{document}

Workaround

As workaround, you may put your tikzpicture in a box (via \makebox):

\documentclass[a4paper,12pt,fleqn]{article}
\usepackage[no-math,quiet]{fontspec}
\setmainfont[Ligatures=TeX]{Linux Libertine O}
\newfontfamily\arabicfont[Script=Arabic,Mapping=arabicdigits]{Amiri}
\usepackage{tikz}
\usepackage[quiet]{polyglossia}
\setmainlanguage{bahasai} % Indonesian Language, Left to Right Direction
\setotherlanguage{arabic} % Arabic Language, Right to Left Direction

\tikzset{
  arabic node/.style={
    execute at begin node={\Arabic},
    execute at end node={\endArabic},
  },
}

\begin{document}

\begin{Arabic}
لَاحِظِ الصُّوۡرَةَ الشَّجَرِيَّةَ التَّالِيَةَ:

\makebox{\begin{tikzpicture}
    [parent anchor=west,child anchor=east,grow=west,
     sibling distance=15mm, level distance=35mm
    ]
    \node[arabic node] {الۡأَصۡلُ}
        child {node[arabic node] {الۡفَرۡعُ الۡأَوَّلُ}}
        child {node[arabic node] {الۡفَرۡعُ الثَّانِيۡ}
            child {node[arabic node] {فَرۡعُ الۡفَرۡعِ الۡأَوَّلِ الۡأَوَّلُ}}
            child {node[arabic node] {فَرۡعُ الۡفَرۡعِ الۡأَوَّلِ الثَّانِيۡ}}
    };
\end{tikzpicture}}
\end{Arabic}

\end{document}
7
  • 1
    \begin{tikzpicture}[xscale=-1] ... \end{tikzpicture}, I guess.
    – AlexG
    Oct 27 '15 at 11:12
  • So it is saver to put tikzpicture outside RTL enviroment and align it using centering or maybe raggedleft command? Oct 28 '15 at 9:03
  • After those tests I also try to use pst-tree. When I put the pst-tree in an Arabic environment it display as I need i.e. in Right to Left Direction and the text also displayed correctly, but there is another problem, the connector line between node is lost. I'm sorry I'm not sure it is better to put this in a new question or just to put it here and it is just for my test. Oct 28 '15 at 9:13
  • The bug you are referring to in your answer has been fixed in version 18.3 of the bidi package.
    – user91727
    Nov 13 '15 at 15:27
  • @user91727 I tried version 19 of the bidi package... without success (the bug is already present). Dec 1 '15 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.