Message Boards Message Boards

TensorScript - Writing tensors component in Mathematica

Subsuperscript only accepts three arguments, hence it is not possible to create tensors components as is done in General Relativity.

For this, I created TensorScript. Simple usage is as follows:

enter image description here

Where negative indices are on top.

Code (not the best or smarttest implementation, but it works):

TensorScript /: MakeBoxes[TensorScript[head_Symbol, vars___], format_] := Module[{parse, Up, Down},
    parse[n_Integer /; n < 0] := Up[-n];
    parse[-v_] := Up[v];
    parse[v_] := Down[v];

    TemplateBox[{
       ToBoxes@head,
       RowBox@Riffle[parse /@ {vars} /. {Down[v_] :> ToBoxes@Invisible@v, Up[v_] :> ToBoxes@v}, "\[InvisibleSpace]"],
       RowBox@Riffle[parse /@ {vars} /. {Up[v_] :> ToBoxes@Invisible@v, Down[v_] :> ToBoxes@v}, "\[InvisibleSpace]"],
       RowBox@Riffle[ToBoxes /@ {head, vars}, ","]
       }, "TensorScript",
       DisplayFunction :> (SubsuperscriptBox[#1, #2, #3] &),
       InterpretationFunction :> (RowBox@{"TensorScript", "[", RowBox@{#4},"]"} &),
       Tooltip -> Automatic]
]
POSTED BY: Thales Fernandes
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract