6

the desired Arabic font is Droid Arabic Naskh source here. Problem is that when I compile the document using xetex I get funny boxes instead of non-Arabic charset as in the MWE below:

MWE

\documentclass[11pt]{scrbook}
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage[numerals=mashriq,abjadjimnotail=true]{arabic}
\newfontfamily\arabicfont[Script=Arabic,Scale=1.2,Ligatures=TeX]{Droid Arabic Naskh}
\begin{document}


هذا نص بالعربية وفيه بعض الرموز الاخرى مثلا (-، * ، + ، )


\end{document}

Output
enter image description here

Question
Is there a way to provide a fallback font for Droid Arabic Naskh font to typeset all non-Arabic charsets and what fallback font would be more suitable than any other for this job?

Update

\documentclass[11pt]{scrbook}
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage[numerals=mashriq,abjadjimnotail=true]{arabic}
\setotherlanguages{english}
\newfontfamily\arabicfont[Script=Arabic,Scale=1.2,Ligatures=TeX]{Droid Arabic Naskh}
\newfontfamily\englishfont{Linux Libertine O}

\usepackage[Latin,Arabic]{ucharclasses}

\setTransitionsForLatin{\begingroup\englishfont}{\endgroup}

\renewenvironment{english}
 {\begin{LTR}\begin{otherlanguage*}{english}}
 {\end{otherlanguage*}\end{LTR}}
\renewrobustcmd{\textenglish}[1]{\LR{\foreignlanguage{english}{#1}}}

\begin{document}


هذا نص بالعربية وفيه بعض الرموز الاخرى مثلا (-، * ، + ، )

\end{document}

Output

enter image description here

  • Marking the language changes with \foreignlanguage{english}{...}, \begin{otherlanguage*}{english}...\end{otherlanguage*} is better and will automatically do what you're looking for, because \englishfont would be selected, with the added benefit of correct hyphenation. – egreg Apr 29 '15 at 11:02
  • thanks for the tip, but still those funny boxes appear when I am writing in Arabic using the desired font. Any idea? Based on that I will minimize the MWE further to highlight this part only. – doctorate Apr 29 '15 at 11:05
  • If I would mark the text in between the commas in MWE as English language it would be a daunting way to do it. There might be a smarter way of providing a fallback font for those characters not provided by the font of interest. – doctorate Apr 29 '15 at 11:13
3

Marking the language changes with \foreignlanguage{english}{...}, \begin{otherlanguage*}{english}...\end{otherlanguage*} is better and will automatically do what you're looking for, because \englishfont would be selected, with the added benefit of correct hyphenation.

For the problematic characters, use ucharclasses:

\documentclass[11pt]{scrbook}
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage[numerals=mashriq,abjadjimnotail=true]{arabic}
\setotherlanguages{english}
\newfontfamily\arabicfont[Script=Arabic,Scale=1.2,Ligatures=TeX]{Scheherazade}
\newfontfamily\englishfont{Linux Libertine O}

\usepackage[Latin,Arabic]{ucharclasses}

\setTransitionsForLatin{\begingroup\englishfont}{\endgroup}

\renewenvironment{english}
 {\begin{LTR}\begin{otherlanguage*}{english}}
 {\end{otherlanguage*}\end{LTR}}
\renewrobustcmd{\textenglish}[1]{\LR{\foreignlanguage{english}{#1}}}

\begin{document}


هذا نص بالعربية وفيه بعض الرموز الاخرى مثلا (-، * ، + ، )

\begin{english}This is a text in Arabic with some 
characters like (, +, *, -)\end{english}

ة وفيه بعض الرموز الاخرى مثلا (-، * ، + ،\textenglish{This is a text in Arabic with some
characters like (, +, *, -)}

\end{document}

The redefinitions of english and \textenglish are due to weaknesses in the setup.

enter image description here

  • now boxes disappeared, but the directions right-to-left (RTL) not preserved when LaTeX sees the non-Arabic charset. Parantheses were mirrored in Arabic, for example. – doctorate Apr 29 '15 at 11:35
  • can I use another Arabic font as a fallback instead of English font with ucharclasses, I suggest Amiri font: amirifont.org – doctorate Apr 29 '15 at 11:39
  • @doctorate This is a blurry area; experiment with the various possibilities. – egreg Apr 29 '15 at 11:42
  • I will put the code (same of the answer) and output to spot it. Please be patient with me. – doctorate Apr 29 '15 at 11:43
  • pls see the update. I applied exactly the same code in your answer with replacing the font only and the boxes disappeared but the problem is with punctuations: they don't look correct as your first line of output you showed in your answer. I am clueless to that result. – doctorate Apr 29 '15 at 11:49
0

After some trials and errors, I found one solution to this problem; by using another Arabic font that already supports the Latin charsets which is not supported by the Arabic font of interest. It is just like complementing the required charset of one font with those of another. In my trial, I used Amiri font:

\documentclass[11pt]{scrbook}
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage[numerals=mashriq,abjadjimnotail=true]{arabic}
\setotherlanguages{english}
\newfontfamily\arabicfont[Script=Arabic,Scale=1.2,Ligatures=TeX]{Droid Arabic Naskh}
\newfontfamily\arabicfontx[Script=Arabic,Scale=1.2,Ligatures=TeX]{Amiri}
\newfontfamily\englishfont{Linux Libertine O}

\usepackage[Latin,Arabic]{ucharclasses}
\setTransitionsForLatin{\begingroup\arabicfontx}{\endgroup}

\begin{document}


هذا نص بالعربية وفيه بعض الرموز الاخرى مثلا (- ، * ، + ، ).

\end{document}

Output
enter image description here

Caution
This answers works fine for the small text in the MWE but it broke after couple of pages in my document which is a bit long, in addition one or two charset could not be typset and therefore appeared as funny boxes. So I don't recommend this as a solution to the problem, still answer is only relevant to RTL languages, such as Hebrew and Arabic.

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.