math_diminset.h \
math_dotsinset.C \
math_dotsinset.h \
+ math_exfuncinset.C \
+ math_exfuncinset.h \
math_factory.C \
math_factory.h \
math_fracinset.C \
#include "math_cursor.h"
#include "math_parser.h"
#include "math_charinset.h"
+#include "math_arrayinset.h"
+#include "math_deliminset.h"
#include "lyx_main.h"
#include "BufferView.h"
#include "gettext.h"
}
- string pipeThroughMaple(string const & extra, MathArray const & ar)
+ MathArray pipeThroughMaple(string const & extra, MathArray const & ar)
{
string header =
"readlib(latex):\n"
}
string full = "latex(" + extra + '(' + expr + "));";
- string res = captureOutput("maple -q", header + full + trailer);
+ string out = captureOutput("maple -q", header + full + trailer);
// change \_ into _
+
+ //
+ MathArray res;
+ mathed_parse_cell(res, out);
return res;
}
+
+ MathArray pipeThroughOctave(string const &, MathArray const & ar)
+ {
+ string out = captureOutput("octave -q", ar.octavize());
+ if (out.size() > 6) // remove 'ans = '
+ out = out.substr(6);
+
+ // parse output as matrix or single number
+ MathAtom at(new MathArrayInset(out));
+ MathArrayInset const * mat = at.nucleus()->asArrayInset();
+ MathArray res;
+ if (mat->ncols() == 1 && mat->nrows() == 1)
+ res.push_back(mat->cell(0));
+ else {
+ res.push_back(MathAtom(new MathDelimInset("(", ")")));
+ res.back()->cell(0).push_back(at);
+ }
+ return res;
+ }
MathArray pipeThroughExtern(string const & arg, MathArray const & ar)
if (extra.empty())
extra = "noextra";
- MathArray res;
-
- if (lang == "octave") {
-
- string out = captureOutput("octave -q", ar.octavize());
- if (out.size() > 6)
- out = out.substr(6);
- mathed_parse_cell(res, out);
-
- } else if (lang == "maple") {
+ if (lang == "octave")
+ return pipeThroughOctave(extra, ar);
- mathed_parse_cell(res, pipeThroughMaple(extra, ar));
+ if (lang == "maple")
+ return pipeThroughMaple(extra, ar);
- } else {
+ // create normalized expression
+ ostringstream os;
+ os << "[" << extra << ' ';
+ ar.writeNormal(os);
+ os << "]";
+ string data = os.str().c_str();
- // create normalized expression
- ostringstream os;
- os << "[" << extra << ' ';
- ar.writeNormal(os);
- os << "]";
- string data = os.str().c_str();
-
- // search external script
- string file = LibFileSearch("mathed", "extern_" + lang);
- if (file.empty()) {
- lyxerr << "converter to '" << lang << "' not found\n";
- return MathArray();
- }
-
- // run external sript
- string out = captureOutput(file, data);
- mathed_parse_cell(res, out);
+ // search external script
+ string file = LibFileSearch("mathed", "extern_" + lang);
+ if (file.empty()) {
+ lyxerr << "converter to '" << lang << "' not found\n";
+ return MathArray();
}
-
+
+ // run external sript
+ string out = captureOutput(file, data);
+ MathArray res;
+ mathed_parse_cell(res, out);
return res;
}
mathcursor->selGet(ar);
lyxerr << "use selection: " << ar << "\n";
} else {
+ mathcursor->end();
mathcursor->stripFromLastEqualSign();
ar = mathcursor->cursor().cell();
mathcursor->insert(MathAtom(new MathCharInset('=', LM_TC_VAR)));
#endif
#include "math_arrayinset.h"
+#include "math_parser.h"
#include "support/LOstream.h"
+#include "Lsstream.h"
MathArrayInset::MathArrayInset(int m, int n)
{}
+MathArrayInset::MathArrayInset(string const & str)
+ : MathGridInset(1, 1)
+{
+ vector< vector<string> > dat;
+ istringstream is(str);
+ while (is) {
+ string line;
+ getline(is, line);
+ istringstream ls(line);
+ typedef std::istream_iterator<string> iter;
+ vector<string> v = vector<string>(iter(ls), iter());
+ if (v.size())
+ dat.push_back(v);
+ }
+
+ for (row_type row = 1; row < dat.size(); ++row)
+ addRow(0);
+ for (col_type col = 1; col < dat[0].size(); ++col)
+ addCol(0);
+ for (row_type row = 0; row < dat.size(); ++row)
+ for (col_type col = 0; col < dat[row].size(); ++col)
+ mathed_parse_cell(cell(index(row, col)), dat[row][col]);
+}
+
+
MathInset * MathArrayInset::clone() const
{
return new MathArrayInset(*this);
MathArrayInset(int m, int n);
///
MathArrayInset(int m, int n, char valign, string const & halign);
+ /// convienience constructor from whitespace/newline seperated data
+ MathArrayInset(string const & str);
///
MathInset * clone() const;
///
--- /dev/null
+#include "math_exfuncinset.h"
+#include "support.h"
+#include "debug.h"
+#include "support/LOstream.h"
+
+
+using std::ostream;
+
+
+MathExFuncInset::MathExFuncInset(string const & name)
+ : MathNestInset(1), name_(name)
+{}
+
+
+MathInset * MathExFuncInset::clone() const
+{
+ return new MathExFuncInset(*this);
+}
+
+
+void MathExFuncInset::write(MathWriteInfo & os) const
+{
+ os << '\\' << name_ << '{';
+ cell(0).write(os);
+ os << '}';
+}
+
+
+void MathExFuncInset::writeNormal(ostream & os) const
+{
+ os << "[" << name_ << ' ';
+ cell(0).writeNormal(os);
+ os << "] ";
+}
+
+
+void MathExFuncInset::metrics(MathMetricsInfo const & mi) const
+{
+ mi_ = mi;
+ mathed_string_dim(LM_TC_TEXTRM, mi_, name_, ascent_, descent_, width_);
+ lyxerr << "should not happen\n";
+}
+
+
+void MathExFuncInset::draw(Painter & pain, int x, int y) const
+{
+ drawStr(pain, LM_TC_TEXTRM, mi_, x, y, name_);
+ lyxerr << "should not happen\n";
+}
+
+
+string MathExFuncInset::octavize() const
+{
+ return name_ + '(' + cell(0).octavize() + ')';
+}
--- /dev/null
+// -*- C++ -*-
+#ifndef MATH_EXFUNCINSET_H
+#define MATH_EXFUNCINSET_H
+
+#include "math_nestinset.h"
+
+// f(x) in one block (as opposed to 'f','(','x',')' or 'f','x')
+// for interfacing external programs
+
+class MathExFuncInset : public MathNestInset {
+public:
+ ///
+ explicit MathExFuncInset(string const & name);
+ ///
+ MathInset * clone() const;
+ ///
+ void write(MathWriteInfo & os) const;
+ ///
+ void writeNormal(std::ostream &) const;
+ ///
+ void metrics(MathMetricsInfo const & st) const;
+ ///
+ void draw(Painter &, int x, int y) const;
+ ///
+ string octavize() const;
+
+private:
+ ///
+ string const name_;
+ ///
+ mutable MathMetricsInfo mi_;
+};
+#endif
{
switch (l->token) {
case LM_TK_FUNCLIM:
- return MathAtom(new MathFuncLimInset(l));
+ return MathAtom(new MathFuncLimInset(l->name));
case LM_TK_SPECIAL:
return MathAtom(new MathSpecialCharInset(l->id));
case LM_TK_SYM:
#include "math_funcliminset.h"
-#include "mathed/math_parser.h"
-#include "mathed/support.h"
+#include "support.h"
#include "support/LOstream.h"
using std::ostream;
-MathFuncLimInset::MathFuncLimInset(const latexkeys * l)
- : sym_(l)
+MathFuncLimInset::MathFuncLimInset(string const & name)
+ : name_(name)
{}
void MathFuncLimInset::write(MathWriteInfo & os) const
{
- os << '\\' << sym_->name << ' ';
+ os << '\\' << name_ << ' ';
}
void MathFuncLimInset::writeNormal(ostream & os) const
{
- os << "[" << sym_->name << "] ";
+ os << "[" << name_ << "] ";
}
void MathFuncLimInset::metrics(MathMetricsInfo const & mi) const
{
mi_ = mi;
- mathed_string_dim(LM_TC_TEXTRM, mi_, sym_->name, ascent_, descent_, width_);
+ mathed_string_dim(LM_TC_TEXTRM, mi_, name_, ascent_, descent_, width_);
}
void MathFuncLimInset::draw(Painter & pain, int x, int y) const
{
- drawStr(pain, LM_TC_TEXTRM, mi_, x, y, sym_->name);
+ drawStr(pain, LM_TC_TEXTRM, mi_, x, y, name_);
}
#include "math_diminset.h"
-struct latexkeys;
-
// "normal" symbols that don't take limits and don't grow in displayed
// formulae
class MathFuncLimInset : public MathDimInset {
public:
///
- explicit MathFuncLimInset(latexkeys const *);
+ explicit MathFuncLimInset(string const & name);
///
MathInset * clone() const;
///
private:
///
- latexkeys const * sym_;
+ string const name_;
///
mutable MathMetricsInfo mi_;
};
pos = 0;
return true;
}
+
+
+string MathRootInset::octavize() const
+{
+ return "root(" + cell(1).octavize() + ',' + cell(0).octavize() + ')';
+}
bool idxUp(int & idx, int & pos) const;
///
bool idxDown(int & idx, int & pos) const;
+ ///
+ string octavize() const;
};
#endif