[XeTeX] How to enable hyperlinks with hyperref
Maxim Cournoyer
maxim.cournoyer at gmail.com
Mon Nov 23 01:20:20 CET 2009
Hello Peter, thank you very much for your kind help.
> \usepackage[xetex]{hyperref} % or
> > \usepackage[dvipdfm]{hyperref}
>
> None of these specialised forms is needed nowadays, hyperref
> determines automatically which TeX variant in which mode is running.
>
> >
> > I'm using babelbib
>
> I haven't used it yet...
>
> > Here's my preamble :
> >
> > \documentclass[12pt,letterpaper,draft]{article}
>
> If you pass the letterpaper option to geometry, then you can save the
> \special line.
> >
> >
> > % Packages
> > \usepackage[canadien,english]{babel}
> > \usepackage[top=2.75cm, bottom=3cm, left=2.5cm, right=2.5cm]{geometry}
> > \usepackage{fancyhdr}
> > \usepackage{ifpdf}
>
> Ifxetex is a nice package, too!
>
> > \usepackage[fixlanguage]{babelbib}
> > \usepackage[dvipdfm]{hyperref}
> >
> > % Layout et options
> > \special{papersize=8.5in,11in}
> > \setlength{\headheight}{15pt}
>
> Isn't this line better put to the geometry options? Or is it specific
> for fancyhdr?
>
> > \renewcommand{\baselinestretch}{1.5}
> > \hypersetup{urlcolor=cyan}
> >
> > % XeTeX specific
> > \usepackage{xunicode}
>
> If xunicode, or xltxtra, find that fontspec wasn't loaded before, it
> gets load.
>
> > \usepackage{fontspec}
> > \usepackage{xltxtra}
I have followed and implemented your recommendations; the result is a cleaner preamble :
\documentclass[12pt,draft]{article}
% Packages
\usepackage[canadien,english]{babel}
\usepackage[letterpaper,margin=2.5cm,headheight=15pt]{geometry}
\usepackage{fancyhdr}
\usepackage[fixlanguage]{babelbib}
\usepackage{hyperref}
% Layout and options
\renewcommand{\baselinestretch}{1.5}
% XeTeX specific
\usepackage{xunicode}
\usepackage{xltxtra}
\setromanfont[Mapping=tex-text]{Linux Libertine O}
\setsansfont[Mapping=tex-text]{Linux Biolinum O}
\setmonofont[Mapping=tex-text,Scale=0.9]{Courier New}
Also, I didn't know about ifxetex. I'll sure make something useful with
it as I refine my approach and learn more. (this is my first touch with
TeX/LaTeX/XeTeX)
> And you can swear every oath that the following minimal code fails on your PC?
>
> \documentclass[12pt]{article}
> \usepackage{ifpdf,ifxetex}
> \usepackage[svgnames]{xcolor}
> \usepackage[letterpaper]{geometry}
> \ifxetex
> \immediate\write16{==High ¡I'm from XeTeX!==}
> \usepackage[no-math]{fontspec}
> % \usepackage{xltxtra,xunicode}
> \usepackage[raiselinks=true]{hyperref}
> \defaultfontfeatures{Mapping=tex-text}
> % \setromanfont{Lucida Bright} % The Lucida fonts are in Java...
> % \setsansfont{Lucida Sans}
> % \setmonofont{Lucida Sans Typewriter}
> % \newfontface\slanted[RawFeature={slant=0.194},Colour=884444]
> {Lucida Bright}
> % \DeclareRobustCommand{\textsl}[1]{{\slanted #1}}
> \else
> \immediate\write16{==Notice: No XeTeX==}
> \usepackage[utf8]{inputenc}
> \ifpdf
> \immediate\write16{==\jobname: Bonjour, PDF!==}
> \usepackage{cmap}
> \usepackage[activate={true,nocompatibility}]{microtype}
> \usepackage[bookmarks=true,backref=section,debug=true]{hyperref}
> \makeatletter
> \@ifundefined{pdffilemoddate}{%
> \PackageError{sourcetime}{%
> pdfTeX >= 1.30.0 required%
> }%
> \let\pdffilemoddate\@gobble
> }{}%
> \newcommand*{\SourceFile}[1]{%
> \edef\@SourceFileDate{\pdffilemoddate{#1}}%
> % empty in case of errors, but don't harm in next comparison
> \ifnum\pdfstrcmp{\@SourceFileDate}{\@CurrentSourceFileDate}>0 %
> \let\@CurrentSourceFileDate\@SourceFileDate
> \expandafter\@ParseDate\@SourceFileDate\@nil
> \hypersetup{%
> pdfcreationdate={\@SourceFileDate},%
> pdfmoddate={\@SourceFileDate}%
> }%
> \PackageInfo{sourcetime}{%
> Using file `#1'%
> }%
> \fi
> }
> \newcommand*{\@CurrentSourceFileDate}{}
> \expandafter\def\expandafter\@ParseDate\detokenize{D:}
> #1#2#3#4#5#6#7#8{%
> \year=#1#2#3#4\relax
> \month=#5#6\relax
> \day=#7#8\relax
> \@ParseTime
> }
> \def\@ParseTime #1#2#3#4#5\@nil{%
> \time=\numexpr #1#2 * 60 + #3#4\relax
> }
> \makeatother
> \SourceFile{\jobname.tex}
> \else
> \immediate\write16{==Bad luck – \jobname: DVI==}
> \usepackage[protrusion=true,expansion=false]{microtype}
> \fi
> \usepackage[T1]{fontenc}
> \usepackage[full]{textcomp}
> % \usepackage{lucida}
> \renewcommand{\sfdefault}{pag}
> \renewcommand{\rmdefault}{ppl}
> \renewcommand{\ttdefault}{pcr}
> \makeatletter
> \newcommand*\TeX at logo@spacing[6]{%
> \def\xxt at kern@Te{#1}%
> \def\xxt at kern@eX{#2}%
> \def\xxt at lower@e{#3}%
> \def\xxt at kern@La{#4}%
> \def\xxt at kern@aT{#5}%
> \def\xxt at kern@eL{#6}%
> }
> \DeclareRobustCommand\XeTeX{%
> \leavevmode
> \smash{%
> X\lower\xxt at lower@e
> \hbox{\kern\xxt at kern@eX
> \setbox0=\hbox{E}\dimen0=\ht0\advance\dimen0by\dp0%
> \reflectbox{E}%
> }\kern\xxt at kern@Te\TeX}}%
> \DeclareRobustCommand\XeLaTeX{%
> \leavevmode
> \smash{%
> X\lower\xxt at lower@e
> \hbox{\kern\xxt at kern@eX
> \setbox0=\hbox{E}\dimen0=\ht0\advance\dimen0by\dp0\relax
> \reflectbox{E}%
> }\kern\xxt at kern@eL\LaTeX}}
> \TeX at logo@spacing{-0.15em}{-0.125em}{0.5ex}{-0.36em}{-0.12em}
> {-0.13em}
> \makeatother
> \fi
> \def\TheTitle{The Common Planet}
> \hypersetup{%
> unicode,
> pdftitle=\TheTitle,
> pdfauthor=directly from the author,
> pdfsubject=The Refferrentz,
> pdfkeywords={A one too three!},
> urlcolor=DarkBlue,
> linkcolor=NavyBlue,
> verbose,
> colorlinks
> }
> \begin{document}
> \title{\textcolor{DarkGoldenrod}{\TheTitle}}
> \author{Clark Kent\\
> \href{mailto:Clark_Kent at FlatEarth.NET}{\small\itshape Clark
> \textunderscore Kent at FlatEarth.NET}}
> \date{\today}
> \maketitle
> \tableofcontents
> \newpage
>
> \section{First Page}
> The text body of the first page.
> \newpage
> \section{On Second Page}
> The text continues on the second page.
> \newpage
> \section{The Third Page}
> The text \textsl{further} continues on the third page.
>
> \end{document}
It does work (even with the links!!), after making slight corrections to
please the compiler (removing the [no-math] option from package and the
lone line {Lucida Bright}).
After 2 hours trying to find what was not right with my code... It turns
out that the hyperref cannot generate links when my document is in draft
mode. Changing \documentclass[12pt,draft]{article} to
\documentclass[12pt]{article} allowed XeTeX to generate the hyperlinks.
I'll remember it for a long time. May the draft mode be damn. Wouldn't
this be a bug? I haven't entirely RTFM, but it seems a bit weird to me.
Thank you again and good night all,
Maxim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/xetex/attachments/20091122/3e36dc1a/attachment-0001.html>
More information about the XeTeX
mailing list