hyperlink - xelatex 和 tikz 超链接节点似乎没有链接

标签 hyperlink tikz xelatex

我按照https://tex.stackexchange.com/questions/36109/making-tikz-nodes-hyperlinkable上的食谱进行操作创建可单击链接到文档中其他位置的节点。节点链接在使用 lualatex 构建时可以工作,但在使用 xelatex 构建时似乎根本不起作用——尽管它们确实按预期渲染到屏幕上(节点上的绿色覆盖层是为了证明 hyperlink node 正在被调用,当我不调试时它会消失)。

我的MWE:

\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage[colorlinks,linkcolor=green!50!black]{hyperref}

\tikzset{
  hyperlink node/.style={
    alias=sourcenode,
    append after command={
      let \p1 = (sourcenode.north west),
          \p2=(sourcenode.south east),
          \n1={\x2-\x1},
          \n2={\y1-\y2} in
      node [draw=green!50!black,rounded corners,opacity=0.5,fill=green,inner sep=0pt,outer sep=0pt,anchor=north west,at=(\p1)] {\hyperlink{#1}{\phantom{\rule{\n1}{\n2}}}}
    }
  },
  mynode/.style={rectangle, rounded corners, fill=white,draw=black},
  edge/.style={>=Stealth},
}

\begin{document}

\begin{tikzpicture}

  \node [mynode] (a) {Not a link};
  \node [mynode,hyperlink node=LinkHere] (b) [right=30mm] {This is a link};

  \path (a) -> (b);

\end{tikzpicture}

In text, though:

Not a link.

\hyperlink{LinkHere}{This is a link} also

\clearpage

This page deliberately left blank.

\clearpage

\hypertarget{LinkHere}{}
Link lands here.
\end{document}

使用 xelatex 构建,单击绿色节点不会将我带到第三页,但单击文本链接(下面的绿色文本,“这是一个链接”)可以。当我使用 lualatex 构建 PDF 时,这两个超链接都有效。

为什么这在 lualatex 中有效,但在 xelatex 中无效,我该怎么办?另外,我喜欢从 xelatex 获得的输出(布局和字体渲染有点不同),但链接很重要。使用 xelatex 构建时,如何使超链接节点正常工作?

使用

  • XeTeX 3.1415926-2.5-0.9999.3-2013060708(TeX Live 2013)
  • LuaTeX,版本 beta-0.76.0-2013061708(TeX Live 2013)(修订版 4627)

简单调用:

$ xelatex mwe.tex; mv mwe.pdf mwe-xelatex.pdf
$ lualatex mwe.tex; mv mwe.pdf mwe-lualatex.pdf

我刚刚确定使用 navigator.sty包而不是 hyperref.sty使用 \jumplink 时表现出相同的行为差异和\anchor而不是\hyperlink\hypertarget .

最佳答案

啊哈。

TL;DR: replace \hyperlink{#1}{\phantom{\rule{\n1}{\n2}}}} with \hyperlink{#1}{\XeTeXLinkBox{\phantom{\rule{\n1}{\n2}}}}}

我在下面添加了工作(文本)链接:

\hyperlink{LinkHere}{\rule{1in}{1in}}

这几乎就是我在超链接节点中所拥有的内容。该规则呈现为绿色,因为它是 \hyperlink,但是当使用 xelatex 编译 PDF 时,单击它没有任何反应。问题并不在于 xelatex 和 TikZ,而是 xelatex 和 hyperref.sty。每https://tex.stackexchange.com/questions/56802/hyperlinking-a-drawing xelatex 仅在找到文本时链接。

\XeTeXLinkBox 已添加到 hyperref.sty 中,专门用于处理此问题。您仍然需要使用 \phantom{} 来隐藏规则。

比 MWE 稍微多一点,它确实满足了我的要求,并演示了使用 \XeTeXLinkBox 和不使用它的区别。

\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage[colorlinks,linkcolor=green!50!black]{hyperref}

\setlength{\XeTeXLinkMargin}{0pt}
\tikzset{
  hyperlink node/.style={
    alias=sourcenode,
    append after command={
      let \p1 = (sourcenode.north west),
          \p2=(sourcenode.south east),
          \n1={\x2-\x1},
          \n2={\y1-\y2} in
      node [draw=green!50!black,rounded corners,opacity=0.5,fill=green,inner sep=0pt,outer sep=0pt,anchor=north west,at=(\p1)] {\hyperlink{#1}{\XeTeXLinkBox{\phantom{\rule{\n1}{\n2}}}}}
    }
  },
  mynode/.style={rectangle, rounded corners, fill=white,draw=black},
  edge/.style={>=Stealth},
}

\begin{document}

\begin{tikzpicture}

  \node [mynode] (a) {Not a link};
  \node [mynode,hyperlink node=LinkHere] (b) [right=30mm] {This is a link};

  \path (a) -> (b);

\end{tikzpicture}

In text, though:

Not a link.

\hyperlink{LinkHere}{This is a link} also

---

\hyperlink{LinkHere}{test\ldots \rule{1in}{1in}\ldots big green box doesn't work, text does}

---

\hyperlink{LinkHere}{test\ldots \XeTeXLinkBox{\rule{1in}{1in}}\ldots big green box now \emph{does} work, and so does text}

---

\clearpage

This page deliberately left blank.

\clearpage

\hypertarget{LinkHere}{}
Link lands here.
\end{document}

关于hyperlink - xelatex 和 tikz 超链接节点似乎没有链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24198272/

相关文章:

html - 文件 ://protocol not working under ssl?

c - 如何将 lsusb 设备的结果链接到/dev/ttyUSB*

android - 使字符串可点击,在 TextView 中加下划线

latex - XeTeX - 检测何时需要重新运行

latex - 我可以在 LaTeX 而不是 TeX 中编写 cls 文件吗?

xml - LaTex 到 Tei (xml)

html - mailinator中的电子邮件链接目标已更改

latex - 使用 Tikz 连接节点而不跨越其他 block

latex - Tikz:从节点绘制边到另一边的标签

latex /tikZ : how to draw 2 vertical arrows from 2 nodes south to 1 node north?