5

\texttt does not work as expected when using it with the polyglossia package, in a segment in the Hebrew language, even when the actual text to be set is Latin. I tried reading fontspec documentation, but was overwhelmed by the quantity of the material, and the fix I tried did not work:

\documentclass{article} % Compile with xelatex
\usepackage{polyglossia}
\setmainlanguage{hebrew}
\setotherlanguage{english}
\newfontfamily\hebrewfont[Script=Hebrew]{David CLM}% or whatever
\begin{document}
\setLTR
The following should be mono-spaced, but isn't: \texttt{This should be mono-spaced.}
\end{document}

Based on the suggestions below, I tried also the following, but this does not help:

\documentclass{article}     % Compile with xelatex
\usepackage{polyglossia}
\setmainfont[Script=Hebrew]{Ezra SIL}% 
\setmonofont[Script=Hebrew]{FreeMono}% 
\setmainlanguage{hebrew}    % Document main language is Hebrew
\setotherlanguage{english}  % But it uses English every so often
\begin{document}
\setLTR\textenglish{The following should be mono-spaced, but isn't: 
  \texttt{This should be mono-spaced.}
}
\end{document}
4
  • fontenc won't help you. The relevant packages are fontspec and polyglossia.
    – Caramdir
    Feb 10, 2011 at 21:34
  • 1
    I replaced David CLM with Ezra Sil because that is the only hebrew font that I have and I get error; it indicates that the main roman font does not contain Hebrew scrip which is very strange and I think this is a bug. Polyglossia used to allow users to choose ttfont for RTL scripts but I am not sure about the current situation.
    – IRAN
    Feb 10, 2011 at 23:41
  • I changed to Ezra SIL, and even though there is "error" message, just like you, I do not get a mono-spaced font.
    – Yossi Gil
    Feb 11, 2011 at 9:52
  • And, I added \setmonofont[Mapping=tex-text]{Courier New}, but this did not help.
    – Yossi Gil
    Feb 11, 2011 at 10:53

1 Answer 1

5

Well \texttt switches to the tt-family. This is as default the tt-font from the latin modern family, which doesn't contain the hebrew script. So you can't use it in a hebrew environment.

You should either define a "tthebrewfamily":

\newfontfamily\tthebrewfamily[Script=Hebrew]{...}% 
\DeclareTextFontCommand{\texttthebrew}{\tthebrewfamily}

Or you set with \setmainfont, setmonofont the standard fonts to fonts which contain and activate Hebrew. In this case you will probably have to use \ttfamilylatin etc in the english parts (and perhaps have to define this fonts).

Addition: It did take me some time to find two different fonts with the opentype feature "Script hebrew". With this the following worked without error:

\documentclass{article} % Compile with xelatex

\usepackage{polyglossia}
\setmainfont[Script=Hebrew]{Ezra SIL}% 
\setmonofont[Script=Hebrew]{DejaVu Sans}% 

\setmainlanguage{hebrew}
\setotherlanguage{english}

\begin{document}
\setLTR
This should be \texttt{mono-spaced}\ldots

\end{document}

But while looking through the fonts I saw that quite a lot have Hebrew characters but only very few the Script Hebrew. So I'm wondering if it is a good idea that polyglossia (gloss-hebrew) request it. Is it needed to type Hebrew?

5
  • both \setmainfont and \setmonofont gives the same error.
    – IRAN
    Feb 11, 2011 at 11:46
  • It is not very common that you need to write Hebrew with mono spaced font. The reason is that mono space is traditionally used for typing out computer interaction bits, and this is rarely done in Hebrew. However, my particular application is writing text in Hebrew which has English computer interaction, which should use the mono space font.
    – Yossi Gil
    Feb 11, 2011 at 20:10
  • I may be missing something, but the above does not produce monospaced font for me.
    – Yossi Gil
    Feb 11, 2011 at 20:15
  • @Yossi: DejaVu Sans isn't a monospaced font. Try for example FreeMono instead.
    – Caramdir
    Feb 12, 2011 at 2:23
  • If your mono-text is in english, why don't you switch to english before the \texttt? (And yes dejaVu isn't monospaced, but I was looking only for two different fonts with script hebrew to show that it works in theory.) Feb 12, 2011 at 11:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .