Patch attached. To test it, you need Maple and tclsh somewhere in $PATH.
If you put your cursor in a cell and press M-m M-m M-s (or M-x math-extern maple simplify) a '=' and the result of Maple's "simplify" command applied to the formula will be appended. Similar: M-m M-m M-f (or M-x math-extern maple factor) M-m M-m M-x (or M-x math-extern maple expand) Alternately, you could select some part of a formula, press the hotkeys and get the selected part replaced by the result of the operation. Note that you have to put in explicit multiplication marks in form of '*' or '\cdot'. I haven't found a reliable way to guess the proper places to put them in automatically. Andre' -- André Pönitz .............................................. [EMAIL PROTECTED]
Index: lib/bind/math.bind =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/bind/math.bind,v retrieving revision 1.7 diff -u -p -r1.7 math.bind --- lib/bind/math.bind 2001/10/15 10:30:32 1.7 +++ lib/bind/math.bind 2001/10/31 15:45:30 @@ -105,6 +105,10 @@ \bind "C-Tab" "tab-insert" \bind "M-m space" "math-space" \bind "M-m S-G" "math-greek-toggle" +\bind "M-m M-m M-x" "math-extern maple expand" +\bind "M-m M-m M-s" "math-extern maple simplify" +\bind "M-m M-m M-f" "math-extern maple factor" +\bind "M-m M-x M-x" "math-extern mathml view" # This should be handled properly by some "get the next key" method Index: lib/mathed/extern_maple =================================================================== RCS file: extern_maple diff -N extern_maple --- /dev/null Tue May 5 22:32:27 1998 +++ extern_maple Wed Oct 31 16:45:30 2001 @@ -0,0 +1,158 @@ +#!/usr/bin/tclsh + +set lyxish [lindex $::argv 0] +set outfile [lindex $::argv 1] + +puts "outfile: '$outfile'" +puts "lyxish: '$lyxish'" + +proc binder {vars dats} { + foreach var $vars dat $dats { + uplevel set $var [list $dat] + } +} + +proc slurp {file} { + set t "" + set f [open $file r] + while {![eof $f]} { + append t [gets $f]\n + } + close $f + set t +} + +proc macro_mint {arg} { + binder {from to what var} $arg + return "int($what,$var=$from..$to)" +} + +proc macro {name args} { + set cmd macro_$name + if {[llength [info commands $cmd]] == 1} { + return [$cmd $args] + } else { + return "$name\($args)" + } +} + +proc formula {type content} { + return "$content" +} + +proc grid {args} { + return "$args" +} + +proc row {args} { + return "$args" +} + +proc cell {args} { + return "$args" +} + +proc cell {args} { + return "$args" +} + +proc symbol {name} { + switch -- "$name" { + cdot { return "*" } + } + return "`$name`" + puts "symbol '$name'" +} + +proc char {char type} { + return "$char" +} + +proc sqrt {base} { + return "sqrt($arg)" +} + +proc frac {num denom} { + return "(($num)/($denom))" +} + +proc root {base radix} { + return "(($arg)^(1/($radix))" +} + +proc sup {base exp} { + return "(($base)^($exp))" +} + +proc sub {base exp} { + return "`${base}_$exp`" +} + +proc delim {left right nest} { + return "$left$nest$right" +} + +# returns 1 iff extra '*' is needed +proc need_star {c1 c2} { + return 0 + if {[string match {[*+/-]} $c1]} { return 0 } + if {[string match {[*+/-]} $c2]} { return 0 } + if {[string match {)} $c1] && {[string match {(} $c1]}} { return 0 } + if {[string match {^} $c1]} { return 0 } + if {[string match {^} $c2]} { return 0 } + if {[string match {[0-9]} $c1] && [string match {[0-9]} $c2]} { return 0 } + return 1 +} + +# try to sneak in missing multiplication +proc par {str} { + set chars [split $str {}] + + set res "" + # loop over adjacent pairs of chars + foreach c1 [lreplace $chars end end] c2 [lreplace $chars 0 0] { + append res $c1 + if {[need_star $c1 $c2]} { + append res {*} + } + } + append res [lindex $chars end] + puts "par: $str -> $res" + set res +} + +proc simplify {args} { + return "simplify($args)" +} + +proc expand {args} { + return "expand($args)" +} + +proc factor {args} { + return "factor($args)" +} + +proc maplize {str} { + puts "maplizing 1: '$str'" + set str "[subst $str]" + puts "maplizing 2 res: '$str'" + set str +} + +proc maple_header {} { return { +readlib(latex): +#`latex/csname_font` := `\\it `: +`latex/csname_font` := ``: +`latex/latex/*` := subs(`\\,`=`\\cdot `,eval(`latex/latex/*`)): +#`latex/latex/symbol` := subs(('_' = '`\\_`',eval(`latex/latex/symbol`)): +}} + +file delete $outfile +exec echo "[maple_header]\nlatex([maplize $lyxish]); quit;" | maple -q > $outfile + +set result "[slurp $outfile]" +puts "result: '$result'" +regsub -all -- {\\_} $result {_} result +puts "result: '$result'" +exec echo "$result" > $outfile Index: lib/mathed/extern_mathml =================================================================== RCS file: extern_mathml diff -N extern_mathml --- /dev/null Tue May 5 22:32:27 1998 +++ extern_mathml Wed Oct 31 16:45:30 2001 @@ -0,0 +1,133 @@ +#!/usr/bin/tclsh + +set lyxish [lindex $::argv 0] +set outfile [lindex $::argv 1] + +puts "outfile: '$outfile'" +puts "lyxish: '$lyxish'" + +proc binder {vars dats} { + foreach var $vars dat $dats { + uplevel set $var [list $dat] + } +} + +proc slurp {file} { + set t "" + set f [open $file r] + while {![eof $f]} { + append t [gets $f]\n + } + close $f + set t +} + +proc tag {tag content} { + return "<$tag>$content</$tag>" +} + + +proc macro {name args} { + set cmd macro_$name + if {[llength [info commands $cmd]] == 1} { + return [$cmd $args] + } else { + return "$name\($args)" + } +} + +proc formula {type content} { + return $content +} + +proc char {char type} { + switch -- "$char" { + {=} - + {+} - + {-} - + {*} - + {/} { return [tag mo $char] } + default { puts "unknown char '$char'" } + } + switch -- {$type} { + mathop { return [tag mo $char] } + mathbin { return [tag mo $char] } + mathord { return [tag mo $char] } + mathpunct { return [tag mo $char] } + mathalpha { return [tag mi $char] } + mathopen { return [tag mi $char] } + mathclose { return [tag mi $char] } + default { return [tag mi $char] } + } +} + +proc grid {args} { + return "$args" +} + +proc row {args} { + return "$args" +} + +proc cell {args} { + return "$args" +} + +proc sqrt {arg} { + tag msqrt $arg +} + +proc frac {num denom} { + tag mfrac "$num$denom" +} + +proc root {base radix} { + tag mroot "$base$radix" +} + +proc sub {base exp} { + tag msub "$base$exp" +} + +proc sup {base exp} { + tag msup "$base$exp" +} + +proc cdot {} { + return "*" +} + +# returns 1 iff extra '*' is needed +proc need_star {c1 c2} { + if {[string match {[0-9]} $c1] && [string match {[a-zA-Z]} $c2]} { return 1 } + if {[string match {[0-9]} $c2] && [string match {[a-zA-Z]} $c1]} { return 1 } + if {[string match {)} $c1] && [string match {(} $c2]} { return 1 } + return 0 +} + + +proc par {args} { + tag mrow $args +} + +proc expand {args} { + return "expand($args)" +} + +proc view {args} { + return "$args" +} + +proc mathmlize {str} { + puts "mathmlizing input: '$str'" + set str [subst $str] + puts "mathmlizing output: '$str'" + set str +} + +file delete $outfile +puts [mathmlize $lyxish] +#exec xterm -e less $outfile.x +exec touch $outfile +#set result [slurp $outfile] +#puts "result: '$result'"