3

I'm having a great trouble using a multi-language packages like polyglossia/babel with hyperref.

1st trial: babel

When I learned to use babel with hebrew I came across the problem described here and here which made me realise that it is currently impossible to use bable in-order to write multilanguage bidirectional documents with hyperref.

2nd and current trial: polyglossia

While trying to use polyglossia for my documents, I came across weird problems regarding font configuration I still can't fully solve. And this is the part I'm mostly unsure of

Setup

I use archlinux with with the following texlive packages:

$ pacman -Qsq texlive
texlive-bibtexextra
texlive-bin
texlive-core
texlive-culmus
texlive-fontsextra
texlive-formatsextra
texlive-humanities
texlive-langextra
texlive-latexextra
texlive-music
texlive-pictures

I use xelatex in order to produce the documents because pdflatex and lualatex works with polyglossia.

Example

In the following document, I tried to simplify the problem as much as possible without using unnecessary packages.

\documentclass[a4paper]{book}

% General
\usepackage{hyperref}

% Language
\usepackage{polyglossia}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\setmainfont{DejaVu Sans}

\begin{document}

\title{הספר שלי}
\author{דורון בכר}
\maketitle
שלום רב,\\
קוראים לי דורון.
% The following 2 lines demonstrate the problem fairly:
% -----------------------------------------------------
%\textenglish{This is a sentence with a url inside it: \url{https://github.com/doronbehar} and it causes problems}
%\textenglish{This is a sentence without a url and it doesn't make problems if all of the document doesn't use hyperref}

\end{document}

Problem

If you uncomment the last sentence (right above end{document}) There is no problem when compiling. I don't get any font errors and I can see all characters in the output document. But, if I try to uncomment the sentence with the URL as well, I get the following warnings and errors:

Package polyglossia Warning: No hyphenation patterns were loaded for `Hebrew'
(polyglossia)                I will use \language=\l@nohyphenation instead on input line 21.

After a few packages loaded, I get:

Package hyperref Warning: Rerun to get /PageLabels entry.

(/usr/share/texmf-dist/tex/latex/euenc/eu1lmtt.fd)

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

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

l.32 ...de it: \url{https://github.com/doronbehar}

I can't getrid of the warning at the begining and the error as well.

Note:

I've seen a live and working example of using both of these packages from overleaf.com Here. But the writer doesn't use there actual hyperlinks nor urls.

3

The warning is imho a bug in the language processing of polyglossia, but harmless.

The error is due to the fact that \url's are written with a typewriter font. polyglossia doesn't handle this correctly: despite that you are in english context it tests if the typewriter font is usable for hebrew. You can find quite a number of questions regarding the "current roman font" problem. The easiest to get around it is to use fonts which have the script:

\documentclass[a4paper]{book}

\usepackage{polyglossia}
\usepackage{hyperref}

\setdefaultlanguage{hebrew}


\setotherlanguage{english}

\setmainfont{DejaVu Sans}
\setmonofont{DejaVu Sans}%<--

\begin{document}

\textenglish{This is a sentence with a url inside it: \texttt{blub} and it causes problems}


\end{document}
3

You need to tell it what to use for sans and monowidth fonts in Hebrew, even though the URL is typeset in an English context. For example:

\documentclass{book}
% load last unless you know something needs to be loaded later
\usepackage{hyperref}
% bidi needs to be loaded later
\usepackage{polyglossia}
\setmainlanguage{hebrew}
% US English
\setotherlanguage{english}
\setmainfont{DejaVu Serif}
\setsansfont{DejaVu Sans}
\setmonofont{DejaVu Sans Mono}
\newfontfamily\hebrewfont{DejaVu Sans}[Script=Hebrew]
\newfontfamily\hebrewfontsf{DejaVu Sans}[Script=Hebrew]
\newfontfamily\hebrewfonttt{DejaVu Sans}[Script=Hebrew]

\begin{document}


\title{הספר שלי}
\author{דורון בכר}
\maketitle
שלום רב,

קוראים לי דורון.

\textenglish{This is a sentence with a url inside it: \url{https://github.com/doronbehar} and it causes problems}
\textenglish{This is a sentence without a url and it doesn't make problems if all of the document doesn't use hyperref}

\end{document}

However, I'm not convinced that it uses the fonts I would expect in this case:

active url

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.