Skip to content

Commit

Permalink
Remove strong dep on latexify; move to extension
Browse files Browse the repository at this point in the history
  • Loading branch information
moble committed Oct 21, 2024
1 parent 0645a2a commit c539947
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 29 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ version = "1.5.3"

[deps]
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand All @@ -17,13 +16,15 @@ ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
FastDifferentiation = "eb9bf01b-bf85-4b60-bf87-ee5de06c00be"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
GenericLinearAlgebra = "14197337-ba66-59df-a3e3-ca00e7dcff7a"
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"

[extensions]
QuaternionicChainRulesCoreExt = "ChainRulesCore"
QuaternionicFastDifferentiationExt = "FastDifferentiation"
QuaternionicForwardDiffExt = "ForwardDiff"
QuaternionicSymbolicsExt = "Symbolics"
QuaternionicLatexifyExt = "Latexify"

[compat]
ChainRulesCore = "1"
Expand Down
2 changes: 1 addition & 1 deletion ext/QuaternionicFastDifferentiationExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Quaternionic: normalize, absvec,
AbstractQuaternion, Quaternion, Rotor, QuatVec,
quaternion, rotor, quatvec,
QuatVecF64, RotorF64, QuaternionF64,
wrapper, components, _pm_ascii, _pm_latex
wrapper, components
using PrecompileTools
isdefined(Base, :get_extension) ? (using FastDifferentiation) : (using ..FastDifferentiation)

Expand Down
30 changes: 30 additions & 0 deletions ext/QuaternionicLatexifyExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module QuaternionicLatexifyExt

import Quaternionic: AbstractQuaternion, QuatVec
isdefined(Base, :get_extension) ? (using Latexify) : (using ..Latexify)

function _pm_latex_latexify(x)
# Utility function to print a component of a quaternion in LaTeX
s = Latexify.latexify(x, env=:raw, bracket=true)
if s[1] "+-"
s = "+" * s
end
if occursin(r"[+^/-]", s[2:end])
s = " " * s[1] * " " * "\\left(" * s[2:end] * "\\right)"
else
s = " " * s[1] * " " * s[2:end]
end
s
end

function Base.show(io::IO, ::MIME"text/latex", q::AbstractQuaternion)
s = Latexify.LaTeXStrings.latexstring(
q isa QuatVec ? "" : Latexify.latexify(q[1], env=:raw, bracket=true),
_pm_latex_latexify(q[2]), "\\,\\mathbf{i}",
_pm_latex_latexify(q[3]), "\\,\\mathbf{j}",
_pm_latex_latexify(q[4]), "\\,\\mathbf{k}"
)
print(io, s)
end

end # module
5 changes: 2 additions & 3 deletions ext/QuaternionicSymbolicsExt.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module QuaternionicSymbolicsExt

using StaticArrays: SVector
using Latexify: latexify
import Quaternionic: normalize, absvec,
AbstractQuaternion, Quaternion, Rotor, QuatVec,
quaternion, rotor, quatvec,
Expand Down Expand Up @@ -196,9 +195,9 @@ function _pm_ascii(x::Symbolics.Num)
end
s
end
function _pm_latex(x::Num)
function _pm_latex(x::Symbolics.Num)

Check warning on line 198 in ext/QuaternionicSymbolicsExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/QuaternionicSymbolicsExt.jl#L198

Added line #L198 was not covered by tests
# Utility function to print a component of a quaternion in LaTeX
s = latexify(x, env=:raw, bracket=true)
s = Symbolics.Latexify.latexify(x, env=:raw, bracket=true)

Check warning on line 200 in ext/QuaternionicSymbolicsExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/QuaternionicSymbolicsExt.jl#L200

Added line #L200 was not covered by tests
if s[1] "+-"
s = "+" * s
end
Expand Down
3 changes: 2 additions & 1 deletion src/Quaternionic.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Quaternionic

using StaticArrays, LinearAlgebra, PrecompileTools
using Latexify, LaTeXStrings
import LaTeXStrings
import Random: AbstractRNG, default_rng, randn!

export AbstractQuaternion
Expand Down Expand Up @@ -56,6 +56,7 @@ end
@require FastDifferentiation="eb9bf01b-bf85-4b60-bf87-ee5de06c00be" include("../ext/QuaternionicFastDifferentiationExt.jl")
@require ForwardDiff="f6369f11-7733-5829-9624-2563aa707210" include("../ext/QuaternionicForwardDiffExt.jl")
@require Symbolics="0c5d862f-8b57-4792-8d23-62f2024744c7" include("../ext/QuaternionicSymbolicsExt.jl")
@require Latexify="23fbe1c1-3f47-55db-b15f-69d7ec21a316" include("../ext/QuaternionicLatexifyExt.jl")
end

# COV_EXCL_STOP
Expand Down
46 changes: 23 additions & 23 deletions src/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,29 +89,29 @@ function Base.show(io::IO, q::Rotor)
print(io, ")")
end

function _pm_latex(x)
# Utility function to print a component of a quaternion in LaTeX
s = latexify(x, env=:raw, bracket=true)
if s[1] "+-"
s = "+" * s
end
if occursin(r"[+^/-]", s[2:end])
s = " " * s[1] * " " * "\\left(" * s[2:end] * "\\right)"
else
s = " " * s[1] * " " * s[2:end]
end
s
end

function Base.show(io::IO, ::MIME"text/latex", q::AbstractQuaternion)
s = latexstring(
q isa QuatVec ? "" : latexify(q[1], env=:raw, bracket=true),
_pm_latex(q[2]), "\\,\\mathbf{i}",
_pm_latex(q[3]), "\\,\\mathbf{j}",
_pm_latex(q[4]), "\\,\\mathbf{k}"
)
print(io, s)
end
# function _pm_latex(x)
# # Utility function to print a component of a quaternion in LaTeX
# s = "$x"
# if s[1] ∉ "+-"
# s = "+" * s
# end
# if occursin(r"[+^/-]", s[2:end])
# s = " " * s[1] * " " * "\\left(" * s[2:end] * "\\right)"
# else
# s = " " * s[1] * " " * s[2:end]
# end
# s
# end

# function Base.show(io::IO, ::MIME"text/latex", q::AbstractQuaternion)
# s = LaTeXStrings.latexstring(
# q isa QuatVec ? "" : "$(q[1])",
# _pm_latex(q[2]), "\\,\\mathbf{i}",
# _pm_latex(q[3]), "\\,\\mathbf{j}",
# _pm_latex(q[4]), "\\,\\mathbf{k}"
# )
# print(io, s)
# end

function Base.read(s::IO, QT::Type{Q}) where {T<:Number, Q<:AbstractQuaternion{T}}
w = read(s,T)
Expand Down

0 comments on commit c539947

Please sign in to comment.