mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
some work on math-extern
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2997 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
cc5b1b9def
commit
6cfb068d37
@ -68,6 +68,8 @@ libmathed_la_SOURCES = \
|
||||
math_kerninset.h \
|
||||
math_lefteqninset.C \
|
||||
math_lefteqninset.h \
|
||||
math_limitopinset.C \
|
||||
math_limitopinset.h \
|
||||
math_macro.C \
|
||||
math_macro.h \
|
||||
math_macroarg.C \
|
||||
|
@ -1,54 +0,0 @@
|
||||
#include "math_exintinset.h"
|
||||
#include "math_support.h"
|
||||
#include "debug.h"
|
||||
#include "math_mathmlstream.h"
|
||||
#include "math_symbolinset.h"
|
||||
|
||||
|
||||
MathExIntInset::MathExIntInset(MathScriptInset const & scripts,
|
||||
MathArray const & core, MathArray const & diff)
|
||||
: int_(new MathSymbolInset("int")),
|
||||
scripts_(scripts), core_(core), diff_(diff)
|
||||
{}
|
||||
|
||||
|
||||
MathInset * MathExIntInset::clone() const
|
||||
{
|
||||
return new MathExIntInset(*this);
|
||||
}
|
||||
|
||||
|
||||
void MathExIntInset::write(WriteStream & os) const
|
||||
{
|
||||
scripts_.write(int_.nucleus(), os);
|
||||
os << core_ << "d" << diff_;
|
||||
}
|
||||
|
||||
|
||||
void MathExIntInset::normalize(NormalStream & os) const
|
||||
{
|
||||
//os << "[int " << scripts_ << ' ' << core_ << ' ' << diff_ << ']'
|
||||
}
|
||||
|
||||
|
||||
void MathExIntInset::metrics(MathMetricsInfo const &) const
|
||||
{
|
||||
lyxerr << "should not happen\n";
|
||||
}
|
||||
|
||||
|
||||
void MathExIntInset::draw(Painter &, int, int) const
|
||||
{
|
||||
lyxerr << "should not happen\n";
|
||||
}
|
||||
|
||||
|
||||
void MathExIntInset::maplize(MapleStream & os) const
|
||||
{
|
||||
//os << name_.c_str() << '(' << cell(0) << ')';
|
||||
}
|
||||
|
||||
void MathExIntInset::mathmlize(MathMLStream & os) const
|
||||
{
|
||||
//os << name_.c_str() << '(' << cell(0) << ')';
|
||||
}
|
@ -12,6 +12,7 @@
|
||||
#include "math_mathmlstream.h"
|
||||
#include "math_scriptinset.h"
|
||||
#include "math_stringinset.h"
|
||||
#include "math_symbolinset.h"
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
@ -43,8 +44,6 @@ string charSequence(MathArray::const_iterator it, MathArray::const_iterator end)
|
||||
MathCharInset const * p = it->nucleus()->asCharInset();
|
||||
if (p) {
|
||||
for (MathTextCodes c = p->code(); it != end; ++it) {
|
||||
if (!it->nucleus())
|
||||
break;
|
||||
p = it->nucleus()->asCharInset();
|
||||
if (!p || p->code() != c)
|
||||
break;
|
||||
@ -76,36 +75,8 @@ void extractStrings(MathArray & dat)
|
||||
}
|
||||
|
||||
|
||||
bool needAsterisk(MathAtom const &, MathAtom const &)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void guessAsterisks(MathArray & dat)
|
||||
{
|
||||
if (dat.size() <= 1)
|
||||
return;
|
||||
MathArray ar;
|
||||
ar.push_back(*dat.begin());
|
||||
MathArray::const_iterator it = dat.begin();
|
||||
MathArray::const_iterator jt = it + 1;
|
||||
for (; jt != dat.end(); ++it, ++jt) {
|
||||
if (needAsterisk(*it, *jt))
|
||||
ar.push_back(MathAtom(new MathCharInset('*')));
|
||||
ar.push_back(*it);
|
||||
}
|
||||
ar.push_back(*dat.end());
|
||||
ar.swap(dat);
|
||||
}
|
||||
|
||||
|
||||
MathInset * singleItem(MathArray & ar)
|
||||
{
|
||||
lyxerr << "ar.size: " << ar.size() << "\n";
|
||||
//lyxerr << "ar.begin: " << ar.begin() << "\n";
|
||||
//lyxerr << "ar.nuc: " << ar.begin()->nucleus() << "\n";
|
||||
lyxerr << "ar.nuc: " << *ar.begin()->nucleus() << "\n";
|
||||
return ar.size() == 1 ? ar.begin()->nucleus() : 0;
|
||||
}
|
||||
|
||||
@ -114,9 +85,7 @@ void extractMatrices(MathArray & ar)
|
||||
{
|
||||
lyxerr << "\nMatrices from: " << ar << "\n";
|
||||
for (MathArray::iterator it = ar.begin(); it != ar.end(); ++it) {
|
||||
if (!it->nucleus())
|
||||
continue;
|
||||
MathDelimInset * del = it->nucleus()->asDelimInset();
|
||||
MathDelimInset * del = (*it)->asDelimInset();
|
||||
if (!del)
|
||||
continue;
|
||||
MathInset * arr = singleItem(del->cell(0));
|
||||
@ -138,43 +107,91 @@ string extractString(MathInset * p)
|
||||
}
|
||||
|
||||
|
||||
// replace '('...')' sequences by a real MathDelimInset
|
||||
void extractDelims(MathArray & ar) {
|
||||
// define a function for tests
|
||||
typedef bool TestItemFunc(MathInset *);
|
||||
|
||||
// define a function for replacing pa
|
||||
typedef MathInset * ReplaceArgumentFunc(const MathArray & ar);
|
||||
|
||||
// search end of nested sequence
|
||||
MathArray::iterator searchNestedEnd(
|
||||
MathArray::iterator it,
|
||||
MathArray::iterator last,
|
||||
TestItemFunc testOpen,
|
||||
TestItemFunc testClose
|
||||
)
|
||||
{
|
||||
for (int level = 0; it != last; ++it) {
|
||||
if (testOpen(it->nucleus()))
|
||||
++level;
|
||||
if (testClose(it->nucleus()))
|
||||
--level;
|
||||
if (level == 0)
|
||||
break;
|
||||
}
|
||||
return it;
|
||||
}
|
||||
|
||||
|
||||
// replace nested sequences by a real Insets
|
||||
void replaceNested(
|
||||
MathArray & ar,
|
||||
TestItemFunc testOpen,
|
||||
TestItemFunc testClose,
|
||||
ReplaceArgumentFunc replaceArg
|
||||
)
|
||||
{
|
||||
// use indices rather than iterators for the loop because we are going
|
||||
// to modify the array.
|
||||
lyxerr << "\nDelims from: " << ar << "\n";
|
||||
for (MathArray::size_type i = 0; i < ar.size(); ++i) {
|
||||
// check whether this is the begin of the sequence
|
||||
MathArray::iterator it = ar.begin() + i;
|
||||
if (extractString(it->nucleus()) != "(")
|
||||
if (!testOpen(it->nucleus()))
|
||||
continue;
|
||||
|
||||
// search matching closing paranthesis
|
||||
int level = 1;
|
||||
MathArray::iterator jt = it + 1;
|
||||
for (; jt != ar.end(); ++jt) {
|
||||
string s = extractString(jt->nucleus());
|
||||
if (s == "(")
|
||||
++level;
|
||||
if (s == ")")
|
||||
--level;
|
||||
if (level == 0)
|
||||
break;
|
||||
}
|
||||
// search end of sequence
|
||||
MathArray::iterator jt = searchNestedEnd(it, ar.end(), testOpen, testClose);
|
||||
if (jt == ar.end())
|
||||
continue;
|
||||
|
||||
// create a proper deliminset
|
||||
MathAtom at(new MathDelimInset("(", ")"));
|
||||
at->cell(0) = MathArray(it + 1, jt);
|
||||
// create a proper inset as replacement
|
||||
MathInset * p = replaceArg(MathArray(it + 1, jt));
|
||||
|
||||
// replace the original stuff by the new inset
|
||||
ar.erase(it + 1, jt + 1);
|
||||
*it = at;
|
||||
lyxerr << "\nDelims to: " << ar << "\n";
|
||||
(*it).reset(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool testParanOpen(MathInset * p)
|
||||
{
|
||||
return extractString(p) == "(";
|
||||
}
|
||||
|
||||
|
||||
bool testParanClose(MathInset * p)
|
||||
{
|
||||
return extractString(p) == ")";
|
||||
}
|
||||
|
||||
|
||||
MathInset * replaceByDelimInset(const MathArray & ar)
|
||||
{
|
||||
MathDelimInset * del = new MathDelimInset("(", ")");
|
||||
del->cell(0) = ar;
|
||||
return del;
|
||||
}
|
||||
|
||||
|
||||
// replace '('...')' sequences by a real MathDelimInset
|
||||
void extractDelims(MathArray & ar) {
|
||||
lyxerr << "\nDelims from: " << ar << "\n";
|
||||
replaceNested(ar, testParanOpen, testParanClose, replaceByDelimInset);
|
||||
lyxerr << "\nDelims to: " << ar << "\n";
|
||||
}
|
||||
|
||||
|
||||
// replace 'f' '(...)' and 'f' '^n' '(...)' sequences by a real MathExFuncInset
|
||||
// assume 'extractDelims' ran before
|
||||
void extractFunctions(MathArray & ar)
|
||||
@ -188,8 +205,6 @@ void extractFunctions(MathArray & ar)
|
||||
MathArray::iterator it = ar.begin() + i;
|
||||
|
||||
// is this a function name?
|
||||
if (!it->nucleus())
|
||||
continue;
|
||||
MathFuncInset * func = (*it)->asFuncInset();
|
||||
if (!func)
|
||||
continue;
|
||||
@ -226,12 +241,56 @@ void extractFunctions(MathArray & ar)
|
||||
}
|
||||
|
||||
|
||||
bool testIntSymbol(MathInset * p)
|
||||
{
|
||||
return p->asSymbolInset() && p->asSymbolInset()->name() == "int";
|
||||
}
|
||||
|
||||
|
||||
bool testSmallD(MathInset * p)
|
||||
{
|
||||
string s = extractString(p);
|
||||
return s.size() && s[0] == 'd';
|
||||
}
|
||||
|
||||
|
||||
// replace '\int' ['_^'] x 'd''x'(...)' sequences by a real MathExIntInset
|
||||
// assume 'extractDelims' ran before
|
||||
void extractIntegrals(MathArray & ar)
|
||||
{
|
||||
// we need at least three items...
|
||||
if (ar.size() <= 2)
|
||||
return;
|
||||
|
||||
lyxerr << "\nIntegrals from: " << ar << "\n";
|
||||
for (MathArray::size_type i = 0; i < ar.size() - 1; ++i) {
|
||||
MathArray::iterator it = ar.begin() + i;
|
||||
|
||||
// is this a integral name?
|
||||
if (!testIntSymbol(it->nucleus()))
|
||||
continue;
|
||||
|
||||
// search 'd'
|
||||
MathArray::iterator jt =
|
||||
searchNestedEnd(it, ar.end(), testIntSymbol, testSmallD);
|
||||
|
||||
// create a proper inset as replacement
|
||||
//MathInset * p = replaceArg(MathArray(it + 1, jt));
|
||||
|
||||
// replace the original stuff by the new inset
|
||||
//ar.erase(it + 1, jt + 1);
|
||||
//(*it).reset(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void extractStructure(MathArray & ar)
|
||||
{
|
||||
extractStrings(ar);
|
||||
extractMatrices(ar);
|
||||
extractDelims(ar);
|
||||
extractFunctions(ar);
|
||||
extractIntegrals(ar);
|
||||
}
|
||||
|
||||
|
||||
|
@ -50,7 +50,7 @@ class MathNestInset;
|
||||
class MathScriptInset;
|
||||
class MathStringInset;
|
||||
class MathSpaceInset;
|
||||
class MathMacroTemplate;
|
||||
class MathSymbolInset;
|
||||
|
||||
class NormalStream;
|
||||
class OctaveStream;
|
||||
@ -62,6 +62,7 @@ class MathArray;
|
||||
class LaTeXFeatures;
|
||||
class BufferView;
|
||||
class UpdatableInset;
|
||||
class MathMacroTemplate;
|
||||
|
||||
|
||||
class MathInset {
|
||||
@ -188,6 +189,7 @@ public:
|
||||
virtual MathScriptInset const * asScriptInset() const { return 0; }
|
||||
virtual MathSpaceInset * asSpaceInset() { return 0; }
|
||||
virtual MathStringInset * asStringInset() { return 0; }
|
||||
virtual MathSymbolInset * asSymbolInset() { return 0; }
|
||||
virtual UpdatableInset * asHyperActiveInset() const { return 0; }
|
||||
|
||||
/// identifies things that can get scripts
|
||||
|
54
src/mathed/math_limitopinset.C
Normal file
54
src/mathed/math_limitopinset.C
Normal file
@ -0,0 +1,54 @@
|
||||
#include "math_limitopinset.h"
|
||||
#include "math_support.h"
|
||||
#include "math_mathmlstream.h"
|
||||
#include "math_symbolinset.h"
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
MathLimitOpInset::MathLimitOpInset(MathScriptInset const & scripts,
|
||||
MathArray const & core)
|
||||
: int_(new MathSymbolInset("int")),
|
||||
scripts_(scripts), core_(core)
|
||||
{}
|
||||
|
||||
|
||||
MathInset * MathLimitOpInset::clone() const
|
||||
{
|
||||
return new MathLimitOpInset(*this);
|
||||
}
|
||||
|
||||
|
||||
void MathLimitOpInset::write(WriteStream & os) const
|
||||
{
|
||||
scripts_.write(int_.nucleus(), os);
|
||||
os << core_ << "d" << diff_;
|
||||
}
|
||||
|
||||
|
||||
void MathLimitOpInset::normalize(NormalStream & os) const
|
||||
{
|
||||
//os << "[int " << scripts_ << ' ' << core_ << ' ' << diff_ << ']'
|
||||
}
|
||||
|
||||
|
||||
void MathLimitOpInset::metrics(MathMetricsInfo const &) const
|
||||
{
|
||||
lyxerr << "should not happen\n";
|
||||
}
|
||||
|
||||
|
||||
void MathLimitOpInset::draw(Painter &, int, int) const
|
||||
{
|
||||
lyxerr << "should not happen\n";
|
||||
}
|
||||
|
||||
|
||||
void MathLimitOpInset::maplize(MapleStream & os) const
|
||||
{
|
||||
//os << name_.c_str() << '(' << cell(0) << ')';
|
||||
}
|
||||
|
||||
void MathLimitOpInset::mathmlize(MathMLStream & os) const
|
||||
{
|
||||
//os << name_.c_str() << '(' << cell(0) << ')';
|
||||
}
|
@ -1,16 +1,16 @@
|
||||
// -*- C++ -*-
|
||||
#ifndef MATH_EXINTINSET_H
|
||||
#define MATH_EXINTINSET_H
|
||||
#ifndef MATH_LIMITOPINSET_H
|
||||
#define MATH_LIMITOPINSET_H
|
||||
|
||||
// /\int_l^u f(x) dxin one block (as opposed to 'f','(','x',')' or 'f','x')
|
||||
// /\sum_l^u f(x) in one block
|
||||
// for interfacing external programs
|
||||
|
||||
#include "math_scriptinset.h"
|
||||
|
||||
class MathExIntInset : public MathInset {
|
||||
class MathLimitOpInset : public MathInset {
|
||||
public:
|
||||
///
|
||||
MathExIntInset(MathScriptInset const &, MathArray const &, MathArray const &);
|
||||
MathLimitOpInset(MathScriptInset const &, MathArray const &);
|
||||
///
|
||||
MathInset * clone() const;
|
||||
///
|
@ -18,17 +18,18 @@ public:
|
||||
///
|
||||
MathInset * clone() const;
|
||||
///
|
||||
bool isActive() const { return false; }
|
||||
///
|
||||
void metrics(MathMetricsInfo const & st) const;
|
||||
///
|
||||
void draw(Painter &, int x, int y) const;
|
||||
///
|
||||
void write(WriteStream & os) const;
|
||||
void substitute(MathMacro const & macro);
|
||||
|
||||
///
|
||||
void normalize(NormalStream &) const;
|
||||
///
|
||||
void substitute(MathMacro const & macro);
|
||||
///
|
||||
bool isActive() const { return false; }
|
||||
void write(WriteStream & os) const;
|
||||
|
||||
private:
|
||||
/// A number between 1 and 9
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include "math_symbolinset.h"
|
||||
#include "math_parser.h"
|
||||
#include "math_mathmlstream.h"
|
||||
#include "debug.h"
|
||||
#include "math_support.h"
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
MathSymbolInset::MathSymbolInset(const latexkeys * l)
|
||||
@ -16,18 +16,6 @@ MathInset * MathSymbolInset::clone() const
|
||||
}
|
||||
|
||||
|
||||
void MathSymbolInset::write(WriteStream & os) const
|
||||
{
|
||||
os << '\\' << sym_->name.c_str() << ' ';
|
||||
}
|
||||
|
||||
|
||||
void MathSymbolInset::normalize(NormalStream & os) const
|
||||
{
|
||||
os << "[symbol " << sym_->name.c_str() << "]";
|
||||
}
|
||||
|
||||
|
||||
MathTextCodes MathSymbolInset::code() const
|
||||
{
|
||||
switch(sym_->token) {
|
||||
@ -58,6 +46,12 @@ MathTextCodes MathSymbolInset::code2() const
|
||||
}
|
||||
|
||||
|
||||
string MathSymbolInset::name() const
|
||||
{
|
||||
return sym_->name;
|
||||
}
|
||||
|
||||
|
||||
void MathSymbolInset::metrics(MathMetricsInfo const & mi) const
|
||||
{
|
||||
mi_ = mi;
|
||||
@ -76,7 +70,7 @@ void MathSymbolInset::metrics(MathMetricsInfo const & mi) const
|
||||
mathed_string_dim(LM_TC_TEX, mi_, sym_->name, ascent_, descent_, width_);
|
||||
}
|
||||
if (isRelOp())
|
||||
width_ += mathed_char_width(LM_TC_TEX, mi_, 'I');
|
||||
width_ += mathed_char_width(LM_TC_TEX, mi_, 'I');
|
||||
}
|
||||
|
||||
|
||||
@ -112,27 +106,39 @@ bool MathSymbolInset::takesLimits() const
|
||||
}
|
||||
|
||||
|
||||
void MathSymbolInset::normalize(NormalStream & os) const
|
||||
{
|
||||
os << "[symbol " << name().c_str() << "]";
|
||||
}
|
||||
|
||||
|
||||
void MathSymbolInset::maplize(MapleStream & os) const
|
||||
{
|
||||
if (sym_->name == "cdot")
|
||||
if (name() == "cdot")
|
||||
os << '*';
|
||||
else
|
||||
os << sym_->name.c_str();
|
||||
os << name().c_str();
|
||||
}
|
||||
|
||||
|
||||
void MathSymbolInset::mathmlize(MathMLStream & os) const
|
||||
{
|
||||
os << sym_->name.c_str();
|
||||
os << name().c_str();
|
||||
}
|
||||
|
||||
|
||||
void MathSymbolInset::octavize(OctaveStream & os) const
|
||||
{
|
||||
if (sym_->name == "cdot")
|
||||
if (name() == "cdot")
|
||||
os << '*';
|
||||
else
|
||||
os << sym_->name.c_str();
|
||||
os << name().c_str();
|
||||
}
|
||||
|
||||
|
||||
void MathSymbolInset::write(WriteStream & os) const
|
||||
{
|
||||
os << '\\' << name().c_str() << ' ';
|
||||
}
|
||||
|
||||
|
||||
|
@ -18,10 +18,6 @@ public:
|
||||
///
|
||||
MathInset * clone() const;
|
||||
///
|
||||
void write(WriteStream & os) const;
|
||||
///
|
||||
void normalize(NormalStream &) const;
|
||||
///
|
||||
void metrics(MathMetricsInfo const & st) const;
|
||||
///
|
||||
void draw(Painter &, int x, int y) const;
|
||||
@ -31,13 +27,21 @@ public:
|
||||
bool isScriptable() const;
|
||||
/// identifies things that can get \limits or \nolimits
|
||||
bool takesLimits() const;
|
||||
///
|
||||
MathSymbolInset * asSymbolInset() { return this; }
|
||||
|
||||
///
|
||||
void normalize(NormalStream &) const;
|
||||
///
|
||||
void maplize(MapleStream &) const;
|
||||
///
|
||||
void mathmlize(MathMLStream &) const;
|
||||
///
|
||||
void octavize(OctaveStream &) const;
|
||||
///
|
||||
void write(WriteStream & os) const;
|
||||
///
|
||||
string name() const;
|
||||
private:
|
||||
///
|
||||
MathTextCodes code() const;
|
||||
|
Loading…
Reference in New Issue
Block a user