954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Math output

Hi!!!!!!!
I have made a window application in which i am entering mathematical equations and side by side the corresponding math format is generated like we see in books.
In this, I am using LATEX/MimeTEX for generating math format and it uses special symbols for generating math format.
Like for square root ,we use "\sqrt" , for divide symbol we use "\div" , for fraction we use "\frac" and so on .The complete list of symbols can be seen on following link:
http://www.forkosh.com/mimetextutorial.html

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.

Can anyone give me the solution for this.............
If anyone finds solution for this,and if he\she wants then I will attach my application. :)

vinnijain
Junior Poster
145 posts since Jul 2009
Reputation Points: 11
Solved Threads: 12
 

Hi, you have working code that takes the user input and displays it in Math format, is that correct?
If so, could you post that code here and we can show you how to rework it :)

Ryshad
Nearly a Posting Virtuoso
1,307 posts since Aug 2009
Reputation Points: 512
Solved Threads: 246
 

my application is attached here............
In this open "Eq2ImgWinForms" in visual studio
Kindly help me and reply soon..........

Attachments eq2img_all.zip (1522.15KB)
vinnijain
Junior Poster
145 posts since Jul 2009
Reputation Points: 11
Solved Threads: 12
 

personally, i would display the readable characters in the textbox, then parse the textbox.text trhough a function that swaps out the readable characters for math format using string.replace.

private string FormatText(string input)
        {
            input = input.Replace("÷", "//div");
            input = input.Replace("√", "sqrt");
            //and so on
            return input;
         }

            //then call the function like this:
            WriteEquation(FormatText(textBoxEquation.Text));


it may be easier to use regular expressions, but i have very limited experience with them so someone more versed may be able to point you in the right direction.

Ryshad
Nearly a Posting Virtuoso
1,307 posts since Aug 2009
Reputation Points: 512
Solved Threads: 246
 
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
 
Take a look at these articles: http://www.c-sharpcorner.com/UploadFile/mgold/CodeDomCalculator08082005003253AM/CodeDomCalculator.aspx http://www.bestcode.com/html/bcparser_net.html

Hi,I have already read these articles..........
These are for calculations.But I want to show math format not the calculations............
And the application which I have attached ,in that I have done almost everything.........I just want you to modify it in such a way that it becomes user friendly.For example, for fraction latex symbol used is "\frac {}{}",but for user I want that if he clicks on fraction button then in textbox there should appear "()/()" but in coding it should implement for MIMETex................
Kindly help me regarding this ,how in code I could replace the textbox text with Mimetex and correspondingly it generate math output......

vinnijain
Junior Poster
145 posts since Jul 2009
Reputation Points: 11
Solved Threads: 12
 

The way i see it there are two choices:

1) you can try the way i suggested, populate the textbox with the user friendly text then reformat it using string functions/regex.

2) build two strings, any time you add to the user friendly textbox, add the math format to a class level string variable as well. This way you'll have one string that the user can read and one that is formatted for the MIMETex. The problem you'll have here is keeping the two in sync...very tricky, since you'd have to capture the changes in the textbox : /

I think 1) is the way to go... just pass the string through a function that pulls out the user friendly text and rearranges it into MIMETex format.

Regular expressions would probably be helpful to you here. Check out:
http://msdn.microsoft.com/en-us/library/30wbz966(VS.71).aspx
http://www.regular-expressions.info/

Ryshad
Nearly a Posting Virtuoso
1,307 posts since Aug 2009
Reputation Points: 512
Solved Threads: 246
 

Hi Ryshad,
I tried in the same way.
But ,for example, for fractions I used "()/()" in textbox and in FormatText() function I added a line "input = input.Replace("()/()","\\frac {}{}");".
But its not working......
Also ,I am not able to get how to reformat it using string function.
As I have already given you my code.Kindly modify that and help me out...

vinnijain
Junior Poster
145 posts since Jul 2009
Reputation Points: 11
Solved Threads: 12
 

Hi,

The replace function will only replace exact string matches, so if the user has entered numebrs into the brackets then the string will no longer match : "(12)/(24)" != "()/()"

