A brief description of the problem
How can I embed verbatim English text in a Hebrew paragraph?
A demonstration of the problem by way of a minimal working example
Consider the following LaTeX code, saved in the file ~/Test.tex
.
\documentclass{article}
\usepackage[bidi=basic,provide=*,english,hebrew]{babel}
\babelfont{rm}{FreeSerif}
\usepackage{enumitem}
\begin{document}
א
Hello, world!
א
\foreignlanguage{english}{Hello, world!}
א
\verb|Hello, world!|
א
%\foreignlanguage{english}{\verb|Hello, world!|}
\end{document}
The code uses babel
to configure the document's main language as Hebrew, and the document's secondary language as English. Then, in the document's body, it prints four Hebrew sentences in which an English phrase is embedded. The English phrase ends with an exclamation point. The exclamation point is to be considered part of the English phrase, and therefore should be typeset to the right of the English phrase.
When the following commands are executed in the Terminal:
> cd ~
> lualatex Test
the file ~/Test.pdf
is created. When opened in a PDF viewer, it displays as follows. (I screenshot only the relevant part of the display.)
As can be seen, in the first sentence the exclamation point is positioned wrongly. This is corrected in the second sentence by wrapping the English phrase, including the exclamation point, inside a \foreignlanguage{english}{...}
command. Unfortunately, the same trick fails when the English phrase is the argument to a \verb
command. I had to comment out the last line of code in the document's body because otherwise the document would not compile, and ~/Test.log
would include the following message:
! Missing } inserted.
<inserted text>
}
l.18 \foreignlanguage{english}{\verb|Hello, world!|}
?
! Emergency stop.
<inserted text>
}
l.18 \foreignlanguage{english}{\verb|Hello, world!|}
End of file on the terminal!
The desired output sould be similar to the second typeset line, except that the English phrase, including the exclamation point, should be typeset using the same font as the one used to typeset them in the third typeset line.