mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-12 22:14:35 +00:00
recognize a few "well known functions"
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2993 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
9921635d78
commit
3516a9a2fc
@ -124,7 +124,7 @@ namespace {
|
|||||||
if (pos == string::npos || pos < 15)
|
if (pos == string::npos || pos < 15)
|
||||||
break; // caret position not found
|
break; // caret position not found
|
||||||
pos -= 15; // skip the "on line ..." part
|
pos -= 15; // skip the "on line ..." part
|
||||||
if (expr[pos] == '*')
|
if (expr[pos] == '*' || (pos > 0 && expr[pos - 1] == '*'))
|
||||||
break; // two '*' in a row are definitely bad
|
break; // two '*' in a row are definitely bad
|
||||||
expr.insert(pos, "*");
|
expr.insert(pos, "*");
|
||||||
}
|
}
|
||||||
|
@ -19,18 +19,6 @@ MathInset * MathExFuncInset::clone() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MathExFuncInset::write(WriteStream & os) const
|
|
||||||
{
|
|
||||||
os << '\\' << name_.c_str() << '{' << cell(0) << '}';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void MathExFuncInset::normalize(NormalStream & os) const
|
|
||||||
{
|
|
||||||
os << '[' << name_.c_str() << ' ' << cell(0) << ']';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void MathExFuncInset::metrics(MathMetricsInfo const & mi) const
|
void MathExFuncInset::metrics(MathMetricsInfo const & mi) const
|
||||||
{
|
{
|
||||||
mi_ = mi;
|
mi_ = mi;
|
||||||
@ -44,7 +32,33 @@ void MathExFuncInset::draw(Painter & pain, int x, int y) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MathExFuncInset::normalize(NormalStream & os) const
|
||||||
|
{
|
||||||
|
os << '[' << name_.c_str() << ' ' << cell(0) << ']';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MathExFuncInset::maplize(MapleStream & os) const
|
||||||
|
{
|
||||||
|
os << name_.c_str() << '(' << cell(0) << ')';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MathExFuncInset::mathmlize(MathMLStream & os) const
|
||||||
|
{
|
||||||
|
os << MTag(name_.c_str()) << cell(0) << ETag(name_.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void MathExFuncInset::octavize(OctaveStream & os) const
|
void MathExFuncInset::octavize(OctaveStream & os) const
|
||||||
{
|
{
|
||||||
os << name_.c_str() << '(' << cell(0) << ')';
|
os << name_.c_str() << '(' << cell(0) << ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MathExFuncInset::write(WriteStream & os) const
|
||||||
|
{
|
||||||
|
os << '\\' << name_.c_str() << '{' << cell(0) << '}';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,15 +14,20 @@ public:
|
|||||||
///
|
///
|
||||||
MathInset * clone() const;
|
MathInset * clone() const;
|
||||||
///
|
///
|
||||||
void write(WriteStream & os) const;
|
|
||||||
///
|
|
||||||
void normalize(NormalStream &) const;
|
|
||||||
///
|
|
||||||
void metrics(MathMetricsInfo const & st) const;
|
void metrics(MathMetricsInfo const & st) const;
|
||||||
///
|
///
|
||||||
void draw(Painter &, int x, int y) const;
|
void draw(Painter &, int x, int y) const;
|
||||||
|
|
||||||
|
///
|
||||||
|
void normalize(NormalStream &) const;
|
||||||
|
///
|
||||||
|
void maplize(MapleStream &) const;
|
||||||
|
///
|
||||||
|
void mathmlize(MathMLStream &) const;
|
||||||
///
|
///
|
||||||
void octavize(OctaveStream &) const;
|
void octavize(OctaveStream &) const;
|
||||||
|
///
|
||||||
|
void write(WriteStream & os) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
///
|
///
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
|
|
||||||
std::ostream & operator<<(ostream & os, MathArray const & ar)
|
std::ostream & operator<<(std::ostream & os, MathArray const & ar)
|
||||||
{
|
{
|
||||||
NormalStream ws(os);
|
NormalStream ns(os);
|
||||||
ws << ar;
|
ns << ar;
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,8 +55,9 @@ string charSequence(MathArray::const_iterator it, MathArray::const_iterator end)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void glueChars(MathArray & dat)
|
void extractStrings(MathArray & dat)
|
||||||
{
|
{
|
||||||
|
//lyxerr << "\nStrings from: " << ar << "\n";
|
||||||
MathArray ar;
|
MathArray ar;
|
||||||
MathArray::const_iterator it = dat.begin();
|
MathArray::const_iterator it = dat.begin();
|
||||||
while (it != dat.end()) {
|
while (it != dat.end()) {
|
||||||
@ -71,6 +72,7 @@ void glueChars(MathArray & dat)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ar.swap(dat);
|
ar.swap(dat);
|
||||||
|
//lyxerr << "\nStrings to: " << ar << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -110,6 +112,7 @@ MathInset * singleItem(MathArray & ar)
|
|||||||
|
|
||||||
void extractMatrices(MathArray & ar)
|
void extractMatrices(MathArray & ar)
|
||||||
{
|
{
|
||||||
|
lyxerr << "\nMatrices from: " << ar << "\n";
|
||||||
for (MathArray::iterator it = ar.begin(); it != ar.end(); ++it) {
|
for (MathArray::iterator it = ar.begin(); it != ar.end(); ++it) {
|
||||||
if (!it->nucleus())
|
if (!it->nucleus())
|
||||||
continue;
|
continue;
|
||||||
@ -120,39 +123,59 @@ void extractMatrices(MathArray & ar)
|
|||||||
if (!arr || !arr->asArrayInset())
|
if (!arr || !arr->asArrayInset())
|
||||||
continue;
|
continue;
|
||||||
*it = MathAtom(new MathMatrixInset(*(arr->asArrayInset())));
|
*it = MathAtom(new MathMatrixInset(*(arr->asArrayInset())));
|
||||||
|
lyxerr << "\nMatrices to: " << ar << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convert this inset somehow to a string
|
||||||
|
string extractString(MathInset * p)
|
||||||
|
{
|
||||||
|
if (p && p->getChar())
|
||||||
|
return string(1, p->getChar());
|
||||||
|
if (p && p->asStringInset())
|
||||||
|
return p->asStringInset()->str();
|
||||||
|
return string();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// replace '('...')' sequences by a real MathDelimInset
|
||||||
void extractDelims(MathArray & ar) {
|
void extractDelims(MathArray & ar) {
|
||||||
// use indices rather than iterators for the loop because we are going
|
// use indices rather than iterators for the loop because we are going
|
||||||
// to modify the array.
|
// to modify the array.
|
||||||
|
lyxerr << "\nDelims from: " << ar << "\n";
|
||||||
for (MathArray::size_type i = 0; i < ar.size(); ++i) {
|
for (MathArray::size_type i = 0; i < ar.size(); ++i) {
|
||||||
MathArray::iterator it = ar.begin() + i;
|
MathArray::iterator it = ar.begin() + i;
|
||||||
if (!it->nucleus())
|
if (extractString(it->nucleus()) != "(")
|
||||||
continue;
|
|
||||||
if ((*it)->getChar() != '(')
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// search last closing paranthesis
|
// search matching closing paranthesis
|
||||||
MathArray::iterator et = ar.end();
|
int level = 1;
|
||||||
for (MathArray::iterator jt = it + 1; jt != ar.end(); ++jt)
|
MathArray::iterator jt = it + 1;
|
||||||
if ((*jt)->getChar() == ')')
|
for (; jt != ar.end(); ++jt) {
|
||||||
et = jt;
|
string s = extractString(jt->nucleus());
|
||||||
if (et == ar.end())
|
if (s == "(")
|
||||||
|
++level;
|
||||||
|
if (s == ")")
|
||||||
|
--level;
|
||||||
|
if (level == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (jt == ar.end())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// create a proper deliminset
|
// create a proper deliminset
|
||||||
MathAtom at(new MathDelimInset("(", ")"));
|
MathAtom at(new MathDelimInset("(", ")"));
|
||||||
at->cell(0) = MathArray(it + 1, et);
|
at->cell(0) = MathArray(it + 1, jt);
|
||||||
|
|
||||||
// replace the original stuff by the new inset
|
// replace the original stuff by the new inset
|
||||||
ar.erase(it + 1, et + 1);
|
ar.erase(it + 1, jt + 1);
|
||||||
*it = at;
|
*it = at;
|
||||||
|
lyxerr << "\nDelims to: " << ar << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// replace 'f' '(...)' and 'f' '^n' '(...)' sequences by a real MathExFuncInset
|
||||||
// assume 'extractDelims' ran before
|
// assume 'extractDelims' ran before
|
||||||
void extractFunctions(MathArray & ar)
|
void extractFunctions(MathArray & ar)
|
||||||
{
|
{
|
||||||
@ -160,6 +183,7 @@ void extractFunctions(MathArray & ar)
|
|||||||
if (ar.size() <= 1)
|
if (ar.size() <= 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
lyxerr << "\nFunctions from: " << ar << "\n";
|
||||||
for (MathArray::size_type i = 0; i < ar.size() - 1; ++i) {
|
for (MathArray::size_type i = 0; i < ar.size() - 1; ++i) {
|
||||||
MathArray::iterator it = ar.begin() + i;
|
MathArray::iterator it = ar.begin() + i;
|
||||||
|
|
||||||
@ -197,13 +221,14 @@ void extractFunctions(MathArray & ar)
|
|||||||
|
|
||||||
// remove the source of the argument from the array
|
// remove the source of the argument from the array
|
||||||
ar.erase(jt);
|
ar.erase(jt);
|
||||||
|
lyxerr << "\nFunctions to: " << ar << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void extractStructure(MathArray & ar)
|
void extractStructure(MathArray & ar)
|
||||||
{
|
{
|
||||||
glueChars(ar);
|
extractStrings(ar);
|
||||||
extractMatrices(ar);
|
extractMatrices(ar);
|
||||||
extractDelims(ar);
|
extractDelims(ar);
|
||||||
extractFunctions(ar);
|
extractFunctions(ar);
|
||||||
@ -213,7 +238,7 @@ void extractStructure(MathArray & ar)
|
|||||||
void write(MathArray const & dat, WriteStream & wi)
|
void write(MathArray const & dat, WriteStream & wi)
|
||||||
{
|
{
|
||||||
MathArray ar = dat;
|
MathArray ar = dat;
|
||||||
glueChars(ar);
|
extractStrings(ar);
|
||||||
for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it) {
|
for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it) {
|
||||||
MathInset const * p = it->nucleus();
|
MathInset const * p = it->nucleus();
|
||||||
if (it + 1 != ar.end()) {
|
if (it + 1 != ar.end()) {
|
||||||
@ -228,21 +253,10 @@ void write(MathArray const & dat, WriteStream & wi)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void normalize(MathArray const & dat, NormalStream & os)
|
void normalize(MathArray const & ar, NormalStream & os)
|
||||||
{
|
{
|
||||||
MathArray ar = dat;
|
for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
|
||||||
glueChars(ar);
|
(*it)->normalize(os);
|
||||||
for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it) {
|
|
||||||
MathInset const * p = it->nucleus();
|
|
||||||
if (it + 1 != ar.end()) {
|
|
||||||
if (MathScriptInset const * q = asScript(it)) {
|
|
||||||
q->normalize(p, os);
|
|
||||||
++it;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
p->normalize(os);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,6 +48,7 @@ class MathHullInset;
|
|||||||
class MathMatrixInset;
|
class MathMatrixInset;
|
||||||
class MathNestInset;
|
class MathNestInset;
|
||||||
class MathScriptInset;
|
class MathScriptInset;
|
||||||
|
class MathStringInset;
|
||||||
class MathSpaceInset;
|
class MathSpaceInset;
|
||||||
class MathMacroTemplate;
|
class MathMacroTemplate;
|
||||||
|
|
||||||
@ -170,34 +171,23 @@ public:
|
|||||||
///
|
///
|
||||||
virtual bool covers(int x, int y) const;
|
virtual bool covers(int x, int y) const;
|
||||||
|
|
||||||
/// identifies NestInsets
|
/// identifies certain types of insets
|
||||||
virtual MathNestInset * asNestInset() { return 0; }
|
|
||||||
/// identifies CharInsets
|
|
||||||
virtual MathCharInset const * asCharInset() const { return 0; }
|
|
||||||
/// identifies ScriptInsets
|
|
||||||
virtual MathScriptInset * asScriptInset() { return 0; }
|
|
||||||
virtual MathScriptInset const * asScriptInset() const { return 0; }
|
|
||||||
/// identifies HullInsets
|
|
||||||
virtual MathHullInset * asHullInset() { return 0; }
|
|
||||||
virtual MathHullInset const * asHullInset() const { return 0; }
|
|
||||||
/// identifies SpaceInset
|
|
||||||
virtual MathSpaceInset * asSpaceInset() { return 0; }
|
|
||||||
/// identifies GridInset
|
|
||||||
virtual MathGridInset * asGridInset() { return 0; }
|
|
||||||
/// identifies ArrayInsets
|
|
||||||
virtual MathArrayInset * asArrayInset() { return 0; }
|
virtual MathArrayInset * asArrayInset() { return 0; }
|
||||||
/// identifies MatrixInsets
|
|
||||||
virtual MathMatrixInset const * asMatrixInset() const { return 0; }
|
|
||||||
/// identifies BoxInsets
|
|
||||||
virtual MathBoxInset * asBoxInset() { return 0; }
|
virtual MathBoxInset * asBoxInset() { return 0; }
|
||||||
/// identifies DelimInsets
|
virtual MathCharInset const * asCharInset() const { return 0; }
|
||||||
virtual MathDelimInset * asDelimInset() { return 0; }
|
virtual MathDelimInset * asDelimInset() { return 0; }
|
||||||
virtual MathDelimInset const * asDelimInset() const { return 0; }
|
virtual MathDelimInset const * asDelimInset() const { return 0; }
|
||||||
/// identifies FuncInsets
|
|
||||||
virtual MathFuncInset * asFuncInset() { return 0; }
|
virtual MathFuncInset * asFuncInset() { return 0; }
|
||||||
/// identifies macro templates
|
virtual MathGridInset * asGridInset() { return 0; }
|
||||||
|
virtual MathHullInset * asHullInset() { return 0; }
|
||||||
|
virtual MathHullInset const * asHullInset() const { return 0; }
|
||||||
virtual MathMacroTemplate * asMacroTemplate() { return 0; }
|
virtual MathMacroTemplate * asMacroTemplate() { return 0; }
|
||||||
/// identifies hyperactive insets
|
virtual MathMatrixInset const * asMatrixInset() const { return 0; }
|
||||||
|
virtual MathNestInset * asNestInset() { return 0; }
|
||||||
|
virtual MathScriptInset * asScriptInset() { return 0; }
|
||||||
|
virtual MathScriptInset const * asScriptInset() const { return 0; }
|
||||||
|
virtual MathSpaceInset * asSpaceInset() { return 0; }
|
||||||
|
virtual MathStringInset * asStringInset() { return 0; }
|
||||||
virtual UpdatableInset * asHyperActiveInset() const { return 0; }
|
virtual UpdatableInset * asHyperActiveInset() const { return 0; }
|
||||||
|
|
||||||
/// identifies things that can get scripts
|
/// identifies things that can get scripts
|
||||||
|
@ -22,10 +22,6 @@ public:
|
|||||||
void metrics(MathMetricsInfo const & st) const;
|
void metrics(MathMetricsInfo const & st) const;
|
||||||
///
|
///
|
||||||
void draw(Painter &, int x, int y) const;
|
void draw(Painter &, int x, int y) const;
|
||||||
///
|
|
||||||
void write(WriteStream & os) const;
|
|
||||||
///
|
|
||||||
void normalize(NormalStream &) const;
|
|
||||||
///
|
///
|
||||||
int ascent() const;
|
int ascent() const;
|
||||||
///
|
///
|
||||||
@ -33,11 +29,20 @@ public:
|
|||||||
///
|
///
|
||||||
int width() const;
|
int width() const;
|
||||||
///
|
///
|
||||||
|
string str() const { return str_; }
|
||||||
|
///
|
||||||
|
MathStringInset * asStringInset() { return this; }
|
||||||
|
|
||||||
|
///
|
||||||
|
void normalize(NormalStream &) const;
|
||||||
|
///
|
||||||
void octavize(OctaveStream &) const;
|
void octavize(OctaveStream &) const;
|
||||||
///
|
///
|
||||||
void maplize(MapleStream &) const;
|
void maplize(MapleStream &) const;
|
||||||
///
|
///
|
||||||
void mathmlize(MathMLStream &) const;
|
void mathmlize(MathMLStream &) const;
|
||||||
|
///
|
||||||
|
void write(WriteStream & os) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// the string
|
/// the string
|
||||||
|
Loading…
Reference in New Issue
Block a user