Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
2  
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. –  Szabolcs May 22 '13 at 1:09

2 Answers 2

up vote 9 down vote accepted

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"
share|improve this answer
1  
or a b // InputForm ? –  cormullion 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. –  Mr.Wizard May 22 '13 at 6:51

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.