This is what you want to do:

In [1]: %paste
import sympy
from sympy.printing.latex import LatexPrinter

class CustomLatexPrinter(LatexPrinter):
    def _print_Adjoint(self, expr):
        mat = expr.arg
        from sympy.matrices import MatrixSymbol
        if not isinstance(mat, MatrixSymbol):
            return r"\left(%s\right)^H" % self._print(mat)
        else:
            return "%s^H" % self._print(mat)

## -- End pasted text --

In [2]: def my_latex(expr, **settings):
   ...:     return CustomLatexPrinter(settings).doprint(expr)
   ...:

In [3]: %paste
Nk, Nx = sympy.symbols('N_k N_x')
FT = sympy.MatrixSymbol('\mathcal{F}', Nx, Nk)
s = sympy.MatrixSymbol('s',Nk,1)
Sigmax = sympy.MatrixSymbol('\Sigma_x', Nx, Nx)
Sigmak = sympy.MatrixSymbol('\Sigma_k', Nk, Nk)
W = sympy.MatrixSymbol('W',Nk,Nk)
F = FT*W
m = sympy.MatrixSymbol('m',1,Nx)

Sigmax = m*F*Sigmak*F.adjoint()*m.adjoint()

## -- End pasted text --

In [4]: my_latex(Sigmax)
Out[4]: 'm \\mathcal{F} W \\Sigma_{k} W^H \\mathcal{F}^H m^H'



Jason
moorepants.info
+01 530-601-9791

On Sun, Jan 31, 2016 at 6:03 PM, Michael Hansen <
[email protected]> wrote:

>
> import sympy
> from sympy.printing.latex import LatexPrinter
>
> class CustomLatexPrinter(LatexPrinter):
>     def _print_Adjoint(self, expr):
>         mat = expr.arg
>         from sympy.matrices import MatrixSymbol
>         if not isinstance(mat, MatrixSymbol):
>             return r"\left(%s\right)^H" % self._print(mat)
>         else:
>             return "%s^H" % self._print(mat)
>
>
> sympy.init_session()
> sympy.Basic.__str__ = lambda self: CustomLatexPrinter().doprint(self)
>
> Nk, Nx = sympy.symbols('N_k N_x')
> FT = sympy.MatrixSymbol('\mathcal{F}', Nx, Nk)
> s = sympy.MatrixSymbol('s',Nk,1)
> Sigmax = sympy.MatrixSymbol('\Sigma_x', Nx, Nx)
> Sigmak = sympy.MatrixSymbol('\Sigma_k', Nk, Nk)
> W = sympy.MatrixSymbol('W',Nk,Nk)
> F = FT*W
> m = sympy.MatrixSymbol('m',1,Nx)
>
> Sigmax = m*F*Sigmak*F.adjoint()*m.adjoint()
>
> latex(Sigmax)
>
> Last line's result is:
>
> 'm \\mathcal{F} W \\Sigma_{k} W^\\dag \\mathcal{F}^\\dag m^\\dag'
>
>
> If I do:
>
>
> tmp = CustomLatexPrinter()
> tmp.doprint(Sigmax)
>
>
> The result is:
>
>
> 'm \\mathcal{F} W \\Sigma_{k} W^H \\mathcal{F}^H m^H'
>
>
> I think I just don't know what to overload.
>
> On Sunday, January 31, 2016 at 3:04:32 PM UTC-5, Michael Hansen wrote:
>>
>> Quick question. Is there a way to change what symbols are used for things
>> like adjoint for a matrix. In latex, it is currently \dagger but I would
>> rather use "H" or something like that.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/bd7962ee-edd1-4d9e-af36-b3537f99055a%40googlegroups.com
> <https://groups.google.com/d/msgid/sympy/bd7962ee-edd1-4d9e-af36-b3537f99055a%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAP7f1AgxUxOn_OeDM2xXrZqimpa2Rq%2BYbWTSKfiMTNpD1dHCAg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to