]> git.lyx.org Git - features.git/commitdiff
Fix XHTML output for fractions and fix a crash reported on the list
authorRichard Heck <rgheck@comcast.net>
Thu, 12 May 2011 13:16:36 +0000 (13:16 +0000)
committerRichard Heck <rgheck@comcast.net>
Thu, 12 May 2011 13:16:36 +0000 (13:16 +0000)
by Jan Paul Imhoff. The problem was that we were assuming (as we still
do in some places) that there are always at least two cells.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@38717 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/InsetMathFrac.cpp

index 752dd54bea51d3583dce802437256697012bec37..90937619bf2a8d46f93710a20db708bc9f84ea17 100644 (file)
@@ -366,18 +366,21 @@ bool InsetMathFrac::extraBraces() const
 }
 
 
+// FIXME This will crash on unitone and is wrong in other cases.
 void InsetMathFrac::maple(MapleStream & os) const
 {
        os << '(' << cell(0) << ")/(" << cell(1) << ')';
 }
 
 
+// FIXME This will crash on unitone and is wrong in other cases.
 void InsetMathFrac::mathematica(MathematicaStream & os) const
 {
        os << '(' << cell(0) << ")/(" << cell(1) << ')';
 }
 
 
+// FIXME This will crash on unitone and is wrong in other cases.
 void InsetMathFrac::octave(OctaveStream & os) const
 {
        os << '(' << cell(0) << ")/(" << cell(1) << ')';
@@ -386,19 +389,107 @@ void InsetMathFrac::octave(OctaveStream & os) const
 
 void InsetMathFrac::mathmlize(MathStream & os) const
 {
-       os << MTag("mfrac")
-          << MTag("mrow") << cell(0) << ETag("mrow")
-                << MTag("mrow") << cell(1) << ETag("mrow")
-                << ETag("mfrac");
+       switch (kind_) {
+       case ATOP:
+               os << MTag("mfrac", "linethickeness='0'")
+                  << MTag("mrow") << cell(0) << ETag("mrow")
+                        << MTag("mrow") << cell(1) << ETag("mrow")
+                        << ETag("mfrac");
+               break;
+
+       // we do not presently distinguish these
+       case OVER:
+       case FRAC:
+       case DFRAC:
+       case TFRAC:
+       case CFRAC:
+       case CFRACLEFT:
+       case CFRACRIGHT:
+               os << MTag("mfrac")
+                  << MTag("mrow") << cell(0) << ETag("mrow")
+                        << MTag("mrow") << cell(1) << ETag("mrow")
+                        << ETag("mfrac");
+               break;
+
+       case NICEFRAC:
+               os << MTag("mfrac", "bevelled='true'")
+                  << MTag("mrow") << cell(0) << ETag("mrow")
+                        << MTag("mrow") << cell(1) << ETag("mrow")
+                        << ETag("mfrac");
+               break;
+
+       case UNITFRAC:
+               if (nargs() == 3)
+                       os << cell(2);
+               os << MTag("mfrac", "bevelled='true'")
+                  << MTag("mrow") << cell(0) << ETag("mrow")
+                        << MTag("mrow") << cell(1) << ETag("mrow")
+                        << ETag("mfrac");
+               break;
+
+       case UNIT:
+               // FIXME This is not right, because we still output mi, etc,
+               // when we output the cell. So we need to prevent that somehow.
+               if (nargs() == 2)
+                       os << cell(0) 
+                          << MTag("mstyle mathvariant='normal'") 
+                          << cell(1) 
+                          << ETag("mstyle");
+               else
+                       os << MTag("mstyle mathvariant='normal'") 
+                          << cell(0)
+                          << ETag("mstyle");
+       }
 }
 
 
 void InsetMathFrac::htmlize(HtmlStream & os) const
 {
-       os << MTag("span", "class='frac'")
-                << MTag("span", "class='numer'") << cell(0) << ETag("span")
-                << MTag("span", "class='denom'") << cell(1) << ETag("span")
-                << ETag("span");
+       switch (kind_) {
+       case ATOP:
+               os << MTag("span", "class='frac'")
+                        << MTag("span", "class='numer'") << cell(0) << ETag("span")
+                        << MTag("span", "class='numer'") << cell(1) << ETag("span")
+                        << ETag("span");
+               break;
+
+       // we do not presently distinguish these
+       case OVER:
+       case FRAC:
+       case DFRAC:
+       case TFRAC:
+       case CFRAC:
+       case CFRACLEFT:
+       case CFRACRIGHT:
+               os << MTag("span", "class='frac'")
+                        << MTag("span", "class='numer'") << cell(0) << ETag("span")
+                        << MTag("span", "class='denom'") << cell(1) << ETag("span")
+                        << ETag("span");
+               break;
+
+       case NICEFRAC:
+               os << cell(0) << '/' << cell(1);
+               break;
+
+       case UNITFRAC:
+               if (nargs() == 3)
+                       os << cell(2) << ' ';
+               os << cell(0) << '/' << cell(1);
+               break;
+
+       case UNIT:
+               // FIXME This is not right, because we still output i, etc,
+               // when we output the cell. So we need to prevent that somehow.
+               if (nargs() == 2)
+                       os << cell(0) 
+                          << MTag("span") 
+                          << cell(1) 
+                          << ETag("span");
+               else
+                       os << MTag("span") 
+                          << cell(0)
+                          << ETag("span");
+       }
 }