How to Rearrange and Simplify Fractions in Mathematica for LaTeX?

  • Context: Mathematica 
  • Thread starter Thread starter Silviu
  • Start date Start date
  • Tags Tags
    Fractions
Click For Summary

Discussion Overview

The discussion revolves around using Mathematica to rearrange and simplify fractions for better formatting when exporting to LaTeX. Participants seek assistance with specific code examples and the functionality of Mathematica in handling fractions and expressions.

Discussion Character

  • Technical explanation
  • Homework-related
  • Debate/contested

Main Points Raised

  • Some participants inquire about extracting variables from fractions in Mathematica to improve LaTeX output, specifically wanting to transform expressions like ##\frac{7 p_1 p_2}{2 \cdot 5}## into ##\frac{7 }{2 \cdot 5} p_1 p_2##.
  • There are questions about factoring out common denominators from multiple fractions, indicating a desire for automated solutions rather than manual adjustments.
  • One participant suggests using the ExportString function in Mathematica, providing examples of how to format expressions for LaTeX export, but others express confusion about its application in more complex scenarios.
  • Some participants share their experiences with using ExportString, noting that the placement of quotation marks affects the output, leading to further inquiries about correct usage.
  • There is a mention of the need for experimentation with the Mathematica Help documentation, indicating that the solutions may not be straightforward for all users.

Areas of Agreement / Disagreement

Participants express varying levels of understanding and success with Mathematica's capabilities, leading to unresolved questions about specific implementations and the effectiveness of suggested methods. No consensus is reached on the best approach to achieve the desired formatting.

Contextual Notes

Participants note limitations in their understanding of Mathematica's functions and the specific requirements for formatting expressions for LaTeX, leading to a reliance on trial and error and documentation.

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: 691
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,070
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: 687
  • M2.png
    M2.png
    34.9 KB · Views: 696
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
3K
  • · Replies 11 ·
Replies
11
Views
6K
  • · Replies 5 ·
Replies
5
Views
1K
  • · Replies 7 ·
Replies
7
Views
1K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
Replies
10
Views
3K