Skip to content

Commit

Permalink
Merge pull request #7 from goropikari/rm_unnecessary_backslash
Browse files Browse the repository at this point in the history
Add support for more special functions. Fix for DiffEq 4.
  • Loading branch information
korsbo committed Feb 2, 2018
2 parents 58c19da + deb476f commit 6eaeffc
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ notifications:
# uncomment the following lines to override the default test script
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia -e 'Pkg.clone("https://github.com/korsbo/Latexify.jl"); Pkg.build("Latexify"); Pkg.test("Latexify"; coverage=true)'
- julia -e 'Pkg.clone(pwd()); Pkg.build("Latexify"); Pkg.test("Latexify"; coverage=true)'
after_success:
# push coverage results to Coveralls
- julia -e 'cd(Pkg.dir("Latexify")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
Expand Down
33 changes: 32 additions & 1 deletion src/latexoperation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ function latexoperation(ex::Expr, prevOp::AbstractArray)

op == :log10 && return "\\log_{10}\\left( $(args[2]) \\right)"
op == :log2 && return "\\log_{2}\\left( $(args[2]) \\right)"
op == :asin && return "\\arcsin\\left( $(args[2]) \\right)"
op == :asinh && return "\\mathrm{arcsinh}\\left( $(args[2]) \\right)"
op == :sinc && return "\\mathrm{sinc}\\left( $(args[2]) \\right)"
op == :acos && return "\\arccos\\left( $(args[2]) \\right)"
op == :acosh && return "\\mathrm{arccosh}\\left( $(args[2]) \\right)"
op == :cosc && return "\\mathrm{cosc}\\left( $(args[2]) \\right)"
op == :atan && return "\\arctan\\left( $(args[2]) \\right)"
op == :atan2 && return "\\arctan\\left( $(args[2]) \\right)"
op == :atanh && return "\\mathrm{arctanh}\\left( $(args[2]) \\right)"
op == :acot && return "\\mathrm{arccot}\\left( $(args[2]) \\right)"
op == :acoth && return "\\mathrm{arccoth}\\left( $(args[2]) \\right)"
op == :asec && return "\\mathrm{arcsec}\\left( $(args[2]) \\right)"
op == :sech && return "\\mathrm{sech}\\left( $(args[2]) \\right)"
op == :asech && return "\\mathrm{arcsech}\\left( $(args[2]) \\right)"
op == :acsc && return "\\mathrm{arccsc}\\left( $(args[2]) \\right)"
op == :csch && return "\\mathrm{csch}\\left( $(args[2]) \\right)"
op == :acsch && return "\\mathrm{arccsch}\\left( $(args[2]) \\right)"
op == :sqrt && return "\\$op{$(args[2])}"
op == :abs && return "\\left\\|$(args[2])\\right\\|"
op == :exp && return "e^{$(args[2])}"
Expand All @@ -51,7 +68,21 @@ function latexoperation(ex::Expr, prevOp::AbstractArray)
return "\\mathrm{$op}\\left[$argstring\\right]"
end

length(args) == 2 && return "\\$op\\left( $(args[2]) \\right)"
length(args) == 2 && return if op in (# Greek letters
:alpha, :beta, :gamma, :delta, :epsilon, :zeta, :eta, :theta,
:iota, :kappa, :lambda, :mu, :nu, :xi, :pi, :rho, :sigma, :tau,
:upsilon, :phi, :chi, :psi, :omega,
:Gamma, :Delta, :Theta, :Lambda, :Xi, :Pi, :Sigma, :Upsilon,
:Phi, :Psi, :Omega,
# trigonometric functions
:sin, :cos, :tan, :cot, :sec, :csc, :sinh, :cosh, :tanh, :coth,
# log
:log)
"\\$op\\left( $(args[2]) \\right)"
else
"$op\\left( $(args[2]) \\right)"
end


