Issue 124259 - mathvariant="normal" is ignored on import of .mml file
Summary: mathvariant="normal" is ignored on import of .mml file
Alias: None
Product: Math
Classification: Application
Component: code (show other issues)
Version: 3.3.0 or older (OOo)
Hardware: All All
: P3 Normal (vote)
Target Milestone: ---
Assignee: AOO issues mailing list
QA Contact:
Depends on:
Reported: 2014-02-18 19:05 UTC by Regina Henschel
Modified: 2014-03-11 09:14 UTC (History)
4 users (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: 4.1.0-dev
Developer Difficulty: ---

File as exported by AOO but with removed annotation element (464 bytes, application/mathml+xml)
2014-02-18 19:05 UTC, Regina Henschel
no flags Details
screenshot of original document (165.91 KB, image/png)
2014-02-19 07:32 UTC, Edwin Sharp
no flags Details

Note You need to log in before you can comment on or make changes to this issue.
Description Regina Henschel 2014-02-18 19:05:20 UTC
Created attachment 82621 [details]
File as exported by AOO but with removed annotation element

Open the attached file. It will open in Math.
The formula should look like
  int {func e^x nospace{nitalic d x}}
and does so in Browser.
But AOO imports it as
  int  {e^x {d x}}

The upright orientation of 'func e' and 'nitalic d' had been correctly written as attribute mathvariant="normal" on export. But this attribute is ignored when reading the file.
Comment 1 Edwin Sharp 2014-02-19 07:27:53 UTC
Can not reproduce
Both Math and iceweasel 24.2.0 show the same
AOO410m1(Build:9750)  -  Rev. 1566800
2014-02-11_04:11:01 - Rev. 1566981
Comment 2 Edwin Sharp 2014-02-19 07:32:12 UTC
Created attachment 82625 [details]
screenshot of original document
Comment 3 Edwin Sharp 2014-02-19 07:34:38 UTC
Sorry for misunderstanding.
Comment 4 Rainer Bielefeld 2014-03-10 05:58:19 UTC
I am not familiar with correct translation of <> to ODF, but I see the result, some more characters in italic than should be (see attached screenshot comparison).

Not a new problem, already visible with OOo 3.1.1, 2.0.2, 1.1.5
Comment 5 Andre 2014-03-10 08:29:56 UTC
Maybe this is a font problem?  No math font with upright characters available? Can anybody reproduce this on Windows or Mac?
Comment 6 Regina Henschel 2014-03-10 15:12:53 UTC
No, it is not a font problem. Look into menu Font in module Math. Variables and Text are written in usual fonts, e.g. "Times New Roman", but set Variables are set in italic, whereas Text is set upright.

Please look into the command window. The characters e, d and x are identifier elements (mi) in MML and therefore correspond to the category "Variables". Therefore you see them italic. But the attribute mathvariant="normal" forces a upright setting. But this attribute of MML is ignored. The corresponding command in StarMath would be nitalic.

The translation of MML
<mi mathvariant="normal">e</mi>
to StarMath should be
nitalic e.
Comment 7 Andre 2014-03-11 08:52:16 UTC
As usual the implementation is stranger than one might think.  The relevant code part is SmXMLIdentifierContext_Impl::EndElement() in starmath/source/mathmlimport.cxx.

- The italic state is represented in an object of SmXMLContext_Helper as nIsItalic.  Its type is sal_Int8 and seems to be used as a boolean value with values -1 for true and 0 for false.

- The (not) italic flag in the MathML file seems to be ignored completely.  The nIsItalic flag is -1 (true) for all identifiers in the formula.

- There is a hard coded rule in EndElement() that looks like this:

    if (((aStyleHelper.nIsItalic == -1) && (aToken.aText.Len() > 1))
        || ((aStyleHelper.nIsItalic == 0) && (aToken.aText.Len() == 1)))
        pNode = new SmTextNode(aToken,FNT_FUNCTION);
        aStyleHelper.nIsItalic = -1;
        pNode = new SmTextNode(aToken,FNT_VARIABLE);

The typographical rule is not unusual (multiletter names (like function names) upright, single letter names (like variable names) italic).  It is just the wrong place to enforce it.

That means that the single letter variables, function names and operators in the bug doc are forced to italic because 
a) the flag for using upright font for 'e' and 'd' is ignored when the XML text is read and
b) it is ignored also when text node for the internal formula representation is created.

I made an experiment by changing the names in the bug doc from 'e' to 'ee' and 'd' to 'dd' and they are displayed upright.
Comment 8 Andre 2014-03-11 09:14:04 UTC
Ah, I found the reason why the mathvariant="normal" is ignored on input: It is a construct from MathML 2, while AOO only supports MathML 1.1.  MathML 1.1 has only the 'fontstyle' attribute, which is deprecated in MathML 2.

So, changing the tag
  <mi mathvariant="normal">
  <mi fontstyle="normal">
would make the importer correctly set the nIsItalic flag.  But only to be ignored in SmXMLIdentifierContext_Impl::EndElement() because the text it applies to is only one character long.

A possible fix for this bug could look like this:

- Fix the bug doc to conform to MathML 1.1

- Remove the rule from EndElement() that ignores the MathML instructions in certain cases.