Skip to content

Commit 937f3c2

Browse files
authored
compatibility with Latexify.jl (#439)
1 parent c29cf98 commit 937f3c2

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ version = "1.0.52"
55
[deps]
66
CommonEq = "3709ef60-1bee-4518-9f2f-acd86f176c50"
77
CommonSolve = "38540f10-b2f7-11e9-35d8-d573e4eb0ff2"
8+
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
89
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
910
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
1011
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
@@ -14,6 +15,7 @@ SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
1415
[compat]
1516
CommonEq = "0.2"
1617
CommonSolve = "0.2"
18+
Latexify = "0.15"
1719
PyCall = "1.91"
1820
RecipesBase = "0.7, 0.8, 1.0, 1.1"
1921
SpecialFunctions = "0.8, 0.9, 0.10, 1.0"

src/SymPy.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ include("lambdify.jl")
7575
include("patternmatch.jl")
7676
include("permutations.jl")
7777
include("plot_recipes.jl")
78+
include("latexify_recipe.jl")
7879

7980
##################################################
8081

src/latexify_recipe.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
using Latexify: Latexify
3+
4+
# Recipe to hook into Latexify.jl's `latexify` function for `Sym`s.
5+
# We do not use SymPy's `latex` function here since it behaves a bit different
6+
# from Latexify.jl. Thus, we let Latexify.jl handle everything for the sake of
7+
# consistency.
8+
# For example, SymPy doesn't print a multiplication symbol by default while
9+
# Latexify uses a `"\\cdot"` (unless the keyword argument `cdot=false` is set).
10+
Latexify.@latexrecipe function _(x::Sym)
11+
return string(x)
12+
end

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ include("test-logical.jl")
1717
#include("test-permutations.jl")
1818
include("test-physics.jl")
1919
include("test-external-module.jl")
20+
include("test-latexify.jl")

test/test-latexify.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using SymPy
2+
using Test
3+
4+
@testset "Latexify" begin
5+
@vars α
6+
@test_nowarn SymPy.Latexify.latexify(- 3/(8*α) + 1/(8*α^2))
7+
@test occursin("\\cdot", SymPy.Latexify.latexify(- 3/(8*α) + 1/(8*α^2), cdot=true))
8+
@test !occursin("\\cdot", SymPy.Latexify.latexify(- 3/(8*α) + 1/(8*α^2), cdot=false))
9+
end

0 commit comments

Comments
 (0)