@@ -159,6 +159,15 @@ function printproductsign(io::IO, pj::T, j, mimetype) where {T}
159
159
(showone (T) || pj != one (T)) && print (io, showop (mimetype, " *" ))
160
160
end
161
161
162
+ function printproductsign (io:: IO , pj:: T , j, mimetype) where {T<: Complex }
163
+ j == 0 && return
164
+ (a,b) = reim (pj)
165
+ ! iszero (a) && ! iszero (b) && return # parentheses inserted, no * needed
166
+ ! iszero (a) && return printproductsign (io, a, j, mimetype)
167
+ print (io, showop (mimetype, " *" ))
168
+ end
169
+
170
+
162
171
# show a single term
163
172
# Other types can overload Polynomials.printcofficient with a mimetype
164
173
# or Base.show_unquoted(io, pj, indent, prec)
@@ -203,24 +212,51 @@ function printcoefficient(io::IO, a::Rational{T}, j, mimetype::MIME"text/latex")
203
212
end
204
213
205
214
# print complex numbers with parentheses as needed
206
- function printcoefficient (io:: IO , pj:: Complex{T} , j, mimetype) where {T}
215
+ function printcoefficient (io:: IO , pj:: S , j, mimetype) where {T,S <: Complex{T} }
207
216
208
- hasreal = abs (real (pj)) > 0 || isnan (real (pj)) || isinf (real (pj))
209
- hasimag = abs (imag (pj)) > 0 || isnan (imag (pj)) || isinf (imag (pj))
217
+ (a,b) = reim (pj)
218
+ hasreal = ! iszero (a) || isnan (a) || isinf (a)
219
+ hasimag = ! iszero (b) || isnan (b) || isinf (b)
210
220
211
221
if hasreal && hasimag
212
- Base. show_unquoted (io, pj, 0 , Base. operator_precedence (:* ))
222
+ iszero (j) || print (io, " (" )
223
+ print (io, a)
224
+
225
+ # print b
226
+ if isone (b) || isone (- b)
227
+ if hasneg (S) && b < 0
228
+ print (io, showop (mimetype, " -" ))
229
+ else
230
+ print (io, showop (mimetype, " +" ))
231
+ end
232
+ else
233
+ if hasneg (S) && b < 0
234
+ print (io, showop (mimetype, " -" ))
235
+ (showone (S) || ! isone (- b)) && print (io, - b)
236
+ else
237
+ print (io, showop (mimetype," +" ))
238
+ print (io, b)
239
+ end
240
+ (isnan (b) || isinf (b)) && print (io, showop (mimetype, " *" ))
241
+ end
242
+
243
+ print (io, imagsymbol (mimetype))
244
+ iszero (j) || print (io, " )" )
245
+
213
246
elseif hasreal
214
- a = real (pj)
215
- (j== 0 || showone (T) || a != one (T)) && printcoefficient (io, a, j, mimetype)
247
+
248
+ (iszero (j) || showone (T) || isone (a)) && printcoefficient (io, a, j, mimetype)
249
+
216
250
elseif hasimag
217
- b = imag (pj)
218
- (showone (T) || b != one (T)) && printcoefficient (io, b, j, mimetype)
219
- (isnan (imag (pj)) || isinf (imag (pj))) && print (io, showop (mimetype, " *" ))
220
- print (io, im)
221
- else
222
- return nothing
251
+
252
+ (showone (T) || ! isone (b)) && printcoefficient (io, b, j, mimetype)
253
+ (isnan (b) || isinf (b)) && print (io, showop (mimetype, " *" ))
254
+ print (io, imagsymbol (mimetype))
255
+
223
256
end
257
+
258
+ return nothing
259
+
224
260
end
225
261
226
262
# # show exponent
@@ -252,3 +288,6 @@ function unicode_subscript(io, j)
252
288
print (io, a[Int (i)- 44 ])
253
289
end
254
290
end
291
+
292
+ imagsymbol (:: Any ) = " im"
293
+ imagsymbol (:: MIME"text/latex" ) = " i"
0 commit comments