1

The following code produces the expected output seen below. (I use Overleaf with the 2022 LuaLaTeX engine.)

\documentclass{article}
%\usepackage[bidi=basic,provide=*,english,hebrew,layout=graphics]{babel}
%\babelfont{rm}[Renderer=HarfBuzz]{FreeSerif}
\usepackage{adjustbox}
\usepackage{tabularray}
\usepackage{tikz}
\usetikzlibrary{calc}
\NewDocumentCommand{\points}{}{%
\draw (0,0) node [circle,fill=red,label={[label distance=.5cm]-90:$r$}] (r1) {}
      (1,0) node [circle,fill=red,label={[label distance=.5cm]-90:$r'$}] (r2) {}
      (2,0) node [circle,fill=blue,label={[label distance=.5cm]-90:$b'$}] (b1) {}
      (3,0) node [circle,fill=blue,label={[label distance=.5cm]-90:$b$}] (b2) {};
}
\NewDocumentCommand{\colsinnersep}{}{2cm}
\begin{document}
\begin{adjustbox}{center}
\begin{tblr}{cells={halign=c,valign=m},row{1}={belowsep={.5cm}},column{1}={rightsep={\colsinnersep}},column{2}={leftsep={\colsinnersep}}}
Before
&
After
\\
\begin{tikzpicture}[baseline=0]
\points;
\draw[very thick] (r1) |- ($(b1)+(0,.5)$) -- (b1);
\draw[very thick] (r2) |- ($(b2)+(0,-.5)$) -- (b2);
\end{tikzpicture}
&
\begin{tikzpicture}[baseline=0]
\points;
\draw[very thick] (r1) |- ($(b2)+(0,.5)$) -- (b2);
\draw[very thick] (r2) |- ($(b1)+(0,-.5)$) -- (b1);
\end{tikzpicture}
\end{tblr}
\end{adjustbox}
\end{document}

Document's language is English by default

However, when the two commented-out lines are uncommented thus making the document's main language Hebrew, the following incorrect output is produced.

The document's main language is Hebrew

Note that the problem is not that table's original left and right columns have switched places. This is correct behavior, since Hebrew is a right-to-left language. The problem is that the pictures are no longer centered in the columns, and the colored nodes are not aligned with their labels. Another problem is that the nodes' labels are written from right to left.

Why has this happened? How can it be fixed?

Evan Aad
  • 11,066
  • 1
    It looks like it works with an up to date version of babel. just copy the relevant files to your project. I think babel.sty, luababel.def and babel-bidi-basic.lua should be enough for this example. – Udi Fogiel May 01 '23 at 08:55

2 Answers2

2

Babel had a bug with "inline" tikz pictures. See this page and Tikz sweeps location of text inside node with Hebrew.

Adding the following line after \usepackage{tikz} should solve this (credit to Salim Bou):

\makeatletter
\AddToHook{env/tikzpicture/begin}{\bbl@pictsetdir\tw@}
        \bbl@add\tikz@atbegin@node{\bbl@pictresetdir}
        \bbl@sreplace\tikz{\begingroup}{\begingroup\bbl@pictsetdir\tw@}
\makeatother

But working with an up to date version of babel would be better.

Udi Fogiel
  • 3,824
0

You could add \selectlanguage{english} in each of the TikZ pictures' cells just before the begin{tikzpicture} commands. The result is:

Selecting English as the language in each of the TikZ pictures' cells

Evan Aad
  • 11,066