## if we have reached this far without a return, then error.
error("Latexify.jl's latexoperation does not know what to do with one of the
Expand Down
2 changes: 1 addition & 1 deletion test/REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ParameterizedFunctions 2.3.0
ParameterizedFunctions 3.0.0
4 changes: 2 additions & 2 deletions test/latexalign_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ using ParameterizedFunctions
f = @ode_def feedback begin
dx = y/c_1 - x
dy = x^c_2 - y
end c_1=>1.0 c_2=>1.0
end c_1 c_2

g = @ode_def test2 begin
dx = p_x - d_x*x - d_x_y*y*x
dy = p_y - d_y*y
dz = p_z
end p_x=>1.0 d_x=>1.0 d_x_y=>1. p_y=>2.0 d_y=>1.0 p_z=>1.
end p_x d_x d_x_y p_y d_y p_z

test_results = []

Expand Down
20 changes: 19 additions & 1 deletion test/latexraw_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ push!(test_results, latexraw(1.00) == "1.0")
push!(test_results, latexraw(1) == "1")
push!(test_results, latexraw(:(log10(x))) == "\\log_{10}\\left( x \\right)")
push!(test_results, latexraw(:(sin(x))) == "\\sin\\left( x \\right)")
push!(test_results, latexraw(:(asin(x))) == "\\arcsin\\left( x \\right)")
push!(test_results, latexraw(:(asinh(x))) == "\\mathrm{arcsinh}\\left( x \\right)")
push!(test_results, latexraw(:(sinc(x))) == "\\mathrm{sinc}\\left( x \\right)")
push!(test_results, latexraw(:(acos(x))) == "\\arccos\\left( x \\right)")
push!(test_results, latexraw(:(acosh(x))) == "\\mathrm{arccosh}\\left( x \\right)")
push!(test_results, latexraw(:(cosc(x))) == "\\mathrm{cosc}\\left( x \\right)")
push!(test_results, latexraw(:(atan(x))) == "\\arctan\\left( x \\right)")
push!(test_results, latexraw(:(atan2(x))) == "\\arctan\\left( x \\right)")
push!(test_results, latexraw(:(atanh(x))) == "\\mathrm{arctanh}\\left( x \\right)")
push!(test_results, latexraw(:(acot(x))) == "\\mathrm{arccot}\\left( x \\right)")
push!(test_results, latexraw(:(acoth(x))) == "\\mathrm{arccoth}\\left( x \\right)")
push!(test_results, latexraw(:(asec(x))) == "\\mathrm{arcsec}\\left( x \\right)")
push!(test_results, latexraw(:(sech(x))) == "\\mathrm{sech}\\left( x \\right)")
push!(test_results, latexraw(:(asech(x))) == "\\mathrm{arcsech}\\left( x \\right)")
push!(test_results, latexraw(:(acsc(x))) == "\\mathrm{arccsc}\\left( x \\right)")
push!(test_results, latexraw(:(csch(x))) == "\\mathrm{csch}\\left( x \\right)")
push!(test_results, latexraw(:(acsch(x))) == "\\mathrm{arccsch}\\left( x \\right)")
push!(test_results, latexraw(:(f(x))) == "f\\left( x \\right)")
push!(test_results, latexraw("x = 4*y") == "x = 4 \\cdot y")
push!(test_results, latexraw(:(sqrt(x))) == "\\sqrt{x}")
push!(test_results, latexraw(complex(1,-1)) == "1-1\\textit{i}")
Expand All @@ -28,7 +46,7 @@ push!(test_results, latexraw(1//2) == "\\frac{1}{2}")
f = @ode_def feedback begin
dx = y/c_1 - x
dy = x^c_2 - y
end c_1=>1.0 c_2=>1.0
end c_1 c_2
push!(test_results, latexraw(f) == ["\\frac{dx}{dt} = \\frac{y}{c_{1}} - x", "\\frac{dy}{dt} = x^{c_{2}} - y"])

println("latexraw_test successes: \n", test_results)
Expand Down

0 comments on commit 6eaeffc

Please sign in to comment.