Going back up a tree using forest package

Here is a tree that is, in spirit, what I want: Going down with arrows and back up in red or in blue (with blue edges having labels).

\begin{forest}
for tree={parent anchor=children,edge={->}}
[AAA
[BBB
[D]
{\draw[->,blue] () to[out=north,in=south west,edge label=foo] (!u);}
[E]
{\draw[->,red] () to[out=north,in=south east] (!u);}
]
{\draw[->,blue] () to[out=north,in=south west,edge label=bar] (!u);}
[CCC
[F]
[G]
]
{\draw[->,red] () to[out=north,in=south east] (!u);}
]
\end{forest}


I have a few questions:

1. How can I define macros---say, upred and upblue{label}---so I won't have to repeat myself too much?
2. Some arrow heads in the tree are messed up. Why?
3. The tree is very compact. How can it be loosened a bit?

Any help would be appreciated, especially on the first point.

Thanks,

MC

• Welcome to TeX.SE! The problem of the arrows is due to the fact that you do not set appropriate anchors in your targets. If you replace (!u) by (!u.-90),say, it should become better. I am saying "should" because you make it inconvenient to test this. To encourage more people to look at your question, please provide a compilable version, i.e. some code that starts with \documentclass and ends with \end{document}. – user121799 Oct 5 '18 at 23:12
• You have two pseudo Michel Charpentier (user:171866) and user171864, use only one and ask a moderator to delete the other. – AndréC Nov 11 '18 at 7:02

I may completely misinterpret the question. Assuming that you wish to draw the arrows running back in blue or red, depending on whether they are on the left or right, you may simply modify the edge path.

\documentclass{article}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={parent anchor=children,
where n=1{edge path={%
\noexpand\draw[-latex] (!u.parent anchor)--(.child anchor);
\noexpand\draw[-latex,blue] (.child anchor) to[out=90,in=-135] \forestoption{edge
label} (!u.-130);
}}{edge path={%
\noexpand\draw[-latex] (!u.parent anchor)--(.child anchor);
\noexpand\draw[-latex,red] (.child anchor) to[out=90,in=-45] \forestoption{edge
label} (!u.-50);
}}
},
[AAA
[BBB,edge label={node[midway,left=1pt]{foo}}
[D,edge label={node[midway,left=1pt]{bar}}]
[E]
]
[CCC
[F]
[G]
]
]
\end{forest}
\end{document}


The problem of incorrect arrows is taken care of by specifying appropriate end points (anchors).

• Take a look at edge path'. It is much simpler to use. – cfr Nov 11 '18 at 4:29