mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-26 19:25:39 +00:00
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:
parent
6446bf8b49
commit
7534cb5d5e
@ -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
|
void MathBraceInset::infoize(std::ostream & os) const
|
||||||
{
|
{
|
||||||
os << "Nested Block: ";
|
os << "Nested Block: ";
|
||||||
|
@ -23,13 +23,21 @@ public:
|
|||||||
/// we write extra braces in any case...
|
/// we write extra braces in any case...
|
||||||
bool extraBraces() const { return true; }
|
bool extraBraces() const { return true; }
|
||||||
///
|
///
|
||||||
|
void metrics(MathMetricsInfo & mi) const;
|
||||||
|
///
|
||||||
void draw(MathPainterInfo &, int x, int y) const;
|
void draw(MathPainterInfo &, int x, int y) const;
|
||||||
///
|
///
|
||||||
void write(WriteStream & os) const;
|
void write(WriteStream & os) const;
|
||||||
/// write normalized content
|
/// write normalized content
|
||||||
void normalize(NormalStream & ns) const;
|
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;
|
void infoize(std::ostream & os) const;
|
||||||
|
|
||||||
|
@ -74,6 +74,7 @@ void MathExIntInset::maplize(MapleStream & os) const
|
|||||||
os << ')';
|
os << ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MathExIntInset::mathematicize(MathematicaStream & os) const
|
void MathExIntInset::mathematicize(MathematicaStream & os) const
|
||||||
{
|
{
|
||||||
if ( symbol_ == "int" )
|
if ( symbol_ == "int" )
|
||||||
|
@ -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)
|
bool testIntDiff(MathInset * p)
|
||||||
{
|
{
|
||||||
return testString(p, "d");
|
return testString(p, "d");
|
||||||
@ -516,40 +527,27 @@ void extractIntegrals(MathArray & ar)
|
|||||||
for (MathArray::size_type i = 0; i + 1 < ar.size(); ++i) {
|
for (MathArray::size_type i = 0; i + 1 < ar.size(); ++i) {
|
||||||
MathArray::iterator it = ar.begin() + i;
|
MathArray::iterator it = ar.begin() + i;
|
||||||
|
|
||||||
// is this a integral name?
|
|
||||||
if (!testIntSymbol(it->nucleus()))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// search 'd'
|
// search 'd'
|
||||||
MathArray::iterator jt =
|
MathArray::iterator jt =
|
||||||
endNestSearch(it, ar.end(), testIntSymbol, testIntDiff);
|
endNestSearch(it, ar.end(), testIntegral, testIntDiff);
|
||||||
|
|
||||||
// something sensible found?
|
// something sensible found?
|
||||||
if (jt == ar.end())
|
if (jt == ar.end())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// create a proper inset as replacement
|
// is this a integral name?
|
||||||
MathExIntInset * p = new MathExIntInset("int");
|
if (!testIntegral(it->nucleus()))
|
||||||
|
continue;
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// core ist part from behind the scripts to the 'd'
|
// 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
|
// use the "thing" behind the 'd' as differential
|
||||||
MathArray::iterator tt = extractArgument(p->cell(1), jt + 1, ar.end());
|
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
|
// replace '\sum' ['_^'] f(x) sequences by a real MathExIntInset
|
||||||
// assume 'extractDelims' ran before
|
// assume 'extractDelims' ran before
|
||||||
@ -587,43 +600,36 @@ void extractSums(MathArray & ar)
|
|||||||
MathArray::iterator it = ar.begin() + i;
|
MathArray::iterator it = ar.begin() + i;
|
||||||
|
|
||||||
// is this a sum name?
|
// is this a sum name?
|
||||||
if (!testSymbol(it->nucleus(), "sum"))
|
if (!testSum(it->nucleus()))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// create a proper inset as replacement
|
// create a proper inset as replacement
|
||||||
MathExIntInset * p = new MathExIntInset("sum");
|
MathExIntInset * p = new MathExIntInset("sum");
|
||||||
|
|
||||||
// collect lower bound and summation index
|
// collect lower bound and summation index
|
||||||
MathArray::iterator st = it + 1;
|
MathScriptInset * sub = (*it)->asScriptInset();
|
||||||
if (st != ar.end())
|
if (sub && sub->hasDown()) {
|
||||||
if (MathScriptInset * sub = (*st)->asScriptInset())
|
|
||||||
if (sub->hasDown()) {
|
|
||||||
// try to figure out the summation index from the subscript
|
// try to figure out the summation index from the subscript
|
||||||
MathArray & ar = sub->down().data();
|
MathArray & ar = sub->down().data();
|
||||||
MathArray::iterator it =
|
MathArray::iterator xt =
|
||||||
find_if(ar.begin(), ar.end(), &testEqualSign);
|
find_if(ar.begin(), ar.end(), &testEqualSign);
|
||||||
if (it != ar.end()) {
|
if (xt != ar.end()) {
|
||||||
// we found a '=', use everything in front of that as index,
|
// we found a '=', use everything in front of that as index,
|
||||||
// and everything behind as lower index
|
// and everything behind as lower index
|
||||||
p->cell(1) = MathArray(ar.begin(), it);
|
p->cell(1) = MathArray(ar.begin(), xt);
|
||||||
p->cell(2) = MathArray(it + 1, ar.end());
|
p->cell(2) = MathArray(xt + 1, ar.end());
|
||||||
} else {
|
} else {
|
||||||
// use everything as summation index, don't use scripts.
|
// use everything as summation index, don't use scripts.
|
||||||
p->cell(1) = ar;
|
p->cell(1) = ar;
|
||||||
}
|
}
|
||||||
++st;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// collect upper bound
|
// collect upper bound
|
||||||
if (st != ar.end())
|
if (sub && sub->hasUp())
|
||||||
if (MathScriptInset * sup = (*st)->asScriptInset())
|
p->cell(3) = sub->up().data();
|
||||||
if (sup->hasUp()) {
|
|
||||||
p->cell(3) = sup->up().data();
|
|
||||||
++st;
|
|
||||||
}
|
|
||||||
|
|
||||||
// use some behind the script as core
|
// use something behind the script as core
|
||||||
MathArray::iterator tt = extractArgument(p->cell(0), st, ar.end());
|
MathArray::iterator tt = extractArgument(p->cell(0), it + 1, ar.end());
|
||||||
|
|
||||||
// cleanup
|
// cleanup
|
||||||
ar.erase(it + 1, tt);
|
ar.erase(it + 1, tt);
|
||||||
@ -809,14 +815,14 @@ void extractLims(MathArray & ar)
|
|||||||
|
|
||||||
void extractStructure(MathArray & ar)
|
void extractStructure(MathArray & ar)
|
||||||
{
|
{
|
||||||
|
extractIntegrals(ar);
|
||||||
|
extractSums(ar);
|
||||||
splitScripts(ar);
|
splitScripts(ar);
|
||||||
extractNumbers(ar);
|
extractNumbers(ar);
|
||||||
extractMatrices(ar);
|
extractMatrices(ar);
|
||||||
extractDelims(ar);
|
extractDelims(ar);
|
||||||
extractFunctions(ar);
|
extractFunctions(ar);
|
||||||
extractDets(ar);
|
extractDets(ar);
|
||||||
extractIntegrals(ar);
|
|
||||||
extractSums(ar);
|
|
||||||
extractDiff(ar);
|
extractDiff(ar);
|
||||||
extractExps(ar);
|
extractExps(ar);
|
||||||
extractLims(ar);
|
extractLims(ar);
|
||||||
|
@ -368,9 +368,11 @@ void MathScriptInset::normalize(NormalStream & os) const
|
|||||||
bool d = hasDown() && down().size();
|
bool d = hasDown() && down().size();
|
||||||
bool u = hasUp() && up().size();
|
bool u = hasUp() && up().size();
|
||||||
|
|
||||||
if (u)
|
if (u && d)
|
||||||
|
os << "[subsup ";
|
||||||
|
else if (u)
|
||||||
os << "[sup ";
|
os << "[sup ";
|
||||||
if (d)
|
else if (d)
|
||||||
os << "[sub ";
|
os << "[sub ";
|
||||||
|
|
||||||
if (nuc().size())
|
if (nuc().size())
|
||||||
@ -378,9 +380,11 @@ void MathScriptInset::normalize(NormalStream & os) const
|
|||||||
else
|
else
|
||||||
os << "[par]";
|
os << "[par]";
|
||||||
|
|
||||||
if (d)
|
if (u && d)
|
||||||
|
os << down().data() << ' ' << up().data() << ']';
|
||||||
|
else if (d)
|
||||||
os << down().data() << ']';
|
os << down().data() << ']';
|
||||||
if (u)
|
else if (u)
|
||||||
os << up().data() << ']';
|
os << up().data() << ']';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user