# How to concatenate functions and strings

I have

f[x_]=Log[1+x]



Is there a way to get the answer to print out as

Ln(1+x) = x-x^2/2+x^3/3-x^4/4+O(x^5)


I've tried to use StringJoin but this doesn't seem to work

Thanks for the help in advance

• why doesn't Ln[1 + x] == Series[f[x], {x, 0, 4}] // TraditionalForm work for you? – user42582 Aug 30 '17 at 11:08
• Because when I go change f[x] then it doesn't automatically update the left hand side of the answer – NumberCruncher Aug 30 '17 at 11:20
• f[x] == Series[f[x], {x, 0, 4}] // TraditionalForm ? – user42582 Aug 30 '17 at 11:21
• How do I get the mathematica formatting on the question. I hope what I've typed in the question isn't misleading, I do want the answer to appear in traditional form, it's just that when I copied and pasted from mathematica it came out this way – NumberCruncher Aug 30 '17 at 11:23
• @user42582 Oh man, that works :P Thanks very much – NumberCruncher Aug 30 '17 at 11:26

It seems that

f[x] == Series[f[x], {x, 0, 4}] // TraditionalForm


does the trick.

On a more general note, one could also use:

pretty[f_, x_, n_] := Module[{},
f[x] == Series[f[x], {x, 0, n}] // TraditionalForm
]


like so:

pretty[f,x,4]


to get the desired output.

Note, that there is no concatenation needed. Furthermore, Mathematica does not need to splice together functions and strings (even though it could have done, easily). See TraditionalForm from Wolfram Language reference guide.

• Thank you very much for this. How do you get the mathematica like formatting – NumberCruncher Aug 30 '17 at 12:03
• you're welcome; please give an example of what you mean by "mathematica-like formating"; would mathematica.stackexchange.com/editing-help help out? – user42582 Aug 30 '17 at 12:50
• That definitely helps. What I meant was formatting the text so it looks like mathematica code rather than plain text. Thanks. – NumberCruncher Aug 30 '17 at 13:11

Try this

StringJoin[{ToString[f[x]], " = ", ToString[g[x]]}]


$Log[1+x] = x-\frac{x^2}{2}+\frac{x^3}{3}-\frac{x^4}{4}+O\left(x^5\right)$