+
+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>
* 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>
* array.h (operator<<):
inset = m->arg(n)->Clone();
} else {
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";
}
raw_pointer_insert(inset, it.getPos() + 1);
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()
{
last_ = 0;
#include <iosfwd>
#include "mathed/support.h"
+#include "math_defs.h"
class MathedInset;
class MathMacro;
void deep_copy();
///
void substitute(MathMacro *);
+ ///
+ void push_back(MathedInset * inset, int t);
+ ///
+ void push_back(byte, MathedTextCodes);
private:
/// Buffer
buffer_type bf_;
os << '}';
}
+
void MathAccentInset::WriteNormal(ostream & os)
{
latexkeys const * l = lm_get_key_by_id(code, LM_TK_ACCENT);
- os << "{accent " << l->name << " ";
+ os << "[accent " << l->name << " ";
if (inset) {
inset->WriteNormal(os);
} else {
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)) {
latexkeys const * l = lm_get_key_by_id(c, LM_TK_SYM);
if (l)
- os << "{symbol " << l->name << "}";
+ os << "[symbol " << l->name << "] ";
} else
- os << "{char " << char(c) << "}";
+ os << "[char " << char(c) << "] ";
}
- os << "} ";
+ os << "] ";
}
}
-void
-MathBigopInset::draw(Painter & pain, int x, int y)
+void MathBigopInset::draw(Painter & pain, int x, int y)
{
string s;
short t;
{
bool const limp = GetLimits();
- os << "{bigop " << name;
+ os << "[bigop " << name;
if (limp && !(sym_ != LM_int && sym_ != LM_oint
&& (GetStyle() == LM_ST_DISPLAY)))
&& (GetStyle() == LM_ST_DISPLAY)))
os << " nolimits";
- os << "} ";
+ os << "] ";
}
void MathBigopInset::Metrics()
os << '\\' << name << ' ';
}
+
void MathDotsInset::WriteNormal(ostream & os)
{
- os << "{" << name << "} ";
+ os << "[" << name << "] ";
}
idx_ = idxp;
}
+MathParInset * MathFracInset::denom()
+{
+ return &den_;
+}
+
void MathFracInset::Write(ostream & os, bool fragile)
{
os << '}';
}
+
void MathFracInset::WriteNormal(ostream & os)
{
- os << '{' << name << ' ';
+ os << '[' << name << ' ';
MathParInset::WriteNormal(os);
os << " ";
den_.WriteNormal(os);
- os << "} ";
+ os << "] ";
}
int getMaxArgumentIdx() const;
///
void SetStyle(short);
+ ///
+ MathParInset * denom();
private:
///
int idx_;
os << "\\" << name << ' ';
}
+
void MathFuncInset::WriteNormal(std::ostream & os)
{
- os << "{" << name << "} ";
+ os << "[" << name << "] ";
}
-
#include <config.h>
#include <map>
#include "math_defs.h"
#include "math_parser.h"
+#include "support/lstrings.h"
namespace {
void MathMacro::WriteNormal(ostream & os)
{
- os << "{macro " << name << " ";
- for (int i = 0; i < nargs(); ++i)
+ os << "[macro " << name << " ";
+ for (int i = 0; i < nargs(); ++i) {
arg(i)->WriteNormal(os);
- os << "} ";
+ os << ' ';
+ }
+ os << "] ";
}
void MathMacroArgument::WriteNormal(std::ostream & os)
{
- os << "{macroarg " << number_ << "} ";
+ os << "[macroarg " << number_ << "] ";
}
#include "math_macrotable.h"
#include "math_macro.h"
#include "math_macrotemplate.h"
-#include "math_iter.h"
#include "array.h"
#include "math_accentinset.h"
#include "math_deliminset.h"
// This macro doesn't have arguments
{
MathMacroTemplate & m = provideTemplate("notin", 0);
- MathedIter iter(&m.GetData());
- iter.insertInset(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not),
- LM_TC_INSET);
+ m.push_back(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not), LM_TC_INSET);
}
// This macro doesn't have arguments
mathed_parse(m.array, p, 0);
}
- // These two are only while we are still with LyX 2.x
{
MathMacroTemplate & m = provideTemplate("emptyset", 0);
- MathedIter iter(&m.GetData());
- iter.insertInset(new MathAccentInset('0', LM_TC_RM, LM_not),
- LM_TC_INSET);
+ m.push_back(new MathAccentInset('0', LM_TC_RM, LM_not), LM_TC_INSET);
}
{
MathMacroTemplate & m = provideTemplate("perp", 0);
- MathedIter iter(&m.GetData());
- iter.insert(LM_bot, LM_TC_BOP);
+ m.GetData().push_back(LM_bot, LM_TC_BOP);
}
{
mathed_parse(m.array, p, 0);
}
- {
- MathMacroTemplate & m = provideTemplate("binom", 2);
- istringstream is("\\choose{#1}{#2}");
- 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);
+ frac->push_back(new MathMacroArgument(1), LM_TC_INSET);
+ frac->denom()->push_back(new MathMacroArgument(2), 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);
+ inset->push_back(frac, LM_TC_ACTIVE_INSET);
+
+ MathMacroTemplate & m = provideTemplate("binom", 2);
+ m.push_back(inset, LM_TC_ACTIVE_INSET);
}
-*/
}
void MathParInset::WriteNormal(ostream & os)
{
if (array.empty()) {
- os << "{}";
+ os << "[par] ";
return;
}
- os << "{par ";
+ os << "[par ";
int brace = 0;
latexkeys const * l;
string str = data.GetString();
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();
s != str.end(); ++s) {
l = lm_get_key_by_id(c, (data.fcode() == LM_TC_BSYM) ?
LM_TK_BIGSYM : LM_TK_SYM);
if (l) {
- os << '{' << l->name << '}';
+ os << " [" << l->name << "] ";
} else {
#ifdef WITH_WARNINGS
#warning this does not compile on gcc 2.97
// Is there a standard logical XOR?
if ((data.fcode() == LM_TC_TEX && c != '{' && c != '}') ||
(data.fcode() == LM_TC_SPECIAL))
- os << '{';
+ os << "[";
else {
if (c == '{')
++brace;
}
}
if (data.fcode()>= LM_TC_RM && data.fcode()<= LM_TC_TEXTRM)
- os << "} ";
+ os << "] ";
} else {
if (MathIsInset(cx)) {
MathedInset * p = data.GetInset();
if (cx == LM_TC_UP)
- os << "{superscript ";
+ os << "[superscript ";
if (cx == LM_TC_DOWN)
- os << "{subscript ";
+ os << "[subscript ";
p->WriteNormal(os);
if (cx == LM_TC_UP || cx == LM_TC_DOWN)
- os << "} ";
+ os << "] ";
data.Next();
} else {
switch (cx) {
case LM_TC_TAB:
{
- os << "} {";
+ os << "] [";
data.Next();
break;
}
case LM_TC_CR:
{
- os << "}} ";
+ os << "] ] ";
data.Next();
break;
}
if (brace > 0)
os << string(brace, '}');
- os << "} ";
+ os << "] ";
}
return array;
}
+void MathParInset::push_back(MathedInset * inset, int t)
+{
+ array.push_back(inset, t);
+}
+
MathedArray const & MathParInset::GetData() const
{
virtual MathedArray & GetData();
///
virtual MathedArray const & GetData() const;
+ ///
+ //virtual MathedArray & GetData(int i);
/// Paragraph position
virtual void GetXY(int &, int &) const;
///
void clear();
///
string label() const;
+ ///
+ void push_back(MathedInset *, int);
//protected:
/// Paragraph data is stored here
MathedArray array;
bool yy_mtextmode= false;
-inline
void mathPrintError(string const & msg)
{
lyxerr << "Line ~" << yylineno << ": Math parse error: " << msg << endl;
}
-inline
int parse_align(char * hor, char *)
{
int nc = 0;
int accent = 0;
int nestaccent[8];
-inline
void setAccent(int ac)
{
if (ac > 0 && accent < 8)
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
}
case LM_TK_CHOOSE:
+ handle_frac(data, par, LM_OT_ATOP);
+ break;
+
case LM_TK_STACK:
+ handle_frac(data, par, LM_OT_STACKREL);
+ break;
+
case LM_TK_FRAC:
- {
- 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);
- data.insertInset(fc.Clone(), LM_TC_ACTIVE_INSET);
+ handle_frac(data, par, LM_OT_FRAC);
break;
- }
-
+
case LM_TK_SQRT:
{
char c;
os << '}';
}
+
void MathRootInset::WriteNormal(ostream & os)
{
- os << "{root ";
+ os << "[root ";
uroot_.WriteNormal(os);
os << " ";
MathParInset::WriteNormal(os);
- os << "} ";
+ os << "] ";
}
void MathSpaceInset::WriteNormal(ostream & os)
{
- os << "{space " << space_ << "} ";
+ os << "[space " << space_ << "] ";
}
void MathSqrtInset::WriteNormal(ostream & os)
{
- os << "{sqrt ";
+ os << "[sqrt ";
MathParInset::WriteNormal(os);
- os << "} ";
+ os << "] ";
}
}
-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
array->insert(array->begin() + pos,
a.begin(), a.end());