overlays of edge related shapes in forest

My question Drawing an ellipse around an edge in forest resulted in the following code with a forest style circle edge. I want to show and hide this edge for presentations with beamerbut cannot figure out how to do this. I already found visible on but I cannot combine this with the forest style.

\documentclass{beamer}

\usepackage[linguistics]{forest}

\usetikzlibrary{shapes.geometric,fit}

\forestset{%
circle edge/.style={
tikz+={
\node [fit=(.child anchor) (!u.parent anchor), draw=red, ellipse, inner ysep=1.5pt, line
width=0.25mm] {};
}
},
}

\tikzset{
invisible/.style={opacity=0,text opacity=0},
visible on/.style={alt=#1{}{invisible}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
},
}
\forestset{
visible on/.style={
for ancestors'={
/tikz/visible on={#1},
edge={/tikz/visible on={#1}}}}}

\begin{document}

\frame{

\begin{forest}
[S
[NP$_x$ [he,tier=words]]
[VP
[V x z y
[V x y, circle edge={/tikz/visible on=<3>}
[baked]]]
[NP$_z$ [her,tier=words]]
[NP$_y$ [a cake,roof,tier=words]]]]
\end{forest}

\pause\pause\pause

}

\end{document}


Edit: My solution below works for simple cases like <3->but it fails for <2,4>because of the comma. Is there a way to get the comma through to beamer?

You can deal with the comma in an overlay specification by using curly brackets around it.

          [V x y, circle edge=<{2,4}>


You can control the colour of the ellipse, without use of a second argument, by declaring a toks option.

For example, use circle edge colour for the colour and then use this option as the value for draw when drawing the node.

\forestset{%
circle edge/.style={
tikz+={
\node [fit=(.child anchor) (!u.parent anchor), visible on=#1, ellipse, inner ysep=1.5pt, line
width=0.25mm, draw=\foresteoption{circle edge colour}] {};
},
},


Declare the option and set the default for a red ellipse.

  declare toks={circle edge colour}{red},
}


Putting this together, we can create a blue ellipse on slides 2 and 4.

          [V x y, circle edge=<{2,4}>, circle edge colour=blue


Complete code (note that the \pause\pause\pause is superfluous as far as I can tell):

% addaswyd o ateb (a chwestiwn) Stefan Müller: http://tex.stackexchange.com/a/355485/
\documentclass{beamer}
\usepackage[linguistics]{forest}
\usetikzlibrary{shapes.geometric,fit}
\forestset{%
circle edge/.style={
tikz+={
\node [fit=(.child anchor) (!u.parent anchor), visible on=#1, ellipse, inner ysep=1.5pt, line
width=0.25mm, draw=\foresteoption{circle edge colour}] {};
},
},
declare toks={circle edge colour}{red},
}

\tikzset{% set up for transitions using tikz with beamer overlays - developed by Daniel (http://tex.stackexchange.com/a/55849/) and, in earlier form, by Matthew Leingang (http://tex.stackexchange.com/a/6155/) and modified for this use, I think by Qrrbrbirlbel (http://tex.stackexchange.com/a/112471/)
invisible/.style={opacity=0,text opacity=0},
visible on/.style={alt=#1{}{invisible}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
},
}
\begin{document}

\begin{frame}
\centering
\begin{forest}
[S
[NP$_x$ [he,tier=words]]
[VP
[V x z y
[V x y, circle edge=<{2,4}>, circle edge colour=blue
[baked]]]
[NP$_z$, calign with current [her,tier=words]]
[NP$_y$ [a cake,roof,tier=words]]]]
\end{forest}
\end{frame}

\end{document}


Found the answer here Using beamer overlays with forest generated trees. One can call the visible on style in circle edge and pass the <3-> information as an argument. An open issue is how to pass <2,4>. The comma is a problem.

The only disadvantage of this is that one cannot pass the color argument for the color of the ellipse without having two arguments.

\documentclass{beamer}

\usepackage[linguistics]{forest}

\usetikzlibrary{shapes.geometric,fit}

\forestset{%
circle edge/.style={
tikz+={
\node [fit=(.child anchor) (!u.parent anchor), draw=red, visible on=#1, ellipse, inner ysep=1.5pt, line
width=0.25mm] {};
}
},
}

\tikzset{
invisible/.style={opacity=0,text opacity=0},
visible on/.style={alt=#1{}{invisible}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
},
}

\begin{document}

\frame{

\begin{forest}
[S
[NP$_x$ [he,tier=words]]
[VP
[V x z y
[V x y, circle edge=<3->
[baked]]]
[NP$_z$ [her,tier=words]]
[NP$_y$ [a cake,roof,tier=words]]]]
\end{forest}

\pause\pause\pause

}

\end{document}

• You don't actually need the \forestset visible on part here - you aren't using it at all. – cfr Feb 25 '17 at 1:15
• I am very sorry. This is really embarrassing. Usually I do this and I also have the URL in the code I use. I removed it from the code here since it does not belong there, but I should have provided it in the description. Did this now. – Stefan Müller Feb 26 '17 at 8:26
• Do you know a way to deal with <2,4>? – Stefan Müller Feb 26 '17 at 8:33
• Please see my answer below. You can declare a toks for the colour and just need curly brackets to deal with the comma. – cfr Feb 26 '17 at 23:19
• I tried the curly brackets everywhere but inside the angle brackets. Thanks! – Stefan Müller Feb 27 '17 at 8:32