| | |
Math output
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
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.
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.
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.
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
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
@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
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
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
•
•
Join Date: Jul 2009
Posts: 126
Reputation:
Solved Threads: 10
•
•
•
•
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}"
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.
Here, try this:
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
C# Syntax (Toggle Plain Text)
const string matchNumerator = @"\((?<Numerator>[\d,]*(\.\d*)*)\)"; 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
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
•
•
Join Date: Jul 2009
Posts: 126
Reputation:
Solved Threads: 10
C# Syntax (Toggle Plain Text)
# //and this right here is your string in latex format # string latex = @"\frac {" + dNumerator.ToString() + "}{" + dDenominator.ToString() + "}"; # decimal valueOut = dNumerator / dDenominator; # 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 .....
C# Syntax (Toggle Plain Text)
const string matchNumerator = @"\((?<Numerator>[\d,]*(\.\d*)*)\)"; const string matchDenominator = @"\((?<Denominator>[\d,]*(\.\d*)*)\)"; const string matchBoth = matchNumerator + @"\/" + matchDenominator; //Here is the change he told you to make //const string txtBoxInput = @"()/()"; string txtBoxInput = txtTextBox.Text; System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(txtBoxInput, matchBoth); if (m.Success) { decimal dNumerator, dDenominator; if (decimal.TryParse(m.Groups["Numerator"].Value, out dNumerator) && decimal.TryParse(m.Groups["Denominator"].Value, out dDenominator)) { //and this right here is your string in latex format string latex = @"\frac {" + dNumerator.ToString() + "}{" + dDenominator.ToString() + "}"; decimal valueOut = dNumerator / dDenominator; MessageBox.Show(latex); } }
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
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
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:
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.
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:
C# Syntax (Toggle Plain Text)
private string FormatText(string input) { const string matchNumerator = @"\((?<Numerator>[\d,]*(\.\d*)*)\)"; const string matchDenominator = @"\((?<Denominator>[\d,]*(\.\d*)*)\)"; const string matchBoth = matchNumerator + @"\/" + matchDenominator; //Here is the change he told you to make //const string txtBoxInput = @"()/()"; System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(input, matchBoth); while (m.Success) { decimal dNumerator, dDenominator; if (decimal.TryParse(m.Groups["Numerator"].Value, out dNumerator) && decimal.TryParse(m.Groups["Denominator"].Value, out dDenominator)) { //and this right here is your string in latex format string latex = @"\frac {" + dNumerator.ToString() + "}{" + dDenominator.ToString() + "}"; input = input.Remove(m.Index, m.Length); input = input.Insert(m.Index, latex); } m = System.Text.RegularExpressions.Regex.Match(input, matchBoth); } input = input.Replace("÷", "\\div"); input = input.Replace("√", "sqrt"); input = input.Replace("x", "\\times"); input = input.Replace("π", "\\pi"); input = input.Replace("θ", "\\theta"); input = input.Replace("∞", "\\infty"); //and so on return input; }
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.
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
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
•
•
Join Date: Jul 2009
Posts: 126
Reputation:
Solved Threads: 10
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.
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.
•
•
Join Date: Jul 2009
Posts: 126
Reputation:
Solved Threads: 10
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 :
Thanks once again to you Ryshad and all others who replied my thread.............
I am able to modify it myself.........
There was little modification which I have made and finally I got success.
Modified code is :
C# Syntax (Toggle Plain Text)
const string matchNumerator = @"\((?<Numerator>[\d,]*(\.\d*)*)\)"; const string matchDenominator = @"\((?<Denominator>[\d,]*(\.\d*)*)\)"; const string matchBoth = matchNumerator + @"\/" + matchDenominator; //Here is the change he told you to make //const string txtBoxInput = @"()/()"; System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(input, matchBoth); decimal dNumerator, dDenominator; if (decimal.TryParse(m.Groups["Numerator"].Value, out dNumerator) && decimal.TryParse(m.Groups["Denominator"].Value, out dDenominator)) { //and this right here is your string in latex format string latex = @"\frac {" + dNumerator.ToString() + "}{" + dDenominator.ToString() + "}"; input = input.Remove(m.Index, m.Length); input = input.Insert(m.Index, latex); }
Thanks once again to you Ryshad and all others who replied my thread.............
![]() |
Similar Threads
- how to use regex or an array to display some output from an arithmetic input? (VB.NET)
- Trouble with area (Java)
- math help (PHP)
- math program (C)
- Math.max prob???...XD (Java)
- So Stuck (C++)
- Assigning Array Values En Masse (Java)
- Output in Text file-How to apply fprintf()? (C)
- Output in the text file (C)
- missing function header (C++)
Other Threads in the C# Forum
- Previous Thread: How to generate button at runtime and its text from database for windows application
- Next Thread: password setting in a software
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# c#gridviewcolumn chat check checkbox client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms function gdi+ httpwebrequest image index input install java label list listbox listener localization mandelbrot math mouseclick mysql networking object operator path photoshop picturebox pixelinversion post prime programming radians regex remote remoting richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml





