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

add SymPy plugin #186

Closed
wants to merge 2 commits into from
Closed
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
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
version:
- '0.7'
- '0.7'
- '1' # Leave this line unchanged. '1' will automatically expand to the latest stable 1.x release of Julia.
- 'nightly'
os:
Expand All @@ -40,7 +40,11 @@ jobs:
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/julia-buildpkg@v1
env:
PYTHON: ""
- uses: julia-actions/julia-runtest@v1
env:
PYTHON: ""
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
with:
Expand All @@ -62,7 +66,7 @@ jobs:
# julia --project=docs -e '
# using Documenter: doctest
# using Latexify
# doctest(Latexify)'
# doctest(Latexify)'
- run: julia --project=docs docs/make.jl
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
DiffEqBiological = "eb300fae-53e8-50a0-950c-e21f52c2b7e0"
ParameterizedFunctions = "65888b18-ceab-5e60-b2b9-181511a3b968"
SymPy = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6"
SymEngine = "123dc426-2d89-5057-bbad-38513e3affd8"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "DataFrames"]
test = ["Test", "DataFrames", "SymPy"]
9 changes: 6 additions & 3 deletions src/Latexify.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ function __init__()
@require SymEngine = "123dc426-2d89-5057-bbad-38513e3affd8" begin
include("plugins/SymEngine.jl")
end
@require SymPy = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6" begin
include("plugins/SymPy.jl")
end
@require DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" begin
include("plugins/DataFrames.jl")
end
Expand All @@ -73,7 +76,7 @@ end
"""
@append_latexify_test!(fname, expr)

Generate a Latexify test and append it to the file `fname`.
Generate a Latexify test and append it to the file `fname`.

The expression `expr` should return a string when evaluated.

Expand All @@ -83,7 +86,7 @@ Latexify.@append_latexify_test!("./tests/latexify_tests.jl", latexify(:(x/y)))
```

The macro returns the output of the expression and can often be rendered
for a visual check that the test itself is ok.
for a visual check that the test itself is ok.
```
Latexify.@append_latexify_test!("./tests/latexify_tests.jl", latexify(:(x/y))) |> render
```
Expand All @@ -93,7 +96,7 @@ macro append_latexify_test!(fname, expr)
return :(
str = "@test $($(string(expr))) == replace(\nraw\"$($(esc(expr)))\", \"\\r\\n\"=>\"\\n\")\n\n";
open($fname, "a") do f
write(f,str)
write(f,str)
end;
$(esc(expr))
)
Expand Down
11 changes: 9 additions & 2 deletions src/latexoperation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ This uses the information about the previous operations to decide if
a parenthesis is needed.

"""
function latexoperation(ex::Expr, prevOp::AbstractArray; cdot=true, index=:bracket, kwargs...)::String
function latexoperation(ex::Expr, prevOp::AbstractArray; kwargs...)::String
# If we used `cdot` and `index` as keyword arguments before `kwargs...`
# and they are indeed contained in `kwargs`, they would get lost when
# passing `kwargs...` to `latexraw`below. Thus, we need to set default
# values as follows.
cdot = get(kwargs, :cdot, true)
index = get(kwargs, :index, :bracket)

op = ex.args[1]
filter!(x -> !(x isa LineNumberNode), ex.args)
args = map(i -> typeof(i) ∉ (String, LineNumberNode) ? latexraw(i; kwargs...) : i, ex.args)
Expand Down Expand Up @@ -143,7 +150,7 @@ function latexoperation(ex::Expr, prevOp::AbstractArray; cdot=true, index=:brack
return string(ex.args[end])
end

if ex.head == :macrocall
if ex.head == :macrocall
ex.head = :call
end

Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ using Test
@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.jl") end
@testset "SymPy Plugin" begin include("plugins/SymPy.jl") end
@testset "unocode2latex" begin include("unicode2latex.jl") end
@testset "cdot test" begin include("cdot_test.jl") end
@testset "numberformatters" begin include("numberformatters_test.jl") end
Expand Down