4
$\begingroup$

The package xAct does something really nice when it handles large outputs, which is to represent the expression as a symbol and display that symbol when the cursor hovers over it. For example,

<< xAct`xCoba`
m = DefManifold[M, 4, {a, b, c}];
ch = DefChart[chart, M, {0, 1, 2, 3}, {e[], r[], t[], q[]}];
$LargeComponentSize = 1;
CTensor[{x + y}, {chart}][\[Mu]]

The expression x+y is mapped to a red circle, which displays the expression when you hover the mouse over it. I've been trying to figure out how to do this natively in Mathematica but have been unsuccessful. I've tried using Iconize, Short, and Shallow, but these don't achieve what I want. How can I do this natively without utilizing any packages?

Thanks

Edit: Per MarcoB's comment, heres some examples of my attempts:

<< xAct`xCoba`
m = DefManifold[M, 4, {a, b, c}];
ch = DefChart[chart, M, {0, 1, 2, 3}, {e[], r[], t[], q[]}];
$LargeComponentSize = 1;
Column[{
  Row[{"xAct's representation of expression", Spacer[20], 
    CTensor[{{x + y, x + y, x + y, x + y}, {x + y, x + y, x + y, 
        x + y}, {x + y, x + y, x + y, x + y}, {x + y, x + y, x + y, 
        x + y}}, {chart, chart}][\[Mu]]}],
  Row[{"Iconize of expression", Spacer[20], 
    Table[Iconize[x + y], {i, 1, 4}, {j, 1, 4}] // MatrixForm}],
  Row[{"Use of Shallow function", Spacer[20], 
    Table[Shallow[x + y, 1], {i, 1, 4}, {j, 1, 4}] // MatrixForm}],
  Row[{"Normal expression", Spacer[20], 
    MatrixForm[{{x + y, x + y, x + y, x + y}, {x + y, x + y, x + y, 
       x + y}, {x + y, x + y, x + y, x + y}, {x + y, x + y, x + y, 
       x + y}}]}]
  }]

enter image description here

Top one is xActs representation of an expression using a symbol. Hovering the mouse over one of the symbols in the matrix prints the expression in a small prompt (in this case, the (1,2) component of the matrix holds the expression x+y).

Below that is my attempt using Iconize. Hovering the mouse over the Iconized expression doesnt print the expression in a small prompt, like xAct.

Below that is my attempt using Shallow[]. This just prints the first Head of the expression and the number of subexpressions with no way to see what the expression is without uniconizing.

Last one is the normal expression.

What I want to reproduce natively is xActs representation of the expression. Long expressions are replaced by a representative symbol and the expression can be seen by hovering the mouse over the symbol.

$\endgroup$
1
  • $\begingroup$ Can you show the attempts you have made so far, and an example of an expression you want to iconize, and a possible desired result? As it stands, otherwise, it is unclear what you find unsatisfactory in the outputs of e.g. Iconize. $\endgroup$
    – MarcoB
    Commented Apr 19, 2022 at 13:59

1 Answer 1

2
$\begingroup$

Ah, I figured out xAct probably uses the Tooltip[] function. An expression can be represented by a symbol as

Tooltip[\[GrayCircle], ToString[x + y]]

enter image description here

Hovering the mouse over the gray circle yields a small Tooltip box that prints the expression being represented by the gray circle.

$\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.