Skip to content

Commit 97665ee

Browse files
committed
Added option to print complex numbers with another imaginary unit symbol than
1 parent 5221953 commit 97665ee

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/show.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,22 +202,24 @@ function printcoefficient(io::IO, a::Rational{T}, j, mimetype::MIME"text/latex")
202202
abs(a.den) == one(T) ? print(io, a.num) : print(io, "\\frac{$(a.num)}{$(a.den)}")
203203
end
204204

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}
207207

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)
210213

211214
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,")")
213217
elseif hasreal
214-
a = real(pj)
215218
(j==0 || showone(T) || a != one(T)) && printcoefficient(io, a, j, mimetype)
216219
elseif hasimag
217-
b = imag(pj)
218220
(showone(T) || b != one(T)) && printcoefficient(io, b, j, mimetype)
219221
(isnan(imag(pj)) || isinf(imag(pj))) && print(io, showop(mimetype, "*"))
220-
print(io, im)
222+
print(io, imagsymbol)
221223
else
222224
return nothing
223225
end

0 commit comments

Comments
 (0)