# Revision history [back]

One way to obtain \mathbf{i} instead of just i is to use a string replacement.

To also get the real part before the imaginary part, why not use a little helper function.

The following might do what you want.

def latex_of_complex(z):
r"""
Return a LaTeX string for this complex number.

EXAMPLE::

sage: latex_of_complex(0)
0
sage: latex_of_complex(2)
2
sage: latex_of_complex(4*i)
4 \mathbf{i}
sage: latex_of_complex(7 + 8*i)
7 + 8 \mathbf{i}
"""
if z == 0:
return LatexExpr('0')
a = z.real()
b = z.imag()
if b == 0:
return latex(a)
s = (latex(a) + ' + ') if a else ''
return LatexExpr(s) + latex(b * i).replace('i', r'\mathbf{i}')


Now use latex_of_complex instead of latex to latexify complex numbers with the requested customization.