13
$\begingroup$

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.

$\endgroup$
2
  • 3
    $\begingroup$ Re: converting to MATLAB friendly expression, see this answer $\endgroup$
    – rm -rf
    May 22, 2013 at 0:00
  • $\begingroup$ For MATLAB, use what rm said. For C, use CForm. $\endgroup$
    – Szabolcs
    May 22, 2013 at 1:09

3 Answers 3

13
$\begingroup$

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"
$\endgroup$
2
  • 1
    $\begingroup$ or a b // InputForm ? $\endgroup$
    – cormullion
    May 22, 2013 at 6:40
  • $\begingroup$ @cormullion Yes; I guess that might not be apparent to a new user from my answer alone; thanks for pointing that out. $\endgroup$
    – Mr.Wizard
    May 22, 2013 at 6:51
4
$\begingroup$

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

$\endgroup$
-1
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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