看起来 ( tex
)animation
答案是我现在能想到的最好的答案。以下.Rnw
文件将创建一个 pdf,中间有一个图形,下面有 2 个文本超链接,它们分别切换红色和蓝色框的可见性。我在这里找到了使这项工作的 Tex 代码。我还没有看过@Aaron 的ocgtools
建议,但会到达那里。谢谢大家的建议!
\documentclass{article}
%----------------------------------------------------------------%\
\usepackage[OT1]{fontenc}
\usepackage{Sweave}
\usepackage{animate}
\usepackage{hyperref}
\usepackage[margin=0.4in]{geometry}
%----------------------------------------------------------------%
\makeatletter
% command to create a toggle link
\newcommand{\ShowHideLayer}[3]{%
% #1: anim No. (zero-based),
% #2: layer No. (zero-based),
% #3: link text
\leavevmode%
\pdfstartlink user {
/Subtype /Link
/Border [\@pdfborder]%
/A <<
/S/JavaScript
/JS (
\if at anim@useocg%
if(a#1.fr[#2].state==true){
a#1.fr[#2].state=false;
}else{
a#1.fr[#2].state=true;
}
\else
if (a#1.fr[#2].display==display.visible){
a#1.fr[#2].display=display.hidden;
}else{
a#1.fr[#2].display=display.visible;
}
this.dirty=false;
\fi
)
>>
}#3%
\pdfendlink%
}
% command to create a link to show/hide all layers
\newcommand{\ShowHideAll}[2]{%
% #1: anim No. (zero-based),
% #2: link text
\leavevmode%
\pdfstartlink user {
/Subtype /Link
/Border [\@pdfborder]%
/A <<
/S/JavaScript
/JS (
var countvisible=0;
for(var i in a#1.fr){
\if at anim@useocg
if(a#1.fr[i].state==true){countvisible++;}
\else
if (a#1.fr[i].display==display.visible){countvisible++;}
\fi
}
if(countvisible){
for(var i in a#1.fr){
\if at anim@useocg
a#1.fr[i].state=false;
\else
a#1.fr[i].display=display.hidden;
this.dirty=false;
\fi
}
}
else{
for(var i in a#1.fr){
\if at anim@useocg
a#1.fr[i].state=true;
\else
a#1.fr[i].display=display.visible;
this.dirty=false;
\fi
}
}
)
>>
}#2%
\pdfendlink%
}
\makeatother
\begin{document}
% heres the R-making of the plots, saved to working directory,
% which should be the folder containing this .Rnw file
% 3 versions of the same plot, one for each layer
<<echo = FALSE, hide = TRUE>>=
pdf("layer-0.pdf")
plot(NULL, type = "n", xlim = c(0, 1), ylim = c(0, 1), xlab = "", ylab = "")
dev.off()
pdf("layer-1.pdf")
plot(NULL, type = "n", xlim = c(0, 1), ylim = c(0, 1), axes = FALSE, xlab = "", ylab = "")
rect(0, .7, .7, 0, border = "blue", lwd = 2)
dev.off()
pdf("layer-2.pdf")
plot(NULL, type = "n", xlim = c(0, 1), ylim = c(0, 1), axes = FALSE, xlab = "", ylab = "")
rect(.3, 1, 1, .3, border = "red", lty = 2, lwd = 2)
dev.off()
@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{center}
%animated layer-set No. 0
% v-- frame rate ignored
\animategraphics[width=1\linewidth,step]{1}{layer-}{0}{2}
\ShowHideLayer{0}{1}{toggle red box}\\
\ShowHideLayer{0}{2}{toggle blue box}\\
\end{center}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}