3.2. Standard output

It is important to have nice-looking output expressions, mainly when we deal with very large expressions. xTensor` has built-in rules to convert tensors and derivatives into 2-dimensional boxes for StandardForm output. Those boxes can be cut and pasted, using InterpretationBox. Additionally, translation to LATEX will be shown below.

The output of tensors in StandardForm has been defined with 2-dimensional boxes, but the internal structure is kept in 1-dimensional form (as usual in Mathematica):

In[117]:=

{T[a, b, -c], S[a, b], v[-a], r[]}

Out[117]=

{T_ (  c)^ab , S_  ^ab, v_a^ , r_^}

In[118]:=

InputForm[%]

Out[118]//InputForm=

{T[a, b, -c], S[a, b], v[-a], r[]}

No rules have been defined for OutputForm because the output is simple enough:

In[119]:=

OutputForm[%%]

Out[119]//OutputForm=

{T[a, b, -c], S[a, b], v[-a], r[]}

The ouput representation of the heads can be given at definition time, or changed later. Again, this is only possible in StandardForm. When using this option, it is very important to remember that the input and output names of the same tensor are different!

PrintAs                    Option of DefType functions to define the output of a head

Output of defined heads.

The tensor TT will be output as τ. PrintAs must give a string or a function that applied on the defined symbol gives a string

In[120]:=

DefTensor[TT[a, -b], M3, PrintAs→"τ"]

** DefTensor: Defining tensor TT[a, -b] .

In[121]:=

TT[a, -c]

Out[121]=

τ_ ( c)^a

In[122]:=

InputForm[%]

Out[122]//InputForm=

TT[a, -c]

As an example of a printas function we can use:

In[123]:=

FirstCharacter[symbol_] := First[Characters[ToString[symbol]]]

In[124]:=

DefTensor[Force[a], M3, PrintAs→FirstCharacter]

** DefTensor: Defining tensor Force[a] .

In[125]:=

Force[a]

Out[125]=

F_ ^a

The 2-dimensional boxes are based on a combination of three built-in's:
    SubsuperscriptBox, which construct the sub/super-indices structures,
    StyleBox, which arranges the indices with the proper interspaces, and
    InterpretationBox, which stores both the box-form and the input-form of the expression. Note the option Editable->False, which prevents desynchronization.

In[126]:=

ToBoxes[%]

Out[126]=

InterpretationBox[StyleBox[SubsuperscriptBox[F, , a], AutoSpacing→False], F_ ^a, Editable→False]

We can cut-and-paste the output, but not edit it, nor construct a tensor directly in box-form:

In[127]:=

F_ ^a

In[127]:=

InputForm[%]

Out[127]//InputForm=

InterpretationBox[StyleBox[\(F\_\ \%a\), Rule[AutoSpacing, False]], Force[a], Rule[Editable, False]]


Created by Mathematica  (May 16, 2008) Valid XHTML 1.1!