9

I want to write a document that will contain only Hebrew text (and some diagrams). I understand that babel is probably the best way to do it but I am getting utterly confused and haven't been able to attain Hello World level yet.

So I am asking for a minimal working example of a Hello World in Hebrew.

If that matters, I work in TeXnicCenter but am ready to switch anything else that runs under windows if necessary.

EDIT:

This is the file that produces the 100 errors:

\documentclass{article}
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage{hebrew} 
\newfontfamily{\hebrewfont}{New Peninim MT}
\setmainfont{New Peninim MT}

\begin{document}
\maketitle
\end{document}
8
  • 3
    My suggestion is to try XeLaTeX and Polyglossia, instead. Installing the Hebrew support for babel is rather painful.
    – egreg
    Commented Oct 15, 2013 at 17:00
  • @egreg Can you give me a MWE, please? Commented Oct 15, 2013 at 17:13
  • Felix, you have some commented-out parts in your "file producing 100 errors"; please remove them from the example.
    – einpoklum
    Commented Oct 15, 2013 at 20:31
  • @einpoklum done - does that help? Commented Oct 15, 2013 at 20:36
  • It does in that it's clear what the file has. However, it's not clear how this example is related to your question. I answered the first part of your question below.
    – einpoklum
    Commented Oct 15, 2013 at 20:42

4 Answers 4

9

I suggest you to try XeLaTeX and Polyglossia; in my experience, installing full Hebrew for babel has been painful. Not that I know any Hebrew, but I had to typeset some text in that language.

Here's an example. You may need to change the font name; what font to use depends on your operating system, but any OpenType or TrueType system font supporting Hebrew should be good. The \newfontfamily{\hebrewfont}{...} may be needed or not, depending on how the font advertises its support for Hebrew.

The text has been taken from the page on Jerusalem in the Hebrew Wikipedia, http://he.wikipedia.org/wiki/ירושלים

If http://translate.google.com is not mistaken, the title should mean “Hello world”.

\documentclass{article}
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage{hebrew}
\setmainfont{New Peninim MT}
\newfontfamily{\hebrewfont}{New Peninim MT}
\begin{document}
\title{שלום עולם}
\author{שלום עולם}
\maketitle

העיר מקודשת ליהדות, לנצרות ולאסלאם, והיוותה מרכז חיי העם היהודי בימי
קדם ומושא געגועיו בזמן שהייתו בגלות. משום מרכזיותה בעולמם של המאמינים,
הייתה העיר מוקד למלחמות וסכסוכים הנמשכים עד עצם היום הזה. מאז סוף המאה
ה-19 התפתחו סביב העיר העתיקה שכונות העיר החדשה, המהוות כיום את רובה
המוחלט של העיר. במרכזה של ירושלים השלמה עומד הר הבית, שמפריד בין מערב
ירושלים למזרח ירושלים.

בשנת 1981 הוכרזה העיר העתיקה של ירושלים כאתר מורשת עולמית על ידי ארגון
אונסק"ו של האומות המאוחדות, והיא נמצאת ברשימת האתרים בסיכון.


\end{document}

enter image description here

