5

This is a question about xelatex, even though I mention LyX here.

My goal is to produce an RTL table with one row, two columns, which looks more or less like that:

                                                                      +---+---+
                                                                      | 2 | 1 |
                                                                      +---+---+

I tried to produce it in LyX and then exported to XeTeX and got the following code:

%% LyX 2.0.8.1 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[english,hebrew]{article}
\usepackage{fontspec}
\setmainfont[Mapping=tex-text]{David CLM}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
%% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}

\makeatother

\usepackage{xunicode}
\usepackage{polyglossia}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\begin{document}
\begin{tabular}{|c|c|}
\hline 
{\beginL 2\endL} & {\beginL 1\endL}\tabularnewline
\hline 
\end{tabular}
\end{document}

It seems opposite, and indeed, when compiling this tex file with xelatex I get an opposite table:

                                                                      +---+---+
                                                                      | 1 | 2 |
                                                                      +---+---+

So I figured out this is a LyX bug, but before "solving" it, LyX people like to be sure what the correct XeTeX code should be. Is it simply the columns switched, as I thought? Or perhaps something else is wrong there?

  • It could be a "feature" rather than a bug. – John Kormylo Jul 21 '15 at 14:13
  • @JohnKormylo but I'm not sure the on-screen LyX display should be different from the PDF display. – scottkosty Jul 21 '15 at 14:41
  • From my understanding, the table itself is not entered RTL in the source, but LTR and then will automatically be made RTL by bidi. (Also the \beginL and \endL code isn't necessary, nor are the global language options, (and a few other things) but I assume you can't change this since it's generated by LyX. – Alan Munn Jul 24 '15 at 0:59
  • @AlanMunn how would one enter the table RTL in the source? – scottkosty Jul 24 '15 at 2:20
  • @scottkosty I don't know about LyX but in the code above the first column at the left will be the first column on the right when typeset in RTL mode. – Alan Munn Jul 24 '15 at 2:24
1
+50

By writing \setdefaultlanguage{hebrew} you set the entire document Right-to-Left by default, which affects also the order of table columns. This has to do with the bidi package that is loaded by polyglossia. By the way, the commands \beginL and \endL are not needed when using these packages.

So, LyX should produce the opposite columns order in RTL mode. Note also that if you load polyglossia you don't need to load fontspec not xunicode.

So the code should be the following:

\documentclass[english,hebrew]{article}
\usepackage{polyglossia}
\setmainfont[Mapping=tex-text]{David CLM}

\providecommand{\tabularnewline}{\\}

\setdefaultlanguage{hebrew}
\setotherlanguage{english}


\begin{document}
\begin{tabular}{|c|c|}
\hline 
1 & 2 \tabularnewline
\hline 
\end{tabular}
\end{document}
  • Thanks Ariel. Let's see if I understand this (I'm new to RTL and bidi) --- The reason why we input it LTR into LaTeX is because that is what we "mean". That is, we mean that 1 should be in "row 1" and 2 should be in "row 2". When we compile, "row 1" is determined to start from the right because it is RTL. Is that the correct intuition? – scottkosty Jul 24 '15 at 16:30
  • @scottkosty Yes, that's a good way of thinking about it. (Substituting 'column' for 'row', which I assume is what you meant.) – Alan Munn Jul 24 '15 at 19:18
  • @AlanMunn Ah yes thanks for the correction. OK this is good to know. – scottkosty Jul 24 '15 at 21:24
  • Can you confirm that when you say "are not needed when using these packages", that \beginL and \endL are never useful when using the polyglossia package? From what I understand, polyglossia is smart and knows that e.g. Hebrew should be RTL so it is not necessary to say it explicitly. I guess that babel is not as smart and that is why it is necessary with babel? – scottkosty Jul 24 '15 at 21:28
  • @scottkosty bidi uses \beginL etc. internally, but they are not user level commands in general. bidi does provide different user level commands and environments for embedding RTL text within LTR and vice versa. I know nothing about RTL languages and babel so I can't help you with your second question. – Alan Munn Jul 24 '15 at 22:48
-1

The easy way is:

Write your table like this

                                                                      +---+---+
                                                                  | 1 | 2 |
                                                                  +---+---+

After you generate pdf you get:

                                                                      +---+---+
                                                                  | 2 | 1 |
                                                                  +---+---+

I used this idea always time.

  • 1
    Your answer is not so clear. How do you write the table in the Latex code? – Ariel Aug 4 '15 at 12: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.