# Help on output formatting

Again, I am writing homework sheets. I have tried

 a = "(portionOfCircle)";
SectorArea =  a * Pi * r^2
SectorArea =  a * Pi * r^2 // TeXForm
With[{a = "portionOfCircle"}, Defer[a * Pi * r^2 // TeXForm]]


I would like the output to be in LaTeX form such as $$\text{(portion of circle)}\cdot \pi r^2$$ instead my code will output $$\pi \text{(portion of circle)}\cdot r^2$$

Also, I would like

 a = RandomChoice[{Pi/6, Pi/4, 5 Pi/4}]/(2 Pi)
SectorArea = a*Pi*r^2
SectorArea = a*Pi*r^2 // TeXForm
With[{a = a}, Defer[a*Pi*r^2]]


to output $$\frac{\pi/4}{2\pi}\cdot \pi r^2$$ instead, it simplifies the fraction hiding the concept i'm trying to emphasize.

Any help would be much appreciated.

Just to clarify my comment earlier, here is a solution for the second part of the question (no need to duplicate an answer to the first part) that I think serves the intended purpose:

Row[{Row[{RandomChoice[{Pi/6, Pi/4, 5 Pi/4}]}]/HoldForm[2 Pi],
" \[Times] ", HoldForm[Pi*r^2]}] // TraditionalForm Here I added the \[Times] symbol just to show that you can add arbitrary decorations by means of Row, to make the output look even clearer.

• very nice! this is exactly what I was looking for ... thank all of u for your help much appreciated! Mar 18, 2013 at 2:13
• Yes, this is nice. +1. Mar 18, 2013 at 8:29

What you want to use (for the first part) is HoldForm.

i.e.

TeXForm@With[{a = "portionOfCircle"}, HoldForm[a*Pi*r^2]]


which returns

\text{portionOfCircle} \pi  r^2


as desired.

The problem with using Defer is that it simply holds until the expression evaluated. In your example, when the output of Defer is fed to TeXForm it gets evaluated prior to formatting it for TeX output. HoldForm will preserve the form under all future manipulations until you explicitly call ReleaseForm.

• thank you @covopsdaf2, i think I need to add HoldForm to my bag of tools.. I understand it thank you, does exactly what I needed. Mar 16, 2013 at 23:19
• HoldForm is the way I would go, too (+1). Maybe also combined with Row when you mix strings and numbers.
– Jens
Mar 17, 2013 at 3:22
• @Jens HoldForm does not address the second part of the question, which (to me at least) was the main one. Mar 17, 2013 at 21:25
• @LeonidShifrin It's so easy to do this with Row and HoldForm, I just don't think one should even start the way the OP did...
– Jens
Mar 17, 2013 at 22:06
• @Jens The second part of the question was not about positioning, and I don't see how you solve that problem with Row and HoldForm. But, whatever, no big deal anyway. Mar 17, 2013 at 22:11