Math output

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Aug 2009
Posts: 391
Reputation: Ryshad has a spectacular aura about Ryshad has a spectacular aura about 
Solved Threads: 69
Ryshad's Avatar
Ryshad Ryshad is offline Offline
Posting Whiz

Re: Math output

 
2
  #41
Oct 5th, 2009
That is not what the code does. This is why sknake and i aren't sure you have understood the code.

The code we gave you uses regular expressions to locate "(number1)/(number2)" in a string. It then extracts this, converts it into latex format "/frac {number1}{number2}".

You said you wanted to display user friendly text in the textbox, we assumed you could do that yourself. Your question, was how to convert that back to latex format.

Now, i want to make it more user friendly in such a way that when user clicks on divide button then a divide sign should appear like "÷" but in coding it should implement "\div" and generate the coresponding math format.Similarly for fraction ,in the textbox there should appear "()/()" and in background it should implement "\frac {}{}".Similarly for other functions also such text should appear in textbox which user can understand easily but in ocding it should implement the symbols which mimeTex can understand.
You already had the code to convert the Latex string into the image. We gave you an example of how to convert user friendly text into latex. We never said that the code would do everything you need it to, that isnt how we work here at Daniweb.
The best way to learn is by experimenting with the code. We will gladly help you if you hit an error or a problem, but we wont do all the work for you.

You say that you understand what the code is doing, if thats not the case we will explain it for you. But if you do understand it then the next step is to take that concept and work out how you can use it to acheive your goal.
Please don't take for granted the work that solvers do for you. Take the time to fully understand the code they give you so that you might adapt it to future problems.

"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 391
Reputation: Ryshad has a spectacular aura about Ryshad has a spectacular aura about 
Solved Threads: 69
Ryshad's Avatar
Ryshad Ryshad is offline Offline
Posting Whiz

Re: Math output

 
1
  #42
Oct 5th, 2009
@ddanbe
The root of it all is this:

Vinnijain has a form which has a textbox for the user to type out an equation in Latex. There is a picturebox which then displays the equation in the standard math format.
vinnijain wants to make it more user friendly so that when a user clicks a button, the textbox displays userfriendly text "()/()" but the code handles it as latex format "/frac {}{}".
We have shown him how to convert the user friendly format to latex. He already has the code required to convert the latex string to an image of the math notation.

There! 5 pages of thread condensed into 3 short paragraphs
Please don't take for granted the work that solvers do for you. Take the time to fully understand the code they give you so that you might adapt it to future problems.

"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 126
Reputation: vinnijain is an unknown quantity at this point 
Solved Threads: 10
vinnijain vinnijain is offline Offline
Junior Poster

Re: Math output

 
1
  #43
Oct 5th, 2009
The code we gave you uses regular expressions to locate "(number1)/(number2)" in a string. It then extracts this, converts it into latex format "/frac {number1}{number2}"
yes, Ryshad you gave me the code ans as you mentioned that it converts into latex format.........
But the problem is that since that code is for converting it to latex format but actually its not converting it.........
And thats the main problem .
Last edited by vinnijain; Oct 5th, 2009 at 7:35 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 391
Reputation: Ryshad has a spectacular aura about Ryshad has a spectacular aura about 
Solved Threads: 69
Ryshad's Avatar
Ryshad Ryshad is offline Offline
Posting Whiz

Re: Math output

 
0
  #44
Oct 5th, 2009
Here, try this:
  1. const string matchNumerator = @"\((?<Numerator>[\d,]*(\.\d*)*)\)";
  2. const string matchDenominator = @"\((?<Denominator>[\d,]*(\.\d*)*)\)";

Adding the * after (\.\d*) means that the decimal place and trailing digit is optional. As sknake showed in his original post, the code accepts a number in the format "(1.2)/(3.4)".
Changing it to this will allow it to handle both "(2.3)" and "(2)".

Please try to be clearer when pointing out a problem. You were just saying that it didnt work.

