MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Getting TraditionalForm to put in a multiplication sign.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg120858] Re: Getting TraditionalForm to put in a multiplication sign.
  • From: Frank K <fkampas at gmail.com>
  • Date: Sat, 13 Aug 2011 06:48:31 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <j1lomg$nmi$1@smc.vnet.net> <j1r5c4$fi1$1@smc.vnet.net> <j206ud$77n$1@smc.vnet.net>

On Aug 11, 5:21 am, Simon <simonjty... at gmail.com> wrote:
> Hi Peter,
>
> Using Format is a good idea, but you probably want to combine it with Interpretation so that the output can be reused. In the following I've also restricted the Format to only work on TraditionalForm expressions, but that's not necessary:
>
> In[1]:= Unprotect[Times];
>         Format[HoldPattern[Times[x_, y__]], TraditionalForm] :=
>           Interpretation[Row[{x, y}, "*"], Times[x, y]];
>         Protect[Times];
>
> In[6]:= a f[x] + b g[x + y] + 2 c
>         % // TraditionalForm
>
> Out[6]= 2 c + a f[x] + b g[x + y]
>
> Out[7]//TraditionalForm= a*f(x)+b*g(x+y)+2*c
>
> The problem with Format/Interpretation is that if you try to change an expression to TraditionalForm in place with Ctrl-Shift-T (or the appropriate context/normal menu option), you run into a recursion bug:http://stackoverflow.com/q/4112299/421225
>
> To get around this, maybe it's best to use a manually constructed MakeBoxes rule. For example:
>
> Unprotect[Times];
> Times /: MakeBoxes[HoldPattern[Times[x_, y__]], TraditionalForm] :=
>   With[{row = ToBoxes[Row[{x, y}, "*"], TraditionalForm]},
>    InterpretationBox[row, x y]];
> Protect[Times];
>
> or
>
> Unprotect[Times];
> Times /: MakeBoxes[HoldPattern[Times[x_, y__]], form_] :=
>   With[{row = ToBoxes[Row[{x, y}, "*"], form]},
>    InterpretationBox[row, x y]];
> Protect[Times];
>
> if you want it applying to all formattings.

It's important to remember that what you see on the screen is not
always what you get when you do Export.




  • Prev by Date: Re: Just another Mathematica "Gotcha"
  • Next by Date: Re: Odd glitch opening Mathematica notebook on a Mac
  • Previous by thread: Re: Getting TraditionalForm to put in a multiplication sign.
  • Next by thread: Mathgroup on Google Groups