re-adjust math-extern heuristics to new super/subscript inset

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4810 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2002-07-30 17:51:19 +00:00
parent 6446bf8b49
commit 7534cb5d5e
5 changed files with 103 additions and 60 deletions

View File

@ -65,6 +65,30 @@ void MathBraceInset::normalize(NormalStream & os) const
}
void MathBraceInset::maplize(MapleStream & os) const
{
os << cell(0);
}
void MathBraceInset::octavize(OctaveStream & os) const
{
os << cell(0);
}
void MathBraceInset::mathmlize(MathMLStream & os) const
{
os << MTag("mrow") << cell(0) << ETag("mrow");
}
void MathBraceInset::mathematicize(MathematicaStream & os) const
{
os << cell(0);
}
void MathBraceInset::infoize(std::ostream & os) const
{
os << "Nested Block: ";

View File

@ -23,13 +23,21 @@ public:
/// we write extra braces in any case...
bool extraBraces() const { return true; }
///
void metrics(MathMetricsInfo & mi) const;
///
void draw(MathPainterInfo &, int x, int y) const;
///
void write(WriteStream & os) const;
/// write normalized content
void normalize(NormalStream & ns) const;
///
void metrics(MathMetricsInfo & mi) const;
void maplize(MapleStream &) const;
///
void mathematicize(MathematicaStream &) const;
///
void octavize(OctaveStream &) const;
///
void mathmlize(MathMLStream &) const;
///
void infoize(std::ostream & os) const;

View File

@ -74,6 +74,7 @@ void MathExIntInset::maplize(MapleStream & os) const
os << ')';
}
void MathExIntInset::mathematicize(MathematicaStream & os) const
{
if ( symbol_ == "int" )

View File

@ -498,6 +498,17 @@ bool testIntSymbol(MathInset * p)
}
bool testIntegral(MathInset * p)
{
return
testIntSymbol(p) ||
( p->asScriptInset()
&& p->asScriptInset()->nuc().size()
&& testIntSymbol(p->asScriptInset()->nuc().back().nucleus()) );
}
bool testIntDiff(MathInset * p)
{
return testString(p, "d");
@ -516,40 +527,27 @@ void extractIntegrals(MathArray & ar)
for (MathArray::size_type i = 0; i + 1 < ar.size(); ++i) {
MathArray::iterator it = ar.begin() + i;
// is this a integral name?
if (!testIntSymbol(it->nucleus()))
continue;
// search 'd'
MathArray::iterator jt =
endNestSearch(it, ar.end(), testIntSymbol, testIntDiff);
endNestSearch(it, ar.end(), testIntegral, testIntDiff);
// something sensible found?
if (jt == ar.end())
continue;
// create a proper inset as replacement
MathExIntInset * p = new MathExIntInset("int");
// collect subscript if any
MathArray::iterator st = it + 1;
if (st != ar.end())
if (MathScriptInset * sub = (*st)->asScriptInset())
if (sub->hasDown()) {
p->cell(2) = sub->down().data();
++st;
}
// collect superscript if any
if (st != ar.end())
if (MathScriptInset * sup = (*st)->asScriptInset())
if (sup->hasUp()) {
p->cell(3) = sup->up().data();
++st;
}
// is this a integral name?
if (!testIntegral(it->nucleus()))
continue;
// core ist part from behind the scripts to the 'd'
p->cell(0) = MathArray(st, jt);
MathExIntInset * p = new MathExIntInset("int");
// handle scripts if available
if (!testIntSymbol(it->nucleus())) {
p->cell(2) = it->nucleus()->asScriptInset()->down().data();
p->cell(3) = it->nucleus()->asScriptInset()->up().data();
}
p->cell(0) = MathArray(it + 1, jt);
// use the "thing" behind the 'd' as differential
MathArray::iterator tt = extractArgument(p->cell(1), jt + 1, ar.end());
@ -573,6 +571,21 @@ bool testEqualSign(MathAtom const & at)
}
bool testSumSymbol(MathInset * p)
{
return testSymbol(p, "sum");
}
bool testSum(MathInset * p)
{
return
testSumSymbol(p) ||
( p->asScriptInset()
&& p->asScriptInset()->nuc().size()
&& testSumSymbol(p->asScriptInset()->nuc().back().nucleus()) );
}
// replace '\sum' ['_^'] f(x) sequences by a real MathExIntInset
// assume 'extractDelims' ran before
@ -587,43 +600,36 @@ void extractSums(MathArray & ar)
MathArray::iterator it = ar.begin() + i;
// is this a sum name?
if (!testSymbol(it->nucleus(), "sum"))
if (!testSum(it->nucleus()))
continue;
// create a proper inset as replacement
MathExIntInset * p = new MathExIntInset("sum");
// collect lower bound and summation index
MathArray::iterator st = it + 1;
if (st != ar.end())
if (MathScriptInset * sub = (*st)->asScriptInset())
if (sub->hasDown()) {
// try to figure out the summation index from the subscript
MathArray & ar = sub->down().data();
MathArray::iterator it =
find_if(ar.begin(), ar.end(), &testEqualSign);
if (it != ar.end()) {
// we found a '=', use everything in front of that as index,
// and everything behind as lower index
p->cell(1) = MathArray(ar.begin(), it);
p->cell(2) = MathArray(it + 1, ar.end());
} else {
// use everything as summation index, don't use scripts.
p->cell(1) = ar;
}
++st;
}
MathScriptInset * sub = (*it)->asScriptInset();
if (sub && sub->hasDown()) {
// try to figure out the summation index from the subscript
MathArray & ar = sub->down().data();
MathArray::iterator xt =
find_if(ar.begin(), ar.end(), &testEqualSign);
if (xt != ar.end()) {
// we found a '=', use everything in front of that as index,
// and everything behind as lower index
p->cell(1) = MathArray(ar.begin(), xt);
p->cell(2) = MathArray(xt + 1, ar.end());
} else {
// use everything as summation index, don't use scripts.
p->cell(1) = ar;
}
}
// collect upper bound
if (st != ar.end())
if (MathScriptInset * sup = (*st)->asScriptInset())
if (sup->hasUp()) {
p->cell(3) = sup->up().data();
++st;
}
if (sub && sub->hasUp())
p->cell(3) = sub->up().data();
// use some behind the script as core
MathArray::iterator tt = extractArgument(p->cell(0), st, ar.end());
// use something behind the script as core
MathArray::iterator tt = extractArgument(p->cell(0), it + 1, ar.end());
// cleanup
ar.erase(it + 1, tt);
@ -809,14 +815,14 @@ void extractLims(MathArray & ar)
void extractStructure(MathArray & ar)
{
extractIntegrals(ar);
extractSums(ar);
splitScripts(ar);
extractNumbers(ar);
extractMatrices(ar);
extractDelims(ar);
extractFunctions(ar);
extractDets(ar);
extractIntegrals(ar);
extractSums(ar);
extractDiff(ar);
extractExps(ar);
extractLims(ar);

View File

@ -368,9 +368,11 @@ void MathScriptInset::normalize(NormalStream & os) const
bool d = hasDown() && down().size();
bool u = hasUp() && up().size();
if (u)
if (u && d)
os << "[subsup ";
else if (u)
os << "[sup ";
if (d)
else if (d)
os << "[sub ";
if (nuc().size())
@ -378,9 +380,11 @@ void MathScriptInset::normalize(NormalStream & os) const
else
os << "[par]";
if (d)
if (u && d)
os << down().data() << ' ' << up().data() << ']';
else if (d)
os << down().data() << ']';
if (u)
else if (u)
os << up().data() << ']';
}