[Tex/LaTex] Greek and Hebrew in a single pdflatex babel document

greekhebrewpdftex

The following creates a perfect english document with some greek letters:

\documentclass[]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[polutonikogreek,english]{babel}

\begin{document}
English or \textgreek{ανηρ} text.
\end{document}

However, when I add this, It gets all upset about the hebrew characters being invalid characters.:

\documentclass[]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[polutonikogreek,hebrew,english]{babel}

\begin{document}
English or \textgreek{ανηρ} text.

And this גהר.
\end{document}

I have tried changing And this גהר., guessing there might be something like And this \texthebrew{גהר}. but I guess there is not?

I wonder if anyone can point me in the right direction. (In case it matters, I am trying to stuff this in a beamer document. The above is jut my MWE)


This related question does not answer the question for Hebrew: How to use both English and Greek (Tex Live & pdflatex) and even Hebrew easily in one document

This related question uses polyglossa instead of babel for xelatex users Perfect example document (template) for English, Greek and Hebrew (XeLaTeX)

Best Answer

I think the main problem is that the Hebrew fonts are missing. After installing the Hebrew fonts from CTAN, the following code compiles with pdfLaTeX (using texlive) without any errors:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8x]{inputenc}
\usepackage[polutonikogreek,hebrew,english]{babel}

\begin{document}
  English or \textgreek{ανηρ} text.

  And this \foreignlanguage{hebrew}{גהר}.
\end{document}

Please note that I also changed the input encryption to utf8x. Unfortunately, the above puts "גהר" at the right end of the line (since Hebrew is written from right to left).

A really dirty hack to solve this problem using this answer could be to use the calc package and define the command \inlinehebrew in the following way:

\usepackage{calc}
\newcommand{\inlinehebrew}[1]{%
  \parbox{\widthof{\foreignlanguage{hebrew}{#1}}}{\foreignlanguage{hebrew}{#1}}}  

Then

And this \inlinehebrew{גהר}.

generates the following output

And this גהר.

but, since it includes a parbox, it breaks many things and can only be used for very short texts.

Let me add two remarks in passing:

  • Although not applicable in your situation: Because of the hassles involved in the above solution, I strongly recommend using Xe(La)TeX and polyglossia for writing Hebrew in LaTeX.
  • Instead of using the (old) Hebrew fonts linked above, it might be better to use culmus-latex which uses the culmus fonts which in opinion look nicer.
Related Question