# Right-to-left text in LaTeX - reversed numbers and parentheses

Finally I got my Hebrew working on LaTeX.

Everything's working great except for two issues - numbers and parentheses. Numbers are written the other way around (one hundred would be written 001), and parentheses are reversed too )like this(. Is there a solution for the problem?

MWE:

\documentclass[english,hebrew]{article}
\usepackage[utf8x]{inputenc}
\usepackage{babel}
\begin{document}
המספר (מאה) בספרות הוא 100
\end{document}

-
Please add a minimal working example (MWE) that illustrates your problem. This should provide context within which you use Hebrew numbers and parentheses for others to work with. –  Werner Dec 15 '11 at 19:55
Thanks for the reply. I added it. –  David Dec 15 '11 at 20:09
I cannot test your MWE due to missing fonts issues, but have you tried using the \foreignlanguage command from babel for short text in a different language? Something like \foreignlanguage{english}{100} –  Gonzalo Medina Dec 15 '11 at 20:29
Better yet, according to hebrew.dtx you can use the switch \unsethebrew to switch from the Hebrew font encoding to the current font encoding, and from the right-to-left mode to left-to-right mode. The command \sethebrew switches back. –  Gonzalo Medina Dec 15 '11 at 20:39
As someone who started with LaTeX and Babel a few weeks ago, let me save you some headaches: use XeTeX and polyglossia instead. Things like this work there out of the box, and other little quirks that Babel has are working fine there. –  daniel.jackson Dec 16 '11 at 13:45

You can use Artyom Beilis' BiDiTex, which pre-processes a (La)TeX file to reverse parentheses and enclose numbers in appropriate macros.

The documentation lists the problem you mention exactly, in section 1... that's the motivation for writing that utility.

Using the question's MWE:

\documentclass[english,hebrew]{article}
\usepackage[utf8x]{inputenc}
\usepackage{babel}
\usepackage{biditex}
%BIDION
\begin{document}
המספר (מאה) בספרות הוא 100
\end{document}
%BIDIOFF


And running

cat mwe.tex | biditex.exe -o mwe_out.tex


you get:

\documentclass[english,hebrew]{article}
\usepackage[utf8x]{inputenc}
\usepackage{babel}
\usepackage{biditex}
\begin{document}
המספר )מאה( בספרות הוא \Lnum{100}
\end{document}


Which results when LaTeXing in the output you'd expect:

Of course, you would want to scriptify all of this.

By the way, BiDiTeX seems to require UTF-8 input.

-

I agree daniel.jackson, Polyglossia and XeTeX are the way to go. Here's my working example, though minimal it is not:

\documentclass[12pt]{article}

%polyglossia packages - polyglossia must be first
\usepackage{polyglossia}
\usepackage{bidi}

%XeTeX packages
\usepackage{fontspec}
\usepackage{xltxtra}
\usepackage{xunicode}

%settings for packages
\setdefaultlanguage{english}
\setotherlanguage{hebrew}
\setmainfont{Linux Libertine O}

\begin{document}

Here is a whole phrase or section in left-to-right direction:

\setRL
הנשיא האמריקאי ברק אובמה נאם הערב (שישי) בוועידת הקהילות היהודיות שנערכה בוושינגטון.
\unsetRL

Or, for when a few words will do:

\RL{\ldots נאם הערב (שישי) בוועידת\ldots}

And it works fine with numbers as well:

\RL{\ldots נאם 100 + 30 = 130 הערב (שישי) בוועידת\ldots}

Even nested environments work just fine:

\RL{\ldots נאם \LR{with English in the middle} הערב (שישי) בוועידת\ldots}

\end{document}


-
bidi, fontspec, xltxtra and xunicode are all unnecessary. And in fact it's necessary to load polyglossia last more often than not. –  daniel.jackson Dec 16 '11 at 23:20
I agree that xltxtra, and xunicode are unnecessary (though they are in my template so I rarely remove them) but the commands I issued \RL{}, \setRL, etc. are command for the bidi package and the command \setmainfont{Linux Libertine O) is for the fontspec package. I was under the impression that the standard font did not have many non-latin glyphs. –  AdamRedwine Dec 17 '11 at 13:59
Right, but both of those are included by polyglossia, so there's no need to explicitly load them. –  daniel.jackson Dec 17 '11 at 16:59
Huh... I did not know that. Thanks for the info. –  AdamRedwine Dec 18 '11 at 2:55
@daniel.jackson It's not polyglossia that has to be last. It's the line \setotherlanguage{hebrew} that has to go after any other package loading, because that line loads bidi. –  Ari Brodsky Dec 23 '12 at 10:10