Skip to main content

symbolic - 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.



Answer



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"

Comments