4

I want to create a tree using forest with large \llbracket and \rrbracket around it (semantic interpretation brackets). schemabox looks hopeful but doesn't seem to work.

How do I do this?

(Alternatively, is there another tree package I can use that can do this?)

\documentclass[a4paper]{article}
\usepackage{graphicx}
\usepackage{forest}
\begin{document}

% big open double-bracket here
\begin{forest}
 [A tree] 
\end{forest}
% big close double-bracket here

\end{document}
  • Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – cfr Oct 6 '14 at 19:29
  • Thanks, I didn't think a mwe would be applicable itfp. Added. – Joe Oct 6 '14 at 19:31
3
\documentclass[a4paper]{article}
\usepackage{graphicx}
\usepackage{forest,stmaryrd}
\begin{document}

$\left\llbracket
\begin{forest}
 [A tree] 
\end{forest}
\right\rrbracket$

\end{document}

A macro to do this, vertically centred:

\newcommand{\brr}[1]{
\left\llbracket\raisebox{-.5\height}{ #1 }
\right\rrbracket}

Use:

\begin{equation}
\brr{\begin{forest}[X]\end{forest}}
\end{equation}
|improve this answer|||||
  • Wouldn't a bracketedforest environment be useful? – egreg Oct 6 '14 at 20:36
  • 1
    I'm actually using this in an equation and the brackets extend a bit far down. It looks like there's a margin at the bottom of the tree. Any ideas? – Joe Oct 6 '14 at 20:39
  • @Joe tex delimiters always stretch same amount up and down so if teh box with the forest isn't vertically centred it will do that, you can always use \left(\raisebox{-.5\height}{\begin{forest}... or whatever vertical adjustment makes the brackets come out right – David Carlisle Oct 6 '14 at 20:55
  • I turned both your pieces of advice into a macro and updated your answer, hope you don't mind! – Joe Oct 7 '14 at 9:10
  • Can't you avoid the \raisebox by using the baseline tikz option? – Bordaigorl Oct 7 '14 at 10:09
2

Since forest uses tikz you could simply do the drawing in tikz:

enter image description here

Code:

\documentclass[a4paper]{article}
\usepackage{graphicx}
\usepackage{forest}

\newcommand{\StubSize}{0.5em}%
\newcommand{\BraceForest}[1][]{%
    \begin{scope}[overlay]
        \coordinate (Left Start)  at ($(current bounding box.south west)+(\StubSize,0ex)$);
        \coordinate (Left End)    at ($(current bounding box.north west)+(\StubSize,0ex)$);
        \coordinate (Right Start) at ($(current bounding box.south east)-(\StubSize,0ex)$);
        \coordinate (Right End)   at ($(current bounding box.north east)-(\StubSize,0ex)$);
        \draw [#1] (Left Start) 
                -- (current bounding box.south west)
                -- (current bounding box.north west)
                -- (Left End);
        \draw [#1] (Right Start) 
                -- (current bounding box.south east)
                -- (current bounding box.north east)
                -- (Right End);
    \end{scope}
}


\begin{document}

\begin{forest}
 [A tree] 
 \BraceForest[red,ultra thick]%
\end{forest}

\end{document}
|improve this answer|||||
  • Thanks very much. I think David Carlisle's answer looks a bit more canonical though! This may come in handy if the brackets get out of hand... – Joe Oct 6 '14 at 21:38

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.