Last Comment Bug 154931 - Make MathML handle the <semantics> tag implicitly
: Make MathML handle the <semantics> tag implicitly
Status: RESOLVED FIXED
:
Product: Core
Classification: Components
Component: MathML (show other bugs)
: Trunk
: All All
: -- normal (vote)
: mozilla1.3final
Assigned To: rbs
: Hixie (not reading bugmail)
Mentors:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2002-06-28 19:58 PDT by Jason Harris
Modified: 2011-08-05 22:43 PDT (History)
3 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
testcase (811 bytes, application/xhtml+xml)
2002-06-28 20:01 PDT, Jason Harris
no flags Details
extended testcase (1.11 KB, application/xhtml+xml)
2003-02-04 13:38 PST, rbs
no flags Details
stop-gap patch (1.08 KB, patch)
2003-02-04 14:30 PST, rbs
dbaron: review+
roc: superreview+
asa: approval1.3b-
asa: approval1.3+
Details | Diff | Splinter Review

Description Jason Harris 2002-06-28 19:58:31 PDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.1a+) Gecko/20020628
BuildID:    2002062808

The two main generators of MathML generate MathML with both presentation and
content. Unfortunately due to XSLT issues it is not always viable to use style
sheets to transform the content away.

Thus, it is vital for the support of MathML in Mozilla that Mozilla handles the
content tags implicitly. A good stopgap measure might be just to ignore all
other annotations besides the primary child. This would make Mozilla work with
both Mathematica and Maple since by default both of these MathML generators put
presentation first.

Indeed the majority of users who perform computations with MathML highly desire
the ability to have both presentation and content mathml in the same mathML
fragment. 

Here is an example of a simple MathML fragment which is causing problems:

<math xmlns='http://www.w3.org/1998/Math/MathML'>
 <semantics>
  <mrow>
   <msup>
    <mi>x</mi>
    <mn>2</mn>
   </msup>
   <mo>+</mo>
   <mi>y</mi>
  </mrow>
  <annotation-xml encoding='MathML-Content'>
   <apply>
    <plus/>
    <apply>
     <power/>
     <ci>x</ci>
     <cn type='integer'>2</cn>
    </apply>
    <ci>y</ci>
   </apply>
  </annotation-xml>
 </semantics>
</math>

Reproducible: Always
Steps to Reproduce:
1.Create a text file containing the above MathML
2.Open the text file in Mozilla

Actual Results:  You will see the presentation renders correctly, but it will be
followed by garbage semantics.

Expected Results:  You should see the presentation renders correctly, but the
semantics should not appear at all.
Comment 1 Jason Harris 2002-06-28 20:01:17 PDT
Created attachment 89658 [details]
testcase
Comment 2 rbs 2002-06-28 20:30:52 PDT
I am sending this comment from a public booth at the Interntaional MathML 
Conference in Chicago where Mathematica & Maple folks have been hammering me 
with this issue. A stop-gap fix is simply to add the following style rule in 
mathml.css:

annotation-xml[encoding='MathML-Content'] { 
  display: none;
}

roc/waterson/asa, care to r/sr/a, thanks.

hixie, would be so kind to checkin the fix too, if approved? As you might 
imagine, I don't have all the setup to pursue the fix in the proper channels 
from this end, but I am hoping that the one-liner can still make it before the 
final build for Netscape 7.0 is pulled -- which is really why Wolfram & Maple 
have been hammering me with the issue here.
Comment 3 David Baron :dbaron: ⌚️UTC-7 (review requests must explain patch) 2002-06-29 13:31:51 PDT
That style rule should really be in a namespace.  Otherwise it could slow things
down.  What namespace should it be in?
Comment 4 Hixie (not reading bugmail) 2002-06-29 15:41:52 PDT
mathml.css has a default namespace declared
Comment 5 Hixie (not reading bugmail) 2002-06-29 16:00:31 PDT
erm, i was about to make a patch for this, when i found that attachment 89658 [details]
already works fine. I can't see why. The annotation-xml node is display:none but
there are no corresponding rules.

In principle, r=hixie, but I think something odd may be going on here.
Comment 6 Hixie (not reading bugmail) 2002-06-29 16:05:46 PDT
Oh, I think actually that may just have been a bug in the DOM inspector. I think
I changed the mathml.css file before loading any MathML content, and since the
exported mathml.css file is just a symlink to the one I was editing, it took
effect. Or something.

Anyway, r=hixie on rbs' patch:

Index: mathml.css
===================================================================
RCS file: /cvsroot/mozilla/layout/mathml/content/src/mathml.css,v
retrieving revision 1.14
diff -u -r1.14 mathml.css
--- mathml.css	27 Feb 2002 01:35:24 -0000	1.14
+++ mathml.css	29 Jun 2002 22:57:23 -0000
@@ -407,3 +407,10 @@
 }
 :-moz-math-font-style-anonymous {
 }
