4
$\begingroup$

I have obtained a formula in Mathematica and I want to transfer it to Microsoft Word so I did this:

ff = (-2 a17 denP[re] + b17 Sqrt[denE[re]] denP[re]^(3/2))/(
  2 (a17 - b17 Sqrt[denE[re]] Sqrt[denP[re]] + 
     c171 denE[re] denP[re])^2);
nn = ff /. {denE[re] -> 
     "\!\(\*SubscriptBox[\(\[Rho]\), \
\(e\)]\)(\!\(\*SubscriptBox[\(r\), \(e\)]\))", 
    denP[re] -> 
     "\!\(\*SubscriptBox[\(\[Rho]\), \
\(p\)]\)(\!\(\*SubscriptBox[\(r\), \(e\)]\))", 
    a17 -> Subscript[a, 17], b17 -> Subscript[b, 17], 
    c171 -> Subscript[c, 171]} // TraditionalForm

but when I copy and paste it in Word, "" are present enter image description here on the other hand if I remove "" in nn Mathematica doesn't print them. Any idea?

$\endgroup$
11
  • 1
    $\begingroup$ I deleted my answer. You can't add explicit ( ) using strings. Ofcourse they will show as strings in word. Better to not do this and leave it as is. That is the right way. But if insist on having () around each term, may be there is a way that someone could find for you. $\endgroup$
    – Nasser
    Apr 25 at 6:42
  • $\begingroup$ Thanks but I have a lot long formulas which I apply such a procedure to them, so finding a efficient method will help me so much. $\endgroup$
    – Wisdom
    Apr 25 at 7:02
  • $\begingroup$ If you right click and choose Copy As > LaTeX, it seems to give an accurate LaTeX expression, without ". Can you then put LaTeX in a Word equation? Not sure how Word works, so not sure how feasible this is. $\endgroup$
    – thorimur
    Apr 25 at 7:04
  • $\begingroup$ @thorimur I tried this, but Word has problem with showing LaTex. At the moment I copy and paste the code which includes "" and then remove them using "Find and Replace' in Word. $\endgroup$
    – Wisdom
    Apr 25 at 7:06
  • $\begingroup$ Hmm, what version of word are you using? It seems that Word does support LaTeX input in the equation editor, you might just have to fiddle with it a bit. If you get LaTeX working in Word, try using TeXForm instead of the whole {TraditionalForm then Copy As > ...} routine; it'll be quicker, especially if combined with CopyToClipboard which will copy the output directly upon evaluating! :) $\endgroup$
    – thorimur
    Apr 25 at 7:15

2 Answers 2

5
$\begingroup$
ClearAll["Global`*"]

Format[re] := Subscript[r, e]
Format[a17] := Subscript[a, 17]
Format[b17] := Subscript[b, 17]
Format[c171] := Subscript[c, 171]
Format[denE] := Subscript[ρ, e]
Format[denP] := Subscript[ρ, p]

(ff = (-2 a17 denP[re] + 
      b17 Sqrt[
        denE[re]] denP[re]^(3/2))/(2 (a17 - 
         b17 Sqrt[denE[re]] Sqrt[denP[re]] + 
         c171 denE[re] denP[re])^2)) // TraditionalForm

enter image description here

Edit | Copy As | MathML then paste into Word

This would be simplified a little if you used indexed variables such as a[17], b[17], c[171], r[e] instead of a17, b17, c171, re. Then you could use

ClearAll["Global`*"]

(Format[#[n_]] := Subscript[#, n]) & /@ {a, b, c, r};
Format[denE] := Subscript[ρ, e]
Format[denP] := Subscript[ρ, p]

(ff = (-2 a[17] denP[r[e]] + 
      b[17] Sqrt[
        denE[r[e]]] denP[r[e]]^(3/2))/(2 (a[17] - 
         b[17] Sqrt[denE[r[e]]] Sqrt[denP[r[e]]] + 
         c[171] denE[r[e]] denP[r[e]])^2)) // TraditionalForm

enter image description here

$\endgroup$
3
$\begingroup$

Update:

From https://superuser.com/questions/340650/type-math-formulas-in-microsoft-word-the-latex-way it says

If you are running Office 365 version 1707 or later, the Equation Editor allows you to convert LaTex into the native format. See the first part of this answer.

I have old word (2010) so I can't test the above. My word equation editor will not accept inserting raw latex in it.

enter image description here

But if you have newer version of word, you can convert the modified expression, after you adding those explicit "()" around the terms, to latex using TeXForm (which will keep the parentheses (surprise)), as mentioned in comments above by thorimur.

Then copy the raw latex into Word equation editor. It should work.

Alternative is to use copy as bitmap:

enter image description here

To do that, select the output from Mathematica using the mouse, then copy/paste as bitmap into word.

enter image description here

I would not recommend doing all of this myself. Output does not look best. Using bitmaps for math is not good. Using Word itself for math is not good.

Best solution is to throw away Word. Generate pure Latex from Mathematica, and use a Latex compiler to generate the PDF. That will produce best output. A professional looking document. But if insist on using Word, the above should do it.

OLD answer

Just remove the "" from the code you used, then it works. Where did the "" stuff come from? If you add "" then it will show up in word ofcourse.

ff = (-2 a17 denP[re] + 
     b17 Sqrt[
       denE[re]] denP[re]^(3/2))/(2 (a17 - 
        b17 Sqrt[denE[re]] Sqrt[denP[re]] + c171 denE[re] denP[re])^2);
nn = ff /. {denE[
      re] -> \!\(\*SubscriptBox[\(\[Rho]\), \(e\)]\) \
(\!\(\*SubscriptBox[\(r\), \(e\)]\)), 
    denP[re] -> \!\(\*SubscriptBox[\(\[Rho]\), \(p\)]\) \
(\!\(\*SubscriptBox[\(r\), \(e\)]\)), a17 -> Subscript[a, 17], 
    b17 -> Subscript[b, 17], c171 -> Subscript[c, 171]} // 
  TraditionalForm

Gives

enter image description here

The copied this to Word, and it works:

enter image description here

on the other hand if I remove "" in nn Mathematica doesn't print them.

I am not seeing this. Does not print what? The question is, where did the "" come? Did you add then yourself?

$\endgroup$
2
  • $\begingroup$ Thanks but this is not true! I want to get \rho_e (r_e) not what you have gotten in Word, Look at the result carefully to get my mean $\endgroup$
    – Wisdom
    Apr 25 at 6:36
  • $\begingroup$ @Wisdom I see., You want to have explicit ( ) added? Well., adding them using strings is not the right way to do this. But now I understand. Will delete this then. $\endgroup$
    – Nasser
    Apr 25 at 6:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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