-2001-08-13 Angus Leeming <a.leeming@ic.ac.uk>
-
- * math_parser.C (lexArg): remove default argument from the .C file
- as it causes DEC cxx to complain about a redefinition.
-
2001-08-13 André Pönitz <poenitz@gmx.net>
* math_factory.[Ch]: new files for the creation of math insets
* math_parser.C:
math_cursor.C: reading support for TeX style \over and \choose
+ * formulabase.C: re-enabling the "selected text gets converted to
+ math when pressing C-m" feature.
+
+2001-08-13 Angus Leeming <a.leeming@ic.ac.uk>
+
+ * math_parser.C (lexArg): remove default argument from the .C file
+ as it causes DEC cxx to complain about a redefinition.
+
2001-08-10 André Pönitz <poenitz@gmx.net>
* math_scopeinset.[Ch]: new inset for {} blocks
using std::endl;
using std::vector;
-extern char const * latex_mathenv[];
-extern MathCursor * mathcursor;
-
InsetFormula::InsetFormula()
: par_(new MathMatrixInset)
InsetFormula::InsetFormula(string const & s)
: par_(mathed_parse_normal(s))
{
+ if (!par_)
+ par_ = mathed_parse_normal("$" + s + "$");
+
+ if (!par_) {
+ lyxerr << "cannot interpret '" << s << "' as math\n";
+ par_ = new MathMatrixInset(LM_OT_SIMPLE);
+ }
metrics();
}
write(os);
}
+
int InsetFormulaBase::latex(Buffer const *, ostream & os,
bool fragile, bool spacing) const
{
return latex(os, fragile, spacing);
}
+
int InsetFormulaBase::ascii(Buffer const *, ostream & os, int spacing) const
{
return ascii(os, spacing);
}
+
int InsetFormulaBase::linuxdoc(Buffer const *, ostream & os) const
{
return linuxdoc(os);
}
+
int InsetFormulaBase::docBook(Buffer const *, ostream & os) const
{
return docBook(os);
void InsetFormulaBase::edit(BufferView * bv, bool front)
{
+ // looks hackish but seems to work
edit(bv, front ? 0 : 1, 0, 0);
}
void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
{
if (bv->available()) {
-// Feature "Read math inset from selection" disabled.
-// // use selection if available..
-// string sel;
-// if (action == LFUN_MATH_IMPORT_SELECTION)
-// sel = "";
-// else
-// sel = bv->getLyXText()->selectionAsString(bv->buffer());
-
- InsetFormula * f;
-// if (sel.empty()) {
+ // use selection if available..
+ //string sel;
+ //if (action == LFUN_MATH_IMPORT_SELECTION)
+ // sel = "";
+ //else
+
+ string sel = bv->getLyXText()->selectionAsString(bv->buffer());
+
+ InsetFormulaBase * f;
+ if (sel.empty()) {
f = new InsetFormula;
if (openNewInset(bv, f)) {
// don't do that also for LFUN_MATH_MODE unless you want end up with
f->localDispatch(bv, LFUN_MATH_DISPLAY, string());
f->localDispatch(bv, LFUN_INSERT_MATH, arg);
}
-// } else {
-// f = new InsetFormula(sel);
-// bv->getLyXText()->cutSelection(bv);
-// openNewInset(bv, f);
-// }
+ } else {
+ // create a macro if we see "\\newcommand" somewhere, and an ordinary
+ // formula otherwise
+ if (sel.find("\\newcommand") == string::npos)
+ f = new InsetFormula(sel);
+ else
+ f = new InsetFormulaMacro(sel);
+ bv->getLyXText()->cutSelection(bv);
+ openNewInset(bv, f);
+ }
}
bv->owner()->getLyXFunc()->setMessage(N_("Math editor mode"));
}
{
mathDispatchCreation(bv, arg, true);
}
+
void mathDispatchMathMode(BufferView * bv, string const & arg)
{
mathDispatchCreation(bv, arg, false);
}
+
void mathDispatchMathImportSelection(BufferView * bv, string const & arg)
{
mathDispatchCreation(bv, arg, true);
}
+
void mathDispatchMathMacro(BufferView * bv, string const & arg)
{
if (bv->available()) {
}
}
+
void mathDispatchMathDelim(BufferView * bv, string const & arg)
{
if (bv->available()) {
}
}
+
void mathDispatchInsertMath(BufferView * bv, string const & arg)
{
if (bv->available()) {
InsetFormulaMacro::InsetFormulaMacro()
{
+ // inset name is inherited from Inset
setInsetName("unknown");
}
}
+InsetFormulaMacro::InsetFormulaMacro(string const & s)
+{
+ MathMacroTemplate * t = mathed_parse_macro(s);
+ MathMacroTable::insertTemplate(*t);
+ setInsetName(t->name());
+ delete t;
+ metrics();
+}
+
+
Inset * InsetFormulaMacro::clone(Buffer const &, bool) const
{
return new InsetFormulaMacro(*this);
class MathMacroTemplate;
-// InsetFormulaMacro's ParInset is the ParInset of the macro definition
-// which in turn is stored in the global MathMacroTable.
-// No copying/updating needed anymore...
+// InsetFormulaMacro's only knows its name and asks the global
+// MathMacroTable if it needs to know more.
///
class InsetFormulaMacro: public InsetFormulaBase {
public:
///
InsetFormulaMacro();
- ///
+ /// construct a macro hull from its name and the number of arguments
explicit InsetFormulaMacro(string name, int na);
+ /// constructs a mocro from its LaTeX definition
+ explicit InsetFormulaMacro(string const & s);
///
int ascent(BufferView *, LyXFont const &) const;
///
static_cast<MathMatrixInset *>(const_cast<MathInset *>(formula_->par()));
}
-////////////////////////////////////////////////////////////////////////
-
-
-bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
-{
- return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
-}
-
-
-bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
-{
- if (ti.par_ != it.par_) {
- lyxerr << "can't compare cursor and anchor in different insets\n";
- return true;
- }
- if (ti.idx_ != it.idx_)
- return ti.idx_ < it.idx_;
- return ti.pos_ < it.pos_;
-}
-
-
-MathArray & MathCursorPos::cell(int idx) const
-{
- return par_->cell(idx);
-}
-
-
-MathArray & MathCursorPos::cell() const
-{
- return par_->cell(idx_);
-}
-
-
-MathXArray & MathCursorPos::xcell(int idx) const
-{
- return par_->xcell(idx);
-}
-
-
-MathXArray & MathCursorPos::xcell() const
-{
- return par_->xcell(idx_);
-}
-
-
-MathCursorPos MathCursor::normalAnchor() const
-{
- // use Anchor on the same level as Cursor
- MathCursorPos normal = Anchor_[Cursor_.size() - 1];
- if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
- // anchor is behind cursor -> move anchor behind the inset
- ++normal.pos_;
- }
- return normal;
-}
-
void MathCursor::interpret(string const & s)
{
}
+
+
+////////////////////////////////////////////////////////////////////////
+
+
+bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
+{
+ return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
+}
+
+
+bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
+{
+ if (ti.par_ != it.par_) {
+ lyxerr << "can't compare cursor and anchor in different insets\n";
+ return true;
+ }
+ if (ti.idx_ != it.idx_)
+ return ti.idx_ < it.idx_;
+ return ti.pos_ < it.pos_;
+}
+
+
+MathArray & MathCursorPos::cell(int idx) const
+{
+ return par_->cell(idx);
+}
+
+
+MathArray & MathCursorPos::cell() const
+{
+ return par_->cell(idx_);
+}
+
+
+MathXArray & MathCursorPos::xcell(int idx) const
+{
+ return par_->xcell(idx);
+}
+
+
+MathXArray & MathCursorPos::xcell() const
+{
+ return par_->xcell(idx_);
+}
+
+
+MathCursorPos MathCursor::normalAnchor() const
+{
+ // use Anchor on the same level as Cursor
+ MathCursorPos normal = Anchor_[Cursor_.size() - 1];
+ if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
+ // anchor is behind cursor -> move anchor behind the inset
+ ++normal.pos_;
+ }
+ return normal;
+}
+
while (is_.good()) {
unsigned char c = getuchar();
+
//lyxerr << "reading byte: '" << c << "' code: " << lexcode[c] << endl;
+
+ if (!is_.good())
+ break;
if (lexcode[c] == LexNewLine) {
++lineno_;
} while (c != '\n' && is_.good()); // eat comments
}
- if (lexcode[c] == LexOther) {
- ival_ = c;
+ ival_ = c;
+ if (lexcode[c] == LexOther)
return LM_TK_STR;
- }
- if (lexcode[c] == LexAlpha || lexcode[c] == LexSpace) {
- ival_ = c;
+ if (lexcode[c] == LexAlpha || lexcode[c] == LexSpace)
return LM_TK_ALPHA;
- }
- if (lexcode[c] == LexBOP) {
- ival_ = c;
+ if (lexcode[c] == LexBOP)
return LM_TK_BOP;
- }
if (lexcode[c] == LexMath) {
ival_ = 0;
return LM_TK_MATH;
}
- if (lexcode[c] == LexSelf) {
+ if (lexcode[c] == LexSelf)
return c;
- }
if (lexcode[c] == LexArgument) {
c = getuchar();
if (lexcode[c] == LexESC) {
c = getuchar();
- //lyxerr << "reading second byte: '" << c << "' code: " << lexcode[c] << endl;
- string s;
- s += c;
+ //lyxerr << "reading second byte: '" << c
+ // << "' code: " << lexcode[c] << endl;
+ string s(1, c);
latexkeys const * l = in_word_set(s);
if (l) {
//lyxerr << "found key: " << l << endl;
{
MathTextCodes yyvarcode = LM_TC_VAR;
- int t = yylex();
bool panic = false;
int limits = 0;
- while (t) {
+ while (int t = yylex()) {
+
//lyxerr << "t: " << t << " flags: " << flags << " i: " << ival_
// << " '" << sval_ << "'\n";
//array.dump(lyxerr);
// skip the brace and collect everything to the next matching
// closing brace
flags |= FLAG_BRACE_LAST;
- t = yylex();
+ continue;
} else {
- // take only this single token
+ // handle only this single token, leave the loop if done
flags |= FLAG_LEAVE;
}
}
break;
} else {
flags &= ~FLAG_BRACE;
- t = yylex();
continue;
}
}
if (flags & FLAG_BLOCK) {
- if (t == LM_TK_CLOSE || t == '&' ||
- t == LM_TK_NEWLINE || t == LM_TK_END) {
+ if (t == LM_TK_CLOSE || t == '&' || t == LM_TK_NEWLINE || t == LM_TK_END){
putback(t);
return;
}
flags &= ~FLAG_LEAVE;
break;
}
+ }
- if (panic) {
- lyxerr << " Math Panic, expect problems!\n";
- // Search for the end command.
- do {
- t = yylex();
- } while (is_.good() && t != LM_TK_END && t);
- } else {
+ if (panic) {
+ lyxerr << " Math Panic, expect problems!\n";
+ // Search for the end command.
+ int t;
+ do {
t = yylex();
- }
+ } while (is_.good() && t != LM_TK_END && t);
}
}