You will definitely need to use regular expressions here to find the sections you want to replace. Read through the links i sent you...its been a long time since i worked with Regex so i cant rewrite the code for you atm : /

Perhaps someone more familair with it can give you a sample

Ryshad
Nearly a Posting Virtuoso
1,307 posts since Aug 2009
Reputation Points: 512
Solved Threads: 246
 

hi Sknake,
The links which you have given me,I have already read those.I don't want calculation,but only want to generate math format for the equation entered in the textbox.
The work which I have done is attached in this thread...........
Kindly help me out.....

vinnijain
Junior Poster
145 posts since Jul 2009
Reputation Points: 11
Solved Threads: 12
 

Ryshad has already given you the information you need. You need to make regex patterns with groups for each math command from latex.

sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
 
Ryshad has already given you the information you need. You need to make regex patterns with groups for each math command from latex.

Hello Mr.Scott,
Thanks for your reply........
I don't know much about regular expression......
I tried the links given by Ryshad,they helped me but not much.....
My application is attached in this thread, Can you please give me some hint or sample example in that.Rest I 'll do it on my own.

Like for fraction ,in textbox I want "()/()" and its corresponding latex symbol is "\frac {}{}" and for nth root in textbox there is "root:{}()" and its corresponding latex symbol is "\sqrt[]{}" and so on...........
Kindly help me..........:pretty:

vinnijain
Junior Poster
145 posts since Jul 2009
Reputation Points: 11
Solved Threads: 12
 
private void button5_Click(object sender, EventArgs e)
    {
      const string matchNumerator = @"\((?<Numerator>[\d,]*(\.\d*))\)";
      const string matchDenominator = @"\((?<Denominator>[\d,]*(\.\d*))\)";
      const string matchBoth = matchNumerator + @"\/" + matchDenominator;

      const string txtBoxInput = @"(5.2)/(4.3)";

      
      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))
        {
          string latex = @"\frac {" + dNumerator.ToString() + "}{" + dDenominator.ToString() + "}";
          decimal valueOut = dNumerator / dDenominator;
          System.Diagnostics.Debugger.Break();
        }
      }

    }
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
 

Thanks for this code Mr.Scott.
But this code is not working and its giving error on line :

System.Diagnostics.Debugger.Break();

Also,it is for particular value i.e. @"(5.2)/(4.3)" ,but I want it to use for all type of values.
Kindly help me....:pretty:

vinnijain
Junior Poster
145 posts since Jul 2009
Reputation Points: 11
Solved Threads: 12
 

I know. I gave you one regex, you need to write the rest.

Please mark this thread as solved if you have found an answer to your question and good luck!

sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
 

I know. I gave you one regex, you need to write the rest.

Please mark this thread as solved if you have found an answer to your question and good luck!

Mr.Scott you gave me for one regex ,but that is not working ..........
So how can I proceed further.
Also,kindly give me hint for making it for all values

vinnijain
Junior Poster
145 posts since Jul 2009
Reputation Points: 11
Solved Threads: 12
 

What do you mean "all values"? The demo worked fine for me...

sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
 

Its giving error in line:

System.Diagnostics.Debugger.Break();


Since the code is for particularly for this (@"(5.2)/(4.3)") fraction value
kindly give me common hint for using it for all fraction values .
kindly resolve this error please.

vinnijain
Junior Poster
145 posts since Jul 2009
Reputation Points: 11
Solved Threads: 12
 

hi Sknake,
I am using "()/()" for fraction but its not giving equivalent fraction image ,its displaying the textbox data only........
Also I don't want it to work only for (5.2)/(4.3) but for any fractions.
Kindly tell me how make it general for all fraction values.
Help me please:icon_neutral:

vinnijain
Junior Poster
145 posts since Jul 2009
Reputation Points: 11
Solved Threads: 12
 

The code does work for any fraction. const string txtBoxInput = @"(5.2)/(4.3)"; was the simulated sample input. You can instead take the value of textbox1.Text and the code will still function.

sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You