+
+/**********************************************************************/
+/* Hide embedded semantic MathML content (as opposed to presentational
+   content, which we render). */
+annotation-xml[encoding="MathML-Content"] { 
+  display: none;
+}
Comment 7 David Baron :dbaron: ⌚️UTC-7 (review requests must explain patch) 2002-06-29 16:32:32 PDT
r=dbaron too, then.
Comment 8 Robert O'Callahan (:roc) (Exited; email my personal email if necessary) 2002-06-30 18:40:04 PDT
sr=roc+moz
Comment 9 Hixie (not reading bugmail) 2002-07-01 03:03:03 PDT
checked in to trunk
Comment 10 Judson Valeski 2002-07-10 09:05:17 PDT
please checkin to the 1.0.1 branch. once there, remove the "mozilla1.0.1+"
keyword and add the "fixed1.0.1" keyword.
Comment 11 rbs 2002-07-10 16:11:33 PDT
checked in to branch - marking fixed1.0.1
Comment 12 rbs 2003-02-03 23:46:20 PST
re-opening due to the following comment:
http://groups.google.com/groups?selm=200302031132.LAA06605%40penguin.nag.co.uk

From: David Carlisle (davidc@nag.co.uk)
Subject: rendering of semantics elements in mozilla.
Newsgroups: netscape.public.mozilla.mathml
Date: 2003-02-03 03:55:20 PST

As Mozilla doesn't render Content MathML it would be nice to be able
to combine Content expressions together with Presentation MathML
(and other things) in a semantics element, and have mozilla ignore
everything except the presentation mathml.

In addition to Content mathml, editors and computer algebra systems
often use the semantics element to annotate an expression with
processor-specific information (which is the intended use of this
element). All a browser has to do is ignore the annotations.

there was/is a bugzilla report for this which is marked as fixed

http://bugzilla.mozilla.org/show_bug.cgi?id=154931


however the css rule added at that time appears to be:

/**********************************************************************/
/* Hide embedded semantic MathML content (as opposed to presentational
   content, which we render). */
annotation-xml[encoding="MathML-Content"] { 
  display: none;
}


This leaves non xml annotation elements being rendered (these typically
contain maple or mathematica encodings of the expression)

Also it renders all annotation-xml except content-mathml (for example
the openmath as used examples in chapter 5 of the spec).

The simplest css based rendering rules would be

annotation{  display: none; }
annotation-xml{  display: none; }

ie don't render any annotation at all (and so just render the first child of
the semantics element)

A more complete rule would be:

if there is an <annotation-XML encoding="MathML-presentation">
  render that annotation, and ignore the first child of the semantics
  element and all other annotations, 
else
  render the first child of semantics and ignore all annotations


I don't think you can express this rule purely in css though.
The simpler rule of just ignoring all annotations is still conformant
with the specification and would cover most existing cases that are
causing problems. (The XSLT stylesheet for MathML implements the more
complete rule, as well as doing content-presentation transformation, for
cases when the full functionality is needed).




For example, asking maple to output the expression  cos x as mathml
produces

<math xmlns='http://www.w3.org/1998/Math/MathML'>
<semantics>
 <mrow xref='id3'>
   <mi xref='id1'>cos</mi>
   <mo>&ApplyFunction;</mo>
   <mfenced><mi xref='id2'>x</mi></mfenced>
 </mrow>
 <annotation-xml encoding='MathML-Content'>
  <apply id='id3'><cos id='id1'/><ci id='id2'>x</ci></apply>
 </annotation-xml>
 <annotation encoding='Maple'>
  cos(x)
 </annotation>
</semantics>
</math>


which renders as cos(x)cos(x) in mozilla 1.1 (which I suppose is a bit
old, but I believe newer mozilla are the same?)


David
Comment 13 Jason Harris 2003-02-04 02:57:54 PST
David is right here. It would be nice to have this additional intelligence from the MathML renderer for Mozilla.

In Mathematica by default the first annotation of a semantics element is presentation MathML. (However the user can of course override this.) From David's example and from my vague memory of talking to the Maple folks at MathML2002 I guess the same default is true for Maple.

But, I would expect that Maple has the ability to control which annotations are included in the MathML. (Certainly, Mathematica has a very easy way to control this.) Thus just trying to render the first element of the semantics element should just be a stop gap measure until better handling is implemented for annotations in Mozilla
Comment 14 rbs 2003-02-04 13:25:28 PST
Using Opera? I was bitten once... Resending with a more capable browser that
knows how to wrap :-)

