<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Guy Rutenberg &#187; hyperref</title>
	<atom:link href="http://www.guyrutenberg.com/tag/hyperref/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.guyrutenberg.com</link>
	<description>Keeping track of what I do</description>
	<lastBuildDate>Wed, 16 Jun 2010 19:53:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Getting Hyperref to Work with Hebrew (in XeTeX)</title>
		<link>http://www.guyrutenberg.com/2009/06/27/getting-hyperref-to-work-with-hebrew-in-xetex/</link>
		<comments>http://www.guyrutenberg.com/2009/06/27/getting-hyperref-to-work-with-hebrew-in-xetex/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 10:18:54 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[LaTeX]]></category>
		<category><![CDATA[Hebrew]]></category>
		<category><![CDATA[hyperref]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=389</guid>
		<description><![CDATA[The hyperref package is notoriously known to cause problem with RTL text, which unfortunately include Hebrew. In this post I present some preliminary workarounds that enable the user to use the  hyperref package with Hebrew and possibly other RTL languages. The solution requires XeTeX which is available in TeXLive. I had no success, yet, [...]]]></description>
			<content:encoded><![CDATA[<p>The <code>hyperref</code> package is notoriously known to cause problem with RTL text, which unfortunately include Hebrew. In this post I present some preliminary workarounds that enable the user to use the  <code>hyperref</code> package with Hebrew and possibly other RTL languages. The solution requires XeTeX which is available in TeXLive. I had no success, yet, to port the workaround to pdfTeX, which is more popular.<br />
<span id="more-389"></span></p>
<p>The problem is that because TeX doesn&#8217;t store information regarding the direction of text inside the dvi, RTL text is actually stored in reverse. When a link is inserted in such text, the command to start the link ends up after the command to end the link, which is problematic. When trying to compile such document with pdfTex it throws errors like:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">! pdfTeX error (ext4): pdf_link_stack empty, \pdfendlink used without \pdfstart</pre></div></div>

<p>On the otherhand XeTeX behaves a little nicer and compiles the document, but the wrong parts of the text are marked as links.</p>
<p>My workaround basically changes the order of the start and end link commands. Thus, in RTL text the commands get reversed and actually end up in the correct order. The workaround doesn&#8217;t support links spanning multiple lines and color links (although link border is supported). Further work needs to be done in order to support links in the table of contents. I could get it to work only in LTR mode (which isn&#8217;t good). You should insert the following code to your preamble in order to enable the workaround.</p>

<div class="wp_syntax"><div class="code"><pre class="latex" style="font-family:monospace;"><span style="color: #800000; font-weight: normal;">\<span style="color: #800000; font-weight: bold;">makeatletter</span></span>
<span style="color: #800000; font-weight: normal;">\<span style="color: #800000; font-weight: bold;">def</span></span><span style="color: #800000; font-weight: normal;">\hyper</span>@link#1#2#3<span style="color: #E02020; ">{</span><span style="color: #2C922C; font-style: italic;">%</span>
  <span style="color: #800000; font-weight: normal;">\if</span>@rl
    <span style="color: #800000; font-weight: normal;">\setLR</span>
      <span style="color: #800000; font-weight: normal;">\begingroup</span>
      <span style="color: #800000; font-weight: normal;">\hyper</span>@linkend
        #3
      <span style="color: #800000; font-weight: normal;">\hyper</span>@linkstart<span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">#1</span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;">#2</span><span style="color: #E02020; ">}</span>
    <span style="color: #800000; font-weight: normal;">\setRL</span>
  <span style="color: #800000; font-weight: normal;">\else</span>
    <span style="color: #800000; font-weight: normal;">\hyper</span>@linkstart<span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">#1</span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;">#2</span><span style="color: #E02020; ">}</span>
        #3
    <span style="color: #800000; font-weight: normal;">\hyper</span>@linkend
  <span style="color: #800000; font-weight: normal;">\fi</span>
<span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\<span style="color: #800000; font-weight: bold;">makeatother</span></span></pre></div></div>

<p>I&#8217;ll also note that in order to generate correct pdf bookmarks (not in gibberish), you should set <code>unicode=false</code> in the <code>hyperref</code>&#8217;s options.</p>
<p>You can find a working example bellow (and the corresponding PDF output <a href="/wp-content/uploads/2009/06/xetex-hyperref-test.pdf">here</a>).</p>

<div class="wp_syntax"><div class="code"><pre class="latex" style="font-family:monospace;"><span style="color: #800000; font-weight: normal;">\<span style="color: #800000; font-weight: bold;">documentclass</span></span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">article</span><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\usepackage</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">fontspec</span><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\usepackage</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">xunicode</span><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\usepackage</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">bidi</span><span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #800000; font-weight: normal;">\usepackage</span><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">unicode=false,
 bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
 breaklinks=false,pdfborder=<span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">0 0 1</span><span style="color: #E02020; ">}</span>,backref=false,colorlinks=false</span><span style="color: #E02020; ">]</span>
 <span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">hyperref</span><span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #800000; font-weight: normal;">\<span style="color: #800000; font-weight: bold;">makeatletter</span></span>
<span style="color: #800000; font-weight: normal;">\<span style="color: #800000; font-weight: bold;">def</span></span><span style="color: #800000; font-weight: normal;">\hyper</span>@link#1#2#3<span style="color: #E02020; ">{</span><span style="color: #2C922C; font-style: italic;">%</span>
  <span style="color: #800000; font-weight: normal;">\if</span>@rl
    <span style="color: #800000; font-weight: normal;">\setLR</span>
      <span style="color: #800000; font-weight: normal;">\begingroup</span>
      <span style="color: #800000; font-weight: normal;">\hyper</span>@linkend
        #3
      <span style="color: #800000; font-weight: normal;">\hyper</span>@linkstart<span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">#1</span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;">#2</span><span style="color: #E02020; ">}</span>
    <span style="color: #800000; font-weight: normal;">\setRL</span>
  <span style="color: #800000; font-weight: normal;">\else</span>
    <span style="color: #800000; font-weight: normal;">\hyper</span>@linkstart<span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">#1</span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;">#2</span><span style="color: #E02020; ">}</span>
        #3
    <span style="color: #800000; font-weight: normal;">\hyper</span>@linkend
  <span style="color: #800000; font-weight: normal;">\fi</span>
<span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\<span style="color: #800000; font-weight: bold;">makeatother</span></span>
<span style="color: #800000; font-weight: normal;">\setromanfont</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Times New Roman</span><span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\setRL</span>
<span style="color: #800000; font-weight: normal;">\title</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">בדיקה</span><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\author</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">גיא רוטנברג</span><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\date</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\maketitle</span>
<span style="color: #800000; font-weight: normal;">\pagebreak</span><span style="color: #E02020; ">{</span></span><span style="color: #2020C0; font-weight: normal;"><span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #800000; font-weight: normal;">\section</span><span style="color: #E02020; ">{</span><span style="color: #00008B; font-weight: bold;">סעיף ראשון</span></span><span style="color: #E02020; ">}</span><span style="color: #800000; font-weight: normal;">\<span style="color: #800000; font-weight: bold;">label</span></span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">testlabel</span><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\subsection</span><span style="color: #E02020; ">{</span><span style="color: #00008B; font-weight: bold;">תת-סעיף ראשון</span><span style="color: #E02020; ">}</span><span style="color: #800000; font-weight: normal;">\<span style="color: #800000; font-weight: bold;">label</span></span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">testlabel2</span><span style="color: #E02020; ">}</span>
&nbsp;
לה לה
&nbsp;
לי לי
&nbsp;
לו לו
&nbsp;
<span style="color: #800000; font-weight: normal;">\pagebreak</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\section</span><span style="color: #E02020; ">{</span><span style="color: #00008B; font-weight: bold;">סעיף שני</span></span><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\subsection</span><span style="color: #E02020; ">{</span><span style="color: #00008B; font-weight: bold;">תת-סעיף ראשון</span><span style="color: #E02020; ">}</span>
&nbsp;
לה לה
&nbsp;
<span style="color: #800000; font-weight: normal;">\subsection</span><span style="color: #E02020; ">{</span><span style="color: #00008B; font-weight: bold;">תת-סעיף שני</span><span style="color: #E02020; ">}</span>
&nbsp;
לי לי
חלק <span style="color: #800000; font-weight: normal;">\<span style="color: #800000; font-weight: bold;">ref</span></span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">testlabel</span><span style="color: #E02020; ">}</span>
אבגד
<span style="color: #800000; font-weight: normal;">\hyperref</span><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">testlabel2</span><span style="color: #E02020; ">]{</span><span style="color: #2020C0; font-weight: normal;">בדיקה ארוכה</span><span style="color: #E02020; ">}</span>
&nbsp;
<span style="color: #800000; font-weight: normal;">\setLR</span>
This is a test for LTR links. See section <span style="color: #800000; font-weight: normal;">\<span style="color: #800000; font-weight: bold;">ref</span></span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">testlabel</span><span style="color: #E02020; ">}</span> and <span style="color: #800000; font-weight: normal;">\hyperref</span><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">testlabel2</span><span style="color: #E02020; ">]{</span><span style="color: #2020C0; font-weight: normal;">long label</span><span style="color: #E02020; ">}</span>.
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2009/06/27/getting-hyperref-to-work-with-hebrew-in-xetex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.419 seconds -->
