diff --git a/Project.toml b/Project.toml index 22138cbf..b4b54592 100644 --- a/Project.toml +++ b/Project.toml @@ -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" @@ -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"] diff --git a/ext/SparseArraysExt.jl b/ext/SparseArraysExt.jl new file mode 100644 index 00000000..0c4daad8 --- /dev/null +++ b/ext/SparseArraysExt.jl @@ -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 diff --git a/src/Latexify.jl b/src/Latexify.jl index 943332cc..4547652a 100644 --- a/src/Latexify.jl +++ b/src/Latexify.jl @@ -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 diff --git a/test/plugins/SparseArrays_test.jl b/test/plugins/SparseArrays_test.jl new file mode 100644 index 00000000..6d06309d --- /dev/null +++ b/test/plugins/SparseArrays_test.jl @@ -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") + diff --git a/test/runtests.jl b/test/runtests.jl index ec0d097d..26a58c64 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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