Page 1 of 1

Need to handle Latex Equation :

PostPosted: Tue Mar 30, 2010 5:37 pm
by AnbuChezhian
Hi Jason ,
I need to convert docx containing Latex Equation to image .It seems docx4j does not handled latex equations at all . Can you suggest me some third parties that support these conversions ?
Thanks in advance.

Regards,
Anbu Chezhian.S

Re: Need to handle Latex Equation :

PostPosted: Tue Mar 30, 2010 9:06 pm
by jason
Do you mean using http://svadali.com/blog/2008/10/28/equa ... ing-latex/
which produces something like:

Code: Select all
<w:p>
    <w:pPr>
        <w:rPr>
            <w:rFonts w:eastAsiaTheme="minorEastAsia"/>
        </w:rPr>
    </w:pPr>
    <m:oMathPara>
        <m:oMath>
            <m:nary>
                <m:naryPr>
                    <m:ctrlPr>
                        <w:rPr>
                            <w:rFonts w:ascii="Cambria Math" w:hAnsi="Cambria Math"/>
                            <w:i/>
                        </w:rPr>
                    </m:ctrlPr>
                </m:naryPr>
                <m:sub>
                    <m:r>
                        <w:rPr>
                            <w:rFonts w:ascii="Cambria Math" w:hAnsi="Cambria Math"/>
                        </w:rPr>
                        <m:t>-∞</m:t>
                    </m:r>
                </m:sub>
                <m:sup>
                    <m:r>
                        <w:rPr>
                            <w:rFonts w:ascii="Cambria Math" w:hAnsi="Cambria Math"/>
                        </w:rPr>
                        <m:t>∞</m:t>
                    </m:r>
                </m:sup>
                <m:e>
                    <m:r>
                        <w:rPr>
                            <w:rFonts w:ascii="Cambria Math" w:hAnsi="Cambria Math"/>
                        </w:rPr>
                        <m:t>f</m:t>
                    </m:r>
                    <m:d>
                        <m:dPr>
                            <m:ctrlPr>
                                <w:rPr>
                                    <w:rFonts w:ascii="Cambria Math" w:hAnsi="Cambria Math"/>
                                    <w:i/>
                                </w:rPr>
                            </m:ctrlPr>
                        </m:dPr>
                        <m:e>
                            <m:r>
                                <w:rPr>
                                    <w:rFonts w:ascii="Cambria Math" w:hAnsi="Cambria Math"/>
                                </w:rPr>
                                <m:t>x</m:t>
                            </m:r>
                        </m:e>
                    </m:d>
                    <m:r>
                        <w:rPr>
                            <w:rFonts w:ascii="Cambria Math" w:hAnsi="Cambria Math"/>
                        </w:rPr>
                        <m:t>dx=1</m:t>
                    </m:r>
                </m:e>
            </m:nary>
        </m:oMath>
    </m:oMathPara>
</w:p>


Have a look at http://blogs.msdn.com/murrays/archive/2 ... 900_-.aspx

Office 2007 includes xslt to convert this stuff (omml) to MathML (Google for omml2mml.xsl and mml2omml.xsl). See http://blogs.msdn.com/murrays/archive/2 ... -2007.aspx

So I think you are looking at OMML -> MathML -> SVG -> PNG. There are different choices available for the MathML to SVG step, including http://jeuclid.sourceforge.net/

See generally http://www.w3.org/Math/Software/mathml_ ... rters.html

Please report back on how you go!

cheers .. Jason

Re: Need to handle Latex Equation :

