Second update: Would you take a babel
and lualatex
solution?
At least no ugly hacks are required…
\documentclass{article}
\usepackage[nil,bidi=basic]{babel}
\babelprovide[import=en-AU,main]{australian}
\babelprovide[import=he]{hebrew}
\babelfont[australian]{rm}{Latin Modern Roman}
\babelfont[hebrew]{rm}[Scale=0.8]{Ezra SIL}
\babelfont{tt}{Cousine}
\pagestyle{empty}
\usepackage{minted}
\begin{document}
\section*{Source}
\begin{minted}{latex}
\documentclass{article}
\usepackage[nil,bidi=basic]{babel}
\babelprovide[import=en-AU,main]{australian}
\babelprovide[import=he]{hebrew}
\babelfont[australian]{rm}{Latin Modern Roman}
\babelfont[hebrew]{rm}[Scale=0.8]{Ezra SIL}
\babelfont{tt}{Cousine}
\begin{document}
The first two words of Genesis are: \foreignlanguage{hebrew}{בראשית ברא}.
\end{document}
\end{minted}
\section*{Output}
The first two words of Genesis are: \foreignlanguage{hebrew}{בראשית ברא}.
\end{document}
First updated unsatisfactory answer:
The brace problem is at least partially font related, but also involves interplay with colour.
e.g., consider this:
\documentclass{article}
\TeXXeTstate=1
\usepackage{fontspec}
\usepackage{xcolor}
\pagestyle{empty}
\begin{document}
\setmainfont{Cousine}
\{בראשית ברא\}\par
\textcolor{red}{\{}בראשית ברא\textcolor{red}{\}}\par
English \{בראשית ברא\} English\par
English \textcolor{red}{\{}בראשית ברא\textcolor{red}{\}} English\par
\setmainfont{FreeMono}
\{בראשית ברא\}\par
\textcolor{red}{\{}בראשית ברא\textcolor{red}{\}}\par
English \{בראשית ברא\} English\par
English \textcolor{red}{\{}בראשית ברא\textcolor{red}{\}} English\par
\end{document}
And now for some other work around options for your example:
\documentclass{article}
\TeXXeTstate=1
\usepackage{fontspec}
\usepackage{minted}
\setmonofont{FreeMono}
\pagestyle{empty}
\begin{document}
\begin{minted}{latex}
% Hebrew word order is wrong and uses FreeMono
\begin{document}
The first two words of Genesis are: \texthebrew{בראשית ברא}.
\end{document}
\end{minted}
\begin{minted}[escapeinside=||]{latex}
% correct, but requires escapeinside and FreeMono
\begin{document}
The first two words of Genesis are: \texthebrew{|\beginR|בראשית ברא|\endR|}.
\end{document}
\end{minted}
\setmonofont{Cousine}[Script=Hebrew]
\def\PYGZob{\}}
\def\PYGZcb{\{}
\begin{minted}{latex}
% use Cousine, but Hebrew word order is wrong and requires an ugly hack
\begin{document}
The first two words of Genesis are: \texthebrew{בראשית ברא}.
\end{document}
\end{minted}
\end{document}
Original answer:
I think you can't avoid escaping commands (minted
has an escapeinside
option), because you have to set the text direction to RTL no matter what. You'll see this if you try and put in more than one Hebrew word.
And I couldn't avoid fudging the braces because something about how they get coloured in minted means only one gets automatically mirrored. Maybe someone smarter than me can figure that out.
But what about an easier to use fudge?
\documentclass{article}
\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage{xcolor}
\usepackage{minted}
\pagestyle{empty}
\setmainlanguage{english}
\setotherlanguage{hebrew}
\setmonofont{Courier New}
\newfontfamily\hebrewfont{Ezra SIL}[Scale=0.8,Script=Hebrew]
\newcommand{\texthebrewverb}[1]{%
\PYG{k}{\PYGZbs{}texthebrew}%
\texthebrew{\ttfamily\PYG{n+nb}{\PYGZcb{}}#1\PYG{n+nb}{\PYGZcb{}}}}
\begin{document}
\begin{minted}[escapeinside=||]{latex}
\documentclass{article}
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{hebrew}
\newfontfamily\hebrewfont{Ezra SIL}[Scale=0.8,Script=Hebrew]
\begin{document}
The first two words of Genesis are: \texthebrew{בראשית ברא}.% wrong
The first two words of Genesis are: |\texthebrewverb{בראשית ברא}|. % right
\end{document}
\end{minted}
\end{document}