3

I have made a simple tree in the forest package, using the string of code below.

\documentclass{article}

\usepackage{gb4e}
\noautomath

\usepackage{forest}

\begin{exe}
\ex 

\begin{forest}

[DP
[D'
    [D]
    [NP
        [N'
            [N]]]]]

\end{forest}

\end{exe}
\end{document}

This gives my the output as a standard syntax tree. However, what I would like to do is something like the what the code below typesets.

\documentclass{article}

\usepackage{gb4e}
\noautomath

\usepackage{forest}

\begin{exe}
\ex $[${\subscript{\scriptsize DP}}$[${\subscript{\scriptsize D'}} $[$ D $]$ $[${\subscript{\scriptsize NP}}  $[${\subscript{\scriptsize N'}} $[$N $]$ $]$ $]$ $]$ $]$

\end{exe}
\end{document}

But I wonder if there is an easy way of just making forest print the syntax tree as labeled brackets instead. There ought to be a simple command for this, but I just can't find it in the manual.

Output enter image description here

1
  • 1
    Hi, it's best to post complete compilable documents rather than code fragments. In this case, for example, you've added fragments of gb4e code which are not relevant to the question, and not so obvious to non-linguists. – Alan Munn Oct 31 '15 at 1:48
6

The below code defines style draw brackets, which outputs the bracket representation, and shows two ways to use it. The first usage case replaces the default content of draw tree stage by the new style; the second one adds to it (and also prefixes each output by an \ex to start a new example).

(amsmath is loaded for \text, but one could also use \mbox{\scriptsize ...} and do without amsmath.)

\documentclass{article}

\usepackage{gb4e}
\noautomath

\usepackage{forest}
\usepackage{amsmath}

\forestset{
  draw brackets/.style={
    TeX={[},
    if n children=0{
      TeX={ \forestoption{content} }
    }{
      TeX={$_{\text{\forestoption{content}}}$ }
    },
    for children=draw brackets,
    TeX={]\space},
  }
}  

\begin{document}

Bracket output instead of a tree:
\begin{exe}
\ex 
\begin{forest}
  draw tree stage/.style={for root'=draw brackets},
[DP
[D'
    [D]
    [NP
        [N'
            [N]]]]]
\end{forest}
\end{exe}

Bracket output additional to the tree:
\begin{exe}
\begin{forest}
  draw tree stage/.style={TeX={\ex},for root'=draw tree,TeX={\ex},for root'=draw brackets},
[DP,baseline
[D'
    [D]
    [NP
        [N'
            [N]]]]]
\end{forest}
\end{exe}

\end{document}

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.