# Telling mathematica to output * instead of space for multiplication, so I can copy as plain text

I am trying to get some symbolic expressions in Mathematica which I would like to paste into my C/MATLAB codes. This can be accomplished nicely by selecting the expression and right-clicking to select Copy as plain-text.

However there is one small issue I have.

Consider the simplest possible case for 2 symbols a and b

In[1]:= c = a*b

Out[1]= a b


How can I tell Mathematica to produce all its output as a*b and not a b Without this, I have to go through the pain of replacing manually all spaces in my C/MATLAB codes with the * espcecially for long expressions.

• Re: converting to MATLAB friendly expression, see this answer
– rm -rf
May 22 '13 at 0:00
• For MATLAB, use what rm said. For C, use CForm. May 22 '13 at 1:09

The * multiplication operator is rendered in InputForm:

c = a b;

c // InputForm

a*b


For producing/exporting strings:

ExportString[c, "Text"]

ToString[c, InputForm]

"a*b"

"a*b"

• or a b // InputForm ? May 22 '13 at 6:40
• @cormullion Yes; I guess that might not be apparent to a new user from my answer alone; thanks for pointing that out. May 22 '13 at 6:51

You can set the multiplication symbol in Preferences->Appearance->Numbers->Multiplication

The easiest way to do so is use the "Find and Replace" menu (Ctrl+F), select the blank space between a and b and replace it with * symbol.

It perfectly works for me.