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: [mg120814] Re: Getting TraditionalForm to put in a multiplication sign.
  • From: Simon <simonjtyler at gmail.com>
  • Date: Thu, 11 Aug 2011 05:13:04 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <j1lomg$nmi$1@smc.vnet.net> <j1r5c4$fi1$1@smc.vnet.net>
  • Reply-to: comp.soft-sys.math.mathematica at googlegroups.com

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.




  • Prev by Date: Re: Getting TraditionalForm to put in a multiplication sign.
  • Next by Date: Re: Feature idea (may already be there)
  • Previous by thread: Re: Getting TraditionalForm to put in a multiplication sign.
  • Next by thread: Re: Getting TraditionalForm to put in a multiplication sign.