4

I am trying to make a linguistics tree using the forest package, as in the second example in this thread. I was able to generate the tree for the most part, but I cannot draw the triangle for some reason.

Here is my MWE:

\documentclass{article}
\usepackage{forest}
\usepackage{amsmath,amsfonts,amssymb}
\begin{document}
\begin{forest}
for tree={
  if n children =0{
    font=\itshape,
    tier=terminal
  }{},
}
[TP
    [NP
        [Det
            [The]
        ]
        [$\bar{N}$
            [N
                [ice]
            ]
        ]
    ]
    [$\bar{T}$
        [T
            [+pst,font=\scshape]
        ]
        [VP
            [$\bar{V}$
                [V
                    [melt]
                ]
            ]
            [AdvP
                [quickly,triangle]
            ]
        ]
    ]
]
\end{forest}
\end{document}

When I run this, I get the following error:

! Package pgfkeys Error: I do not know the key '/tikz/triangle' and I am going to ignore it. Perhaps you misspelled it. See the pgfkeys package documentation for explanation. Type H for immediate help.... \end{forest}

I am running Texmaker 4.4.1 on MiKTeX 2.9. My pgf version is 3.0.1a, and I am using pdfTeX version 3.1415926-2.5-1.40.14. A redditor was able to run the code on pdfTeX 3.1415926-2.5-1.40.14 (TeX Live 2013/Debian).

Curiously, I was also successful on my MacBook, using Texmaker 4.2, TeX Live 2014, pgf 3.0.0., and pdfTeX 3.1415926-2.6-1.40.15.

Is there perhaps some way to downgrade my version of pgf? Or is there error from something else?

  • Welcome! Could you please check which version of forest you have? – cfr Feb 6 '16 at 1:28
  • @cfr I am using version 2.0.0. – Andrew W. Feb 6 '16 at 2:45
  • That was my guess because I got just the same error when I ran your code, despite writing the answer you referred to as the source ;). – cfr Feb 6 '16 at 2:47
5

The first thing you should check is the version of forest you have. If you have version 2, then the following answer applies. If you still have version 1, then it is irrelevant.


Assuming you have version 2...

The new version of forest introduces some backwards-incompatible changes. In this case, two of these concern us:

  1. Certain clusters of options are now organised into libraries and must be loaded separately.

  2. Certain options have been renamed or no longer exist.

triangle no longer exists as an option at all. The new option is roof. However, to access roof, you need to load the linguistics library.

The process is not very clear from the documentation. The first problem is that

texdoc forest

now gives you the documented code but not the user manual.

texdoc -l forest

gives you the choice of viewing the user manual, which is now in forest-doc.pdf.

The mechanism for loading libraries is explained on page 20.

Essentially,

\useforestlibrary{<list of libraries>}

loads a list of libraries and

\forestapplylibrarydefaults{<list of libraries>}

applies their default settings, making any additional options etc. available.

\useforestlibrary{}, like \usepackage{} and \usetikzlibrary{} is for use only in the preamble.

\forestapplylibrarydefaults{} can be used in the preamble or the document and applies within the current TeX scope.

An alternative is to pass the name of the library as an option when loading forest

\usepackage[<list of libraries>]{forest}

which has the effect of loading the libraries and applying the defaults document-wide.

Note that

\forestapplylibrarydefaults{<libraries>}

has no effect unless <libraries> have been loaded. Confusingly, however, it does not give an error.

In any case, the upshot of this is that we need to load and apply the linguistics library and change triangle to roof:

\documentclass[tikz, border=10pt, multi]{standalone}
\usepackage{forest}
\usepackage{amsmath,amsfonts,amssymb}
\useforestlibrary{linguistics}
\forestapplylibrarydefaults{linguistics}
\begin{document}
\begin{forest}
for tree={
  if n children =0{
    font=\itshape,
    tier=terminal
  }{},
}
[TP
    [NP
        [Det
            [The]
        ]
        [$\bar{N}$
            [N
                [ice]
            ]
        ]
    ]
    [$\bar{T}$
        [T
            [+pst,font=\scshape]
        ]
        [VP
            [$\bar{V}$
                [V
                    [melt]
                ]
            ]
            [AdvP
                [quickly,roof]
            ]
        ]
    ]
]
\end{forest}
\end{document}

forest version 2 roofs in linguistics

Note that this also changes the anchors and so the appearance of the edges. Hopefully, this is what you want since I believe this style is normal in linguistics. It does, however, mean that your trees will look a little different if you previously used the default style for anchors and edges.

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.