LyX, Hebrew (RTL) and footnotes

I'm using LyX with Hebrew. I noticed that LyX always messes up the footnote line alignment on the very last page. For example, here's what happens with a 3 page document that has footnotes on every one of the three pages:

On the first and the second pages the footnotes are displayed correctly:

However on the last page the footnote line is on the left side (aligning the footnote text in LyX itself doesn't help):

I managed to figure out what was causing the problem by looking at the .tex file. Turns out LyX puts \selectlanguage{english}% at the end of the document (which is why this problem occurs only on the last page of the document).

Here's the format of the .tex file (I omitted the Hebrew text because it's too long):

%% LyX 2.2.3 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[a4paper,hebrew,english]{article}
\usepackage[T1]{fontenc}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\special{papersize=\the\paperwidth,\the\paperheight}

\@ifundefined{date}{}{\date{}}
\makeatother

\usepackage{babel}
\begin{document}
\selectlanguage{hebrew}%

<Some very long Hebrew text with footnotes here>

\noindent <some Hebrew text here> \selectlanguage{english}%

\end{document}


Removing \selectlanguage{english} or replacing it with \selectlanguage{hebrew} solves the problem. But is there a way to prevent LyX from inserting this command at the end of every file (without creating problems with rtl support)?

• This might be a bug. Could you please post a minimal example .lyx file (e.g. the one that produces the .tex file you posted?). For info on how to do that, see wiki.lyx.org/FAQ/MinimalExample – scottkosty Apr 7 '18 at 14:12
• @scottkosty - here's the simplest I was able to produce. – cth Apr 7 '18 at 16:23
• thanks for the example. Going to Document > Settings > Language and setting it to Hebrew fixes the problem for me. Is that an option for you or for other reasons that's not an option? – scottkosty Apr 7 '18 at 16:42
• @scottkosty - wow, thank you. I have no idea why it wasn't set on Hebrew. I think it's a great opportunity to ask what option is generally desired - in other words, is it preferable to set an RTL language if we have a mixed document (i.e. English + Hebrew)? (I assume that in the case of Hebrew alone setting it to Hebrew should be a no brainer). Alternative question - how this option affects the document (aside from the footnotes, as we just learned)? Thank you. – cth Apr 7 '18 at 16:49
• I think that the primary document language can have many effects. I would imagine babel/polyglossia would make choices based on it, such as what language to display certain things. But I guess the only way to see what effects it has on your particular document is to look at the differences in the PDF. Something that's very good for things like this is "diffpdf". It shows the differences between two PDFs. If you happen to be on Ubuntu, you can install with sudo apt-get install diffpdf. – scottkosty Apr 7 '18 at 16:55