0
$\begingroup$

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?

$\endgroup$
1
  • 1
    $\begingroup$ 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? $\endgroup$
    – Nasser
    Commented Sep 3, 2022 at 5:22

1 Answer 1

3
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.