From 7de882829b92db975cf0e671bb93e44e6a0e885e Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Mon, 8 Jan 2007 19:00:24 +0000 Subject: [PATCH] Fix conversion of n-th roots to mathematica and octave syntax. * src/mathed/math_extern.C (pipeThroughOctave): take into account that the output from octave may contain ansi control sequences. * src/mathed/math_rootinset.[Ch] (MathRootInset::mathematica): new virtual method to output n-th roots in mathematica syntax. * src/mathed/math_rootinset.C (MathRootInset::octave): octave has not a root command. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_4_X@16612 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 10 ++++++++++ src/mathed/math_extern.C | 9 +++++---- src/mathed/math_rootinset.C | 8 +++++++- src/mathed/math_rootinset.h | 2 ++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index aa4bc24353..327547387c 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,13 @@ +2007-01-08 Enrico Forestieri + + * src/mathed/math_extern.C (pipeThroughOctave): take into account + that the output from octave may contain ansi control sequences. + + * src/mathed/math_rootinset.[Ch] (mathematica): new virtual method + to output n-th roots in mathematica syntax. + + * src/mathed/math_rootinset.C (octave): octave has not a root command. + 2006-12-29 Jean-Marc Lasgouttes * math_nestinset.C (handleFont): avoid crash on undo when diff --git a/src/mathed/math_extern.C b/src/mathed/math_extern.C index a5f0d01963..7ac04e960e 100644 --- a/src/mathed/math_extern.C +++ b/src/mathed/math_extern.C @@ -1273,11 +1273,12 @@ namespace { expr.insert(pos, 1, '*'); } - if (out.size() < 6) + // remove 'ans = ' taking into account that there may be an + // ansi control sequence before, such as '\033[?1034hans = ' + size_t i = out.find("ans = "); + if (i == string::npos) return MathArray(); - - // remove 'ans = ' - out = out.substr(6); + out = out.substr(i + 6); // parse output as matrix or single number MathAtom at(new MathArrayInset("array", out)); diff --git a/src/mathed/math_rootinset.C b/src/mathed/math_rootinset.C index 8822ae1bf5..974f76cfb6 100644 --- a/src/mathed/math_rootinset.C +++ b/src/mathed/math_rootinset.C @@ -97,9 +97,15 @@ void MathRootInset::maple(MapleStream & os) const } +void MathRootInset::mathematica(MathematicaStream & os) const +{ + os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))"; +} + + void MathRootInset::octave(OctaveStream & os) const { - os << "root(" << cell(1) << ',' << cell(0) << ')'; + os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))"; } diff --git a/src/mathed/math_rootinset.h b/src/mathed/math_rootinset.h index 19e7629300..abe5fdf5c3 100644 --- a/src/mathed/math_rootinset.h +++ b/src/mathed/math_rootinset.h @@ -37,6 +37,8 @@ public: /// void maple(MapleStream &) const; /// + void mathematica(MathematicaStream &) const; + /// void octave(OctaveStream &) const; private: virtual std::auto_ptr doClone() const;