1 // This file contains most of the magic that extracts "context
2 // information" from the unstructered layout-oriented stuff in an
7 #include "math_amsarrayinset.h"
8 #include "math_arrayinset.h"
9 #include "math_charinset.h"
10 #include "math_deliminset.h"
11 #include "math_diffinset.h"
12 #include "math_exfuncinset.h"
13 #include "math_exintinset.h"
14 #include "math_fracinset.h"
15 #include "math_liminset.h"
16 #include "math_matrixinset.h"
17 #include "math_mathmlstream.h"
18 #include "math_numberinset.h"
19 #include "math_scriptinset.h"
20 #include "math_stringinset.h"
21 #include "math_symbolinset.h"
22 #include "math_unknowninset.h"
23 #include "math_parser.h"
26 #include "support/lyxlib.h"
27 #include "support/systemcall.h"
28 #include "support/filetools.h"
33 using std::istringstream;
38 ostream & operator<<(ostream & os, MathArray const & ar)
46 // define a function for tests
47 typedef bool TestItemFunc(MathInset *);
49 // define a function for replacing subexpressions
50 typedef MathInset * ReplaceArgumentFunc(const MathArray & ar);
54 // try to extract a super/subscript
55 // modify iterator position to point behind the thing
56 bool extractScript(MathArray & ar,
57 MathArray::iterator & pos, MathArray::iterator last)
59 // nothing to get here
63 // is this a scriptinset?
64 if (!(*pos)->asScriptInset())
67 // it is a scriptinset, use it.
74 // try to extract an "argument" to some function.
75 // returns position behind the argument
76 MathArray::iterator extractArgument(MathArray & ar,
77 MathArray::iterator pos, MathArray::iterator last, string const & = "")
79 // nothing to get here
83 // something deliminited _is_ an argument
84 if ((*pos)->asDelimInset()) {
89 // always take the first thing, no matter what it is
92 // go ahead if possible
97 // if the next item is a subscript, it most certainly belongs to the
99 extractScript(ar, pos, last);
103 // but it might be more than that.
104 // FIXME: not implemented
105 //for (MathArray::iterator it = pos + 1; it != last; ++it) {
106 // // always take the first thing, no matter
108 // ar.push_back(*it);
116 MathScriptInset const * asScript(MathArray::const_iterator it)
120 if (it->nucleus()->asScriptInset())
125 return it->nucleus()->asScriptInset();
130 // returns sequence of char with same code starting at it up to end
131 // it might be less, though...
133 (MathArray::const_iterator it, MathArray::const_iterator end)
136 for (; it != end && (*it)->asCharInset(); ++it)
137 s += (*it)->getChar();
142 void extractStrings(MathArray & ar)
144 //lyxerr << "\nStrings from: " << ar << "\n";
145 for (MathArray::size_type i = 0; i < ar.size(); ++i) {
146 if (!ar[i]->asCharInset())
148 string s = charSequence(ar.begin() + i, ar.end());
149 ar[i].reset(new MathStringInset(s));
150 ar.erase(i + 1, i + s.size());
152 //lyxerr << "\nStrings to: " << ar << "\n";
156 MathInset * singleItem(MathArray & ar)
158 return ar.size() == 1 ? ar.begin()->nucleus() : 0;
162 void extractMatrices(MathArray & ar)
164 //lyxerr << "\nMatrices from: " << ar << "\n";
165 // first pass for explicitly delimited stuff
166 for (MathArray::iterator it = ar.begin(); it != ar.end(); ++it) {
167 MathDelimInset * del = (*it)->asDelimInset();
170 MathInset * arr = singleItem(del->cell(0));
171 if (!arr || !arr->asGridInset())
173 *it = MathAtom(new MathMatrixInset(*(arr->asGridInset())));
176 // second pass for AMS "pmatrix" etc
177 for (MathArray::iterator it = ar.begin(); it != ar.end(); ++it) {
178 MathAMSArrayInset * ams = (*it)->asAMSArrayInset();
181 *it = MathAtom(new MathMatrixInset(*ams));
183 //lyxerr << "\nMatrices to: " << ar << "\n";
187 // convert this inset somehow to a string
188 bool extractString(MathInset * p, string & str)
193 str = string(1, p->getChar());
196 if (p->asStringInset()) {
197 str = p->asStringInset()->str();
204 // convert this inset somehow to a number
205 bool extractNumber(MathArray const & ar, int & i)
207 istringstream is(charSequence(ar.begin(), ar.end()).c_str());
213 bool extractNumber(MathArray const & ar, double & d)
215 istringstream is(charSequence(ar.begin(), ar.end()).c_str());
221 bool testString(MathInset * p, const string & str)
224 return extractString(p, s) && str == s;
228 // search end of nested sequence
229 MathArray::iterator endNestSearch(
230 MathArray::iterator it,
231 MathArray::iterator last,
232 TestItemFunc testOpen,
233 TestItemFunc testClose
236 for (int level = 0; it != last; ++it) {
237 if (testOpen(it->nucleus()))
239 if (testClose(it->nucleus()))
248 // replace nested sequences by a real Insets
251 TestItemFunc testOpen,
252 TestItemFunc testClose,
253 ReplaceArgumentFunc replaceArg
256 // use indices rather than iterators for the loop because we are going
257 // to modify the array.
258 for (MathArray::size_type i = 0; i < ar.size(); ++i) {
259 // check whether this is the begin of the sequence
260 MathArray::iterator it = ar.begin() + i;
261 if (!testOpen(it->nucleus()))
264 // search end of sequence
265 MathArray::iterator jt = endNestSearch(it, ar.end(), testOpen, testClose);
269 // create a proper inset as replacement
270 MathInset * p = replaceArg(MathArray(it + 1, jt));
272 // replace the original stuff by the new inset
273 ar.erase(it + 1, jt + 1);
281 // split scripts into seperate super- and subscript insets. sub goes in
285 void splitScripts(MathArray & ar)
287 //lyxerr << "\nScripts from: " << ar << "\n";
288 for (MathArray::size_type i = 0; i < ar.size(); ++i) {
289 MathArray::iterator it = ar.begin() + i;
291 // is this script inset?
292 MathScriptInset * p = (*it)->asScriptInset();
296 // no problem if we don't have both...
297 if (!p->hasUp() || !p->hasDown())
300 // create extra script inset and move superscript over
301 MathScriptInset * q = new MathScriptInset;
303 q->up().data().swap(p->up().data());
304 p->removeScript(true);
306 // insert new inset behind
308 ar.insert(i, MathAtom(q));
310 //lyxerr << "\nScripts to: " << ar << "\n";
318 void extractExps(MathArray & ar)
320 //lyxerr << "\nExps from: " << ar << "\n";
322 for (MathArray::size_type i = 0; i + 1 < ar.size(); ++i) {
323 MathArray::iterator it = ar.begin() + i;
326 MathCharInset const * p = (*it)->asCharInset();
327 if (!p || p->getChar() != 'e')
330 // we need an exponent but no subscript
331 MathScriptInset * sup = (*(it + 1))->asScriptInset();
332 if (!sup || sup->hasDown())
335 // create a proper exp-inset as replacement
336 *it = new MathExFuncInset("exp", sup->cell(1));
339 //lyxerr << "\nExps to: " << ar << "\n";
344 // extract det(...) from |matrix|
346 void extractDets(MathArray & ar)
348 //lyxerr << "\ndet from: " << ar << "\n";
349 for (MathArray::iterator it = ar.begin(); it != ar.end(); ++it) {
350 MathDelimInset * del = (*it)->asDelimInset();
355 *it = new MathExFuncInset("det", del->cell(0));
357 //lyxerr << "\ndet to: " << ar << "\n";
365 bool isDigitOrSimilar(char c)
367 return ('0' <= c && c <= '9') || c == '.';
371 // returns sequence of digits
373 (MathArray::const_iterator it, MathArray::const_iterator end)
376 for (; it != end && (*it)->asCharInset(); ++it) {
377 if (!isDigitOrSimilar((*it)->getChar()))
379 s += (*it)->getChar();
385 void extractNumbers(MathArray & ar)
387 //lyxerr << "\nNumbers from: " << ar << "\n";
388 for (MathArray::size_type i = 0; i < ar.size(); ++i) {
389 if (!ar[i]->asCharInset())
391 if (!isDigitOrSimilar(ar[i]->asCharInset()->getChar()))
394 string s = digitSequence(ar.begin() + i, ar.end());
396 ar[i].reset(new MathNumberInset(s));
397 ar.erase(i + 1, i + s.size());
399 //lyxerr << "\nNumbers to: " << ar << "\n";
405 // search deliminiters
408 bool testOpenParan(MathInset * p)
410 return testString(p, "(");
414 bool testCloseParan(MathInset * p)
416 return testString(p, ")");
420 MathInset * replaceDelims(const MathArray & ar)
422 return new MathDelimInset("(", ")", ar);
426 // replace '('...')' sequences by a real MathDelimInset
427 void extractDelims(MathArray & ar)
429 //lyxerr << "\nDelims from: " << ar << "\n";
430 replaceNested(ar, testOpenParan, testCloseParan, replaceDelims);
431 //lyxerr << "\nDelims to: " << ar << "\n";
437 // search well-known functions
441 // replace 'f' '(...)' and 'f' '^n' '(...)' sequences by a real MathExFuncInset
442 // assume 'extractDelims' ran before
443 void extractFunctions(MathArray & ar)
445 // we need at least two items...
449 //lyxerr << "\nFunctions from: " << ar << "\n";
450 for (MathArray::size_type i = 0; i + 1 < ar.size(); ++i) {
451 MathArray::iterator it = ar.begin() + i;
452 MathArray::iterator jt = it + 1;
456 if ((*it)->asUnknownInset()) {
457 // it certainly is if it is well known...
458 name = (*it)->asUnknownInset()->name();
460 // is this a user defined function?
461 // it it probably not, if it doesn't have a name.
462 if (!extractString((*it).nucleus(), name))
464 // it is not if it has no argument
467 // guess so, if this is followed by
468 // a DelimInset with a single item in the cell
469 MathDelimInset * del = (*jt)->asDelimInset();
470 if (!del || del->cell(0).size() != 1)
472 // fall trough into main branch
475 // do we have an exponent like in
476 // 'sin' '^2' 'x' -> 'sin(x)' '^2'
478 extractScript(exp, jt, ar.end());
480 // create a proper inset as replacement
481 MathExFuncInset * p = new MathExFuncInset(name);
483 // jt points to the "argument". Get hold of this.
484 MathArray::iterator st = extractArgument(p->cell(0), jt, ar.end());
486 // replace the function name by a real function inset
489 // remove the source of the argument from the array
490 ar.erase(it + 1, st);
492 // re-insert exponent
493 ar.insert(i + 1, exp);
494 //lyxerr << "\nFunctions to: " << ar << "\n";
503 bool testSymbol(MathInset * p, string const & name)
505 return p->asSymbolInset() && p->asSymbolInset()->name() == name;
509 bool testIntSymbol(MathInset * p)
511 return testSymbol(p, "int");
515 bool testIntDiff(MathInset * p)
517 return testString(p, "d");
521 // replace '\int' ['_^'] x 'd''x'(...)' sequences by a real MathExIntInset
522 // assume 'extractDelims' ran before
523 void extractIntegrals(MathArray & ar)
525 // we need at least three items...
529 //lyxerr << "\nIntegrals from: " << ar << "\n";
530 for (MathArray::size_type i = 0; i + 1 < ar.size(); ++i) {
531 MathArray::iterator it = ar.begin() + i;
533 // is this a integral name?
534 if (!testIntSymbol(it->nucleus()))
538 MathArray::iterator jt =
539 endNestSearch(it, ar.end(), testIntSymbol, testIntDiff);
541 // something sensible found?
545 // create a proper inset as replacement
546 MathExIntInset * p = new MathExIntInset("int");
548 // collect subscript if any
549 MathArray::iterator st = it + 1;
551 if (MathScriptInset * sub = (*st)->asScriptInset())
552 if (sub->hasDown()) {
553 p->cell(2) = sub->down().data();
557 // collect superscript if any
559 if (MathScriptInset * sup = (*st)->asScriptInset())
561 p->cell(3) = sup->up().data();
565 // core ist part from behind the scripts to the 'd'
566 p->cell(0) = MathArray(st, jt);
568 // use the "thing" behind the 'd' as differential
569 MathArray::iterator tt = extractArgument(p->cell(1), jt + 1, ar.end());
572 ar.erase(it + 1, tt);
575 //lyxerr << "\nIntegrals to: " << ar << "\n";
584 bool testEqualSign(MathAtom const & at)
586 return testString(at.nucleus(), "=");
591 // replace '\sum' ['_^'] f(x) sequences by a real MathExIntInset
592 // assume 'extractDelims' ran before
593 void extractSums(MathArray & ar)
595 // we need at least two items...
599 //lyxerr << "\nSums from: " << ar << "\n";
600 for (MathArray::size_type i = 0; i + 1 < ar.size(); ++i) {
601 MathArray::iterator it = ar.begin() + i;
603 // is this a sum name?
604 if (!testSymbol(it->nucleus(), "sum"))
607 // create a proper inset as replacement
608 MathExIntInset * p = new MathExIntInset("sum");
610 // collect lower bound and summation index
611 MathArray::iterator st = it + 1;
613 if (MathScriptInset * sub = (*st)->asScriptInset())
614 if (sub->hasDown()) {
615 // try to figure out the summation index from the subscript
616 MathArray & ar = sub->down().data();
617 MathArray::iterator it =
618 find_if(ar.begin(), ar.end(), &testEqualSign);
619 if (it != ar.end()) {
620 // we found a '=', use everything in front of that as index,
621 // and everything behind as lower index
622 p->cell(1) = MathArray(ar.begin(), it);
623 p->cell(2) = MathArray(it + 1, ar.end());
625 // use everything as summation index, don't use scripts.
631 // collect upper bound
633 if (MathScriptInset * sup = (*st)->asScriptInset())
635 p->cell(3) = sup->up().data();
639 // use some behind the script as core
640 MathArray::iterator tt = extractArgument(p->cell(0), st, ar.end());
643 ar.erase(it + 1, tt);
646 //lyxerr << "\nSums to: " << ar << "\n";
651 // search differential stuff
654 // tests for 'd' or '\partial'
655 bool testDiffItem(MathAtom const & at)
657 return testString(at.nucleus(), "d");
661 bool testDiffArray(MathArray const & ar)
663 return ar.size() && testDiffItem(ar.front());
667 bool testDiffFrac(MathInset * p)
669 MathFracInset * f = p->asFracInset();
670 return f && testDiffArray(f->cell(0)) && testDiffArray(f->cell(1));
674 // is this something like ^number?
675 bool extractDiffExponent(MathArray::iterator it, int & i)
677 if (!(*it)->asScriptInset())
681 if (!extractString((*it).nucleus(), s))
683 istringstream is(s.c_str());
689 void extractDiff(MathArray & ar)
691 //lyxerr << "\nDiffs from: " << ar << "\n";
692 for (MathArray::size_type i = 0; i < ar.size(); ++i) {
693 MathArray::iterator it = ar.begin() + i;
695 // is this a "differential fraction"?
696 if (!testDiffFrac(it->nucleus()))
699 MathFracInset * f = (*it)->asFracInset();
701 lyxerr << "should not happen\n";
705 // create a proper diff inset
706 MathDiffInset * diff = new MathDiffInset;
708 // collect function, let jt point behind last used item
709 MathArray::iterator jt = it + 1;
711 MathArray & numer = f->cell(0);
712 if (numer.size() > 1 && numer[1]->asScriptInset()) {
713 // this is something like d^n f(x) / d... or d^n / d...
716 if (numer.size() > 2)
717 diff->cell(0) = MathArray(numer.begin() + 2, numer.end());
719 jt = extractArgument(diff->cell(0), jt, ar.end());
721 // simply d f(x) / d... or d/d...
722 if (numer.size() > 1)
723 diff->cell(0) = MathArray(numer.begin() + 1, numer.end());
725 jt = extractArgument(diff->cell(0), jt, ar.end());
728 // collect denominator parts
729 MathArray & denom = f->cell(1);
730 for (MathArray::iterator dt = denom.begin(); dt != denom.end();) {
732 MathArray::iterator et = find_if(dt + 1, denom.end(), &testDiffItem);
735 MathArray::iterator st = et - 1;
736 MathScriptInset * script = (*st)->asScriptInset();
737 if (script && script->hasUp()) {
738 // things like d.../dx^n
740 if (extractNumber(script->up().data(), mult)) {
741 //lyxerr << "mult: " << mult << endl;
742 for (int i = 0; i < mult; ++i)
743 diff->addDer(MathArray(dt + 1, st));
747 diff->addDer(MathArray(dt + 1, et));
753 ar.erase(it + 1, jt);
756 //lyxerr << "\nDiffs to: " << ar << "\n";
765 bool testRightArrow(MathAtom const & at)
768 testSymbol(at.nucleus(), "to") ||
769 testSymbol(at.nucleus(), "rightarrow");
774 // replace '\lim_{x->x0} f(x)' sequences by a real MathLimInset
775 // assume 'extractDelims' ran before
776 void extractLims(MathArray & ar)
778 // we need at least three items...
782 //lyxerr << "\nLimits from: " << ar << "\n";
783 for (MathArray::size_type i = 0; i + 2 < ar.size(); ++i) {
784 MathArray::iterator it = ar.begin() + i;
786 // is this a limit function?
787 if (!testSymbol(it->nucleus(), "lim"))
790 // the next one must be a subscript (without superscript)
791 MathScriptInset * sub = (*(it + 1))->asScriptInset();
792 if (!sub || !sub->hasDown() || sub->hasUp())
795 // and it must contain a -> symbol
796 MathArray & s = sub->down().data();
797 MathArray::iterator st = find_if(s.begin(), s.end(), &testRightArrow);
801 // the -> splits the subscript int x and x0
802 MathArray x = MathArray(s, 0, st - s.begin());
803 MathArray x0 = MathArray(s, st - s.begin() + 1, s.size());
805 // use something behind the script as core
807 MathArray::iterator tt = extractArgument(f, it + 2, ar.end());
809 // create a proper inset as replacement
810 MathLimInset * p = new MathLimInset(f, x, x0);
813 ar.erase(it + 1, tt);
816 //lyxerr << "\nLimits to: " << ar << "\n";
824 void extractStructure(MathArray & ar)
830 extractFunctions(ar);
832 extractIntegrals(ar);
841 void write(MathArray const & dat, WriteStream & wi)
845 for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it) {
846 wi.firstitem() = (it == ar.begin());
847 MathInset const * p = it->nucleus();
848 if (it + 1 != ar.end()) {
849 if (MathScriptInset const * q = asScript(it)) {
860 void normalize(MathArray const & ar, NormalStream & os)
862 for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
863 (*it)->normalize(os);
867 void octavize(MathArray const & dat, OctaveStream & os)
870 extractStructure(ar);
871 for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it) {
872 MathInset const * p = it->nucleus();
873 if (it + 1 != ar.end()) {
874 if (MathScriptInset const * q = asScript(it)) {
885 void maplize(MathArray const & dat, MapleStream & os)
888 extractStructure(ar);
889 for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it) {
890 MathInset const * p = it->nucleus();
891 if (it + 1 != ar.end()) {
892 if (MathScriptInset const * q = asScript(it)) {
903 void mathematicize(MathArray const & dat, MathematicaStream & os)
906 extractStructure(ar);
907 for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it) {
908 MathInset const * p = it->nucleus();
909 if (it + 1 != ar.end()) {
910 if (MathScriptInset const * q = asScript(it)) {
911 q->mathematicize2(p, os);
916 p->mathematicize(os);
921 void mathmlize(MathArray const & dat, MathMLStream & os)
924 extractStructure(ar);
927 else if (ar.size() == 1)
928 os << ar.begin()->nucleus();
931 for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it) {
932 MathInset const * p = it->nucleus();
933 if (it + 1 != ar.end()) {
934 if (MathScriptInset const * q = asScript(it)) {
935 q->mathmlize2(p, os);
951 string captureOutput(string const & cmd, string const & data)
953 string outfile = lyx::tempName(string(), "mathextern");
954 string full = "echo '" + data + "' | (" + cmd + ") > " + outfile;
955 lyxerr << "calling: " << full << endl;
957 dummy.startscript(Systemcall::Wait, full);
958 string out = GetFileContents(outfile);
959 lyx::unlink(outfile);
960 lyxerr << "result: '" << out << "'" << endl;
965 MathArray pipeThroughMaple(string const & extra, MathArray const & ar)
967 string header = "readlib(latex):\n";
969 // remove the \\it for variable names
970 //"#`latex/csname_font` := `\\it `:"
972 "`latex/csname_font` := ``:\n";
974 // export matrices in (...) instead of [...]
976 "`latex/latex/matrix` := "
977 "subs(`[`=`(`, `]`=`)`,"
978 "eval(`latex/latex/matrix`)):\n";
980 // replace \\cdots with proper '*'
982 "`latex/latex/*` := "
983 "subs(`\\,`=`\\cdot `,"
984 "eval(`latex/latex/*`)):\n";
986 // remove spurious \\noalign{\\medskip} in matrix output
988 "`latex/latex/matrix`:= "
989 "subs(`\\\\\\\\\\\\noalign{\\\\medskip}` = `\\\\\\\\`,"
990 "eval(`latex/latex/matrix`)):\n";
992 //"#`latex/latex/symbol` "
993 // " := subs((\\'_\\' = \\'`\\_`\\',eval(`latex/latex/symbol`)): ";
995 string trailer = "quit;";
999 string expr = os.str().c_str();
1000 lyxerr << "ar: '" << ar << "'\n";
1001 lyxerr << "ms: '" << os.str() << "'\n";
1003 for (int i = 0; i < 100; ++i) { // at most 100 attempts
1004 // try to fix missing '*' the hard way by using mint
1006 // ... > echo "1A;" | mint -i 1 -S -s -q
1009 // Probably missing an operator such as * p
1011 lyxerr << "checking expr: '" << expr << "'\n";
1012 string out = captureOutput("mint -i 1 -S -s -q -q", expr + ";");
1014 break; // expression syntax is ok
1015 istringstream is(out.c_str());
1018 if (line.find("on line") != 0)
1019 break; // error message not identified
1021 string::size_type pos = line.find('^');
1022 if (pos == string::npos || pos < 15)
1023 break; // caret position not found
1024 pos -= 15; // skip the "on line ..." part
1025 if (expr[pos] == '*' || (pos > 0 && expr[pos - 1] == '*'))
1026 break; // two '*' in a row are definitely bad
1027 expr.insert(pos, "*");
1030 string full = "latex(" + extra + '(' + expr + "));";
1031 string out = captureOutput("maple -q", header + full + trailer);
1037 mathed_parse_cell(res, out);
1042 MathArray pipeThroughOctave(string const &, MathArray const & ar)
1045 OctaveStream vs(os);
1047 string expr = os.str().c_str();
1050 lyxerr << "pipe: ar: '" << ar << "'\n";
1051 lyxerr << "pipe: expr: '" << expr << "'\n";
1053 for (int i = 0; i < 100; ++i) { // at most 100 attempts
1055 // try to fix missing '*' the hard way
1057 // >>> ([[1 2 3 ];[2 3 1 ];[3 1 2 ]])([[1 2 3 ];[2 3 1 ];[3 1 2 ]])
1060 lyxerr << "checking expr: '" << expr << "'\n";
1061 out = captureOutput("octave -q 2>&1", expr);
1062 lyxerr << "checking out: '" << out << "'\n";
1064 // leave loop if expression syntax is probably ok
1065 if (out.find("parse error:") == string::npos)
1068 // search line with single caret
1069 istringstream is(out.c_str());
1073 lyxerr << "skipping line: '" << line << "'\n";
1074 if (line.find(">>> ") != string::npos)
1078 // found line with error, next line is the one with caret
1080 string::size_type pos = line.find('^');
1081 lyxerr << "caret line: '" << line << "'\n";
1082 lyxerr << "found caret at pos: '" << pos << "'\n";
1083 if (pos == string::npos || pos < 4)
1084 break; // caret position not found
1085 pos -= 4; // skip the ">>> " part
1086 if (expr[pos] == '*')
1087 break; // two '*' in a row are definitely bad
1088 expr.insert(pos, "*");
1095 out = out.substr(6);
1097 // parse output as matrix or single number
1098 MathAtom at(new MathArrayInset("array", out));
1099 MathArrayInset const * mat = at.nucleus()->asArrayInset();
1101 if (mat->ncols() == 1 && mat->nrows() == 1)
1102 res.push_back(mat->cell(0));
1104 res.push_back(MathAtom(new MathDelimInset("(", ")")));
1105 res.back()->cell(0).push_back(at);
1113 MathArray pipeThroughExtern(string const & lang, string const & extra,
1114 MathArray const & ar)
1116 if (lang == "octave")
1117 return pipeThroughOctave(extra, ar);
1119 if (lang == "maple")
1120 return pipeThroughMaple(extra, ar);
1122 // create normalized expression
1124 NormalStream ns(os);
1125 os << "[" << extra << ' ';
1128 string data = os.str().c_str();
1130 // search external script
1131 string file = LibFileSearch("mathed", "extern_" + lang);
1133 lyxerr << "converter to '" << lang << "' not found\n";
1137 // run external sript
1138 string out = captureOutput(file, data);
1140 mathed_parse_cell(res, out);