72
72
" Show different operations depending on mimetype. `l-` is leading minus sign."
73
73
function showop (:: MIME"text/plain" , op)
74
74
d = Dict (" *" => " *" , " +" => " + " , " -" => " - " , " l-" => " -" )
75
- d[op]
75
+ get (d, op, " " )
76
76
end
77
77
78
78
function showop (:: MIME"text/latex" , op)
79
79
d = Dict (" *" => " \\ cdot " , " +" => " + " , " -" => " - " , " l-" => " -" )
80
- d[op]
80
+ get (d, op, " " )
81
81
end
82
82
83
83
function showop (:: MIME"text/html" , op)
84
84
d = Dict (" *" => " ∙" , " +" => " + " , " -" => " - " , " l-" => " -" )
85
- d[op]
85
+ get (d, op, " " )
86
86
end
87
87
88
88
@@ -97,7 +97,8 @@ types "text/plain" (default), "text/latex", and "text/html" are supported. By
97
97
default, the terms are in order of ascending powers, matching the order in
98
98
`coeffs(p)`; specifying `descending_powers=true` reverses the order.
99
99
`offset` allows for an integer number to be added to the exponent, just for printing.
100
- `var` allows for overriding the variable used for printing.
100
+ `var` allows for overriding the variable used for printing. Setting multiplication symbol to `""`
101
+ will avoid an operator being printed. Setting `compact=true` will use a compact style for floating point numbers.
101
102
102
103
# Examples
103
104
```jldoctest show
@@ -119,11 +120,17 @@ julia> printpoly(stdout, Polynomial([-1, 0, 1], :z), offset=-1, descending_power
119
120
x - x^-1
120
121
```
121
122
"""
122
- function printpoly (io:: IO , p:: P , mimetype= MIME " text/plain" (); descending_powers= false , offset:: Int = 0 , var= p. var) where {T,P<: AbstractPolynomial{T} }
123
+ function printpoly (io:: IO , p:: P , mimetype= MIME " text/plain" ();
124
+ descending_powers= false , offset:: Int = 0 , var= p. var,
125
+ compact= false , mulsymbol= " *" ) where {T,P<: AbstractPolynomial{T} }
123
126
first = true
124
127
printed_anything = false
125
128
for i in (descending_powers ? reverse (eachindex (p)) : eachindex (p))
126
- printed = showterm (io, P, p[i], var, i+ offset, first, mimetype)
129
+ ioc = IOContext (io,
130
+ :compact => get (io, :compact , compact),
131
+ :multiplication_symbol => get (io, :multiplication_symbol , mulsymbol)
132
+ )
133
+ printed = showterm (ioc, P, p[i], var, i+ offset, first, mimetype)
127
134
first &= ! printed
128
135
printed_anything |= printed
129
136
end
@@ -154,9 +161,11 @@ function printsign(io::IO, pj::T, first, mimetype) where {T}
154
161
end
155
162
156
163
# # print * or cdot, ...
164
+ # # pass `:multiplication_symbol => "" to IOContext have no sign
157
165
function printproductsign (io:: IO , pj:: T , j, mimetype) where {T}
158
166
j == 0 && return
159
- (showone (T) || pj != one (T)) && print (io, showop (mimetype, " *" ))
167
+ multiplication_symbol = showop (mimetype, get (io, :multiplication_symbol ," *" ))
168
+ (showone (T) || pj != one (T)) && print (io, multiplication_symbol)
160
169
end
161
170
162
171
function printproductsign (io:: IO , pj:: T , j, mimetype) where {T<: Complex }
@@ -245,10 +254,9 @@ function printcoefficient(io::IO, pj::S, j, mimetype) where {T,S <: Complex{T}}
245
254
246
255
elseif hasreal
247
256
248
- (iszero (j) || showone (T) || isone (a)) && printcoefficient (io, a, j, mimetype)
257
+ (iszero (j) || showone (T) || ! isone (a)) && printcoefficient (io, a, j, mimetype)
249
258
250
259
elseif hasimag
251
-
252
260
(showone (T) || ! isone (b)) && printcoefficient (io, b, j, mimetype)
253
261
(isnan (b) || isinf (b)) && print (io, showop (mimetype, " *" ))
254
262
print (io, imagsymbol (mimetype))
0 commit comments