@@ -202,22 +202,24 @@ function printcoefficient(io::IO, a::Rational{T}, j, mimetype::MIME"text/latex")
202
202
abs (a. den) == one (T) ? print (io, a. num) : print (io, " \\ frac{$(a. num) }{$(a. den) }" )
203
203
end
204
204
205
- # print complex numbers with parentheses as needed
206
- function printcoefficient (io:: IO , pj:: Complex{T} , j, mimetype) where {T}
205
+ # print complex numbers with parentheses as needed. `imagsymbol` can be given to print the imaginary unit as some other string than `"im"`
206
+ function printcoefficient (io:: IO , pj:: Complex{T} , j, mimetype; imagsymbol :: String = " im " ) where {T}
207
207
208
- hasreal = abs (real (pj)) > 0 || isnan (real (pj)) || isinf (real (pj))
209
- hasimag = abs (imag (pj)) > 0 || isnan (imag (pj)) || isinf (imag (pj))
208
+ a = real (pj)
209
+ b = imag (pj)
210
+
211
+ hasreal = abs (a) > 0 || isnan (a) || isinf (a)
212
+ hasimag = abs (b) > 0 || isnan (b) || isinf (b)
210
213
211
214
if hasreal && hasimag
212
- Base. show_unquoted (io, pj, 0 , Base. operator_precedence (:* ))
215
+ print (io," (" ,a)
216
+ print (printsign (io,b,false ,mimetype),imagsymbol," )" )
213
217
elseif hasreal
214
- a = real (pj)
215
218
(j== 0 || showone (T) || a != one (T)) && printcoefficient (io, a, j, mimetype)
216
219
elseif hasimag
217
- b = imag (pj)
218
220
(showone (T) || b != one (T)) && printcoefficient (io, b, j, mimetype)
219
221
(isnan (imag (pj)) || isinf (imag (pj))) && print (io, showop (mimetype, " *" ))
220
- print (io, im )
222
+ print (io, imagsymbol )
221
223
else
222
224
return nothing
223
225
end
0 commit comments