mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-27 11:52:25 +00:00
Make InsetMathExInt handle products as well as sums.
We can do more here, but it's actually not clear to me whether we even need to give these things special treatment for MathML. I may revert this. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32568 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
c3fc67ef54
commit
46e1424678
@ -71,8 +71,16 @@ void InsetMathExInt::draw(PainterInfo &, int, int) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool InsetMathExInt::isExIntOperator(docstring const & name)
|
||||||
|
{
|
||||||
|
std::string const & sname = to_utf8(name);
|
||||||
|
return sname == "sum" || sname == "prod";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void InsetMathExInt::maple(MapleStream & os) const
|
void InsetMathExInt::maple(MapleStream & os) const
|
||||||
{
|
{
|
||||||
|
// FIXME Products and the like may need special treatment.
|
||||||
os << symbol_ << '(';
|
os << symbol_ << '(';
|
||||||
if (cell(0).size())
|
if (cell(0).size())
|
||||||
os << cell(0);
|
os << cell(0);
|
||||||
@ -87,6 +95,7 @@ void InsetMathExInt::maple(MapleStream & os) const
|
|||||||
|
|
||||||
void InsetMathExInt::maxima(MaximaStream & os) const
|
void InsetMathExInt::maxima(MaximaStream & os) const
|
||||||
{
|
{
|
||||||
|
// FIXME Products and the like may need special treatment.
|
||||||
if (symbol_ == "int")
|
if (symbol_ == "int")
|
||||||
os << "integrate(";
|
os << "integrate(";
|
||||||
else
|
else
|
||||||
@ -102,8 +111,10 @@ void InsetMathExInt::maxima(MaximaStream & os) const
|
|||||||
os << cell(1) << ')';
|
os << cell(1) << ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void InsetMathExInt::mathematica(MathematicaStream & os) const
|
void InsetMathExInt::mathematica(MathematicaStream & os) const
|
||||||
{
|
{
|
||||||
|
// FIXME Products and the like may need special treatment.
|
||||||
if (symbol_ == "int")
|
if (symbol_ == "int")
|
||||||
os << "Integrate[";
|
os << "Integrate[";
|
||||||
else if (symbol_ == "sum")
|
else if (symbol_ == "sum")
|
||||||
@ -125,7 +136,7 @@ void InsetMathExInt::mathematica(MathematicaStream & os) const
|
|||||||
void InsetMathExInt::mathmlize(MathStream & os) const
|
void InsetMathExInt::mathmlize(MathStream & os) const
|
||||||
{
|
{
|
||||||
InsetMathSymbol sym(symbol_);
|
InsetMathSymbol sym(symbol_);
|
||||||
if (symbol_ == "sum") {
|
if (isExIntOperator(symbol_)) {
|
||||||
bool const lower = !cell(1).empty();
|
bool const lower = !cell(1).empty();
|
||||||
bool const upper = !cell(3).empty();
|
bool const upper = !cell(3).empty();
|
||||||
if (lower && upper)
|
if (lower && upper)
|
||||||
@ -189,5 +200,4 @@ void InsetMathExInt::write(WriteStream &) const
|
|||||||
LYXERR0("should not happen");
|
LYXERR0("should not happen");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
// or \sum, \prod... for interfacing external programs
|
// or \sum, \prod... for interfacing external programs
|
||||||
|
|
||||||
#include "InsetMathNest.h"
|
#include "InsetMathNest.h"
|
||||||
|
#include "support/strfwd.h"
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
|
|
||||||
@ -57,11 +57,13 @@ public:
|
|||||||
void write(WriteStream & os) const;
|
void write(WriteStream & os) const;
|
||||||
///
|
///
|
||||||
InsetCode lyxCode() const { return MATH_EXINT_CODE; }
|
InsetCode lyxCode() const { return MATH_EXINT_CODE; }
|
||||||
|
/// is this a sum, product, or whatever that we can handle?
|
||||||
|
/// note that this does not include integrals.
|
||||||
|
static bool isExIntOperator(docstring const &);
|
||||||
private:
|
private:
|
||||||
virtual Inset * clone() const;
|
virtual Inset * clone() const;
|
||||||
///
|
///
|
||||||
bool hasScripts() const;
|
bool hasScripts() const;
|
||||||
|
|
||||||
///
|
///
|
||||||
docstring symbol_;
|
docstring symbol_;
|
||||||
};
|
};
|
||||||
|
@ -80,7 +80,6 @@ typedef bool TestItemFunc(MathAtom const &);
|
|||||||
typedef MathAtom ReplaceArgumentFunc(const MathData & ar);
|
typedef MathAtom ReplaceArgumentFunc(const MathData & ar);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// try to extract a super/subscript
|
// try to extract a super/subscript
|
||||||
// modify iterator position to point behind the thing
|
// modify iterator position to point behind the thing
|
||||||
bool extractScript(MathData & ar,
|
bool extractScript(MathData & ar,
|
||||||
@ -356,7 +355,7 @@ void splitScripts(MathData & ar)
|
|||||||
// leave alone sums and integrals
|
// leave alone sums and integrals
|
||||||
InsetMathSymbol const * sym =
|
InsetMathSymbol const * sym =
|
||||||
script->nuc().front()->asSymbolInset();
|
script->nuc().front()->asSymbolInset();
|
||||||
if (sym && (sym->name() == "sum" || sym->name() == "int"))
|
if (sym && (InsetMathExInt::isExIntOperator(sym->name()) || sym->name() == "int"))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -705,25 +704,29 @@ bool testEqualSign(MathAtom const & at)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool testSumSymbol(MathAtom const & p)
|
bool testSumLikeSymbol(MathAtom const & p)
|
||||||
{
|
{
|
||||||
return testSymbol(p, from_ascii("sum"));
|
return InsetMathExInt::isExIntOperator(p->name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool testSum(MathAtom const & at)
|
docstring testSumLike(MathAtom const & at)
|
||||||
{
|
{
|
||||||
return
|
if (testSumLikeSymbol(at))
|
||||||
testSumSymbol(at) ||
|
return at->name();
|
||||||
( at->asScriptInset()
|
if ( at->asScriptInset()
|
||||||
&& at->asScriptInset()->nuc().size()
|
&& at->asScriptInset()->nuc().size()
|
||||||
&& testSumSymbol(at->asScriptInset()->nuc().back()) );
|
&& testSumLikeSymbol(at->asScriptInset()->nuc().back()) )
|
||||||
|
return at->asScriptInset()->nuc().back()->name();
|
||||||
|
return docstring();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// replace '\sum' ['_^'] f(x) sequences by a real InsetMathExInt
|
// replace '\sum' ['_^'] f(x) sequences by a real InsetMathExInt
|
||||||
|
// and similar things, like \prod. The things we extract are
|
||||||
|
// determined by InsetMathExInt::isExIntOperator().
|
||||||
// assume 'extractDelims' ran before
|
// assume 'extractDelims' ran before
|
||||||
void extractSums(MathData & ar)
|
void extractSumLike(MathData & ar)
|
||||||
{
|
{
|
||||||
// we need at least two items...
|
// we need at least two items...
|
||||||
if (ar.size() < 2)
|
if (ar.size() < 2)
|
||||||
@ -736,11 +739,12 @@ void extractSums(MathData & ar)
|
|||||||
MathData::iterator it = ar.begin() + i;
|
MathData::iterator it = ar.begin() + i;
|
||||||
|
|
||||||
// is this a sum name?
|
// is this a sum name?
|
||||||
if (!testSum(ar[i]))
|
docstring const opname = testSumLike(ar[i]);
|
||||||
|
if (opname.empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// create a proper inset as replacement
|
// create a proper inset as replacement
|
||||||
auto_ptr<InsetMathExInt> p(new InsetMathExInt(buf, from_ascii("sum")));
|
auto_ptr<InsetMathExInt> p(new InsetMathExInt(buf, opname));
|
||||||
|
|
||||||
// collect lower bound and summation index
|
// collect lower bound and summation index
|
||||||
InsetMathScript const * sub = ar[i]->asScriptInset();
|
InsetMathScript const * sub = ar[i]->asScriptInset();
|
||||||
@ -949,7 +953,7 @@ void extractStructure(MathData & ar, ExternalMath kind)
|
|||||||
splitScripts(ar);
|
splitScripts(ar);
|
||||||
extractDelims(ar);
|
extractDelims(ar);
|
||||||
extractIntegrals(ar, kind);
|
extractIntegrals(ar, kind);
|
||||||
extractSums(ar);
|
extractSumLike(ar);
|
||||||
extractNumbers(ar);
|
extractNumbers(ar);
|
||||||
extractMatrices(ar);
|
extractMatrices(ar);
|
||||||
extractFunctions(ar, kind);
|
extractFunctions(ar, kind);
|
||||||
|
Loading…
Reference in New Issue
Block a user