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. :)

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 :)

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

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.

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......

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/

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...

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

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.....

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

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:

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();
        }
      }

    }

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:

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!

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

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

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.

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:

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.

Thanks Mr. Scott.
I have already done this. But,problem is that it is not displaying it as the fraction , its interpreting it as values in brackets.
The application is attached here with modifications.
Kindly help me regarding this................

vinnijan,

You really need to try to figure this out. The code works but you implemented it incorrectly. You're not even trying to learn what the code does but rather seeing the code does not fit your solution as-is then posting back here with another question.

Make this change:

//const string txtBoxInput = @"()/()";
           string txtBoxInput = textBoxEquation.Text;

here I have attested the thumbnail of my output , in which its showing bracket and not the fraction form which we see in books.
Actually when I am entering bracket format in textbox which is user friendly but in math format output I want the fraction form which we see in books.
In textbox I want bracket only but in math format I want it in actual fraction like in books.
Kindly give me some solution..........

Vinnijain,

Here at Daniweb we have a policy of helping those who help themselves.
sknake has now given you all the code you need to take the input fromthe textbox and convert it to a latex format string:

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 = textBoxEquation.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;
          System.Diagnostics.Debugger.Break();
        }

Learning to code involves experimenting with new concepts. You have been shown everything you need to do to solve your problem, now you need to examine the code you have been given, work out what it is doing and apply that to your solution.
We are happy to help, but the only way your coding will move forward is if you take the time to understand each aspect of the project :)

Hi Ryshad,
I understood the code.
As I am new to C#.NET , thats why I need your guidance to learn more new concepts.
I just need hint to proceed further..........

Im not sure i understand what you need a hint with?
I made the changes that sknake gave you and put it all together into the code in my last post. That code will take the text from the textbox, locate "(number1)/(number2)" and convert it into "\frac {number1}{number2}" stored in the variable called latex.

Isnt that what your question required?

Ryshad,
The code which I am using is as follows:

textBoxEquation.AppendText("()/()");
            this.textBoxEquation.Focus();


            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 = textBoxEquation.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;
                    System.Diagnostics.Debugger.Break();

                }

            }

Since I have made for all mathematical symbols and the mathematical equation can be the combination of any symbol.So when we click on any of the math symbol ,it is appended in the textbox.So,when i am using :

string txtBoxInput = textBoxEquation.Text;

It means complete textbox string is assigned to txtBoxInput.
So how can I get fraction value for this "()/()" when its being used with other math symbols too..........
If I would be inserting only "()/()" in textbox it will generate equivalent fraction but not when its being used with other symbols too.........
I want the output as seen in the attached thumbnail
i think you understand what I am trying to say..........

If im not mistaken you are placing that code inside the event handler for the "÷" button. You only need to parse the data using this code when you update the equation image.

The code you have been given will match a single instance of ()/() in the string and convert it. You need to modify it to find multiple instances. You will also need to modify the Regular Expressions to match other kinds of symbols. The links i gave you originally will have all the info you need on writing your own regular expressions.

If im not mistaken you are placing that code inside the event handler for the "÷" button. You only need to parse the data using this code when you update the equation image.

The code you have been given will match a single instance of ()/() in the string and convert it. You need to modify it to find multiple instances. You will also need to modify the Regular Expressions to match other kinds of symbols. The links i gave you originally will have all the info you need on writing your own regular expressions.

The code for the event handler for the "÷" button is:

private void button3_Click(object sender, EventArgs e)
        {
            textBoxEquation.AppendText("÷");
            this.textBoxEquation.Focus();
        }

private void textBoxEquation_TextChanged(object sender, System.EventArgs e)
		{
			WriteEquation(FormatText(textBoxEquation.Text));
		}
        
        private string FormatText(string input)
         {
            input = input.Replace("÷", "\\div");
            input = input.Replace("π", "\\pi");
            input = input.Replace("θ", "\\theta");
            input = input.Replace("∞", "\\infty");
              return input;
         }

Also I want to ask you that when you executed the code ,you were getting the equivalent fraction the values in bracket format?Because I was not getting fraction format as in thumbnail.

I think nobody on daniweb is able to solve my problem.........
Was It so difficult ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.