1

I want to type Hebrew text in tikz.

EDIT: I am expanding the discussion about inserting the text into a rectangle of specific text width.

I tried the following code, after reading this answer and this one, yet I guess I am not using the text effect correctly.

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{tikz}
\usetikzlibrary{decorations.text} 
\usepackage{polyglossia}
\setmainlanguage{hebrew}
\setotherlanguage{english}
\newfontfamily\englishfont{Times New Roman}[Script=Latin,Language=English]
\newfontfamily\hebrewfont{Arial}[Script=Hebrew]

\begin{document} לורם איפסום \begin{center} \begin{tikzpicture} \node (hebrew-with-textwidth)[% color=red,% text width=3cm,% align=right,% decorate,% % {decoration={text effects={reverse text}}} % What is the correct syntax? ] {אחת שתיים שלוש ארבע חמש שש}; \end{tikzpicture} \end{center} \end{document}

I want the words in the node to be reversed, as here:

enter image description here

tush
  • 1,115
  • You specify decorate but don't really specify the decoration or the text that should be reversed. A decoration does decorate a path (the rectangular one from the node in this case), not the text of a node. If you want to use the decoration on text you need to use a horizontal line that is decorated like the linked answer showed. But this is a different thing that right-to-left text. If that should show up correctly, it needs another technic, one that would be independent from TikZ. – Qrrbrbirlbel Oct 18 '22 at 18:10
  • If you just want to type a word but reverse the order of the letters there should be better ways to do this in LaTeX without having to use TikZ. Can you tell us what you actually want/need? Why do you want to reverse letters of right-to-left text? – Qrrbrbirlbel Oct 18 '22 at 18:18
  • @qrrbrbirlbel I want to print a graphics with arrows circles etc. and some Hebrew text annotations on it. Above is just a MWE for a tikz graphics but I want to print such a graphics with tikz. – tush Oct 19 '22 at 05:48
  • @Qrrbrbirlbel Edited original question. – tush Oct 24 '22 at 11:37
  • I have the feeling that this question is not about decorations, since you want to place RTL text inside a node and not on a path. – Jasper Habicht Oct 25 '22 at 17:43
  • @JasperHabicht When I think about it perhaps you are correct. I want to type a "text box" and not print text along a curve. – tush Oct 25 '22 at 17:46
  • What would work is to explicitly tell LaTeX/TikZ that the text inside the node should be regarded as Hebrew using \node[...] {\texthebrew{אחת שתיים שלוש ארבע חמש שש}}. You should also be able to use the option font=\selectlanguage{hebrew} (for example, for the node). – Jasper Habicht Oct 25 '22 at 17:53

1 Answers1

1

For some reason (which I currently don't fully understand), you need to tell LaTeX explicitly that the text inside the node is to be regarded as Hebrew and hence to be typeset right-to-left. You can do this using \texthebrew inside the node or, which is maybe more elegant, using the option font=\selectlanguage{hebrew}:

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{tikz}
\usepackage{polyglossia}
\setmainlanguage{hebrew}
\setotherlanguage{english}
\newfontfamily\englishfont{Times New Roman}[Script=Latin,Language=English]
\newfontfamily\hebrewfont{Arial}[Script=Hebrew]

\begin{document} לורם איפסום \begin{center} \begin{tikzpicture}

\node (hebrew-with-textwidth) [% color=red,% text width=3cm,% align=right,% ] {\texthebrew{אחת שתיים שלוש ארבע חמש שש}};

\node (hebrew-with-textwidth) at (0,-1) [% color=red,% text width=3cm,% align=right,% font=\selectlanguage{hebrew} ] {אחת שתיים שלוש ארבע חמש שש};

\end{tikzpicture} \end{center} \end{document}

enter image description here

  • I am familiar with fontspec's language switch commands but never thought about your approach. +1. – tush Oct 25 '22 at 18:22
  • @tush I am actually unsure why this is. Some answers on this side suggest that the whole tikzpicture environment should be placed inside a LTR language scope, since otherwise things are not drawn or drawn differently. This is probably not needed anymore or a least not with your set-up, but maybe the above effect is still related. – Jasper Habicht Oct 25 '22 at 18:30