# Getting pax/pdfpages to work with xelatex?

Please consider the following MWE, in a form of a batch file, which creates two tex files (one of them gets \includepdfd in the other):

cat > insert.tex <<'EOF'
\documentclass{article}
\usepackage[a4paper]{geometry}

\usepackage{hyperref}

\begin{document}

A test of url: \href{http://www.example.com}{http://www.example.com}

A test of cite: \cite{mytest}

\begin{thebibliography}{9}

\bibitem{mytest} Just Testing, \emph{Just Testing}, 2012.

\end{thebibliography}

\end{document}
EOF

pdflatex insert.tex
pdflatex insert.tex

pdfannotextractor insert.pdf

cat > includer.tex <<'EOF'
\documentclass{article}
\usepackage[a4paper]{geometry}

\usepackage{hyperref}

\usepackage{pdfpages}
\usepackage{pax}

\begin{document}

\def\excerpt{\section{A test of inclusion}

Turns out we cannot just use includepdf in between section and
text, even if it is scaled down - must define the whole section
and use it as a pagecommand, see \url{http://tex.stackexchange.com/questions/5911/}.

}

\end{document}
EOF

# pdflatex includer.tex
# pdflatex includer.tex

xelatex includer.tex
xelatex includer.tex


If I compile the second file, includer.tex, with pdflatex - then all the links work fine in the includer.pdf.

However, if I try to compile includer.tex with xelatex (as in the example), I get:

! Package pax Error: Missing pdfTeX in PDF mode.

See the pax package documentation for explanation.


... after which, the process can continue - but no links in the included pdf work.

The error message is actually quite clear, in that pax doesn't as of yet support xelatex - but I was wandering if anyone, maybe, knows a hack/workaround, so the links would work also with xelatex?

pax uses the following pdftex primitives:

\pdfstartlink
\pdfescapename
\pdfdest
\pdfstrcmp


Only the last one has a counterpart in xetex. You may have better luck with luatex, but \pdfstrcmp and \pdfescapename are only available as \pdf@strcmp and \pdf@escapename by loading pdftexcmds, so possibly

\usepackage{pdftexcmds}
\makeatletter
\let\pdfescapename=\pdf@escapename
\let\pdfstrcmp=\pdf@strcmp
\makeatother
\usepackage{pax}


can work. There's nothing similar with xetex, that uses a completely different model for inserting hyperlinks.

• Many thanks for that, @egreg - wasn't even aware that there are different pdftex primitives supported between engines (pdftex, xetex, luatex) - and it's great to see there's some hope with luatex as it also supports (most) of the fontspec stuff... Many thanks again - cheers! – sdaau Jun 18 '12 at 3:17
• @sdaau Unfortunately, my experiment failed, because my Perl doesn't have a module required by pdfannotextractor. I will retry. – egreg Jun 18 '12 at 6:54
• Hi @egreg - strange, because I actually tried your solution (on my actual work, not on the MWE, though), and works damn fine with my .pax files and lualatex so far!? :) Cheers! – sdaau Jun 18 '12 at 7:00
• @sdaau I tried on a machine where Perl has no problem, and it seems to work: differently from xetex, luatex descends from pdftex and shares many of the specific primitives introduced by it. Some of them have been removed, because they can be emulated with Lua functions (what pdftexcmds does). – egreg Jun 18 '12 at 7:15