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

Latexify sparse arrays #302

Merged
merged 5 commits into from
Aug 8, 2024
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
6 changes: 5 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ Requires = "ae029012-a4dd-5104-9daa-d747884805df"
[weakdeps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
SymEngine = "123dc426-2d89-5057-bbad-38513e3affd8"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[extensions]
DataFramesExt = "DataFrames"
SymEngineExt = "SymEngine"
SparseArraysExt = "SparseArrays"

[compat]
DataFrames = "1"
Expand All @@ -30,12 +32,14 @@ OrderedCollections = "1"
Requires = "0.5, 1"
SymEngine = "0.11, 0.12"
julia = "1.6"
SparseArrays="1.6"

[extras]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
SymEngine = "123dc426-2d89-5057-bbad-38513e3affd8"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["DataFrames", "OffsetArrays", "SymEngine", "Test"]
test = ["DataFrames", "OffsetArrays", "SymEngine", "SparseArrays", "Test"]
10 changes: 10 additions & 0 deletions ext/SparseArraysExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module SparseArraysExt

using Latexify
isdefined(Base, :get_extension) ? (using SparseArrays) : (using ..SparseArrays)

@latexrecipe function f(x::AbstractSparseArray)
return collect(x)
end

end
3 changes: 3 additions & 0 deletions src/Latexify.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ function __init__()
@require DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" begin
include("../ext/DataFramesExt.jl")
end
@require SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" begin
include("../ext/SparseArraysExt.jl")
end
end
end

Expand Down
11 changes: 11 additions & 0 deletions test/plugins/SparseArrays_test.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using SparseArrays

x = sparse([1,2,3],[1,3,2],[0,1,2])
@test latexraw(x) == replace(raw"""\left[
\begin{array}{ccc}
0 & 0 & 0 \\
0 & 0 & 1 \\
0 & 2 & 0 \\
\end{array}
\right]""", "\r\n"=>"\n")

3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ using Test
@testset "latexinline tests" begin include("latexinline_test.jl") end
@testset "latextabular tests" begin include("latextabular_test.jl") end
@testset "mdtable tests" begin include("mdtable_test.jl") end
@testset "DataFrame Plugin" begin include("plugins/DataFrames_test.jl") end
@testset "DataFrames Plugin" begin include("plugins/DataFrames_test.jl") end
@testset "SymEngine Plugin" begin include("plugins/SymEngine_test.jl") end
@testset "SparseArrays Plugin" begin include("plugins/SparseArrays_test.jl") end
@testset "unicode2latex" begin include("unicode2latex.jl") end
@testset "cdot test" begin include("cdot_test.jl") end
@testset "numberformatters" begin include("numberformatters_test.jl") end
Expand Down
Loading