# \hbox issue in RTL context (vmode)

Consedering this example \hbox in RTL context appears on the left isn't it supposed to appear on the right side with \pardir TRT!?

\documentclass{article}
\usepackage[showframe]{geometry}

\parindent0pt

\begin{document}

\pagedir TRT \pardir TRT \textdir TRT \bodydir TRT

Text text text text text text text text text text

\hbox{Text text text text text text text text text text}

\pagedir TLT \pardir TLT \textdir TLT \bodydir TLT

\hbox{Text text text text text text text text text text}

\end{document}

• Use \leavevmode\hbox or \mbox. A \hbox doesn't start a paragraph. – Henri Menke Oct 14 '20 at 18:28
• @HenriMenke This means that we needs to redefined \hbox in RTL context if it is inserted in vmode ? – Salim Bou Oct 14 '20 at 18:34
• The problem is there are commands defined in LTR containing hbox and I need to add them in RTL context without patching every command, is it possible? – Salim Bou Oct 14 '20 at 18:37

As Henri Menke said, \hbox does not start a paragraph and therefore \pardir doesn't affect it. Instead you get a horizontal box which not as wide as the enclosing box. In this case, the inner box is aligned based on the directionality of the outer box, which in this case is the vertical box TeX builds out of the main vertical list (whose directionalty is controlled by \bodydir).

Now you might expect that this doesn't make a difference because you set \bodydir too, but there is only one such box on every page, so one value of \bodydir is respected on every page. As you can see here, it is the last one.

This demonstrates that boxes in the main vertical list which do not go over the full \hsize are incompatible with changing the directionality in the middle of a page.

There are multiple ways to avoid this. You can for example enter a paragraph (by adding \noindent) which always goes over the full width or you can wrap your boxes in an inner vbox which can have it's own consistent direction. (Of course, you have to make sure that this box itself has full width, e.g. by adding a \hrule height 0pt width \textwidth\relax)

The last option is particularly useful if you can't change some commands which use a direction not normally used in your document: E.g.

\documentclass{article}
\usepackage[showframe]{geometry}

\parindent0pt

\begin{document}

\pagedir TRT \pardir TRT \textdir TRT \bodydir TRT

Text text text text text text text text text text

\hbox{Text text text text text text text text text text}

\vbox dir TLT {\hrule height 0pt width \hsize \relax
\hbox{Text text text text text text text text text text}
% Everything here is left to right
}

\end{document}

But be careful: This \vbox can never break over pages, so you shouldn't place long text in there.

• Thanks, the problem is there are commands defined in LTR containing hbox and I need to add them in RTL context without patching every command, is it possible? – Salim Bou Oct 14 '20 at 18:44
• @SalimBou Do the commands have to break over pages? – Marcel Krüger Oct 14 '20 at 18:45
• In general no commands are from beamer class – Salim Bou Oct 14 '20 at 18:48
• @SalimBou I don't understand your comment. I was asking if you want to allow a pagebreak in the commands, not if they are from beamer. – Marcel Krüger Oct 14 '20 at 18:54
• So my answer is no in my case, sorry. – Salim Bou Oct 14 '20 at 18:58