------- Additional Comment #13 From Jason Harris  2003-02-04 02:57 -------

David is right here. It would be nice to have this additional intelligence from
the MathML renderer for Mozilla.

In Mathematica by default the first annotation of a semantics element is
presentation MathML. (However the user can of course override this.) From
David's example and from my vague memory of talking to the Maple folks at
MathML2002 I guess the same default is true for Maple.

But, I would expect that Maple has the ability to control which annotations are
included in the MathML. (Certainly, Mathematica has a very easy way to control
this.) Thus just trying to render the first element of the semantics element
should just be a stop gap measure until better handling is implemented for
annotations in Mozilla
Comment 15 rbs 2003-02-04 13:38:37 PST
Created attachment 113525 [details]
extended testcase
Comment 16 rbs 2003-02-04 13:46:23 PST
So, the ideal is:

if there is an <annotation-XML encoding="MathML-presentation">
  render that annotation, and ignore the first child of the semantics
  element and all other annotations, 
else
  render the first child of semantics and ignore all annotations


I applied the patch on bug 135141 thinking that it might help. But there doesn't
seem a way to get the desired effect -- or my CSS is a bit rusty to get there...

As a stop-gap, we can either have:
annotation { display: none; }
annotation-xml { display: none; }

or as suggested, just render the first child:

semantics > :not(:first-child) { display: none; }
Comment 17 rbs 2003-02-04 14:30:45 PST
Created attachment 113534 [details] [diff] [review]
stop-gap patch
Comment 18 rbs 2003-02-04 14:33:50 PST
Comment on attachment 113534 [details] [diff] [review]
stop-gap patch

re-requesting r/sr
Comment 19 rbs 2003-02-04 14:59:42 PST
The reason why the patch on bug 135141 didn't help is because 'adjacent' (CSS
operator '~') is interpred as 'preceded by'. Since :first-child is preceded by
nothing, there was no way to conditionally select it. If 'adjacent' really meant
what its name suggests, CSS could have done the trick:

semantics > :not(:first-child) {
  display: none;
}
semantics > annotation-xml[encoding="MathML-Presentation"] {
  display: inline;
}
annotation-xml[encoding="MathML-Presentation"] ~ semantics:first-child {
  display: none;
}
Comment 20 rbs 2003-02-04 15:03:47 PST
Oops, s/ semantics:first-child / semantics > :first-child /
With that correction, not sure if the CSS is still valid though.
Comment 21 Hixie (not reading bugmail) 2003-02-04 16:18:26 PST
Yeah, CSS can't do what you're describing. Should be quite easy to do at the C++
level though...
Comment 22 rbs 2003-02-04 16:35:53 PST
Would have been nice if '~' means 'sibling'.
Comment 23 rbs 2003-02-04 16:39:36 PST
Or rather if there was a 'sibling' operator, rather than just the 'preceded by'
operator.
Comment 24 Hixie (not reading bugmail) 2003-02-06 04:06:10 PST
I've proposed :matches(), which is a superset of that, several times. It's very
well defined, but has so far been rejected because it would be a MASSIVE
performance hit.
Comment 25 rbs 2003-02-09 01:27:09 PST
Comment on attachment 113534 [details] [diff] [review]
stop-gap patch

Seeking a= on this simple patch to apply some CSS rules to the <semantics> tag
so that a certain behavior is emulated.
Comment 26 Asa Dotzler [:asa] 2003-02-09 19:02:49 PST
Comment on attachment 113534 [details] [diff] [review]
stop-gap patch

This is going to have to wait 'till we open for final. I think we've got what
we need for beta and until we get the beta released we can't take further
non-critical changes.
Comment 27 rbs 2003-02-10 15:08:34 PST
>I've proposed :matches(), which is a superset of that, several times. It's very
>well defined, but has so far been rejected because it would be a MASSIVE
>performance hit.

Got a reference? I am not that thrilled to add some special C++ for this
<semantics>. Maybe a :-moz-matches() can be of wide use, here and elsewhere? XBL
isn't particularly fast, yet it avoids repetition, thereby cutting the bloat.
Comment 28 rbs 2003-02-10 20:56:35 PST
Comment on attachment 113534 [details] [diff] [review]
stop-gap patch

per asa's comment 26, migrating request for a=1.3final.
Comment 29 Asa Dotzler [:asa] 2003-02-11 12:27:15 PST
Comment on attachment 113534 [details] [diff] [review]
stop-gap patch

a=asa (on behalf of drivers) for checkin to 1.3 final.
Comment 30 rbs 2003-02-11 15:27:29 PST
Checked in mozilla1.3 final.

Note You need to log in before you can comment on or make changes to this bug.