Print an Inert Head with additional labels

50 views
Skip to first unread message

Omar Z

unread,
Mar 18, 2024, 7:35:58 AM3/18/24
to xAct Tensor Computer Algebra
Hello,
I would like to define an inert head, say "H", such that H[tens,n] is printed as "H^n tens".

If I define
DefInertHead[H]
PrintAs[H]^="H"

I have that, for example, H[tens,2] is printed as "H tens".

I know that it should be possible because the command Perturbation[tens,2] in xPert correctly prints the second argument as a power. The H head that I define also has most of the properties of Perturbation, eg it satisfies Leibnitz, if it can be useful. I tried to understand how it was done for Perturbation, but I did not get it.

Options to print with any other type of additional labels would also be appreciated.

Thank you in advance
Omar

Thomas Bäckdahl

unread,
Mar 18, 2024, 7:52:38 AM3/18/24
to xa...@googlegroups.com
Hi!

You can modify the more advanced display properties by changing the corresponding MakeBoxes command.
To tell Mathematica that you want your special code to be used instead of the standard code, you have to turn off the standard code before and turn it on again after your change.
For instance:
DefInertHead[He, PrintAs -> "H"]
xTensorFormStop[InertHead]
MakeBoxes[He[expr_, n_], StandardForm] :=
  xAct`xTensor`Private`interpretbox[He[expr, n],
   RowBox[{SuperscriptBox[PrintAs[Unevaluated[He]], PrintAs[n]], "[",
     MakeBoxes[expr, StandardForm], "]"}]];
xTensorFormStart[InertHead]

If you don't want the brackets, you can easily remove them in the lines above.

To have best control I would recommend that you implement your Leibnitz rules yourself either as rules that you apply when you need them or as UpValues for automatic rules.

Regards
Thomas
--
You received this message because you are subscribed to the Google Groups "xAct Tensor Computer Algebra" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xact+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/xact/2531e66d-a9c0-4ac6-b90c-6a1cf39578c5n%40googlegroups.com.

Omar Z

unread,
Mar 18, 2024, 9:19:16 AM3/18/24
to xAct Tensor Computer Algebra
Thank you very much, your help is very appreciated.
Omar

Reply all
Reply to author
Forward
0 new messages