How to make the output of Maxima cleaner?

a 夏天 提交于 2019-12-04 08:59:49

(1) To suppress output, terminate input expressions with dollar sign (i.e. $) instead of semicolon (i.e. ;).

(2) To get just the TeX-ified expression sans the environment delimiters (i.e. $$), call tex1 instead of tex. Note that tex1 returns a string, which you have to print yourself (while tex prints it for you).

Combining these ideas with the stuff you showed, I think your program could look like this:

"x: 1/2$ print(tex1(\f(x)))$"

I think you might find the Maxima mailing list helpful. [1] I'm pretty sure there have been several attempts to create a system such as the one you describe. You can also look at [2].

[1] http://maxima.sourceforge.net/maximalist.html [2] http://maxima.sourceforge.net/relatedprojects.html

If you really want to use LaTeX then the maxiplot package is the answer. It provides a maxima environment inside of which you enter Maxima commands. When you process your LaTeX file a Maxima batch file is generated. Process this file with Maxima and process your LaTeX file again to typeset the equations generated by Maxima.

If you would rather have 2D math input with live typesetting then use TeXmacs. It is a cross-platform document authoring environment (a word processor on steroids if you like) that includes plugins for Maxima, Mathematica and many more scientific computing tools. If you need to or are not satisfied with the typesetting, you can export your document to LaTeX.

I couldn't find any way to completely clean up Maxima's output within Maxima itself. It always echoes the input line, and always writes some whitespace after the output. The following is an example of a perl script that accomplishes the cleanup.

#!/usr/bin/perl

use strict;

my $var = $ARGV[0];
my $expr = $ARGV[1];

sub do_maxima_to_tex {
  my $m = shift;
  my $c = "maxima --batch-string='exptdispflag:false; print(tex1($m))\$'";
  my $e = `$c`;
  my @x = split(/\(%i\d+\)/,$e); # output contains stuff like (%i1)
  my $f = pop @x;  # remove everything before the echo of the last input
  while ($f=~/\A /) {$f=~s/\A .*\n//} # remove echo of input, which may be more than one line
  $f =~ s/\\\n//g; # maxima breaks latex tokens in the middle at end of line; fix this
  $f =~ s/\n/ /g; # if multiple lines, get it into one line
  $f =~ s/\s+\Z//; # get rid of final whitespace
  return $f;
}

my $e1 = do_maxima_to_tex("diff($expr,$var,1)");
my $e2 = do_maxima_to_tex("diff($expr,$var,2)");

print <<TEX;
The first derivative is \$$e1\$. Differentiating a second time,
we get \$$e2\$.
TEX

If you name this script a.pl, then doing

a.pl z 3*z^4

outputs this:

The first derivative is $12\,z^3$. Differentiating a second time,
we get $36\,z^2$.

For the OP's application, a script like this one could be what is invoked by the write18 in the latex file.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!