[Tex/LaTex] polyglossia and minted – The current roman font does not contain the Hebrew script!

fontsmintedpolyglossia

Trying to use minted with Hebrew as the default language with polyglossia:

\documentclass{article}
\usepackage{minted}
\usepackage{polyglossia}
\setdefaultlanguage[calendar=hebrew, numerals=arabic]{hebrew}
\setotherlanguage{english}
\newfontfamily\hebrewfont{David CLM}

\begin{document}
בדיקה

\begin{english}
\begin{minted}{bash}
    $ for i in {1..2}; do echo 'Hello World'; done
    Hello World
    Hello World
\end{minted}
\end{english}
\end{document}

Results in:

$ xelatex -shell-escape test
! Package polyglossia Error: 
The current roman font does not contain the Hebrew script!
Please define \hebrewfont with \newfontfamily.

See the polyglossia package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.1 \begin{Verbatim}[commandchars=\\\{\}, ]

I think I understand what the error is saying, but not sure why.

I'm in the english environment which should use the default English font… So why am I getting errors about Hebrew stuff?

(I did manage to workaround it by setting the default language to English, but that made other things break unfortunately)

Best Answer

It's a clear bug in how Polyglossia manages the situation, as it seems not taking into account the current language. A temporary workaround is to say

\let\hebrewfonttt\ttfamily

just after \newfontfamily\hebrewfont{David CLM} (it suffices to say it in the preamble, anyway). This assuming that you don't need Hebrew in the minted environment.