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}
einpoklum
  • 12,311

4 Answers4

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

egreg
  • 1,121,712
  • I get an error about a missing expl3.sty file - can you help me with that? Many thanks! – Felix Goldberg Oct 15 '13 at 17:43
  • @FelixGoldberg What TeX distribution are you using? – egreg Oct 15 '13 at 17:46
  • Miktex 2.9 - should I upgrade or something? – Felix Goldberg Oct 15 '13 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.... :( – Felix Goldberg Oct 15 '13 at 19:44
  • I think I know where the problem is - it's the ifpdf.sty file. But I can't open it in a viewer (it shows blank although it's like 8k) and it's protected and I can't overwrite it. So it's all very bleak right now... – Felix Goldberg Oct 15 '13 at 19:53
  • 2
    @FelixGoldberg Ensure you're saving your file as UTF-8 – egreg Oct 15 '13 at 21:01
  • It works at last! I replaced the font by Arial. Thanks a bil! – Felix Goldberg Oct 15 '13 at 21:31
  • @FelixGoldberg: I suggest you: 1. Edit egreg's answer to metnion the distribution and the charset of the source file. 2. Mark the comments as invalid afterwards. – einpoklum Mar 04 '15 at 16:07
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.

einpoklum
  • 12,311
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

Javier Bezos
  • 10,003
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.

Davislor
  • 44,045