[XeTeX] Hyperref query

Heiko Oberdiek oberdiek at uni-freiburg.de
Wed May 12 02:21:19 CEST 2010


Hi,

On Wed, May 12, 2010 at 08:15:38AM +1000, Ross Moore wrote:

> On 11/05/2010, at 10:11 PM, Vafa Khalighi wrote:
> 
> >Even more condensed:
> >
> >\documentclass{article}
> >\makeatletter
> >\def\vafa#1{\ifcase#1\or ??\or ??\or ??\or ??\or ??\fi}
> >\let\@Alph\vafa
> >\makeatother
> >\usepackage{hyperref}
> >\begin{document}
> >\tableofcontents
> >\section{Test}
> >\newpage
> >\appendix
> >\section{Another Test}
> >\end{document}
> >
> >It seems that the actual problem is because of the presence of
> >Persian characters.
> 
> Isn't the problem more fundamental than this?
> 
> Strings cannot be put directly into a PDF document in UTF8 encoding.
> It needs to be either Latin-1 + octal codes, or UTF16 as Hexadecimal.
> 
> So when writing destination names, and into the .out file for
> bookmarks, you need to adjust your macros to produce strings
> in one of these formats.

The .out file can be avoided by using package `bookmark'.

> But in your example, it is the destination name that is
> causing the problem, when constructing a value for
>    \theHsection
> via  \Alph {section} .
> 
> At the relevant place in the coding there is no reason at all
> to be using unicode characters, as this number is only being
> used internally.
> So you should be adjusting a macro somewhere to *not* patch in
> the Persian form of \@Alph but keep using the usual Latin form.
> 
> In particular, the following is wrong:
> 
>    \let\@latinalph\@alph%
>    \let\@latinAlph\@Alph%
>    \let\@alph\abjad%
>    \let\@Alph\abjad%
> 
> This rebinding of \@Alph and \@alph  should not be done *globally*.
> It should be a *local* rebinding, made only when creating numbers
> for visual display, but not when the numbers are being used
> to create destination and label names.

Agreed. Additionally I have updated hyperref, an unknown \@Alph
is replaced by "Alph" + arabic number, instead of an Persian "A",
the result for the destinations names is "Alph1".

> Hyperref recognises commands \0 \1 \2 \3 \8 \9 which
> allows octal codes \000 up to \377  (giving 0--255)
> and \8** and \9***  for octal couplets to obtain 16-bit codes.
> 
> So if you were to be putting Persian numbers to be displayed within
> PDF bookmarks, then you would need macros such as the following:
> 
> 
> \def\abj at oct@i#1{%
>  \ifcase#1\or\814\047\814\104\814\101\or\814\050\or\814\054\or\814\057%
>           \or\814\007\840\015\or\814\110\or\814\062\or\814\055\or\814
> \067\fi%
>   \ifnum#1=\z@\abjad at zero\fi}
> \def\abj at oct@ii#1{%
>   \ifcase#1\or\814\315\or\814\241\or\814\104\or\814\105\or\814\106%
>            \or\814\063\or\814\071\or\814\101\or\814\065\fi
>   \ifnum#1=\z@\fi\abj at oct@i}
> \def\abj at oct@iii#1{%
>   \ifcase#1\or\814\102\or\814\061\or\814\064\or\814\052\or\814\053%
>             \or\814\056\or\814\060\or\814\066\or\814\070\fi
>   \ifnum#1=\z@\fi\abj at oct@ii}
> \def\abj at oct@iv#1{%
>   \ifcase#1\or\814\072\fi
>   \ifnum#1=\z@\fi\abj at oct@iii}
> 
> \pdfstringdefDisableCommands{%
>   \let\abj at num@i\abj at oct@i
>   \let\abj at num@ii\abj at oct@ii
>   \let\abj at num@iii\abj at oct@iii
>   \let\abj at num@iv\abj at oct@iv
> }
> 
> I think I've got the octets correct.
> If not, then Heiko might point out any errors.

a) Option `unicode' is necessary.
b) Big chars (code >= 256):
   * big chars of XeTeX/(LuaTeX) should be supported for bookmarks
   * utf8.def and ucs are supported.
c) alternative input for U+1234 is \unichar{"1234} (because of ucs support)

Yours sincerely
  Heiko Oberdiek


More information about the XeTeX mailing list