2

I'm trying to use Babel for Arabic & Hebrew (both as secondary to English) in pdflatex. I had it working for just Arabic with

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[arabic,hebrew,english]{babel}   

\usepackage{hyperref}
\usepackage{times}
\usepackage{latexsym}
\usepackage{booktabs}
\usepackage{url}
\begin{document}
\AR{أهلاً}
%\foreignlanguage{hebrew}{שלום}
\end{document}

But I can't figure out how to extend this for Hebrew. As soon as I try to add Hebrew (uncomment the line above), it gives me an encoding error on the Hebrew. If I switch to utf8x, it gives me an encoding error on the Arabic.

As suggested, I've tried switching to xelatex and polyglossia. This can display Arabic and Hebrew, however when I add in the style file I need with hyperref, it breaks. Here's that minimal working example:

\documentclass[11pt,a4paper]{article}

\usepackage[hyperref]{sty_file}
\usepackage{times}
\usepackage{latexsym}
\usepackage{booktabs}
\usepackage{url}

\usepackage{polyglossia}

\setdefaultlanguage{english}
%\setotherlanguage{arabic}
%\setotherlanguage{hebrew}

%\newfontfamily\arabicfont{Amiri}[Script=Arabic]
%\newfontfamily\hebrewfont{Noto Sans Hebrew}[Script=Hebrew]

\title{Hebrew Arabic Test}

\begin{document}
\maketitle

English

%\begin{Arabic}
%أهلاً
%\end{Arabic}

%\begin{hebrew}
%שלום
%\end{hebrew}

\end{document}

As soon as you uncomment the first commented lines, it breaks my styling. It would be a lot to paste the style file here, but it is included in this overleaf document.

Any ideas? I've tried everything else I found on this stack exchange with no luck. :/ Thanks!

  • Welcome to TeX.SE! Posting code is just what we're looking for in a question. You're almost there, just complete your minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. The easier it is to copy and test your code, the more likely your question will be answered and can help others in a similar situation. – thymaro May 19 '18 at 5:10
  • 2
    There are posts on this site about getting Hebrew to work with pdflatex, but in my view it's just not work the pain unless you really have to. If at all possible switch to xelatex. You can even use babel now if your requirements are not too complex. – David Purton May 19 '18 at 6:07
  • 1
    @thymaro, sorry about that! Thanks for the reminder. I modified to include a minimal working example where it works and what breaks it. – pjshap May 19 '18 at 12:19
  • 1
    @DavidPurton, when I switch to xelatex, it compiles but neither the Arabic nor the Hebrew display in the PDF, it's just blank. Is there more I need to add for xelatex? – pjshap May 19 '18 at 12:19
  • 1
    @DavidPurton xelatex + polyglossia works without my style file with hyperref, but it breaks the style file as soon as I add Arabic (makes the title not bold anymore). I'll add that minimal example to my post. – pjshap May 19 '18 at 14:42
3

Update

This appears to work for this simple example. The stylesheet loads several packages in an order that conflicted with the packages loaded from polyglossia, and also used some NFSS font commands that needed to be redefined for fontspec.

It must be compiled in XeLaTeX.

\documentclass[11pt,a4paper]{article}

%\usepackage{times}
\usepackage{fontspec}
\RequirePackage{xcolor}
\RequirePackage{hyperref}
\RequirePackage{natbib}
\usepackage{polyglossia}
\setmainfont{TeX Gyre Termes}[
  SizeFeatures = {
    {Size=-10,     OpticalSize=8 },
    {Size= 10,     OpticalSize=10},
    {Size= 11,     OpticalSize=11},
    {Size= 12-13,  OpticalSize=12},
    {Size= 14-18,  OpticalSize=14},
    {Size=    18-, OpticalSize=18}}
]
\defaultfontfeatures{Scale=MatchUppercase}

\setmainlanguage{english}
\setotherlanguage{arabic}
\setotherlanguage{hebrew}

\newfontfamily\arabicfont{Amiri}[Script=Arabic]
\newfontfamily\hebrewfont{Noto Sans Hebrew}[Script=Hebrew]

\usepackage[hyperref]{sty_file}
%% sty_file defines the legacy font command:
% \font\naaclhv  = phvb at 8pt 
%% This is Helvetica Bold.
\makeatletter
\newfontface\@hv{TeX Gyre Heros Bold}[Scale=1.0, OpticalSize=8]
\renewcommand\naaclhv{\fontsize{8}{8}\@hv}
\makeatother

\usepackage{booktabs}
\usepackage{url}

\title{Hebrew Arabic Test}

\begin{document}
\maketitle

English

\begin{Arabic}
أهلاً
\end{Arabic}

\begin{hebrew}
שלום
\end{hebrew}

\end{document}

Possibly-Correct Example

Previous

The following works for me in XeLaTeX:

\documentclass[preview]{standalone}

%\usepackage[hyperref]{sty_file}
%\usepackage{times}
\usepackage{latexsym}
\usepackage{booktabs}
\usepackage{url}

\usepackage{polyglossia}

\setmainlanguage{english}
\setotherlanguage{arabic}
\setotherlanguage{hebrew}

\setmainfont{TeX Gyre Termes}
%\defaultfontfeatures{Scale=MatchUppercase} % Should uncomment this.
\newfontfamily\arabicfont{Amiri}[Script=Arabic]
\newfontfamily\hebrewfont{Noto Sans Hebrew}[Script=Hebrew]

\title{Hebrew Arabic Test}

\begin{document}
\maketitle

English

\begin{Arabic}
أهلاً
\end{Arabic}

\begin{hebrew}
שלום
\end{hebrew}

\end{document}

English/Arabic/Hebrew Sample

Previous

Thank you for posting a link to the stylesheet. It isn’t compatible with fontspec in a number of ways. Some can be easily fixed; for example, the line \font\naaclhv = phvb at 8pt can be patched over by adding this afterward:

\makeatletter
\newfontface\@hv{TeX Gyre Heros Bold}[Scale=1.0, OpticalSize=8]
\renewcommand\naaclhv{\fontsize{8}{8}\@hv}
\makeatother

This makes the line, “Confidential Review Copy. DO NOT DISTRIBUTE.” display properly. Similarly, you can replace times with TeX Gyre Termes or Times New Roman.

However, you would need to rewrite large parts of the stylesheet to get your submission to work the way you want, starting with its \maketitle, and you really should ask the journal itself how to proceed.

  • Yeah, so that displays the Arabic and Hebrew correctly for me now. The problem is, though, that it changes the English font from the one I specified in my style file (which is mandatory for my conference submission). Basically, in order to use Xelatex & Polyglossia, I need to be able to get them to not interfere with my style file, which I still can't figure out how to do. – pjshap May 19 '18 at 17:52
  • @pjshap You didn’t include your style file, so I just commented that line out to get the example to compile. One thing you could try is to load it after polyglossia, which loads fontspec. Alternatively, you load times after your stylesheet, so you could do what I did and set the main font to a Times clone such as TeX Gyre Termes or Times New Roman. – Davislor May 19 '18 at 17:59
  • @pjshap Your basic problem is that you want to use a Type 1 font for English, but OpenType fonts for Hebrew and Arabic. Your main font is set by the times package right now, though, so what I did should give you nearly-identical output. – Davislor May 19 '18 at 18:02
0

Have you tried using Bidi? you can just go: \setRL and type (or copy and paste) in Arabic and Hebrew. You can insert a Latin based language in the middle of a RL language by the simple command \LR{latin text}. Switch RL to LR and LR to RL to reverse the process. See do-it-yourself-tex on CTAN for some illustative examples.

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.