# Pretty Printing in Mathematica

I have a list ep = {I Sqrt[2], {{I, 1/GoldenRatio, Sqrt[2]}, {1, 0, 1}}} and I want to write a function that will output the list ep in the following forms:

and

Playing in the Mathematica Notebook, I did the following:

myOutputForm[ep_List] :=
Module[{ep1, epe, r},
ep1 = Map[HoldForm[#] &, ep[[2]][[1]]];
epe = Map[HoldForm[#] &, ep[[2]][[2]]];
r = Apply[Times, MapThread[Power, {ep1, epe}]]
];


myOutputForm[ep] gives this as output

Which is a bit closer to .

How do I make this function to achieve what I have in

and

?

Any suggestion will be much appreciated.

• The simpleset way is using the Text cell(shortcut for Alt+7), then you can use the shortcup Ctrl+9 to write your formula. See here
– xyz
Nov 23, 2015 at 14:16

Here are two equivalent suggestions to obtain your first form that are slightly more compact than what you have already:

ep[[1]] == Inner[Defer@*Power, Sequence @@ ep[[2]], Times]
ep[[1]] == Times @@ MapThread[Defer@*Power, ep[[2]]]


And here is a suggestion for your second format:

With[{base = ep[[1]]}, HoldForm@Power[base, k]] ==
Inner[
HoldForm@*Power,
Map[Power[#, k] &, HoldForm /@ ep[[2, 1]]], ep[[2, 2]],
Times
]


As for the ordering of factors on the right hand side of these expressions, that is the canonical order that Mathematica likes. Although that is not what you wrote, hopefully that is not an issue, because trying to change that is probably a hopeless battle.

• the order is not a problem at all. My challenge is actually making the output exactly the same (up to the ordering) as presented in the images. In particular, I want the parenthesis and the dots also. Nov 23, 2015 at 13:31
• @evansdoe Just to make sure, do you really need to generate this programmatically though? If the format is what you want, could you just type in the formulae exactly as you like them? Could you provide some context as to what you need this for? Nov 23, 2015 at 15:00
• This is the format I want them. Note that I use LaTeX in writing the format of the output.  ( i \sqrt{2} )^{k} == ( ( i )^{k} )^{1} \cdot ( ( \sqrt{2} )^{k} )^{1} \cdot ( ( \frac{1}{GoldenRation} )^{k} )^{0}  and the second one is as follows  i \sqrt{2} == ( i )^{1} \cdot ( \sqrt{2} )^{1} \cdot ( \frac{1}{GoldenRation} )^{0}  I need it for a project I am working on. The objects we treat are viewed differently at each level. In particular we, consider ( i \sqrt{2} )^{k} as sequences where k runs over a specified range. This is all I can say. Nov 23, 2015 at 21:22
• I have attached a file indicating the exact output format I require. drive.google.com/file/d/0B_EVcKlnBFPcNFByVDhRaEUyVVk/… Nov 23, 2015 at 21:35
• @evansdoe the latex format that you provided here is not in the same order as with the initial question. Apr 11, 2017 at 21:03