Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hook into Latexify.jl #47

Merged
merged 1 commit into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ version = "2.5.5-pre"
[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"

[compat]
RecipesBase = "1"
Requires = "1"
julia = "1"

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

[targets]
test = ["Plots", "StaticArrays", "Test", "UnicodePlots"]
test = ["Latexify", "Plots", "StaticArrays", "Test", "UnicodePlots"]
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ Additionally, there is an un-exported function `RootedTrees.latexify` that can
generate LaTeX code for a rooted tree `t` based on the LaTeX package
[forest](https://ctan.org/pkg/forest). The relevant code that needs to be included
in the preamble can be obtained from the docstring of `RootedTrees.latexify`
(type `?` and `RootedTrees.latexify` in the Julia REPL).
(type `?` and `RootedTrees.latexify` in the Julia REPL). The same format is
used when you are `using Latexify` and their function `latexify`, see
[Latexify.jl](https://github.com/korsbo/Latexify.jl).

### Iteration over `RootedTree`s

Expand Down
8 changes: 8 additions & 0 deletions src/RootedTrees.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ using LinearAlgebra: dot

using RecipesBase: RecipesBase

using Requires: @require


export rootedtree, rootedtree!, RootedTreeIterator

Expand Down Expand Up @@ -402,6 +404,12 @@ end


function __init__()
@require Latexify="23fbe1c1-3f47-55db-b15f-69d7ec21a316" begin
using .Latexify: Latexify

Latexify._latexraw(t::RootedTree; kwargs...) = latexify(t)
end

# canonical_representation!
Threads.resize_nthreads!(CANONICAL_REPRESENTATION_BUFFER,
Vector{Int}(undef, BUFFER_LENGTH))
Expand Down
18 changes: 14 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ using Test
using StaticArrays
using RootedTrees

using Latexify: latexify

using Plots: Plots, plot
Plots.unicodeplots()

Expand Down Expand Up @@ -87,7 +89,9 @@ end
@test α(t1) == 1
@test β(t1) == α(t1)*γ(t1)
@test butcher_representation(t1) == "τ"
@test RootedTrees.latexify(t1) == "\\rootedtree[]"
latex_string = "\\rootedtree[]"
@test RootedTrees.latexify(t1) == latex_string
@test latexify(t1) == "\$" * latex_string * "\$"
@test isempty(RootedTrees.subtrees(t1))

@inferred order(t1)
Expand All @@ -105,7 +109,9 @@ end
@test β(t2) == α(t2)*γ(t2)
@test t2 == t1 ∘ t1
@test butcher_representation(t2) == "[τ]"
@test RootedTrees.latexify(t2) == "\\rootedtree[[]]"
latex_string = "\\rootedtree[[]]"
@test RootedTrees.latexify(t2) == latex_string
@test latexify(t2) == "\$" * latex_string * "\$"
@test RootedTrees.subtrees(t2) == [rootedtree([2])]

t3 = rootedtree([1, 2, 2])
Expand All @@ -116,7 +122,9 @@ end
@test β(t3) == α(t3)*γ(t3)
@test t3 == t2 ∘ t1
@test butcher_representation(t3) == "[τ²]"
@test RootedTrees.latexify(t3) == "\\rootedtree[[][]]"
latex_string = "\\rootedtree[[][]]"
@test RootedTrees.latexify(t3) == latex_string
@test latexify(t3) == "\$" * latex_string * "\$"
@test RootedTrees.subtrees(t3) == [rootedtree([2]), rootedtree([2])]

t4 = rootedtree([1, 2, 3])
Expand All @@ -127,7 +135,9 @@ end
@test β(t4) == α(t4)*γ(t4)
@test t4 == t1 ∘ t2
@test butcher_representation(t4) == "[[τ]]"
@test RootedTrees.latexify(t4) == "\\rootedtree[[[]]]"
latex_string = "\\rootedtree[[[]]]"
@test RootedTrees.latexify(t4) == latex_string
@test latexify(t4) == "\$" * latex_string * "\$"
@test RootedTrees.subtrees(t4) == [rootedtree([2, 3])]

t5 = rootedtree([1, 2, 2, 2])
Expand Down