7

I've been using the "nice empty nodes" style from the forest manual for trees for quite a while now. Today I updated the package, and now it throws an error (though the output still seems to work). Minimal example:

\documentclass{article}
\usepackage{forest}
\forestset{
nice empty nodes/.style={
    for tree={calign=fixed edge angles},
    delay={where content={}{shape=coordinate,for parent={
                for children={anchor=north}}}{}}
},
}
\begin{document}
\begin{forest}
    [{},nice empty nodes
    [b][
    [c]
    [
    [b] [a]
    ]
    ]
    ]
\end{forest}
\end{document}

Error: "Package forest Error: nodewalk stepped to the invalid node; stack: ",tree,tree,parent". \end{forest}"

Anyone got an idea how to fix this?

5

As @cfr points out,

The problem is that node walks have changed dramatically and invalid steps now trigger errors by default. Because the root is empty, it gets nice empty nodes treatment and for parent fails because, well, there is no parent.

So yes, this is a bug in the definition of nice empty nodes, so thanks for finding it and poiting it out. I didn't catch it as the only example of nice empty nodes in the documentation doesn't apply the style to the root node, so the docs compiled just fine ...

The solution is actually very simple (and will be included in the upcoming minor release) as forest now has step siblings.

\documentclass{article}
\usepackage{forest}
\forestset{
nice empty nodes/.style={
    for tree={calign=fixed edge angles},
    delay={where content={}{shape=coordinate,for siblings={anchor=north}}{}}
},
}
\begin{document}
\begin{forest}
    [{},nice empty nodes
    [b][
    [c]
    [
    [b] [a]
    ]
    ]
    ]
\end{forest}
\end{document}

Note that the for parent={for children={...}} idiom is not exactly the same as for siblings={...}, as the current node is not walked in the for siblings case. In our case, this makes no difference, as the current node gets a coordinate shape. To get exactly the (old) for parent={for children={...}} behaviour, say for preceding siblings={...},for current and following siblings={...}. And I promise to include key for current and siblings in the next minor release ... I have just not realized until now there's a case where having it makes sense.

  • Much nicer ;)... – cfr Feb 17 '16 at 1:20
  • This is still broken in the current version of Forest. Is there some reason this fix didn't make it into the bug-fix release at the end of last year? I've got Forest 2.1.2, but the linguistics library is 0.1 from 2015. – cfr Jan 26 '17 at 15:21
  • @cfr I'm not sure I understand: the OP's original code is broken by v2 and will remain so (unless compat=1.0-all, or at minimum compat=1.0-forstep is given as package option). (for) current and siblings is included since v2.0.1. – Sašo Živanović Jan 26 '17 at 15:28
  • 1
    @cfr Argh, I was so focused on for current and siblings I forgot about nice empty nodes completely. (And today, again!) Fixing this right away. Thanks! – Sašo Živanović Jan 26 '17 at 23:31
  • 1
    @cfr Done! CTAN, GitHub. – Sašo Živanović Jan 27 '17 at 1:43
4

Surely a bug? It doesn't work even loading the linguistics library and using the official nice empty nodes in a tree preamble.

This is very inelegant, but it should work for now. The problem is that node walks have changed dramatically and invalid steps now trigger errors by default. Because the root is empty, it gets nice empty nodes treatment and for parent fails because, well, there is no parent. Rather than disable that globally, this hopefully disables it just for this node walk. However, I'm sure there is a more efficient approach.

\documentclass[tikz]{standalone}
\usepackage{forest}
\forestset{%
  nice empty nodes/.style={%
    for tree={calign=fixed edge angles},
    delay={%
      where content={}{%
        shape=coordinate,
        for nodewalk={%
          Nodewalk={%
            on invalid=fake,
          }{%
            parent,
          }{%
            for children={anchor=north},
          }
        }{},
      }{},
    },
  },
}

\begin{document}
\begin{forest}
  nice empty nodes
  [
    [b]
    [
      [c]
      [
        [b]
        [a]
      ]
    ]
  ]
\end{forest}
\end{document}

nicer empty nodes?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.