Am Sonntag, 16. Juli 2006 19:18 schrieb Georg Baum:
> This patch fixes bug 2481 and goes in now since it is obviously correct.

Martin reminded me that I forgot \over. This is a bit special, since 
{1\over 2} is equivalent to \frac{1}{2}, and LyX does therefore not 
distinguish is from \frac once it is read in.
This patch changes that so that the normalization is not done in 
createMathInset, but when a \over inset is written.
This goes in tomorrow if nobody objects.


Georg
Log:
Fix read in of \over (related to bug 2481)
        * src/mathed/math_factory.C
        (createMathInset): Create a MathFracInset of kind OVER for \over

        * src/mathed/math_fracinset.C
        (MathFracInset::draw): handle kind OVER
        (MathFracInset::drawT): ditto
        (MathFracInset::write): ditto
        (MathFracInset::name): ditto
        (MathFracInset::extraBraces): ditto

        * src/mathed/math_fracinset.h
        (Kind): New kind OVER
Index: src/mathed/math_factory.C
===================================================================
--- src/mathed/math_factory.C	(Revision 14475)
+++ src/mathed/math_factory.C	(Arbeitskopie)
@@ -320,8 +320,10 @@ MathAtom createMathInset(string const & 
 		return MathAtom(new MathStackrelInset);
 	if (s == "binom" || s == "choose")
 		return MathAtom(new MathBinomInset(s == "choose"));
-	if (s == "over" || s == "frac")
+	if (s == "frac")
 		return MathAtom(new MathFracInset);
+	if (s == "over")
+		return MathAtom(new MathFracInset(MathFracInset::OVER));
 	if (s == "nicefrac")
 		return MathAtom(new MathFracInset(MathFracInset::NICEFRAC));
 	//if (s == "infer")
Index: src/mathed/math_fracinset.C
===================================================================
--- src/mathed/math_fracinset.C	(Revision 14475)
+++ src/mathed/math_fracinset.C	(Arbeitskopie)
@@ -77,18 +77,17 @@ void MathFracInset::draw(PainterInfo & p
 				y - cell(0).descent() - 5);
 		cell(1).draw(pi, x + cell(0).width() + 5,
 				y + cell(1).ascent() / 2);
+		pi.pain.line(x + cell(0).width(), 
+				y + dim_.des - 2, 
+				x + cell(0).width() + 5, 
+				y - dim_.asc + 2, LColor::math);
 	} else {
 		cell(0).draw(pi, m - cell(0).width() / 2, 
 				y - cell(0).descent() - 2 - 5);
 		cell(1).draw(pi, m - cell(1).width() / 2,
 				y + cell(1).ascent()  + 2 - 5);
 	}
-	if (kind_ == NICEFRAC)
-		pi.pain.line(x + cell(0).width(), 
-				y + dim_.des - 2, 
-				x + cell(0).width() + 5, 
-				y - dim_.asc + 2, LColor::math);
-	if (kind_ == FRAC)
+	if (kind_ == FRAC || kind_ == OVER)
 		pi.pain.line(x + 1, y - 5, 
 				x + dim_.wid - 2, y - 5, LColor::math);
 	drawMarkers(pi, x, y);
@@ -112,17 +111,26 @@ void MathFracInset::drawT(TextPainter & 
 	cell(0).drawT(pain, m - cell(0).width() / 2, y - cell(0).descent() - 1);
 	cell(1).drawT(pain, m - cell(1).width() / 2, y + cell(1).ascent());
 	// ASCII art: ignore niceties
-	if (kind_ == FRAC || kind_ == NICEFRAC)
+	if (kind_ == FRAC || kind_ == OVER || kind_ == NICEFRAC)
 		pain.horizontalLine(x, y, dim_.width());
 }
 
 
 void MathFracInset::write(WriteStream & os) const
 {
-	if (kind_ == ATOP)
+	switch (kind_) {
+	case ATOP:
 		os << '{' << cell(0) << "\\atop " << cell(1) << '}';
-	else // it's \\frac
+		break;
+	case OVER:
+		// \\over is only for compatibility, normalize this to \\frac
+		os << "\\frac{" << cell(0) << "}{" << cell(1) << '}';
+		break;
+	case FRAC:
+	case NICEFRAC:
 		MathNestInset::write(os);
+		break;
+	}
 }
 
 
@@ -131,19 +139,19 @@ string MathFracInset::name() const
 	switch (kind_) {
 	case FRAC:
 		return "frac";
+	case OVER:
+		return "over";
 	case NICEFRAC:
 		return "nicefrac";
 	case ATOP:
 		return "atop";
-	default:
-		return string();
 	}
 }
 
 
 bool MathFracInset::extraBraces() const
 {
-	return kind_ == ATOP;
+	return kind_ == ATOP || kind_ == OVER;
 }
 
 
Index: src/mathed/math_fracinset.h
===================================================================
--- src/mathed/math_fracinset.h	(Revision 14475)
+++ src/mathed/math_fracinset.h	(Arbeitskopie)
@@ -22,6 +22,7 @@ public:
 	///
 	enum Kind {
 		FRAC,
+		OVER,
 		ATOP,
 		NICEFRAC
 	};

Reply via email to