Permission to commit Latex equation editor?

From: <msevior_at_physics.unimelb.edu.au>
Date: Sun Mar 06 2005 - 23:48:16 CET

Hi Everyone,
            As I mentioned recently, I've been working towards using the
itex2MML program to allow users to insert and edit Mathmatical
expression written in Latex into AbiWord.

I'm happy to report that this works very well. See the screenshot:

http://www.ph.unimelb.edu.au/~msevior/abiword/LatexMathSS1.png

The biggest problem is that GtkMathView is very fragile and lacks support
for many valid MathML entities right.

The webpage for itex2MML is here:

http://pear.math.pitt.edu/mathzilla/itex2mml.html

itex2MML is a very small command-line program written is straight C. It
uses lex and yacc to obtain it's expressive power. It reads latex (well
rather it's near equivalent itex) on stdin and produces MathML on stdout.

If the supplied Latex formula is not valid it complains with an error
messge instead of MathML.

On the AbiWord side I've written a little modeless dialog that allows
users to type in Latex and insert it into the document. After inserting
the MathML remains selected so users can alter their expression in the
dialog and overwrite the Mathematical expression in the document. Since
the original Latex is inserted as associated data-item along with the
MathML, I plan to use the dialog to allow users to edit their maths.

The plan is to invoke the dialog and fill it with latex upon a user
selecting an equations and either

a) selecting "Edit Math" from the main menu
b) right click and select "Edit Math" from a context menu.
c) Double clicking the formula

This would be a really powerful way for *me* to enter maths into a
document that I would choose over a graphical equation editor every time.

Right now the API for AP_Dialog_Latex.h is this:

class AP_Dialog_Latex : public XAP_Dialog_Modeless
{
public:
        AP_Dialog_Latex(XAP_DialogFactory * pDlgFactory, XAP_Dialog_Id id);
        virtual ~AP_Dialog_Latex(void);

        typedef enum { a_OK, a_CANCEL } tAnswer;

        AP_Dialog_Latex::tAnswer getAnswer(void) const;
        virtual void convertLatexToMathML(void) =0;
        void setLatex(UT_UTF8String & sLatex)
          { m_sLatex = sLatex;}
        void fillLatex(UT_UTF8String & sLatex);
        virtual void setLatexInGUI(void) = 0;
        void getLatex(UT_UTF8String & sLatex)
        { sLatex = m_sLatex;}
        void setMathML(UT_UTF8String & sMathML)
          { m_sMathML = sMathML;}
        void insertIntoDoc(void);
        void ConstructWindowName(void);
        void setActiveFrame(XAP_Frame *pFrame);
protected:

        AP_Dialog_Latex::tAnswer m_answer;
        UT_UTF8String m_sWindowName;
private:
        UT_UTF8String m_sLatex;
        UT_UTF8String m_sMathML;
}

The crucial "convertLatexToMathML(void)" is a pure abstract class which
needs to implemented on each platform.

For unix I "popen" the executable program itex2MML which needs to be in my
search path like this:

 setLatex(sLatex);
  UT_UTF8String sCommand;
  sCommand = "itex2MML <<FREDDDYYYY\n";
  sCommand += sLatex;
  sCommand += "\n";
  sCommand += "FREDDDYYYY\n";
  fflush(stdin);
  FILE * psRes = popen(sCommand.utf8_str(),"r");
  if(psRes == NULL)
  {
    UT_DEBUGMSG(("itex2MML not found \n"));
    UT_ASSERT(UT_SHOULD_NOT_HAPPEN);
    return;
  }
  char FullLine[1003];
  UT_uint32 numRead = 1000;
  while(numRead == 1000)
  {
    numRead = fread(&FullLine,1,1000,psRes);
    FullLine[numRead] =0;
    sMathML += FullLine;
  }
  UT_DEBUGMSG(("MathML is %s \n",sMathML.utf8_str()));
  pclose(psRes);

So for this code to work we need to have itex2MML installed on a user
system but it does not need to be linked into AbiWord. This of course
introduces a run-time dependency but not a compile time dependency. Unix,
Windows and OSX can be built and run without itex2MML. It would only be
invoked if the abimathview plugin is present.

This code needs a fair bit more rounding out. I have to do error message
checking and pop-up warnings with useful feedback for invalid Latex and if
itex2MML is not present.

I would like to commit this code now and work out how to ship itex2MML later.

What do others think?

Cheers

Martin
Received on Sun Mar 6 23:49:26 2005

This archive was generated by hypermail 2.1.8 : Sun Mar 06 2005 - 23:49:26 CET