Jul 16 2012

## LaTeX – Using hyperref with RTL languages (such as Hebrew)

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:

1. clicking Documet > Settings…
2. Go to the Language tab.
3. 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:

\PreloadUnicodePage{5}

\usepackage[unicode=true] {hyperref}

\def\contentsline#1#2#3#4{%
\ifx\\#4\\%
\csname l@#1\endcsname{#2}{#3}%
\else
\csname l@#1\endcsname{#2}{#3}%
\or % section
\csname l@#1\endcsname{%
}{#3}%
\or % page
\csname l@#1\endcsname{{#2}}{%
}%
\else % all
\csname l@#1\endcsname{%
}{%
}%
\fi
\fi
}

By adding it, you are replacing the hyperref‘s contentsline function. The only difference between the original function and the new one is at line 13. the \beginR, \endR and \L{…}.

I’m not really sure if it’s 100% bulletproof, so let me know if you encounter any problems.

Jul 14 2012

## SheePlayer

Not so long ago, A friend introduced me to Media Player Classic – Home Cinema, which is by all means a great player for windows.

The feature that did it for me, was the ability to download subtitles automatically for your video. Before, I was too lazy to try and figure out which subtitles fit, so most of the time I just watch the video without subtitles. But now, All I have to do is to click on a button and there they are!

I was looking for a player with the same feature on Mac, But couldn’t find one. So… I’ve made one.