In my last post, I’ve shown a way to fix the hyperref package so it would work with RTL languages.

One of the problem float were that the brackets in the pdf bookmarks were inverse. Again, It’s probably caused by the inverse parsing. The solution for that is pretty simple, replace the function that sets the bookmark and add a code to replace between ‘(‘ and ‘)’ (and for the other brackets as well, i.e. “[]{}<>”)

The “problem” was, that the function I had to replace is pretty long, and I was too lazy in order to find a better solution, therefor you will had one big ugly part of code in your solution (until I will have the time to build my own).

So in order to fix the bracket, all you have to do is to add this code to the preamble:

Long ago I’ve tried to use hyperref(which allowing links inside the documents, and bookmarks in pdf output) package in latex while writing in Hebrew. Sadly I’ve failed and didn’t have time to check why.

Today, After encountering this post by a guy asking for help in this situation I’ve managed to work around most of the problems.

At first I’ve found Guy Rutenberg’s post about “Getting Hyperref to Work with Hebrew (in XeTeX)“.
Which made me understand why pdfLaTeX failed miserably.
Guy used XeTeX, which might be fine for you, but I’m using a lot of packages and some of them just doesn’t support XeTeX. So, I thought, maybe ps2pdf will work?

Now it is a good time to say, I’m using LyX. I’m not writing the latex code directly, so that’s why my next choice was ps2pdf, because it’s one of LyX defaults.

I’ve tried to compile a simple article with a table of contents and sections. I had a small smile on my face when it managed to compile, but when I’ve opened the PDF it was one big mass. All the bookmarks were blank. After playing around with it, I figured out that the problem was the encoding of the document. For some reason LyX doesn’t like Unicode so it doesn’t use it by default and ps2pdf doesn’t like other Hebrew encoding at all.

So, first of all, you will have to change the encoding. In LyX You can do that by:

clicking Documet > Settings…

Go to the Language tab.

In the Encoding section choose Other and then Unicode (ucs-extended) (utf8x).

If you are writing a latex code, just write:

\usepackage[utf8x]{inputenc}

In the preamble (and remove the other inputenc importing if exists).

Now when I’ve compiled the document the bookmark were OK, but the links in the table of content weren’t in the right place. The problem as it seems to be, was the very same problem Guy mentioned, parts of document are being processed in a reversed order because of the RTL. The solution for that, was to find the specific buildup of the TOC and change the RTL to LTR before setting up the link and then back for the text itself. So, when I’ve added the following to the preamble everything worked just fine: