Skip to content

Commit 66ac85f

Browse files
authored
Merge pull request #106 from JuliaAlgebra/bl/printapl
🐛 Fix printing of AbstractPolynomialLike
2 parents 3f7ef75 + 20083b7 commit 66ac85f

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/show.jl

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
function Base.show(io::IO, mime::MIME"text/latex",
2-
p::Union{AbstractPolynomialLike, RationalPoly})
1+
const TypesWithShow = Union{AbstractVariable, AbstractMonomial, AbstractTerm,
2+
AbstractPolynomial, RationalPoly}
3+
function Base.show(io::IO, mime::MIME"text/latex", p::TypesWithShow)
34
print(io, "\$\$ ")
45
_show(io, mime, p)
56
print(io, " \$\$")
@@ -8,17 +9,15 @@ end
89
# If the MIME is not specified, IJulia thinks that it supports images, ...
910
# and then use the result of show and tries to interpret it as an svg, ...
1011
# We need the two methods to avoid ambiguity
11-
function Base.show(io::IO, mime::MIME"text/plain",
12-
p::Union{AbstractPolynomialLike, RationalPoly})
12+
function Base.show(io::IO, mime::MIME"text/plain", p::TypesWithShow)
1313
_show(io, mime, p)
1414
end
15-
function Base.show(io::IO, mime::MIME"text/print",
16-
p::Union{AbstractPolynomialLike, RationalPoly})
15+
function Base.show(io::IO, mime::MIME"text/print", p::TypesWithShow)
1716
_show(io, mime, p)
1817
end
1918

20-
Base.print(io::IO, p::Union{AbstractPolynomialLike, RationalPoly}) = show(io, MIME"text/print"(), p)
21-
Base.show(io::IO, p::Union{AbstractPolynomialLike, RationalPoly}) = show(io, MIME"text/plain"(), p)
19+
Base.print(io::IO, p::TypesWithShow) = show(io, MIME"text/print"(), p)
20+
Base.show(io::IO, p::TypesWithShow) = show(io, MIME"text/plain"(), p)
2221

2322
# VARIABLES
2423
function _show(io::IO, mime::MIME, var::AbstractVariable)

test/show.jl

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
@test sprint(show, (x*y^2 + x + 1 + y)) == "xy² + x + y + 1"
44
@test sprint(show, (x + 1 + y) / x^2) == "(x + y + 1) / (x²)"
55
@test sprint(show, (x - y - x + y) / (x^2 - x)) == "(0) / (x² - x)"
6+
@test sprint(show, CustomPoly(1 + x)) == "CustomPoly{$Int,$(typeof(1 + x))}(x + 1)"
67
# Test taken from TypedPolynomials
78
@test sprint(show, x) == "x"
89
@test sprint(show, x^0) == "1"

0 commit comments

Comments
 (0)