Formating fractions

  • Mathematica
  • Thread starter Silviu
  • Start date
  • #1
624
11

Main Question or Discussion Point

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

Answers and Replies

  • #2
kuruman
Science Advisor
Homework Helper
Insights Author
Gold Member
9,126
2,511
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
624
11
\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
kuruman
Science Advisor
Homework Helper
Insights Author
Gold Member
9,126
2,511
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
624
11
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
kuruman
Science Advisor
Homework Helper
Insights Author
Gold Member
9,126
2,511
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

  • #7
624
11
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

  • #8
kuruman
Science Advisor
Homework Helper
Insights Author
Gold Member
9,126
2,511
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.
 

Related Threads on Formating fractions

  • Last Post
Replies
3
Views
2K
Replies
5
Views
8K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
4
Views
4K
  • Last Post
Replies
4
Views
16K
Replies
2
Views
2K
  • Last Post
Replies
3
Views
5K
  • Last Post
Replies
2
Views
3K
  • Last Post
Replies
1
Views
2K
Replies
3
Views
1K
Top