3

I want every output expression in a notebook to use //PowerExpand and also to format numbers as scientific. Is there a way to do this without explicitly calling ScientificForm[] and //PowerExpand on every input?

i.e. I want to be able to enter

In: 4.3*^-5*Sqrt[M]*(L*n^2)^{3/4}
Out: {0.000043 \Sqrt[M] (L n^2)^(3/4)}

and instead get,

Out: 4.3e-5 M^(1/2} L^(3/4} n^(3/2)

Aside: is there a way to make mathematica never use radical symbols, and to use exponents instead?

DilithiumMatrix
  • 582
  • 4
  • 12

2 Answers2

4

With

$PrePrint = ScientificForm@PowerExpand@# &

You would get the desired output. To return to normal just type:

$PrePrint =.
eldo
  • 67,911
  • 5
  • 60
  • 168
  • Thanks! This is working on a new notebook, but when I put it into my existing notebook, and re-run my cells - they keep the same format. Any ideas? – DilithiumMatrix May 30 '14 at 19:43
3

It seems you are using a variation of my comments-in-output code from Notebook formatting - easier descriptions for equations and results? The variation you are using does not actually produce any formal output; it merely prints the evaluated form as a side-effect. Despite its name $PrePrint does not affect the lines produced by Print, as these are not considered output.

You can either add ScientificForm and PowerExpand to your modified $PreRead function:

$PreRead = Replace[#, 
    RowBox[{body__, ";", note_String?(StringMatchQ[#, "\"*\""] &)}] :> 
     Print[ScientificForm @ PowerExpand @ ToExpression@RowBox@{body}, Spacer[50], 
      Style[ToExpression@note, Italic, Red]]] &;

Or as I would prefer you can add it to my original code:

$note = Null;

$PreRead =
  Replace[#,
    RowBox[{body__, ";", note_String?(StringMatchQ[#, "\"*\""] &)}] :>
     ($note = Style[ToExpression@note, Italic, Red]; RowBox[{body}])
  ] &;

$PrePrint = 
  If[$note =!= Null,
    # &[Row[{Pane@#, Spacer[50], $note}], $note = Null],
    #
  ] & @ ScientificForm @ PowerExpand @ # &;
Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371