8
  • I get an error about a missing expl3.sty file - can you help me with that? Many thanks! Commented Oct 15, 2013 at 17:43
  • @FelixGoldberg What TeX distribution are you using?
    – egreg
    Commented Oct 15, 2013 at 17:46
  • Miktex 2.9 - should I upgrade or something? Commented Oct 15, 2013 at 18:13
  • Okay, I updated miktex using the admin tool and now I get 100 (one hundred!) errors of the "Text line contains an invalid character" variety - even after I deleted all Hebrew text from the file. This is getting creepy and very very frustrating.... :( Commented Oct 15, 2013 at 19:44
  • 2
    @FelixGoldberg Ensure you're saving your file as UTF-8
    – egreg
    Commented Oct 15, 2013 at 21:01
4

Babel is not really the best choice for using Hebrew with LaTeX, but it was about the only choice for a very long time, and the XeLaTeX+polyglossia combination has still not caught on widely enough to supplant it (as of 2013; I wrote my Ph.D. thesis' Hebrew parts with eLaTeX and Babel, in 2011.)

So, here's the MWE you asked for:

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

\begin{document}
\selectlanguage{hebrew}
שלום, עולם.
\end{document}

The file needs to be in UTF-8 encoding (note it's utf8x up there, not utf8). If you want windows codepage 1255 encoding (single byte), use

\usepackage[cp1255]{inputenc}

instead of the utf8x line. Also, your TeX distribution should have the necessary packages/files installed to support compiling and rendering documents with Babel and Hebrew.

1
  • Nice suggestion....
    – MadyYuvi
    Commented Sep 2, 2020 at 14:54
4

Babel can now typeset Hebrew with both XeTeX and LuaTeX, which as of 2020 are the recommended engines for non-Latin scripts. The latter has, IMO, some advantages over XeTeX (eg, better bidi algorithms).

\documentclass{article}

% \usepackage[bidi=bidi-r]{babel}   % XeTeX
\usepackage[bidi=basic]{babel}      % LuaTeX

\babelprovide[main, import]{hebrew}

\babelfont{rm}{Libertinus Serif}

\begin{document}

\title{שלום עולם}
\author{שלום עולם}

\maketitle

העיר מקודשת ליהדות, לנצרות ולאסלאם, והיוותה מרכז חיי העם היהודי בימי
קדם ומושא געגועיו בזמן שהייתו בגלות. משום מרכזיותה בעולמם של המאמינים,
הייתה העיר מוקד למלחמות וסכסוכים הנמשכים עד עצם היום הזה. מאז סוף המאה
ה-19 התפתחו סביב העיר העתיקה שכונות העיר החדשה, המהוות כיום את רובה
המוחלט של העיר. במרכזה של ירושלים השלמה עומד הר הבית, שמפריד בין מערב
ירושלים למזרח ירושלים.

בשנת 1981 הוכרזה העיר העתיקה של ירושלים כאתר מורשת עולמית על ידי ארגון
אונסק"ו של האומות המאוחדות, והיא נמצאת ברשימת האתרים בסיכון.

\end{document}

enter image description here

1
  • What does the import option do?
    – Evan Aad
    Commented Nov 15, 2022 at 14:41
2

It would probably be better to redirect the multiple questions from years ago to an up-to-date answer.

In the Modern Toolchain

In 2021, I would recommend switching to Babel in LuaLaTeX, although any combination of Babel or Polyglossia with LuaLaTeX or XeLaTeX should work. Here is a template you can use in LuaLaTeX:

\documentclass[a4paper,italian,10pt]{book}
\tracinglostchars=3
\usepackage[bidi=basic, layout=sectioning.tabular]{babel}
\usepackage{unicode-math}
\usepackage{microtype}

\babelprovide[import=he, onchar=fonts ids]{hebrew}

\babelfont{rm}
          {NewComputerModern10-Book}
\babelfont{sf}
          {NewComputerModernSans10-Book}
\babelfont{tt}
          {NewComputerModernMono10-Book}
\setmathfont{NewCMMath-Book}

\begin{document}
Italiano e תשץצסןנ.
\end{document}

Although Javier Bezos is the maintainer of Babel and the authority on how it works, there are three or four little tweaks I would add to his answer, from personal experience.

In PDFLaTeX

Some publishers and professors still don’t want to upgrade from 8-bit fonts in the 2020s. In theory, there is a package called IvriTeX that should enable the [hebrew] option of babel to work. In practice, even its last maintainer said years ago that it’s better to switch to XeTeX. Since then, LuaLaTeX support for Hebrew has improved greatly.

The culmus-latex package at the same site works as well. Copy the files under texmf in the archive to your texmf-local directory (which you can normally find with kpsewhich --var-value=TEXMFLOCAL), then run

texhash
updmap-sys --enable Map=culmus.map

Use sudo or whatever permission you need on your system to update your texmf-local directory.

\documentclass[a4paper,10pt,hebrew,italian]{book}
\tracinglostchars=3
\usepackage[T1]{fontenc}
\usepackage[use-david]{culmus}
\usepackage[utf8x]{inputenc}
\usepackage{babel}

\pagestyle{empty}

\begin{document}
\begin{otherlanguage}{hebrew}

קדם ומושא געגועיו בזמן שהייתו בגלות. משום מרכזיותה בעולמם של המאמינים,
הייתה העיר מוקד למלחמות וסכסוכים הנמשכים עד עצם היום הזה. מאז סוף המאה
ה-\L{19} התפתחו סביב העיר העתיקה שכונות העיר החדשה, המהוות כיום את רובה
המוחלט של העיר. במרכזה של ירושלים השלמה עומד הר הבית, שמפריד בין מערב
ירושלים למזרח ירושלים.

בשנת \L{1981}  הוכרזה העיר העתיקה של ירושלים כאתר מורשת עולמית על ידי ארגון
אונסק"ו של האומות המאוחדות, והיא נמצאת ברשימת האתרים בסיכון.

\end{otherlanguage}

Italiano e \R{תשץצסןנ}.
\end{document}

Culmus David sample

Note that, with this implementation, you must wrap Arabic numerals and other LTR text within Hebrew paragraphs in \L commands, and short blurbs of RTL text within LTR paragraphs in \R. RTL in math mode belongs inside a \hmbox. Attempting to switch between LTR and RTL languages with \foreignlanguage or \selectlanguage on the same line will not work, but changing the language for entire paragraphs with \begin{otherlanguage} will.

Given the lack of hyphenation patterns for Hebrew, you might want to also load \usepackage{microtype} and set \emergencystretch 3em to improve the spacing of long words LaTeX is unable to hyphenate. Neither of these will harm paragraphs that lay out nicely without them.

You must log in to answer this question.

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