Moving variables outside fractions in Mathematica

  • Context: Mathematica 
  • Thread starter Thread starter Silviu
  • Start date Start date
  • Tags Tags
    Fractions
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
7 replies · 3K views
Silviu
Messages
612
Reaction score
11
Hello! I am new to Mathematica and I need some help with the code I attached. Can someone tell me how to pull the variables out of the fraction i.e. instead of ##\frac{7 p_1 p_2}{2 \cdot 5}## I would like ##\frac{7 }{2 \cdot 5} p_1 p_2## (I need this to make it look better for when I import it to Latex). Also, is there a way to factor out the common denominator of all the fractions? Thank you (and I am sorry if the questions are trivial)!
 

Attachments

  • Mathematica.png
    Mathematica.png
    27.1 KB · Views: 705
Physics news on Phys.org
Silviu said:
Hello! I am new to Mathematica and I need some help with the code I attached. Can someone tell me how to pull the variables out of the fraction i.e. instead of ##\frac{7 p_1 p_2}{2 \cdot 5}## I would like ##\frac{7 }{2 \cdot 5} p_1 p_2## (I need this to make it look better for when I import it to Latex). Also, is there a way to factor out the common denominator of all the fractions? Thank you (and I am sorry if the questions are trivial)!
\frac{7 }{2 \cdot 5} p_1 p_2 → ##\frac{7 }{2 \cdot 5} p_1 p_2##

\frac{3}{24}+\frac{5}{36} = \frac{1}{6}\left( \frac{3}{4}+\frac{5}{6} \right) → ##\frac{3}{24}+\frac{5}{36} =\frac{1}{6}\left( \frac{3}{4}+\frac{5}{6} \right)##
 
kuruman said:
\frac{7 }{2 \cdot 5} p_1 p_2 → ##\frac{7 }{2 \cdot 5} p_1 p_2##

\frac{3}{24}+\frac{5}{36} = \frac{1}{6}\left( \frac{3}{4}+\frac{5}{6} \right) → ##\frac{3}{24}+\frac{5}{36} =\frac{1}{6}\left( \frac{3}{4}+\frac{5}{6} \right)##
I am not sure what you mean... I know how to do it by hand in latex. I need for Mathematica to do it automatically.
 
Silviu said:
I am not sure what you mean... I know how to do it by hand in latex. I need for Mathematica to do it automatically.
Sorry, I was hasty in my reply. I just stick the expression in ExportString bracketed with double quotation marks.
This
ExportString[1/6 (3/4 + 5/6), "TeX"]
will give you
\frac{19}{72}
but this
ExportString["1/6 (3/4 + 5/6)", "TeX"]
will give you
\frac{1}{6}\left(\frac{3}{4}+\frac{5}{6}\right)
 
kuruman said:
Sorry, I was hasty in my reply. I just stick the expression in ExportString bracketed with double quotation marks.
This
ExportString[1/6 (3/4 + 5/6), "TeX"]
will give you
\frac{19}{72}
but this
ExportString["1/6 (3/4 + 5/6)", "TeX"]
will give you
\frac{1}{6}\left(\frac{3}{4}+\frac{5}{6}\right)
Could you please tell me where to put the ExportString and where to put the quotation marks? I tried to put them around For ... //Export expression but it doesn't work (for example it messes up with the quotation marks in the expression itself). Thank you!
 
Here is a screen shot of what I used for your example. I have not used this in a For loop. You may have to experiment a little bit to get it to do what you want. I assume you have gone to Mathematica Help and looked at TeX / Export.

Fraction.png
 

Attachments

  • Fraction.png
    Fraction.png
    20.3 KB · Views: 1,091
kuruman said:
Here is a screen shot of what I used for your example. I have not used this in a For loop. You may have to experiment a little bit to get it to do what you want. I assume you have gone to Mathematica Help and looked at TeX / Export.

View attachment 221769
Yes it works with a simple expression like that, but now with what I have. I am not sure where to put the quotation marks for example... I attached a SS of what I get with and without quotation marks and it doesn't work
 

Attachments

  • M1.png
    M1.png
    25.9 KB · Views: 702
  • M2.png
    M2.png
    34.9 KB · Views: 711
I don't know what you have and I have a vague idea of what you want to do, that's why I suggested that you read the Help documentation and experiment on your own. Maybe someone who is more knowledgeable in these matters can help you.