0

How can insert some hebrew characters into a tex document and then resume in the document's main language?

That is -- I'm working on creating a tex document that will ultimately be converted into a PDF. This document will contain both english, and hebrew, characters. With the help of some other questions I'm getting closer to my goal, but my lack of general understand of LaTeX syntax seems to be a major roadblock.

I have the following tex document

\documentclass{article}
\usepackage{fontspec}
\usepackage{polyglossia}

\setdefaultlanguage{english}
\setotherlanguage{hebrew}

\setmainfont{Times New Roman}
\newfontfamily\hebrew{New Peninim MT}

\begin{document}

Hello World  

\hebrew{\RL{חַ}}

Goodbye World

\end{document}

When I convert this document to a pdf using xelatex, I get

That

That is -- Hello World renders in english (yay!). The hebrew ח renders (yay!). However -- the Goodbye World renders as square blocks.

Conceptually I suspect I have, (unwittingly), told xelatex to render Goodbye World in hebrew using New Peninim MT. However, I'm not sure why that's the case. My naive programmer mind tells me that this

\hebrew{\RL{חַ}}

is telling xelatex that what's inside the brackets should be rendered in hebrew, in right to left mode. However, xelatex seems to stay in hebrew rendering mode when it gets to the Goodbye World text.

So -- my immediate question: How do I get xelatex to render this single hebrew character inline and render the english text in the main font/typeface/language.

My bigger question: Based on the above -- what don't I understand about LaTeX syntax?

8
  • \hebrew is a switch, use \texthebrew{...} instead. Jun 17, 2017 at 18:12
  • Thank you @UlrikeFischer -- \texthebrew did the trick. Happy to mark as best if you wanted to make that comment an answer. Re: "a switch" vs. "the other construct" -- is there a way to tell when something is or isn't a switch in LaTeX code? Is there a place you'd point new people at who wanted to learn the ins and outs of LaTeX syntax? Jun 17, 2017 at 18:27
  • You naturally can look in the code or check the documentation but your own example did show that \hebrew works like a switch, so the first step to understand LaTeX syntax is to believe your own eyes. Jun 17, 2017 at 19:01
  • Use \hebrewfont rather than \hebrew.
    – egreg
    Jun 17, 2017 at 20:28
  • I will @egreg -- is there a reason for that? Jun 17, 2017 at 21:32

1 Answer 1

4

You shouldn't be switching font or typesetting direction explicitly. You are using Polyglossia, so you should let the package take care of this. It already knows Hebrew typesets the other way, but you need to specify a font. This must use \hebrewfont for Polyglossia to pick it up correctly, as egreg suggested.

Even if you didn't use \hebrewfont, you should not use \hebrew as this is already defined by Polyglossia et al. 'Et al.' because I have not checked exactly what is responsible for what, but it is certainly involved:

> \hebrew=macro:
->\@protected@testopt \hebrew \\hebrew {}.
l.223   \show\hebrew

obtained by adding \show\hebrew in the code below.

\documentclass{article}
\usepackage{polyglossia}
\setmainlanguage[variant=british]{english}
\setotherlanguage{hebrew}
\newfontfamily\hebrewfont{Noto Sans Hebrew}[Script=Hebrew]

\begin{document}
% uncomment the next line to see the definition shown above
%\show\hebrew

Hello world!

\begin{hebrew}
  עברית חַ
\end{hebrew}

Goodbye world!
\end{document}

English and Hebrew

You must log in to answer this question.

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