6

We are putting together latex classes for books. We want to make a certain tree style the default for forest. With the example below one has to define the style (sn edges) in every tree. Is there a way to get rid of this specification and make it the default?

\documentclass{minimal}

\usepackage{forest}

\forestset{
sn edges/.style={for tree={parent anchor=south, child anchor=north,align=center,base=bottom,where n children=0{tier=word}{}}}, 
background tree/.style={for tree={text opacity=0.2,draw opacity=0.2,edge={draw opacity=0.2}}}
}


\begin{document}

\begin{forest}
sn edges
[S
  [NP [er\\he] ]
  [NP
    [Det [das\\the] ]
    [N [Buch\\book] ] 
  ]
  [NP
    [Det [der\\the] ]
    [N [Frau\\woman] ] 
  ]
  [V [gibt\\gives] ]
]
\end{forest}

\end{document}
Andrew Swann
  • 95,762
Stefan Müller
  • 6,901
  • 3
  • 29
  • 61

1 Answers1

9

Not sure if the question is unsolved Stefan, but this code for instance is applied to all forest environments:

\forestset{.style={for tree={l=1em, l sep=1em, s sep=1em}}}

In essence, just drop the style name :)

Hope this helps.

JoosBuijs
  • 398
  • 2
    You can also say \forestset{.style={sn edges}} – Andrew Swann May 13 '14 at 12:53
  • 3
    I had no idea this is possible, and I'm the author of forest :-) However, to make the issue clearer, the next version will implement key default preamble. Usage just as above: \forestset{default preamble/.style={sn edges}}} – Sašo Živanović Dec 11 '14 at 14:24
  • @SašoŽivanović Has this feature been added yet? – Alan Munn Jul 19 '15 at 14:45
  • @SašoŽivanović, I'm also interested in whether this feature has been added yet. I don't see it in the July 15 documentation. – Jason Zentz Jul 22 '15 at 19:40
  • 1
    @SašoŽivanović, Are you indicating in your example that the sn edges style will be pre-loaded by forest so that the code for the style doesn't have be copied into the preamble? I like the flexibility and simple syntax of forest, and it's great for compact trees, but I hesitate to recommend it to my linguistics students because it doesn't work "out of the box" the way tikz-qtree does. If I could tell them to just use \usepackage[linguistics]{forest} where the linguistics option would load sn edges and nice empty nodes for every tree, that would be great. – Jason Zentz Jul 22 '15 at 19:42
  • 1
    The feature will be added in v1.1. This summer, promise! ;-) Thanks for the \usepackage[linguistics]{forest} idea, I like it! – Sašo Živanović Jul 22 '15 at 22:36
  • @SašoŽivanović Have you thought about having something like \useforestlibrary{linguistics}? Then people could create libraries as they can for TikZ which grouped related styles etc. together. Otherwise, as soon as you have a linguistics option, somebody (like me) will be asking for a logic option and then somebody else will be using a completely different kind of proof tree and will want otherlogic... and how can you say no to decisiontheory and probability when you've said yes to linguistics, logic and otherlogic? – cfr Oct 23 '15 at 23:32
  • Yess, this is implemented in the upcoming version. \usepackage{forest}\useforestlibrary{linguistics} loads the base package plus linguistics-related stuff, and \usepackage[linguistics]{forest} additionally makes linguistic style the default. And I will be extremely glad to include logic and co! – Sašo Živanović Oct 24 '15 at 01:58
  • 1
    Progress report: it took a long time and lots of work, but I'm finally in the testing phase. TeX.SE is a great help here, as I'm checking for discrepancies between v1.0.x and v1.1 using the code posted on this site! – Sašo Živanović Oct 24 '15 at 02:00
  • I finally know why this method worked. I wrote \pgfkeys{/forest/.is family} and then used \pgfkeys{/forest, ...} at the end of for X propagators. All perfectly legal at first sight, but when /forest is redefined, which is precisely what .style/{...} does, then the redefinition is called not just once, but a million times! – Sašo Živanović Nov 05 '15 at 05:46