If this fixes the issue, please mark the thread as solved
Please don't take for granted the work that solvers do for you. Take the time to fully understand the code they give you so that you might adapt it to future problems.

"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 126
Reputation: vinnijain is an unknown quantity at this point 
Solved Threads: 10
vinnijain vinnijain is offline Offline
Junior Poster

Re: Math output

 
1
  #45
Oct 5th, 2009
  1. #
  2. //and this right here is your string in latex format
  3. #
  4. string latex = @"\frac {" + dNumerator.ToString() + "}{" + dDenominator.ToString() + "}";
  5. #
  6. decimal valueOut = dNumerator / dDenominator;
  7. #
  8. System.Diagnostics.Debugger.Break();

Ryshad according to above lines of code ,it should convert "()/()" to "\frac {}{}". But its not converting it and thats the problem.
And the problem that it is not displaying fraction form is that since the code is not converting it to "\frac {}{}" (latex form) so latex compiler is interpreting it as "()/()" and so its not displaying the required fraction form.
As for converting to fraction form there is no particular coding.I just have to feed latex form input to latex compiler .....
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 391
Reputation: Ryshad has a spectacular aura about Ryshad has a spectacular aura about 
Solved Threads: 69
Ryshad's Avatar
Ryshad Ryshad is offline Offline
Posting Whiz

Re: Math output

 
0
  #46
Oct 5th, 2009
  1. const string matchNumerator = @"\((?<Numerator>[\d,]*(\.\d*)*)\)";
  2. const string matchDenominator = @"\((?<Denominator>[\d,]*(\.\d*)*)\)";
  3. const string matchBoth = matchNumerator + @"\/" + matchDenominator;
  4.  
  5. //Here is the change he told you to make
  6. //const string txtBoxInput = @"()/()";
  7. string txtBoxInput = txtTextBox.Text;
  8.  
  9. System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(txtBoxInput, matchBoth);
  10. if (m.Success)
  11. {
  12. decimal dNumerator, dDenominator;
  13. if (decimal.TryParse(m.Groups["Numerator"].Value, out dNumerator) && decimal.TryParse(m.Groups["Denominator"].Value, out dDenominator))
  14. {
  15.  
  16. //and this right here is your string in latex format
  17. string latex = @"\frac {" + dNumerator.ToString() + "}{" + dDenominator.ToString() + "}";
  18. decimal valueOut = dNumerator / dDenominator;
  19. MessageBox.Show(latex);
  20. }
  21.  
  22. }

That is the code i ran. When i typed "(2.3)/(3.4)" in the textbox i got a messagebox showing "/frac {2.3}{3.4}" and when i typed "(2)/(3)" i got a messagebox showing "/frac {2}{3}".

Did you change the numerator and denominator strings as i showed you?

Post the latest version of your code and i'll see if i can spot where yours is different.
Please don't take for granted the work that solvers do for you. Take the time to fully understand the code they give you so that you might adapt it to future problems.

"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 126
Reputation: vinnijain is an unknown quantity at this point 
Solved Threads: 10
vinnijain vinnijain is offline Offline
Junior Poster

Re: Math output

 
1
  #47
Oct 5th, 2009
My application is attached here...........
Kindly help me please....................
I don't want to continue the thread more but please solve my problem.........
Attached Files
File Type: zip math output.zip (1.01 MB, 2 views)
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 391
Reputation: Ryshad has a spectacular aura about Ryshad has a spectacular aura about 
Solved Threads: 69
Ryshad's Avatar
Ryshad Ryshad is offline Offline
Posting Whiz

Re: Math output

 
1
  #48
Oct 5th, 2009
Okay, firstly: i have made the changes to your code so that it processes fractions. I cant run the project directly as i dont have vs 2008, i have attached the updated version..please let me know if it runs correctly.

