I'm trying to find the best way to draw linguistics-style trees in a way which is as agnostic as possible to the variety of TeX which is used (LaTeX, ConTeXt, or plain ol' TeX). Most of the ways to draw trees are, understandably, made for LaTeX (the qtree
variants and forest
), and aren't easily adapted to ConTeXt or plain TeX.
My first thought was to use METAPOST to draw the trees and include the results as PDF or PS graphics, since this removes any dependency on TeX varieties. I found the metaobj
package for METAPOST which makes drawing trees easy-ish. For example, I have the following MWE:
input metaobj;
prologues:=3;
beginfig(1);
setObjectDefaultOption("Tree")("hbsep")(5mm);
setObjectDefaultOption("Tree")("treenodehsize")(2cm);
setCurveDefaultOption("arrows")("draw");
t:=_T(Tr_(btex VoiceP etex))
(
Tr_(btex \vbox{\hbox{DP}\hbox{He}} etex),
_T(Tr_(""))
(
Tr_(btex Voice etex),
Tr_(btex \vbox{\hbox{$v$P}\hbox{runs}} etex)
)
);
Obj(t).c=origin;
draw_Obj(t);
endfig;
For comparison, I'll include the same tree made with qtree
:
\documentclass{standalone}
\usepackage{qtree}
\begin{document}
\Tree [.VoiceP [.DP\\He ] [ [.Voice ] [.$v$P\\runs ] ] ]
\end{document}
The METAPOST version gets 90% of the way there, but there are some problems with the way that metaobj
trees are drawn:
- A node's branches are each drawn from a different point, instead of a common point at the center-bottom of the node.
- The branching angle and branch lengths are not consistent across the tree. Ideally, these would be the same so that the height of the node text wouldn't change the tree structure too much and node-less branches wouldn't be bent.
- I'm not sure how to center multi-line labels.
How can metaobj
/METAPOST be used to get the desired tree style? And, taking a step back from METAPOST, is this the best way to draw trees in this style in a way which is agnostic to the TeX variant used? I went with METAPOST since it produced diagrams which could easily be used in any flavor of TeX, it allows for the inclusion of TeX code in the drawing routine (for example, to switch fonts), and it produces high-quality graphics with support for lots of useful things (for example, drawing movement arrows using regular METAPOST arrows, colors, all the regular drawing capabilities, support for multiple figures in the same file, etc).
pst-jtree
is format independent, (at least plain TeX and LaTeX) although it depends onpstricks
. Andtikz-qtree.sty
is a wrapper fortikz-qtree.tex
. I've never used it with plain TeX but it might be possible as the code doesn't seem to use any LaTeX specific constructs, andtikz
itself is format independent.pstricks
doesn't work properly with LuaTeX and ConTeXt.