Mathematica How to Rearrange and Simplify Fractions in Mathematica for LaTeX?

  • Thread starter Thread starter Silviu
  • Start date Start date
  • Tags Tags
    Fractions
Click For Summary
The discussion revolves around a user seeking assistance with Mathematica to manipulate fractions for better LaTeX formatting. The user wants to extract variables from a fraction, transforming expressions like 7p1p2/2·5 into (7/2·5)p1p2. Additionally, they inquire about factoring out common denominators from multiple fractions. Responses suggest using the ExportString function to convert expressions to LaTeX format, emphasizing the importance of proper quotation marks around the expressions. However, the user struggles with applying this method to more complex expressions and is encouraged to consult Mathematica's Help documentation for further guidance. The conversation highlights the need for experimentation with Mathematica's functions to achieve the desired formatting.
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: 672
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,050
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: 670
  • M2.png
    M2.png
    34.9 KB · Views: 684
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.
 

Similar threads

  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 11 ·
Replies
11
Views
5K
  • · Replies 5 ·
Replies
5
Views
1K
  • · Replies 7 ·
Replies
7
Views
685
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K