minipage breaks bidi

I am using XeTex and polyglossia for two languages {arabic and english}. The main language is arabic. When I set a minipage and put some mixed language paragraphs inside it, the left-to-right business gets mixed up.

In the MWE below the important thing is the second english sentence which is back-the-front. The choice of arabic font is unimportant.

You can delete all the arabic and the problem remains, but I kept it in to rule out a solution where everything in the minipage is in english.

Can someone please explain why this is happening and how to fix it?

In a previous question I posted, one suggestion was to put a minipage inside a \begin{english} evironment and then again inside another minipage. This seems tortuous, and doesn't allow me mixed paragraphs. Is there not a simpler way?

The MWE is simple, what I really want is a framed box of fixed height/width with mixed language paragraphs. Outside the minipage environment, polyglossia works fine. I do not not how to test whether it is polyglossia or bidi which is the source of this problem.

\documentclass[12pt,oneside]{report}
\usepackage[a4paper]{geometry}
\usepackage{polyglossia}
\setmainlanguage{arabic}
\setotherlanguage{english}
\newfontfamily\arabicfont[Script=Arabic]{Times New Roman}
\begin{document}
\begin{minipage}[t][4in][t]{\linewidth}
هي جملة في العربي

\begin{english}
This is the first english sentence

This is the second english sentence.

\end{english}
هي جملة في العربي
\end{minipage}
\end{document}


The issue can be illustrated in the following minimal plain document:

\input bidi
\setRTL

\hbox{\beginR\vbox{%
\setLTR
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
}\endR}

\bye


I have uploaded version 17.9 of bidi package to CTAN to fix this. It may take a couple of days to reach your TeX distribution.

• I changed the answer to this one because it is more flexible. – Tim Oct 11 '15 at 14:09

It look like a bug of bidi package with minipage environment, command like \setLTR have no effect for the text direction inside minipage. here an example

\documentclass[12pt,oneside]{report}
\usepackage[a4paper]{geometry}
\usepackage{bidi}

\parindent=0pt
\begin{document}
\setRTL

This is the first english sentence

This is the second english sentence.

\begin{minipage}[t]{\linewidth}
\setLTR

This is the first english sentence

This is the second english sentence.

\end{minipage}

\begingroup
\setLTR

This is the first english sentence

This is the second english sentence.

\endgroup

\end{document}


Output

For your case you can solve the problematic with \everypar{\setLTR} inside english environment

\documentclass[12pt,oneside]{report}
\usepackage[a4paper]{geometry}
\usepackage{polyglossia}
\setmainlanguage{arabic}
\setotherlanguage{english}
\newfontfamily\arabicfont[Script=Arabic]{Times New Roman}
\begin{document}
\begin{minipage}[t][4in][t]{\linewidth}
هي جملة في العربي

\begin{english}
\everypar{\setLTR}

This is the first english sentence

This is the second english sentence.

\end{english}
هي جملة في العربي
\end{minipage}
\end{document}

• i have written an issue on Bidi based on your MWE. – Tim Oct 8 '15 at 9:38
• I have also discovered that your solution breaks other parts. So I guess I'll need bidi to be fixed. – Tim Oct 8 '15 at 13:37
• @Tim: What are exactly `other parts'? – Vafa Khalighi Oct 9 '15 at 3:42
• formatting of some paragraphs, esp. lists. I am investigating and will produce MWE when I can to show the problem. – Tim Oct 11 '15 at 14:08