0

I would like to print $a^\dagger$ (meaning conjugate transpose), but using Mathematica library function ConjugateTranspose[a] (displayed as $a^\dagger$ when typing a Ctrl-7 Esc c t Esc) and printing it would just yield plain text, a.k.a.

ConjugateTranspose[a]

I found a solution to replace all ConjugateTranpose[#] to SuperDagger[#], but then it will either produce the result per se, or with HoldForm or Unevaluated, produce the expression:

ConjugateTranspose[a].a/.ConjugateTranspose[#]->SuperDagger[#]

You see, the replacement is also held.

Anyway, how can I print a daggered version of conjugate transpose?

Neo
  • 163
  • 5
  • 1
    This prints as you want. Is this what you mean? Mathematica graphics ClearAll[a]; ConjugateTranspose[a] // TraditionalForm I did not know about SuperDagger. That seems to work also on V 13.1 So what exactly is the problem again? Could you post complete example that you are having problem with? – Nasser Sep 03 '22 at 05:22

1 Answers1

3

With the help of @Nasser in the comments, I modified the code from this answer.

What I want can be done by this code (Notice that I don't need tags for they can only print plain string. Hence I changed CellPrint to Print):

SetAttributes[verbose, HoldAll];
verbose@expr_ := 
  Module[{res = expr}, 
   If[res =!= Null, 
    Print[Unevaluated[expr // TraditionalForm], "=", 
     expr // TraditionalForm]]];
HoldPattern@verbose@Set[lhs_, rhs_] := 
  Print[Unevaluated[lhs // TraditionalForm], 
   "=", (lhs = rhs) // TraditionalForm];
$Pre = verbose;

Execute this code, then evaluating variables will print their values with the expression or the LHS of the assignment.

Neo
  • 163
  • 5