13

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.

smilingbuddha
  • 439
  • 4
  • 8

3 Answers3

13

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"

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
4

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

Ernst Stelzer
  • 2,055
  • 12
  • 24
-1

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.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574