Date: prev next · Thread: first prev next last


Hi Vivien,

If you need a starting document for testing with an already working MathML
example, I suggest to take a look at the ODF specification for Formula:
https://docs.oasis-open.org/office/OpenDocument/v1.3/os/part4-formula/OpenDocument-v1.3-os-part4-formula.odt

I took randomly a piece of MathML from the content, e.g. below from the
content.xml

        <text:p text:style-name="P2">*TBILLEQ is calculated as*</text:p>
        <text:p text:style-name="Formula">
            <draw:frame draw:style-name="fr2" draw:name="Object82"
text:anchor-type="as-char" svg:width="5.369cm" svg:height="1.016cm"
draw:z-index="122">
                *<draw:object xlink:href="./Object 231"*
xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
                <draw:image xlink:href="./ObjectReplacements/Object 231"
xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            </draw:frame>
        </text:p>

Viewed in LibreOffice as:
[image: image.png]

In the subdirectory .*/Object 231* within the ODT you will find:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE math:math PUBLIC "-//OpenOffice.org//DTD Modified W3C MathML
1.01//EN" "math.dtd">
<math:math xmlns:math="http://www.w3.org/1998/Math/MathML";>
 <math:semantics>
  <math:mrow>
   <math:mi math:fontstyle="italic">TBILLEQ</math:mi>
   <math:mo math:stretchy="false">=</math:mo>
   <math:mfrac>
    <math:mrow>
     <math:mn>365</math:mn>
     <math:mo math:stretchy="false">⋅</math:mo>
     <math:mi math:fontstyle="italic">rate</math:mi>
    </math:mrow>
    <math:mrow>
     <math:mn>360</math:mn>
     <math:mo math:stretchy="false">−</math:mo>
     <math:mrow>
      <math:mo math:stretchy="false">(</math:mo>
      <math:mrow>
       <math:mi math:fontstyle="italic">rate</math:mi>
       <math:mo math:stretchy="false">⋅</math:mo>
       <math:mi math:fontstyle="italic">DSM</math:mi>
      </math:mrow>
      <math:mo math:stretchy="false">)</math:mo>
     </math:mrow>
    </math:mrow>
   </math:mfrac>
  </math:mrow>
  <math:annotation math:encoding="StarMath 5.0">TBILLEQ = {365 cdot rate}
over {360 - (rate cdot DSM)}</math:annotation>
 </math:semantics>
</math:math>

I am afraid I do not have the time to experiment myself, but you might want
to strip down the large file into a smaller ODT, containing only one mathml
as example.
You might also want to test if the mathml from the external file is really
working within the draw:object with your ODF application.
At least <math:math> should be a valid child XML:
see
https://tdf.github.io/odftoolkit/odf1.3/OpenDocument-v1.3-reference.html#element_math:math_1
or more formal in the RelaxNG:
https://docs.oasis-open.org/office/OpenDocument/v1.3/os/schemas/OpenDocument-v1.3-schema-rng.html#5458

I am curious about your progress, please report to the list!

Good luck!
Svante

PS: Once you created your MathML in the ODF file, there is a nice HTML
transformation we are using in the ODF TC to generate our HTML documentation
<https://docs.oasis-open.org/office/OpenDocument/v1.3/os/part4-formula/OpenDocument-v1.3-os-part4-formula.html#__RefHeading__1018324_715980110>
.
See
https://github.com/oasis-tcs/odf-tc/?tab=readme-ov-file#odf2html-transformation-not-yet-automated-regression-tests





On Fri, 19 Jan 2024 at 21:09, Michael Stahl <mst@libreoffice.org> wrote:

hi Vivien,

On 17/01/2024 18:26, vivien guillet wrote:
Hello

I cannot find the correct way to add mathml to an odt document using
odftoolkit.

I create a TextPElement / DrawFrameElement / DrawObjectElement container
with the MathML element in it this way:

TextPElement p = odt.getContentRoot().newTextPElement();
DrawFrameElement drawFrame = p.newDrawFrameElement();
DrawObjectElement drawObject= drawFrame.newDrawObjectElement();
MathMathElement math = drawObjectElement.newMathMathElement();

Then the actual mathml nodes in the object

OdfElement semantics = odt.getContentDom().createElement("semantics");
math.appendChild(semantics);

and so on using standard dom operations...

When I open the resulting odt, the object is empty.

Now if I hand-edit the odt zip content.xml file to add an
xmlns="http://www.w3.org/1998/Math/MathML"; attribute to the <math:math>
tag, everything displays just fine.

creating the math element using
OdfElement math =
odt.getContentDom().createElementNS("http://www.w3.org/1998/Math/MathML
","math:math");
yields the same (non working) result

working and non-working documents are in attachements.

unfortunately the mailing list doesn't appear to allow attachments...

perhaps try to copy the "draw:object" elment out of the non-working
content.xml and send that inline, then we can have a look?

So my question is : what would be the correct way to add mathml inside a
document (with the correct mathml namespace attribute) ?

not only the math node must be in the math namespace but all of the
descendants like "semantics" too - i think that's the most likely
explanation: create every element with the namespace.

Any help would be appreciated !

V.


--
To unsubscribe e-mail to: dev+unsubscribe@odftoolkit.org
Problems?
https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.odftoolkit.org/dev/
Privacy Policy: https://www.documentfoundation.org/privacy


-- 
To unsubscribe e-mail to: dev+unsubscribe@odftoolkit.org
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.odftoolkit.org/dev/
Privacy Policy: https://www.documentfoundation.org/privacy

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.