Skip to content

Commit be7c52a

Browse files
authored
hook into Latexify (#47)
1 parent 0acc785 commit be7c52a

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

Project.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ version = "2.5.5-pre"
66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
88
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
9+
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
910

1011
[compat]
1112
RecipesBase = "1"
13+
Requires = "1"
1214
julia = "1"
1315

1416
[extras]
17+
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
1518
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
1619
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1720
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1821
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
1922

2023
[targets]
21-
test = ["Plots", "StaticArrays", "Test", "UnicodePlots"]
24+
test = ["Latexify", "Plots", "StaticArrays", "Test", "UnicodePlots"]

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ Additionally, there is an un-exported function `RootedTrees.latexify` that can
5151
generate LaTeX code for a rooted tree `t` based on the LaTeX package
5252
[forest](https://ctan.org/pkg/forest). The relevant code that needs to be included
5353
in the preamble can be obtained from the docstring of `RootedTrees.latexify`
54-
(type `?` and `RootedTrees.latexify` in the Julia REPL).
54+
(type `?` and `RootedTrees.latexify` in the Julia REPL). The same format is
55+
used when you are `using Latexify` and their function `latexify`, see
56+
[Latexify.jl](https://github.com/korsbo/Latexify.jl).
5557

5658
### Iteration over `RootedTree`s
5759

src/RootedTrees.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ using LinearAlgebra: dot
77

88
using RecipesBase: RecipesBase
99

10+
using Requires: @require
11+
1012

1113
export rootedtree, rootedtree!, RootedTreeIterator
1214

@@ -402,6 +404,12 @@ end
402404

403405

404406
function __init__()
407+
@require Latexify="23fbe1c1-3f47-55db-b15f-69d7ec21a316" begin
408+
using .Latexify: Latexify
409+
410+
Latexify._latexraw(t::RootedTree; kwargs...) = latexify(t)
411+
end
412+
405413
# canonical_representation!
406414
Threads.resize_nthreads!(CANONICAL_REPRESENTATION_BUFFER,
407415
Vector{Int}(undef, BUFFER_LENGTH))

test/runtests.jl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ using Test
22
using StaticArrays
33
using RootedTrees
44

5+
using Latexify: latexify
6+
57
using Plots: Plots, plot
68
Plots.unicodeplots()
79

@@ -87,7 +89,9 @@ end
8789
@test α(t1) == 1
8890
@test β(t1) == α(t1)*γ(t1)
8991
@test butcher_representation(t1) == "τ"
90-
@test RootedTrees.latexify(t1) == "\\rootedtree[]"
92+
latex_string = "\\rootedtree[]"
93+
@test RootedTrees.latexify(t1) == latex_string
94+
@test latexify(t1) == "\$" * latex_string * "\$"
9195
@test isempty(RootedTrees.subtrees(t1))
9296

9397
@inferred order(t1)
@@ -105,7 +109,9 @@ end
105109
@test β(t2) == α(t2)*γ(t2)
106110
@test t2 == t1 t1
107111
@test butcher_representation(t2) == "[τ]"
108-
@test RootedTrees.latexify(t2) == "\\rootedtree[[]]"
112+
latex_string = "\\rootedtree[[]]"
113+
@test RootedTrees.latexify(t2) == latex_string
114+
@test latexify(t2) == "\$" * latex_string * "\$"
109115
@test RootedTrees.subtrees(t2) == [rootedtree([2])]
110116

111117
t3 = rootedtree([1, 2, 2])
@@ -116,7 +122,9 @@ end
116122
@test β(t3) == α(t3)*γ(t3)
117123
@test t3 == t2 t1
118124
@test butcher_representation(t3) == "[τ²]"
119-
@test RootedTrees.latexify(t3) == "\\rootedtree[[][]]"
125+
latex_string = "\\rootedtree[[][]]"
126+
@test RootedTrees.latexify(t3) == latex_string
127+
@test latexify(t3) == "\$" * latex_string * "\$"
120128
@test RootedTrees.subtrees(t3) == [rootedtree([2]), rootedtree([2])]
121129

122130
t4 = rootedtree([1, 2, 3])
@@ -127,7 +135,9 @@ end
127135
@test β(t4) == α(t4)*γ(t4)
128136
@test t4 == t1 t2
129137
@test butcher_representation(t4) == "[[τ]]"
130-
@test RootedTrees.latexify(t4) == "\\rootedtree[[[]]]"
138+
latex_string = "\\rootedtree[[[]]]"
139+
@test RootedTrees.latexify(t4) == latex_string
140+
@test latexify(t4) == "\$" * latex_string * "\$"
131141
@test RootedTrees.subtrees(t4) == [rootedtree([2, 3])]
132142

133143
t5 = rootedtree([1, 2, 2, 2])

0 commit comments

Comments
 (0)