# Print command in matrices to generate inactive numbers

I would like to generate a matrix with elements that come from a print command and are numbers and then multiply the first matrix by another one, element by element.

However, I would like the numbers to remain inactive, and this is the point of my confusion. That is when, i.e, I have in an element $$2 \cdot2$$ I want it to be like that rather than give me back $$4$$.

If the above is not clear I will illustrate with a minimal example. I would like the following

$$\begin{matrix} \langle 2 2 \rangle \langle 2 2 \rangle & \langle 2 3 \rangle \langle 2 3 \rangle & \langle 2 4 \rangle \langle 2 4 \rangle\\ \langle 3 2 \rangle \langle 3 2 \rangle & \langle 3 3 \rangle \langle 3 3 \rangle & \langle 3 4 \rangle \langle 3 4 \rangle\\ \langle 4 2 \rangle \langle 4 2 \rangle & \langle 4 3 \rangle \langle 4 3 \rangle & \langle 4 4 \rangle \langle 4 4 \rangle\\ \end{matrix}$$

The code that I tried

Op1p2[p1_, p2_, p3_, p4_] :=
Print[MatrixForm[
Table[\[LeftAngleBracket]p1, p2\[RightAngleBracket], {p1, 2,
4}, {p2, 2, 4}] Table[\[LeftAngleBracket]p3,
p4\[RightAngleBracket], {p3, 2, 4}, {p4, 2, 4}]]]


but when I run the command Op1p2[p1, p2, p3, p4] it gives back

which is not the desired form.

I tried some alternatives to the above code by using Inactive but it has not worked so far.

If this is just for display, you could override the formatting of Power so that squares render as desired:

MakeBoxes[unsquaredForm[e_], form_]:=InternalWithLocalSettings[
Unprotect[Power];
MakeBoxes[Power[a_, 2], form]:=MakeBoxes[a a, form],

MakeBoxes[e, form],

MakeBoxes[Power[a_,2], form]=.;
Protect[Power]
]


Then:

unsquaredForm @ MatrixForm[
Table[\[LeftAngleBracket]p1,p2\[RightAngleBracket],{p1,2,4},{p2,2,4}]^2
] //TeXForm


$$\left( \begin{array}{ccc} \langle 2,2\rangle \langle 2,2\rangle & \langle 2,3\rangle \langle 2,3\rangle & \langle 2,4\rangle \langle 2,4\rangle \\ \langle 3,2\rangle \langle 3,2\rangle & \langle 3,3\rangle \langle 3,3\rangle & \langle 3,4\rangle \langle 3,4\rangle \\ \langle 4,2\rangle \langle 4,2\rangle & \langle 4,3\rangle \langle 4,3\rangle & \langle 4,4\rangle \langle 4,4\rangle \\ \end{array} \right)$$

• yes this code is only for display. I just want to see big matrices in that form so that I know how to set up some interesting questions. Great answer and resolution btw. Thanks! – A_user_with_NoName Dec 10 '19 at 21:58

Another way

Outer[HoldForm[〈##〉 〈##〉] &, #, #] &@Range[2, 4] // MatrixForm
`

$$\left( \begin{array}{ccc} \langle 2,2\rangle \langle 2,2\rangle & \langle 2,3\rangle \langle 2,3\rangle & \langle 2,4\rangle \langle 2,4\rangle \\ \langle 3,2\rangle \langle 3,2\rangle & \langle 3,3\rangle \langle 3,3\rangle & \langle 3,4\rangle \langle 3,4\rangle \\ \langle 4,2\rangle \langle 4,2\rangle & \langle 4,3\rangle \langle 4,3\rangle & \langle 4,4\rangle \langle 4,4\rangle \\ \end{array} \right)$$