secondly, my post earlier that said you had the code in a button handler was correct, i just thought it was a different button. I have moved the regex code to the FormatText method, where it needs to be:
  1. private string FormatText(string input)
  2. {
  3. const string matchNumerator = @"\((?<Numerator>[\d,]*(\.\d*)*)\)";
  4. const string matchDenominator = @"\((?<Denominator>[\d,]*(\.\d*)*)\)";
  5. const string matchBoth = matchNumerator + @"\/" + matchDenominator;
  6. //Here is the change he told you to make
  7.  
  8. //const string txtBoxInput = @"()/()";
  9. System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(input, matchBoth);
  10. while (m.Success)
  11. {
  12. decimal dNumerator, dDenominator;
  13. if (decimal.TryParse(m.Groups["Numerator"].Value, out dNumerator) && decimal.TryParse(m.Groups["Denominator"].Value, out dDenominator))
  14. {
  15. //and this right here is your string in latex format
  16. string latex = @"\frac {" + dNumerator.ToString() + "}{" + dDenominator.ToString() + "}";
  17. input = input.Remove(m.Index, m.Length);
  18. input = input.Insert(m.Index, latex);
  19. }
  20. m = System.Text.RegularExpressions.Regex.Match(input, matchBoth);
  21.  
  22. }
  23. input = input.Replace("÷", "\\div");
  24. input = input.Replace("√", "sqrt");
  25. input = input.Replace("x", "\\times");
  26. input = input.Replace("π", "\\pi");
  27. input = input.Replace("θ", "\\theta");
  28. input = input.Replace("∞", "\\infty");
  29. //and so on
  30. return input;
  31. }
I have also added a loop so that it handles multiple occurances of fractions in the same string.

My concern, however, is that in doing this for you you wont have learned how all of this works. As such, the code doesnt format "\\sqrt[]{}" or anything else that needs custom formatting. If the code works correctly then its down to you to disect it and work out how to add that functionality to it.
Attached Files
File Type: zip math output.zip (1,004.0 KB, 1 views)
Please don't take for granted the work that solvers do for you. Take the time to fully understand the code they give you so that you might adapt it to future problems.

"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 126
Reputation: vinnijain is an unknown quantity at this point 
Solved Threads: 10
vinnijain vinnijain is offline Offline
Junior Poster

Re: Math output

 
0
  #49
Oct 5th, 2009
Thanks a lot .But the code is not working .It is again giving the original result., i.e. same thing which i was getting in the original code.
Also initially it gave result once but after that it is hanging(runtime problem) and displaying no error.
Last edited by vinnijain; Oct 5th, 2009 at 10:15 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 126
Reputation: vinnijain is an unknown quantity at this point 
Solved Threads: 10
vinnijain vinnijain is offline Offline
Junior Poster

Re: Math output

 
0
  #50
Oct 5th, 2009
Thanks Ryshad,
I am able to modify it myself.........
There was little modification which I have made and finally I got success.
Modified code is :
  1. const string matchNumerator = @"\((?<Numerator>[\d,]*(\.\d*)*)\)";
  2. const string matchDenominator = @"\((?<Denominator>[\d,]*(\.\d*)*)\)";
  3. const string matchBoth = matchNumerator + @"\/" + matchDenominator;
  4. //Here is the change he told you to make
  5.  
  6. //const string txtBoxInput = @"()/()";
  7. System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(input, matchBoth);
  8.  
  9. decimal dNumerator, dDenominator;
  10. if (decimal.TryParse(m.Groups["Numerator"].Value, out dNumerator) && decimal.TryParse(m.Groups["Denominator"].Value, out dDenominator))
  11. {
  12. //and this right here is your string in latex format
  13. string latex = @"\frac {" + dNumerator.ToString() + "}{" + dDenominator.ToString() + "}";
  14. input = input.Remove(m.Index, m.Length);
  15. input = input.Insert(m.Index, latex);
  16.  
  17. }

Thanks once again to you Ryshad and all others who replied my thread.............
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC