mathed67.diff

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1968 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2001-04-27 12:35:55 +00:00
parent 256339c2c3
commit b9d25422e0
20 changed files with 149 additions and 124 deletions

View File

@ -1,7 +1,25 @@
2001-04-27 André Pönitz <poenitz@htwm.de>
* math_parser.C: fix \frac handling bug introduced on 04-24
* math_xiter.C: hotfix for merging "shared" insets
2001-04-25 André Pönitz <poenitz@htwm.de>
* math_*.[Ch]: WriteNormal
* formula.C: Support for new "math extern" command
2001-04-25 Lars Gullik Bjønnes <larsbj@birdstep.com> 2001-04-25 Lars Gullik Bjønnes <larsbj@birdstep.com>
* math_macrotable.C: include <iostream> * math_macrotable.C: include <iostream>
2001-04-24 André Pönitz <poenitz@htwm.de>
* math_macro.[Ch]:
* math_macrotable.[Ch]:
* math_macroarg.[Ch]: restructuring of macro handling
* several files:
2001-04-25 Angus Leeming <a.leeming@ic.ac.uk> 2001-04-25 Angus Leeming <a.leeming@ic.ac.uk>
* array.h (operator<<): * array.h (operator<<):

View File

@ -96,6 +96,19 @@ void MathedArray::substitute(MathMacro * m)
inset = m->arg(n)->Clone(); inset = m->arg(n)->Clone();
} else { } else {
inset->substitute(m); inset->substitute(m);
/*
if (it.IsActive()) {
MathParInset * pinset = static_cast<MathParInset *>(inset);
int n = pinset->getMaxArgumentIdx();
int idx = pinset->getArgumentIdx();
for (int i = 0; i <= n; ++i) {
pinset->setArgumentIdx(i);
pinset->GetData().substitute(m);
}
pinset->setArgumentIdx(idx);
}
*/
//lyxerr << "substituting in an ordinary inset\n"; //lyxerr << "substituting in an ordinary inset\n";
} }
raw_pointer_insert(inset, it.getPos() + 1); raw_pointer_insert(inset, it.getPos() + 1);
@ -112,6 +125,22 @@ MathedArray & MathedArray::operator=(MathedArray const & array)
return *this; return *this;
} }
void MathedArray::push_back(MathedInset * inset, int t)
{
MathedIter it(this);
while (it.Next())
;
it.insertInset(inset, t);
}
void MathedArray::push_back(byte b, MathedTextCodes c)
{
MathedIter it(this);
while (it.Next())
;
it.insert(b, c);
}
void MathedArray::clear() void MathedArray::clear()
{ {
last_ = 0; last_ = 0;

View File

@ -20,6 +20,7 @@
#include <iosfwd> #include <iosfwd>
#include "mathed/support.h" #include "mathed/support.h"
#include "math_defs.h"
class MathedInset; class MathedInset;
class MathMacro; class MathMacro;
@ -120,6 +121,10 @@ public:
void deep_copy(); void deep_copy();
/// ///
void substitute(MathMacro *); void substitute(MathMacro *);
///
void push_back(MathedInset * inset, int t);
///
void push_back(byte, MathedTextCodes);
private: private:
/// Buffer /// Buffer
buffer_type bf_; buffer_type bf_;

View File

@ -115,24 +115,25 @@ void MathAccentInset::Write(ostream & os, bool fragile)
os << '}'; os << '}';
} }
void MathAccentInset::WriteNormal(ostream & os) void MathAccentInset::WriteNormal(ostream & os)
{ {
latexkeys const * l = lm_get_key_by_id(code, LM_TK_ACCENT); latexkeys const * l = lm_get_key_by_id(code, LM_TK_ACCENT);
os << "{accent " << l->name << " "; os << "[accent " << l->name << " ";
if (inset) { if (inset) {
inset->WriteNormal(os); inset->WriteNormal(os);
} else { } else {
if (fn>= LM_TC_RM && fn <= LM_TC_TEXTRM) { if (fn>= LM_TC_RM && fn <= LM_TC_TEXTRM) {
os << "{font " << math_font_name[fn - LM_TC_RM] << "}"; os << "[font " << math_font_name[fn - LM_TC_RM] << "]";
} }
if (MathIsSymbol(fn)) { if (MathIsSymbol(fn)) {
latexkeys const * l = lm_get_key_by_id(c, LM_TK_SYM); latexkeys const * l = lm_get_key_by_id(c, LM_TK_SYM);
if (l) if (l)
os << "{symbol " << l->name << "}"; os << "[symbol " << l->name << "] ";
} else } else
os << "{char " << char(c) << "}"; os << "[char " << char(c) << "] ";
} }
os << "} "; os << "] ";
} }

View File

@ -19,8 +19,7 @@ MathedInset * MathBigopInset::Clone()
} }
void void MathBigopInset::draw(Painter & pain, int x, int y)
MathBigopInset::draw(Painter & pain, int x, int y)
{ {
string s; string s;
short t; short t;
@ -63,7 +62,7 @@ void MathBigopInset::WriteNormal(ostream & os)
{ {
bool const limp = GetLimits(); bool const limp = GetLimits();
os << "{bigop " << name; os << "[bigop " << name;
if (limp && !(sym_ != LM_int && sym_ != LM_oint if (limp && !(sym_ != LM_int && sym_ != LM_oint
&& (GetStyle() == LM_ST_DISPLAY))) && (GetStyle() == LM_ST_DISPLAY)))
@ -73,7 +72,7 @@ void MathBigopInset::WriteNormal(ostream & os)
&& (GetStyle() == LM_ST_DISPLAY))) && (GetStyle() == LM_ST_DISPLAY)))
os << " nolimits"; os << " nolimits";
os << "} "; os << "] ";
} }
void MathBigopInset::Metrics() void MathBigopInset::Metrics()

View File

@ -50,7 +50,8 @@ void MathDotsInset::Write(ostream & os, bool /* fragile */)
os << '\\' << name << ' '; os << '\\' << name << ' ';
} }
void MathDotsInset::WriteNormal(ostream & os) void MathDotsInset::WriteNormal(ostream & os)
{ {
os << "{" << name << "} "; os << "[" << name << "] ";
} }

View File

@ -165,6 +165,11 @@ void MathFracInset::Metrics()
idx_ = idxp; idx_ = idxp;
} }
MathParInset * MathFracInset::denom()
{
return &den_;
}
void MathFracInset::Write(ostream & os, bool fragile) void MathFracInset::Write(ostream & os, bool fragile)
{ {
@ -175,11 +180,12 @@ void MathFracInset::Write(ostream & os, bool fragile)
os << '}'; os << '}';
} }
void MathFracInset::WriteNormal(ostream & os) void MathFracInset::WriteNormal(ostream & os)
{ {
os << '{' << name << ' '; os << '[' << name << ' ';
MathParInset::WriteNormal(os); MathParInset::WriteNormal(os);
os << " "; os << " ";
den_.WriteNormal(os); den_.WriteNormal(os);
os << "} "; os << "] ";
} }

View File

@ -50,6 +50,8 @@ public:
int getMaxArgumentIdx() const; int getMaxArgumentIdx() const;
/// ///
void SetStyle(short); void SetStyle(short);
///
MathParInset * denom();
private: private:
/// ///
int idx_; int idx_;

View File

@ -47,9 +47,10 @@ void MathFuncInset::Write(std::ostream & os, bool /* fragile */)
os << "\\" << name << ' '; os << "\\" << name << ' ';
} }
void MathFuncInset::WriteNormal(std::ostream & os) void MathFuncInset::WriteNormal(std::ostream & os)
{ {
os << "{" << name << "} "; os << "[" << name << "] ";
} }

View File

@ -1,10 +1,10 @@
#include <config.h> #include <config.h>
#include <map> #include <map>
#include "math_defs.h" #include "math_defs.h"
#include "math_parser.h" #include "math_parser.h"
#include "support/lstrings.h"
namespace { namespace {

View File

@ -287,8 +287,10 @@ void MathMacro::Write(ostream & os, bool fragile)
void MathMacro::WriteNormal(ostream & os) void MathMacro::WriteNormal(ostream & os)
{ {
os << "{macro " << name << " "; os << "[macro " << name << " ";
for (int i = 0; i < nargs(); ++i) for (int i = 0; i < nargs(); ++i) {
arg(i)->WriteNormal(os); arg(i)->WriteNormal(os);
os << "} "; os << ' ';
}
os << "] ";
} }

View File

@ -67,5 +67,5 @@ void MathMacroArgument::Write(std::ostream & os, bool /*fragile*/)
void MathMacroArgument::WriteNormal(std::ostream & os) void MathMacroArgument::WriteNormal(std::ostream & os)
{ {
os << "{macroarg " << number_ << "} "; os << "[macroarg " << number_ << "] ";
} }

View File

@ -9,7 +9,6 @@
#include "math_macrotable.h" #include "math_macrotable.h"
#include "math_macro.h" #include "math_macro.h"
#include "math_macrotemplate.h" #include "math_macrotemplate.h"
#include "math_iter.h"
#include "array.h" #include "array.h"
#include "math_accentinset.h" #include "math_accentinset.h"
#include "math_deliminset.h" #include "math_deliminset.h"
@ -85,9 +84,7 @@ void MathMacroTable::builtinMacros()
// This macro doesn't have arguments // This macro doesn't have arguments
{ {
MathMacroTemplate & m = provideTemplate("notin", 0); MathMacroTemplate & m = provideTemplate("notin", 0);
MathedIter iter(&m.GetData()); m.push_back(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not), LM_TC_INSET);
iter.insertInset(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not),
LM_TC_INSET);
} }
// This macro doesn't have arguments // This macro doesn't have arguments
@ -99,18 +96,14 @@ void MathMacroTable::builtinMacros()
mathed_parse(m.array, p, 0); mathed_parse(m.array, p, 0);
} }
// These two are only while we are still with LyX 2.x
{ {
MathMacroTemplate & m = provideTemplate("emptyset", 0); MathMacroTemplate & m = provideTemplate("emptyset", 0);
MathedIter iter(&m.GetData()); m.push_back(new MathAccentInset('0', LM_TC_RM, LM_not), LM_TC_INSET);
iter.insertInset(new MathAccentInset('0', LM_TC_RM, LM_not),
LM_TC_INSET);
} }
{ {
MathMacroTemplate & m = provideTemplate("perp", 0); MathMacroTemplate & m = provideTemplate("perp", 0);
MathedIter iter(&m.GetData()); m.GetData().push_back(LM_bot, LM_TC_BOP);
iter.insert(LM_bot, LM_TC_BOP);
} }
{ {
@ -121,70 +114,16 @@ void MathMacroTable::builtinMacros()
mathed_parse(m.array, p, 0); mathed_parse(m.array, p, 0);
} }
// binom has two arguments
{ {
MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
frac->push_back(new MathMacroArgument(1), LM_TC_INSET);
frac->denom()->push_back(new MathMacroArgument(2), LM_TC_INSET);
MathParInset * inset = new MathDelimInset('(', ')');
inset->push_back(frac, LM_TC_ACTIVE_INSET);
MathMacroTemplate & m = provideTemplate("binom", 2); MathMacroTemplate & m = provideTemplate("binom", 2);
istringstream is("\\choose{#1}{#2}"); m.push_back(inset, LM_TC_ACTIVE_INSET);
mathed_parser_file(is, 0);
MathParInset * p = &m;
mathed_parse(m.array, p, 0);
} }
// binom has two arguments
{
MathMacroTemplate & m = provideTemplate("binom1", 2);
MathedIter iter(&m.GetData());
MathParInset * inset = new MathDelimInset('(', ')');
iter.insertInset(inset, LM_TC_ACTIVE_INSET);
MathedArray array2;
MathedIter iter2(&array2);
MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
iter2.insertInset(frac, LM_TC_ACTIVE_INSET);
frac->setData(array2);
MathedArray array3;
MathedIter iter3(&array3);
iter3.insertInset(new MathMacroArgument(1), LM_TC_INSET);
MathedArray array4;
MathedIter iter4(&array4);
iter4.insertInset(new MathMacroArgument(2), LM_TC_INSET);
frac->SetData(array3, array4);
}
/*
{
boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("perp", 0));
addTemplate(m);
MathedArray array;
MathedIter iter(&array);
iter.insert(LM_bot, LM_TC_BOP);
m->setData(array);
}
// binom has two arguments
{
boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("binom", 2));
addTemplate(m);
MathedArray array;
m->setData(array);
MathedIter iter(&array);
MathParInset * inset = new MathDelimInset('(', ')');
iter.insertInset(inset, LM_TC_ACTIVE_INSET);
array = MathedArray();
MathedIter iter2(&array);
MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
iter2.insertInset(frac, LM_TC_ACTIVE_INSET);
inset->setData(array);
array = MathedArray();
MathedArray array2;
MathedIter iter3(&array);
iter3.insertInset(m->getMacroPar(0), LM_TC_INSET);
MathedIter iter4(&array2);
iter4.insertInset(m->getMacroPar(1), LM_TC_INSET);
frac->SetData(array, array2);
}
*/
} }

View File

@ -411,11 +411,11 @@ void MathParInset::Write(ostream & os, bool fragile)
void MathParInset::WriteNormal(ostream & os) void MathParInset::WriteNormal(ostream & os)
{ {
if (array.empty()) { if (array.empty()) {
os << "{}"; os << "[par] ";
return; return;
} }
os << "{par "; os << "[par ";
int brace = 0; int brace = 0;
latexkeys const * l; latexkeys const * l;
@ -435,7 +435,7 @@ void MathParInset::WriteNormal(ostream & os)
string str = data.GetString(); string str = data.GetString();
if (data.fcode() >= LM_TC_RM && data.fcode() <= LM_TC_TEXTRM) { if (data.fcode() >= LM_TC_RM && data.fcode() <= LM_TC_TEXTRM) {
os << "{font " << math_font_name[data.fcode()-LM_TC_RM] << '{'; os << "[font " << math_font_name[data.fcode()-LM_TC_RM] << " [";
} }
for (string::const_iterator s = str.begin(); for (string::const_iterator s = str.begin();
s != str.end(); ++s) { s != str.end(); ++s) {
@ -444,7 +444,7 @@ void MathParInset::WriteNormal(ostream & os)
l = lm_get_key_by_id(c, (data.fcode() == LM_TC_BSYM) ? l = lm_get_key_by_id(c, (data.fcode() == LM_TC_BSYM) ?
LM_TK_BIGSYM : LM_TK_SYM); LM_TK_BIGSYM : LM_TK_SYM);
if (l) { if (l) {
os << '{' << l->name << '}'; os << " [" << l->name << "] ";
} else { } else {
#ifdef WITH_WARNINGS #ifdef WITH_WARNINGS
#warning this does not compile on gcc 2.97 #warning this does not compile on gcc 2.97
@ -456,7 +456,7 @@ void MathParInset::WriteNormal(ostream & os)
// Is there a standard logical XOR? // Is there a standard logical XOR?
if ((data.fcode() == LM_TC_TEX && c != '{' && c != '}') || if ((data.fcode() == LM_TC_TEX && c != '{' && c != '}') ||
(data.fcode() == LM_TC_SPECIAL)) (data.fcode() == LM_TC_SPECIAL))
os << '{'; os << "[";
else { else {
if (c == '{') if (c == '{')
++brace; ++brace;
@ -471,29 +471,29 @@ void MathParInset::WriteNormal(ostream & os)
} }
} }
if (data.fcode()>= LM_TC_RM && data.fcode()<= LM_TC_TEXTRM) if (data.fcode()>= LM_TC_RM && data.fcode()<= LM_TC_TEXTRM)
os << "} "; os << "] ";
} else { } else {
if (MathIsInset(cx)) { if (MathIsInset(cx)) {
MathedInset * p = data.GetInset(); MathedInset * p = data.GetInset();
if (cx == LM_TC_UP) if (cx == LM_TC_UP)
os << "{superscript "; os << "[superscript ";
if (cx == LM_TC_DOWN) if (cx == LM_TC_DOWN)
os << "{subscript "; os << "[subscript ";
p->WriteNormal(os); p->WriteNormal(os);
if (cx == LM_TC_UP || cx == LM_TC_DOWN) if (cx == LM_TC_UP || cx == LM_TC_DOWN)
os << "} "; os << "] ";
data.Next(); data.Next();
} else { } else {
switch (cx) { switch (cx) {
case LM_TC_TAB: case LM_TC_TAB:
{ {
os << "} {"; os << "] [";
data.Next(); data.Next();
break; break;
} }
case LM_TC_CR: case LM_TC_CR:
{ {
os << "}} "; os << "] ] ";
data.Next(); data.Next();
break; break;
} }
@ -508,7 +508,7 @@ void MathParInset::WriteNormal(ostream & os)
if (brace > 0) if (brace > 0)
os << string(brace, '}'); os << string(brace, '}');
os << "} "; os << "] ";
} }
@ -563,6 +563,11 @@ MathedArray & MathParInset::GetData()
return array; return array;
} }
void MathParInset::push_back(MathedInset * inset, int t)
{
array.push_back(inset, t);
}
MathedArray const & MathParInset::GetData() const MathedArray const & MathParInset::GetData() const
{ {

View File

@ -42,6 +42,8 @@ public:
virtual MathedArray & GetData(); virtual MathedArray & GetData();
/// ///
virtual MathedArray const & GetData() const; virtual MathedArray const & GetData() const;
///
//virtual MathedArray & GetData(int i);
/// Paragraph position /// Paragraph position
virtual void GetXY(int &, int &) const; virtual void GetXY(int &, int &) const;
/// ///
@ -82,6 +84,8 @@ public:
void clear(); void clear();
/// ///
string label() const; string label() const;
///
void push_back(MathedInset *, int);
//protected: //protected:
/// Paragraph data is stored here /// Paragraph data is stored here
MathedArray array; MathedArray array;

View File

@ -141,7 +141,6 @@ istream * yyis;
bool yy_mtextmode= false; bool yy_mtextmode= false;
inline
void mathPrintError(string const & msg) void mathPrintError(string const & msg)
{ {
lyxerr << "Line ~" << yylineno << ": Math parse error: " << msg << endl; lyxerr << "Line ~" << yylineno << ": Math parse error: " << msg << endl;
@ -346,7 +345,6 @@ int yylex(void)
} }
inline
int parse_align(char * hor, char *) int parse_align(char * hor, char *)
{ {
int nc = 0; int nc = 0;
@ -359,7 +357,6 @@ int parse_align(char * hor, char *)
int accent = 0; int accent = 0;
int nestaccent[8]; int nestaccent[8];
inline
void setAccent(int ac) void setAccent(int ac)
{ {
if (ac > 0 && accent < 8) if (ac > 0 && accent < 8)
@ -409,6 +406,18 @@ void do_insert(MathedIter & it, MathedInset * m, MathedTextCodes t)
it.insertInset(m, t); it.insertInset(m, t);
} }
void handle_frac(MathedIter & it, MathParInset * & par, MathedInsetTypes t)
{
MathFracInset fc(t);
MathedArray num;
mathed_parse(num, par, FLAG_BRACE|FLAG_BRACE_LAST);
MathedArray den;
mathed_parse(den, par, FLAG_BRACE|FLAG_BRACE_LAST);
fc.SetData(num, den);
it.insertInset(fc.Clone(), LM_TC_ACTIVE_INSET);
}
} // namespace anon } // namespace anon
@ -675,18 +684,16 @@ void mathed_parse(MathedArray & array, MathParInset * & par, unsigned flags)
} }
case LM_TK_CHOOSE: case LM_TK_CHOOSE:
case LM_TK_STACK: handle_frac(data, par, LM_OT_ATOP);
case LM_TK_FRAC: break;
{
MathFracInset fc(t); case LM_TK_STACK:
MathedArray num; handle_frac(data, par, LM_OT_STACKREL);
mathed_parse(num, par, FLAG_BRACE|FLAG_BRACE_LAST); break;
MathedArray den;
mathed_parse(den, par, FLAG_BRACE|FLAG_BRACE_LAST); case LM_TK_FRAC:
fc.SetData(num, den); handle_frac(data, par, LM_OT_FRAC);
data.insertInset(fc.Clone(), LM_TC_ACTIVE_INSET);
break; break;
}
case LM_TK_SQRT: case LM_TK_SQRT:
{ {

View File

@ -154,11 +154,12 @@ void MathRootInset::Write(ostream & os, bool fragile)
os << '}'; os << '}';
} }
void MathRootInset::WriteNormal(ostream & os) void MathRootInset::WriteNormal(ostream & os)
{ {
os << "{root "; os << "[root ";
uroot_.WriteNormal(os); uroot_.WriteNormal(os);
os << " "; os << " ";
MathParInset::WriteNormal(os); MathParInset::WriteNormal(os);
os << "} "; os << "] ";
} }

View File

@ -52,7 +52,7 @@ void MathSpaceInset::Write(ostream & os, bool /* fragile */)
void MathSpaceInset::WriteNormal(ostream & os) void MathSpaceInset::WriteNormal(ostream & os)
{ {
os << "{space " << space_ << "} "; os << "[space " << space_ << "] ";
} }

View File

@ -51,9 +51,9 @@ void MathSqrtInset::Write(ostream & os, bool fragile)
void MathSqrtInset::WriteNormal(ostream & os) void MathSqrtInset::WriteNormal(ostream & os)
{ {
os << "{sqrt "; os << "[sqrt ";
MathParInset::WriteNormal(os); MathParInset::WriteNormal(os);
os << "} "; os << "] ";
} }

View File

@ -137,8 +137,13 @@ void MathedXIter::Clean(int pos2)
} }
void MathedXIter::Merge(MathedArray const & a) void MathedXIter::Merge(MathedArray const & arr)
{ {
#ifdef WITH_WARNINGS
#warning quick and really dirty: make sure that we really own our inset
#endif
MathedArray a = arr;
#if 0 #if 0
array->insert(array->begin() + pos, array->insert(array->begin() + pos,
a.begin(), a.end()); a.begin(), a.end());