I'm drawing parse trees for formal grammar using the forest
package and would like to have all terminals, that are not Epsilon, to be copied to the bottom and connected to the original node with a dotted line. By reading through the forest documentation I've got a somewhat working minimal example that is missing two essential things: for one, it doesn't copy the content of the original node and uses 'x' as a placeholder, and it currently isn't able to detect the Epsilon nodes and omit the copying for those.
MWE.tex:
\documentclass[paper=a4, fontsize=11pt]{scrartcl}
\usepackage{forest}
\begin{document}
\begin{forest}
before typesetting nodes={
where n children=0{
append={
[x,tier=terminal,edge=dotted]
}
}{}
}
[\(S\)
[\(S_0\)
[\(0\)]
[\(S_0\)
[\(0\)]
[\(S_0\)
[\(0\)]
[\(S_0\)
[\(0\)]
[\(S_0\)
[\(0\)]
]
[\(1\)]
]
[\(1\)]
]
[\(1\)]
]
[\(1\)]
]
[\(S_1\)
[\(2\)]
[\(S_1\)
[\(\epsilon\)]
]
]
]
\end{forest}
\end{document}
MWE.tex produces:
Desired result: