[Tex/LaTex] Getting pax/pdfpages to work with xelatex

paxpdfpagesxetex

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}
\hypersetup{colorlinks=true, linkcolor=blue, citecolor=blue, filecolor=blue, urlcolor=blue} %


\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}
\hypersetup{colorlinks=true, linkcolor=red, citecolor=red, filecolor=red, urlcolor=red} %

\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/}.

}

\includepdf[pages=1,scale=0.6,frame,pagecommand={\excerpt},link]{insert.pdf}


\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?

Best Answer

pax uses the following pdftex primitives:

\pdfstartlink
\pdfendlink
\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.

Related Question