PostPosted: Fri Apr 09, 2010 7:42 pm
by AnbuChezhian
Hi Jason ,
I already tried the one you specified (http://jeuclid.sourceforge.net/ ) , but i could not complete it :(

here is my code :

public String processEquation(String dirName,Node mathNode)
{

mmlString="";
++imageName;
File fileDir=new File(dirName);
if(!fileDir.exists())
{
fileDir.mkdirs();
}

String imgFile=fileDir.getAbsolutePath()+File.separator+"eqn"+imageName+".png";
String mmlFile=fileDir.getAbsolutePath()+File.separator+"eqn"+imageName+".mml";

File imgF = new File(imgFile);

try {

Transformer transformer = tFactory.newTransformer(new javax.xml.transform.stream.StreamSource("home/anbu/omml2mml.xsl"));

DOMSource ds=new DOMSource(mathNode);
StringWriter writer = new StringWriter();
StreamResult sr = new StreamResult(writer);

transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
//convert ooml to mathml
transformer.transform(ds,sr);

mmlString=writer.toString();

mml2PNG(mmlFile,mmlString,imgFile);


} catch (Exception e)
{
e.printStackTrace( );
}

return imgF.getName();
}


public void mml2PNG(String mmlFile, String mml,String imgFile)
{
try
{
System.out.println("MathProperty :"+mathPropHash);
formFileFromArray(mml.getBytes("UTF-16"),mmlFile);
//calling jeuclid here.
ArrayList<String> argList=new ArrayList<String>();

argList.add(mmlFile);
argList.add(imgFile);
argList.add("-backgroundColor");
if(mathPropHash.containsKey("backgroundColor"))
{
String colorHash=getColorHash((String)mathPropHash.get("backgroundColor"));
argList.add(colorHash);
}
else
{
argList.add("#FF00FF");
}
argList.add("-foregroundColor");
if(mathPropHash.containsKey("foregroundColor"))
{
String colorHash=getColorHash((String)mathPropHash.get("foregroundColor"));
argList.add(colorHash);
}
else
{
argList.add("#AA00BB");
}
argList.add("-antiAliasMinSize");
argList.add("1");
argList.add("-fontSize");
if(mathPropHash.containsKey("fontSize"))
{
argList.add((String)mathPropHash.get("fontSize"));
}
else
{
argList.add("50");
}

System.out.println("List:::::::::::"+argList);

String[] args=(String[])argList.toArray(new String[argList.size()]);

//System.out.println(Arrays.asList(args));

net.sourceforge.jeuclid.app.Mml2xxx.main(args);
}
catch (Exception ex)
{
ex.printStackTrace();
}

}

just take "omml2mml.xsl" from this link "http://www.tei-c.org/release/xml/tei/stylesheet/docx/utils/maths/omml2mml.xsl" . Hope this link will help us :) .

while executin am getting this error :

Error encountered during converion process
java.io.IOException: Bad file descriptor
at java.io.FileInputStream.read(Native Method)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager$RewindableInputStream.read(XMLEntityManager.java:2622)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:997)
at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:184)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:798)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:250)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:292)
at net.sourceforge.jeuclid.parser.Parser.parseStreamSourceAsXml(Parser.java:318)
at net.sourceforge.jeuclid.parser.Parser.parseStreamSource(Parser.java:249)
at net.sourceforge.jeuclid.MathMLParserSupport.parseFile(MathMLParserSupport.java:123)
at net.sourceforge.jeuclid.converter.Converter.convert(Converter.java:141)
at net.sourceforge.jeuclid.app.Mml2xxx.main(Mml2xxx.java:130)
at com.zohocorp.zwimport.converter.OOML2MML.mml2PNG(OOML2MML.java:179)
at com.zohocorp.zwimport.converter.OOML2MML.processEquation(OOML2MML.java:93)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) .....

Can we able to fix this problem ?

Regards,
AnbuChezhian.S

Re: Need to handle Latex Equation :

PostPosted: Sat Apr 10, 2010 1:07 am
by jason
Looks like you need to handle entity resolution. http://xml.apache.org/commons/component ... ticle.html might help.

What does the mml you are feeding to jeuclid look like?

Re: Need to handle Latex Equation :

PostPosted: Sat Apr 17, 2010 5:32 pm
by AnbuChezhian
Hi Jason ,
Please see my attached xsl and follow the above process. It is working well now.Hope it will help you too and do reply if its works .

Regards,
Anbu Chezhian.S

Re: Need to handle Latex Equation :

PostPosted: Wed Apr 21, 2010 11:49 pm
by jason
Thanks for posting Anbu

Re: Need to handle Latex Equation :

PostPosted: Thu Nov 16, 2017 1:06 am
by nitinchopkar2
I checked above sample code for MathMl to svg conversion but found that some of function call there but there declaration is not present.

Can you help me how to do.