# Misplaced comma after LTR word in bidirectional document

I am writing documents with both English and Hebrew text in LaTeX. It works well, except for one thing: when there is a punctuation mark after an English word in a Hebrew sentence, the mark is misplaced.

Here is a small reproducible example, a file named test.tex:

\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage{hebrew}
\newfontfamily\hebrewfont{David CLM}
\let\hebrewfonttt\ttfamily
\begin{document}
המסמך הזה כתוב עם LaTeX, ומשלב בין עברית לאנגלית.
\par\noindent\rule{\textwidth}{0.4pt}
\setLTR

This document is written with LaTeX, and combines Hebrew and English.

\unsetLTR
\end{document}


which I process with:

xelatex test.tex


and get the following result:

In the first (Hebrew) sentence, the comma is misplaced. In the Hebrew sentence, the comma should be to the left of the word LaTeX, because the Hebrew text is RTL.

The correct arrangement can be seen in a text editor, such as gedit:

I'm not experienced with LaTeX, and couldn't find a solution online. Will appreciate any help with this, thank you very much!

• If the compiler takes the "LaTeX," bit literally (without moving the comma) can't you just put it into the text as ",LaTeX" ? Or is this a reoccurring fault that needs sorting? Dec 5, 2020 at 15:08
• You mean placing the comma in the "wrong" side of the word, right? Didn't think of it, just tried and it works! Thanks! Could be great if there is any more standard solution, but if there isn't this is what I'll do Dec 5, 2020 at 15:18
• LaTeX\/, should work. Dec 5, 2020 at 15:18
• @UlrikeFischer Thanks! This works fine in the independent tex file example above, but doesn't work in RMarkdown (where I eventually need to prepare the text) Dec 5, 2020 at 15:29

XeTeX and/or the bidi package seems not to handle this correctly. With lualatex and babel it works out of the box (I don't have your font here, so use another one):

% compile with lualatex
\documentclass{article}
\usepackage[english, bidi=basic]{babel}
\usepackage{fontspec}
\babelprovide[import,main]{hebrew}
\babelfont{rm}{Libertinus Serif} %
\begin{document}
המסמך הזה כתוב עם LaTeX, ומשלב בין עברית לאנגלית.
\end{document}


• Thanks! The example you kindly gave works well. However, I need the document to contain LTR as well... When trying to add the \setLTR This document is written with LaTeX, and combines Hebrew and English. \unsetLTR part, I get an error that \setLTR is an undefined control sequence... Dec 5, 2020 at 22:07
• sure it iuses babel and not the bidi package. Use \selectlanguage{english} and check the babel documentation. Dec 5, 2020 at 22:11
• I will check it out, marking as solved - thanks! Dec 6, 2020 at 6:40