Consider the following document:

\newfontfamily\hebrewfont[Script=Hebrew]{David CLM}
קסם קסמה לי הלענה.

Assuming your TeX distro is configured properly, and that the culmus fonts are installed, this will compile. However, if I remove the \newfontfamily line, and try to compile this with TeXLive on a recent Linux distribution, I get:

! Package polyglossia Error: The current roman font does not contain the Hebrew
(polyglossia)                Please define \hebrewfont with \newfontfamily.

Now, I think this shouldn't happen, but that's a matter for another day. My question is, suppose I don't know which Hebrew fonts are installed on the system. Maybe there's Culmus, maybe there's access to the OS' fonts, some of which support Hebrew (and those are different font families in Windows and in Linux) - whatever.

Is there a way to tell polyglossia "use whatever Hebrew font family has available fonts", as opposed to requiring a specific font family?

Bonus points for an answer which supports setting fallbacks a-la-CSS, i.e. "if you have it, then font family A; otherwise, if you have it, then font family B; etc. etc. ; and if you have none then an arbitrary Hebrew font"


1 Answer 1


This is not system independent, since I have used bash and you have to compile with -shell-escape.

But under Linux you could grab the first font that fontconfig finds supporting Hebrew if your preferred font isn't found.

Update with more elegant solution:

\IfFontExistsTF{David CLM}
  {\newfontfamily\hebrewfont{David CLM}[Script=Hebrew]}
   \splice{echo -n '\string\newfontfamily\string\hebrewfont{';
           fc-list :lang=he family | head -1 | tr -d '\string\n';
           echo -n '}[Script=Hebrew]'}}
English \texthebrew{עברית}

Original solution:

% Try to use a preferred font otherwise fall back to the one fontconfig finds.
% Make sure we are in batch mode so compilation continues when preferred font
% isn't found.
\font\testfont="David CLM" at 10pt
% use the bashful to run bash script
% grab the first family fontconfig finds supporting hebrew
% create hebfont.tex looking like:
% \newfontfamily\hebrewfont{Some Font}[Script=Hebrew]
% Note: Don't indent this, since bashful is picky about leading spaces
echo -n '\newfontfamily\hebrewfont{' > hebfont.tex
fc-list :lang=he family | head -1 | tr -d '\n' >> hebfont.tex
echo -n '}[Script=Hebrew]' >> hebfont.tex
  \newfontfamily\hebrewfont{David CLM}[Script=Hebrew]
English \texthebrew{עברית}
  • Well, yeah, that's something, but like you said, it's pretty platform-specific. +1 though. I was disappointed to note that on my system the first font would be the horrid and inappropriate David Transparent.
    – einpoklum
    Sep 19, 2017 at 12:50
  • Yes, I think you'd definitely want to check for a few font options before falling back to fontconfig. Sep 19, 2017 at 12:58
  • Is there some package wrapping your testfont code more elegantly? Also - shouldn't the \bash command only be executed in case "David CLM" is missing?
    – einpoklum
    Sep 19, 2017 at 13:45
  • Yes, you could do that. I updated the answer. bashful seems picky about leading spaces, so don't indent. I don't know of a package that tests for missing fonts, but perhaps fontspec has something buried in it. Sep 19, 2017 at 13:57
  • 1
    I believe that also MiKTeX can use -shell-escape instead of -enable-write18 (the former is the name of the option for TeX Live based binaries).
    – egreg
    Sep 19, 2017 at 14:56

You must log in to answer this question.

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