开发者

standalone library for OpenOffice formula renderer?

Is there a standalone library of OpenOffice's formula renderer? I'm looking for something that can take plain text (e.g. E = mc^2) in the same syntax as used by OpenOffice, and convert to png or pdf fragments.

(note: I don't need the WYSIWYG editor开发者_高级运维, just the renderer. Basically I would like to work in OpenOffice to interactively edit my formulas, and then copy the source text for use in other contexts w/o needing OpenOffice to render them.)


I'm using unoconv to convert OpenOffice/LibreOffice document to PDF.

However, first I had to create some input document with a formula. Unfortunately, it is not possible to use just the formula editor to create ODF file because the output PDF file would contain weird headers and footers.

Therefore, I created a simple text document (in Writer) and embedded the formula as a single object (aligned as a character). I saved the ODT file, unzipped it (since ODT is just a ZIP) and edited the content. Then, I identified what files can be deleted and formatted the remaining files to get a minimal example.

In my example, the formula itself is located in Formula/content.xml. It should be easy to change just the code within the <annotation>...</annotation> tags in an automated way.

Finally, I zipped the directory and produced a new ODT file. Then, using unoconv and pdfcrop, I produced a nice formula as PDF.

standalone library for OpenOffice formula renderer?

# this trick prevents zip from creating an additional directory
cd formula.odt.unzipped
zip -r ../formula.odt .
cd ..

unoconv -f pdf formula.odt  # ODT to PDF
pdfcrop formula.pdf         # keep only the formula

# you can convert the PDF to bitmap as follows
convert -density 300x300 formula-crop.pdf formula.png

Content of the unzipped ODT directory:

Here is the minimal content of an ODT file formula.odt.

formula.odt.unzipped/Formula/content.xml
formula.odt.unzipped/META-INF/manifest.xml
formula.odt.unzipped/content.xml

File formula.odt.unzipped/Formula/content.xml contains:

<?xml version="1.0" encoding="UTF-8"?>
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <semantics>
    <annotation encoding="StarMath 5.0">
        f ( x ) = sum from { { i = 0 } } to { infinity } { {f^{(i)}(0)} over {i!} x^i}
    </annotation>
  </semantics>
</math>

File formula.odt.unzipped/content.xml contains:

<?xml version="1.0" encoding="UTF-8"?>
<office:document-content
    xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
    xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
    xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
    xmlns:xlink="http://www.w3.org/1999/xlink">

  <office:body>
    <office:text>
      <text:p>
        <draw:frame>
          <draw:object xlink:href="./Formula"/>
        </draw:frame>
      </text:p>
    </office:text>
  </office:body>

</office:document-content>

File formula.odt.unzipped/META-INF/manifest.xml contains:

<?xml version="1.0" encoding="UTF-8"?>
<manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" manifest:version="1.2">
 <manifest:file-entry manifest:full-path="/" manifest:version="1.2" manifest:media-type="application/vnd.oasis.opendocument.text"/>
 <manifest:file-entry manifest:full-path="content.xml" manifest:media-type="text/xml"/>
 <manifest:file-entry manifest:full-path="Formula/content.xml" manifest:media-type="text/xml"/>
 <manifest:file-entry manifest:full-path="Formula/" manifest:version="1.2" manifest:media-type="application/vnd.oasis.opendocument.formula"/>
</manifest:manifest>


There are several web services that run LaTeX for you and return an image. For instance, http://rogercortesi.com/eqn/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