2

A demonstration of the issue by way of a minimal working example

I saved the following LaTeX code in the file ~/Test.tex.

\documentclass{article}
\usepackage[bidi=basic,english,hebrew,provide=*]{babel}
\babelfont{rm}{FreeSerif}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{cc}
left & right
\end{tblr}
\end{document}

The code uses the babel package to set the document's main language to Hebrew (a language written from right to left), and the document's secondary language to English. It then creates a simple table using the tabularray package. The table has two columns, and a single row. The first entry in the row is left, and the second entry is right.

I then executed the following commands in the Terminal.

> cd ~
> lualatex Test

This resulted in the file ~/Test.pdf being created. When opened in a PDF viewer this file displays as follows. (I screenshot only the relevant part of the display.)

A tabularray in a Hebrew document

As can be seen, the relative order of the words "left" and "right" is the reverse of what their meanings indicate. This is not a bug. It is due to the fact that the document's main language is Hebrew.

If it is desired to keep the document's main language as Hebrew, but change the table's directionality, one way to accomplish this is to change the language to English just before the table's definition, and change it back to Hebrew just after the table's definition, thus:

\selectlanguage{english}
\begin{tblr}{cc}
left & right
\end{tblr}
\selectlanguage{hebrew}

This produces

A left-to-right tabularray in a Hebrew document

Questions

  1. Is there a way to change the table's language and directionality by passing an argument to tblr rather than by wrapping it in \selectlanguage commands?
  2. Is there a way to change the language and directionality of all the tables in the document using tabularray's \SetTblrInner or \SetTblrOuter commands?

Remark

I'm interested in changing two independent properties: the table's directionality, and the table's language. To clarify the distinction by way of an example, the PDF file of the following Hebrew document containing a tabularrray with a single column and a single row (and therefore no directionality) and the entry -2 in its single cell displays, displays 2- (i.e. the minus sign is typeset to the right of the digit 2), because the table's language is Hebrew, as inherited from the document.

\documentclass{article}
\usepackage[bidi=basic,english,hebrew,provide=*]{babel}
\babelfont{rm}{FreeSerif}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{c}
-2
\end{tblr}
\end{document}

2 Answers 2

4

Note

It appears languages can be nested, as a cascade: table, row, cell, etc.

languages

So, at the babel level, directionality can be somewhat decoupled from language.

MWE

\documentclass{article}
\usepackage{xcolor}

\usepackage[bidi=basic,english,hebrew,provide=*]{babel}
\babelfont{rm}{FreeSerif}
\usepackage{tabularray}
\newcommand\testh{\textcolor{red}אבג רשת}
\newcommand\testt{The cat sat on the mat. \testh}

\begin{document}
\testh

---


\bigskip
\selectlanguage{english}
English
\begin{longtblr}[
  caption = {Test},
    ]{
    cells={c},
    row{1}={bg=blue!20,cmd={\selectlanguage{english}}},
    row{2}={bg=blue!10,cmd={\selectlanguage{hebrew}}},
    row{3}={bg=blue!5,cmd={\selectlanguage{hebrew}}},
    cell{2-3}{1}={cmd={\selectlanguage{english}}},
    }
(E) & 1. left & \testt & 2. right \\
(H$_{1}$) & 1. left & \testt & 2. right \\
(H$_{2}$) & 1. \testh & \testt & 2. xxx \\
\end{longtblr}


\bigskip
\selectlanguage{hebrew}
Hebrew
\begin{longtblr}[
                     caption = {Test},
                        remark{\selectlanguage{english}* Note} = {\selectlanguage{english}Cell language is English.},
]{
    cells={c},
    row{1}={bg=blue!20,cmd={\selectlanguage{english}}},
    row{2}={bg=blue!10,cmd={\selectlanguage{hebrew}}},
    row{3}={bg=blue!5,cmd={\selectlanguage{hebrew}}},
    cell{3}{3}={bg=red!20,
                        cmd={\selectlanguage{english}}},
    cell{2-4}{1}={cmd={\selectlanguage{english}}},
    }
(E) & 1. left & \testt & 2. right \\
(H$_{1a}$) & 1. left & \testt & 2. right \\
(H$_{1b}$) & 1. left & *\testt & 2. right \\
(H$_{2}$) & 1. \testh & \testt & 2. xxx \\
\end{longtblr}

\end{document}
2

A partial answer to question no. 2. Use environment hooks.

\documentclass{article}
\usepackage[bidi=basic,english,hebrew,provide=*]{babel}
\babelfont{rm}{FreeSerif}
\usepackage{tabularray}
\AddToHook{env/tblr/before}{\selectlanguage{english}}
\AddToHook{env/tblr/after}{\selectlanguage{hebrew}}
\begin{document}
\begin{tblr}{cc}
left & right
\end{tblr}
\end{document}

Using environment hooks to set a tblr's language

You must log in to answer this question.

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