#endif
#include <config.h>
-#include <fstream>
#include "formula.h"
#include "commandtags.h"
#include "support/lyxlib.h"
#include "support/syscall.h"
#include "support/lstrings.h"
+#include "support/filetools.h" // LibFileSearch
#include "LyXView.h"
#include "Painter.h"
#include "lyxrc.h"
ar.erase(pos, ar.size());
}
+
+ MathArray pipeThroughExtern(string const & arg, MathArray const & ar)
+ {
+ string lang;
+ string extra;
+ istringstream iss(arg.c_str());
+ iss >> lang >> extra;
+ if (extra.empty())
+ extra = "noextra";
+
+ // create normalized expression
+ string outfile = lyx::tempName(string(), "mathextern");
+ ostringstream os;
+ os << "[" << extra << ' ';
+ ar.writeNormal(os);
+ os << "]";
+ string code = os.str().c_str();
+
+ // run external sript
+ string file = LibFileSearch(string(), "lyx2" + lang);
+ if (file.empty()) {
+ lyxerr << "converter to '" << lang << "' not found\n";
+ return MathArray();
+ }
+ string script = file + " '" + code + "' " + outfile;
+ lyxerr << "calling: " << script << endl;
+ Systemcalls cmd(Systemcalls::System, script, 0);
+
+ // append result
+ MathArray res;
+ mathed_parse_cell(res, GetFileContents(outfile));
+ return res;
+ }
+
}
return result;
}
-#if 0
-void InsetFormula::handleExtern(const string & arg)
-{
- // where are we?
- if (!mathcursor)
- return;
-
- MathArray & ar = mathcursor->cursor().cell();
-
- // parse args
- string lang;
- string extra;
- istringstream iss(arg.c_str());
- iss >> lang >> extra;
- if (extra.empty())
- extra = "noextra";
-
- // strip last '=' and everything behind
- stripFromLastEqualSign(ar);
-
- // create normalized expression
- //string outfile = lyx::tempName("maple.out");
- string outfile = "/tmp/lyx2" + lang + ".out";
- ostringstream os;
- os << "[" << extra << ' ';
- ar.writeNormal(os);
- os << "]";
- string code = os.str().c_str();
-
- // run external sript
- string script = "lyx2" + arg + " '" + code + "' " + outfile;
- lyxerr << "calling: " << script << endl;
- Systemcalls cmd(Systemcalls::System, script, 0);
-
- // append a '='
- ar.push_back(MathAtom(new MathCharInset('=')));
-
- // append result
- ifstream is(outfile.c_str());
- mathed_parse_cell(ar, is);
- mathcursor->end();
-}
-#endif
void InsetFormula::handleExtern(const string & arg)
{
mathcursor->selGet(ar);
lyxerr << "use selection: " << ar << "\n";
} else {
+ mathcursor->end();
ar = mathcursor->cursor().cell();
+ stripFromLastEqualSign(ar);
+ mathcursor->insert(MathAtom(new MathCharInset('=', LM_TC_VAR)));
lyxerr << "use whole cell: " << ar << "\n";
}
-
- // parse args
- string lang;
- string extra;
- istringstream iss(arg.c_str());
- iss >> lang >> extra;
- if (extra.empty())
- extra = "noextra";
-
- // strip last '=' and everything behind
- stripFromLastEqualSign(ar);
-
- // create normalized expression
- //string outfile = lyx::tempName("maple.out");
- string outfile = "/tmp/lyx2" + lang + ".out";
- ostringstream os;
- os << "[" << extra << ' ';
- ar.writeNormal(os);
- os << "]";
- string code = os.str().c_str();
-
- // run external sript
- string script = "lyx2" + lang + " '" + code + "' " + outfile;
- lyxerr << "calling: " << script << endl;
- Systemcalls cmd(Systemcalls::System, script, 0);
-
- // append result
- MathArray br;
- if (selected)
- br.push_back(MathAtom(new MathCharInset('=', LM_TC_VAR)));
- ifstream is(outfile.c_str());
- mathed_parse_cell(br, is);
- mathcursor->insert(br);
+ mathcursor->insert(pipeThroughExtern(arg, ar));
}
+
bool InsetFormula::display() const
{
return mat()->getType() != LM_OT_SIMPLE;
+
#include <config.h>
+#include <sstream>
+
#include "debug.h"
#include "support.h"
#include "support/LOstream.h"
#include "math_scriptinset.h"
+using std::ostringstream;
+
MathScriptInset::MathScriptInset()
: MathNestInset(2), limits_(0)
}
-
MathInset * MathScriptInset::clone() const
{
return new MathScriptInset(*this);
}
+void MathScriptInset::writeNormal(ostream & os) const
+{
+ //lyxerr << "unexpected call to MathScriptInset::writeNormal()\n";
+ writeNormal(0, os);
+}
+
+
+void MathScriptInset::writeNormal(MathInset const * nuc, ostream & os) const
+{
+ bool d = hasDown() && down().data_.size();
+ bool u = hasUp() && up().data_.size();
+
+ ostringstream osb;
+ if (nuc)
+ nuc->writeNormal(osb);
+ else
+ osb << "[par]";
+ string base = osb.str();
+
+ if (u && d) {
+ os << "[sup [sub " << osb.str() << " ";
+ down().data_.writeNormal(os);
+ os << "]";
+ up().data_.writeNormal(os);
+ os << ']';
+ } else if (u) {
+ os << "[sup " << osb.str() << " ";
+ up().data_.writeNormal(os);
+ os << ']';
+ } else if (d) {
+ os << "[sub " << osb.str() << " ";
+ down().data_.writeNormal(os);
+ os << ']';
+ }
+}
+
+
bool MathScriptInset::hasLimits(MathInset const * nuc) const
{
return limits_ == 1 || (limits_ == 0 && nuc && nuc->isScriptable());