我可以将 ocg 命令和超链接组合起来吗?例如,我可以将第二页上的以下两个命令变成只需单击一次即可返回第一页并切换 ocg
\documentclass{article}
\usepackage{ocgx2}
\usepackage{hyperref}
\begin{document}
\hypertarget{target}{Now it's}
\begin{ocg}{Sidebar label}{ocglabel}{1} here \end{ocg}
\newpage
\switchocg{ocglabel}{Click here first to toggle ocg}
\hyperlink{target}{Then click here to go to page 1}
\end{document}
答案1
点击链接时可以执行的多个操作可以串联在一起,这得益于/Next <<...>>
通过PDF 链接注释中的条目,
不幸的是,Evince 似乎没有评估/Next ...
。因此,我们只能使用 Acrobat Reader。这应该作为错误或功能请求报告给 Evince 开发人员。
下面的示例定义了一个命令,用于创建看起来像hyperref
生成的链接的链接,并根据要求结合了 OCG Toggle 和 GoTo 操作。
\documentclass{article}
\usepackage{ocgx2}
\usepackage{hyperref}
\ExplSyntaxOn
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\toggleOCGGoTo[3]{
\leavevmode
\pbs_pdflink:nn{
/Subtype/Link
/A <<
/S/SetOCGState
/State [
/Toggle~\tl_if_exist:cT{ocgx2.ocg.#1}{\tl_use:c{ocgx2.ocg.#1}}
]
/Next << /S/GoTo/D~(#2) >>
>>
%look and feel of hyperref links, if hyperref has been loaded
\cs_if_exist:NTF\Hy@setpdfborder{
\Hy@setpdfborder\g_ocgxii_patch_tl
\ifx\@pdfhighlight\@empty\else/H\@pdfhighlight\fi
\ifx\@linkbordercolor\relax\else/C[\@linkbordercolor]\fi
\ifHy@pdfa /F~4\fi
}{
/Border~[0~0~0]
}
}{
\cs_if_exist:NTF\Hy@colorlink{
\Hy@colorlink\@linkcolor#3\Hy@endcolorlink\Hy@VerboseLinkStop
}{#3}
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatother
\ExplSyntaxOff
\begin{document}
\hypertarget{target}{Now it's}
\begin{ocg}{Sidebar label}{ocglabel}{1} here \end{ocg}
\newpage
\toggleOCGGoTo{ocglabel}{target}{Toggle OCG and go to target}
\end{document}