How to Rearrange and Simplify Fractions in Mathematica for LaTeX?

  • Mathematica
  • Thread starter Silviu
  • Start date
  • Tags
    Fractions
In summary, the conversation is about using ExportString in Mathematica to convert mathematical expressions into TeX format for easier import into LaTeX. The user was having trouble with using quotation marks around the expression and getting it to work properly. They were advised to experiment and consult the Help documentation for further assistance.
  • #1
Silviu
624
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: 626
Physics news on Phys.org
  • #2
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)##
 
  • #3
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.
 
  • #4
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)
 
  • #5
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!
 
  • #6
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: 963
  • #7
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: 617
  • M2.png
    M2.png
    34.9 KB · Views: 637
  • #8
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.
 

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

How do I format fractions in Mathematica?

To format fractions in Mathematica, you can use the built-in function HoldForm to preserve the fraction in its exact form. For example, HoldForm[1/2] will display as 1/2 instead of 0.5.

Can I change the display format of fractions in Mathematica?

Yes, you can use the TraditionalForm function to change the display format of fractions to a more traditional mathematical form. For example, TraditionalForm[1/2] will display as 1/2 with the numerator and denominator written on separate lines.

How do I convert a decimal number to a fraction in Mathematica?

You can use the Rationalize function to convert a decimal number to a fraction in Mathematica. For example, Rationalize[0.5] will output 1/2.

Can I control the precision of fractions in Mathematica?

Yes, you can use the NumberForm function to specify the number of digits to appear after the decimal point. For example, NumberForm[1/3, 3] will display as 0.333.

How do I input mixed fractions in Mathematica?

To input mixed fractions in Mathematica, you can use the FromContinuedFraction function. For example, FromContinuedFraction[{1, 2, 3}] will output 11/3 for the mixed fraction 1 + 2/(3 + 0).

Similar threads

Replies
1
Views
928
Replies
11
Views
3K
Replies
8
Views
2K
Replies
1
Views
2K
Replies
2
Views
695
Replies
8
Views
1K
Replies
1
Views
1K
Back
Top