@@ -34,6 +34,9 @@ the following LaTeX code in the preamble.
3434
3535```
3636
37+ To change the style of `latexify` to a human-readable Butcher-representation,
38+ you can use [`RootedTrees.set_latexify_style`](@ref).
39+
3740# Examples
3841
3942```jldoctest
@@ -48,32 +51,61 @@ function latexify(t::RootedTree)
4851 if isempty (t)
4952 return " \\ varnothing"
5053 end
51- list_representation = butcher_representation (t, false )
52- s = " \\ rootedtree" * replace (list_representation, " τ" => " []" )
53- return replace (s, " [" => " [." )
54+ latexify_style = @load_preference (" latexify_style" , " forest" )
55+ if latexify_style == " butcher"
56+ return butcher_representation (t)
57+ else # forest
58+ list_representation = butcher_representation (t, false )
59+ s = " \\ rootedtree" * replace (list_representation, " τ" => " []" )
60+ return replace (s, " [" => " [." )
61+ end
5462end
5563
5664function latexify (t:: BicoloredRootedTree )
5765 if isempty (t)
5866 return " \\ varnothing"
5967 end
60- list_representation = butcher_representation (rootedtree (t. level_sequence), false )
61- s = " \\ rootedtree" * replace (list_representation, " τ" => " []" )
62- # The first entry of `substrings` is "\\rootedtree".
63- substrings = split (s, " [" )
64- strings = String[]
65- for (color, substring) in zip (t. color_sequence, substrings)
66- if color == false
67- push! (strings, substring * " [." )
68- elseif color == true
69- push! (strings, substring * " [o" )
68+ latexify_style = @load_preference (" latexify_style" , " forest" )
69+ if latexify_style == " butcher"
70+ return butcher_representation (t)
71+ else # forest
72+ list_representation = butcher_representation (rootedtree (t. level_sequence), false )
73+ s = " \\ rootedtree" * replace (list_representation, " τ" => " []" )
74+ # The first entry of `substrings` is "\\rootedtree".
75+ substrings = split (s, " [" )
76+ strings = String[]
77+ for (color, substring) in zip (t. color_sequence, substrings)
78+ if color == false
79+ push! (strings, substring * " [." )
80+ elseif color == true
81+ push! (strings, substring * " [o" )
82+ end
7083 end
84+ # We still need to add the last part dropped by `zip`.
85+ push! (strings, last (substrings))
86+ return join (strings)
7187 end
72- # We still need to add the last part dropped by `zip`.
73- push! (strings, last (substrings))
74- return join (strings)
7588end
7689
7790Latexify. @latexrecipe function _ (t:: Union{RootedTree, BicoloredRootedTree} )
7891 return Latexify. LaTeXString (RootedTrees. latexify (t))
7992end
93+
94+ """
95+ RootedTrees.set_latexify_style(style::String)
96+
97+ Set the style of rooted trees when using [`latexify`](@ref). Possible options are
98+
99+ - "butcher": print the [`butcher_representation`](@ref) of rooted trees
100+ - "forest": use the LaTeX macro `\\ rootedtree` described in the docstring of
101+ [`latexify`](@ref)
102+
103+ This system is based on [Preferences.jl](https://github.com/JuliaPackaging/Preferences.jl).
104+ """
105+ function set_latexify_style (style:: String )
106+ if ! (style in (" butcher" , " forest" ))
107+ throw (ArgumentError (" Invalid printing style: \" $(style) \" " ))
108+ end
109+
110+ @set_preferences! (" latexify_style" => style)
111+ end
0 commit comments