From 247f2a7d47f90c768968ac3a79bb2136bed6525a Mon Sep 17 00:00:00 2001 From: Hendrik Ranocha Date: Thu, 7 Oct 2021 20:45:22 +0200 Subject: [PATCH 1/2] add SYmPy plugin --- .github/workflows/ci.yml | 8 ++++++-- Project.toml | 3 ++- src/Latexify.jl | 9 ++++++--- test/runtests.jl | 1 + 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a42ad77c..33b82f3c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: @@ -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: @@ -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 }} diff --git a/Project.toml b/Project.toml index 921746cd..37a54660 100644 --- a/Project.toml +++ b/Project.toml @@ -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"] diff --git a/src/Latexify.jl b/src/Latexify.jl index 69de2457..13b24015 100644 --- a/src/Latexify.jl +++ b/src/Latexify.jl @@ -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 @@ -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. @@ -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 ``` @@ -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)) ) diff --git a/test/runtests.jl b/test/runtests.jl index 070a6cdb..f3ef6180 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 From c79812e68b82456f008b443d8fe67765b2aae927 Mon Sep 17 00:00:00 2001 From: Hendrik Ranocha Date: Fri, 8 Oct 2021 14:22:04 +0200 Subject: [PATCH 2/2] fix cdot bug for complicated expressions --- src/latexoperation.jl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/latexoperation.jl b/src/latexoperation.jl index 1a3447f3..d84847d2 100644 --- a/src/latexoperation.jl +++ b/src/latexoperation.jl @@ -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) @@ -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