Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #4199 > unrolled thread

Getting TraditionalForm to put in a multiplication sign.

Started byFrank K <fkampas@gmail.com>
First post2011-08-07 10:16 +0000
Last post2011-08-10 10:58 +0000
Articles 5 — 3 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Getting TraditionalForm to put in a multiplication sign. Frank K <fkampas@gmail.com> - 2011-08-07 10:16 +0000
    Re: Getting TraditionalForm to put in a multiplication sign. Peter Pein <petsie@dordos.net> - 2011-08-09 11:23 +0000
      Re: Getting TraditionalForm to put in a multiplication sign. Simon <simonjtyler@gmail.com> - 2011-08-11 09:21 +0000
        Re: Getting TraditionalForm to put in a multiplication sign. Frank K <fkampas@gmail.com> - 2011-08-13 10:53 +0000
    Re: Getting TraditionalForm to put in a multiplication sign. Simon <simonjtyler@gmail.com> - 2011-08-10 10:58 +0000

#4199 — Getting TraditionalForm to put in a multiplication sign.

FromFrank K <fkampas@gmail.com>
Date2011-08-07 10:16 +0000
SubjectGetting TraditionalForm to put in a multiplication sign.
Message-ID<j1lomg$nmi$1@smc.vnet.net>
For purposes of exporting Mathematica expressions to other software,
it would be useful to have a multiplication sign (*) in
TraditionalForm instead of a space.  For example, x * y * (w + z)
instead of x y (w + z).  Anybody know how to do this?

[toc] | [next] | [standalone]


#4231

FromPeter Pein <petsie@dordos.net>
Date2011-08-09 11:23 +0000
Message-ID<j1r5c4$fi1$1@smc.vnet.net>
In reply to#4199
Am 07.08.2011 12:16, schrieb Frank K:
> For purposes of exporting Mathematica expressions to other software,
> it would be useful to have a multiplication sign (*) in
> TraditionalForm instead of a space.  For example, x * y * (w + z)
> instead of x y (w + z).  Anybody know how to do this?
> 

Hi,

will the following do what you want?

Unprotect[Times];
Format[HoldPattern[Times[x_, y__]]] := x \[CenterDot] y;
Protect[Times];
a x^2 + b x + c // TraditionalForm


[toc] | [prev] | [next] | [standalone]


#4322

FromSimon <simonjtyler@gmail.com>
Date2011-08-11 09:21 +0000
Message-ID<j206ud$77n$1@smc.vnet.net>
In reply to#4231
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.

[toc] | [prev] | [next] | [standalone]


#4366

FromFrank K <fkampas@gmail.com>
Date2011-08-13 10:53 +0000
Message-ID<j25l2e$ovr$1@smc.vnet.net>
In reply to#4322
On Aug 11, 5:21 am, Simon <simonjty...@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.

[toc] | [prev] | [next] | [standalone]


#4285

FromSimon <simonjtyler@gmail.com>
Date2011-08-10 10:58 +0000
Message-ID<j1to84$pti$1@smc.vnet.net>
In reply to#4199
I thought there must be an option for this... but couldn't find it.
(AutoMultiplicationSymbol seems to only be for numbers...)
Instead, here's a quick hack that relies on the fact that in the box form of expressions, a single space is almost always used to denote multiplication. 

ClearAll[TradFormX]
SetAttributes[TradFormX, HoldFirst]
TradFormX[expr_, cellStyle_String:"Output", outForm_: TraditionalForm] := 
 CellPrint[Cell[ToBoxes[HoldForm[expr], outForm] /. " " -> "*", cellStyle]]

In[]:= (3 2 a + b) f[x + 2 y]//TradFormX
Out[]= (3*2*a + b)*f(x + 2*y)

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web