Exporting examples for use in other applications



Neuwirth Erich <erich.neuwirth at univie.ac.at> writes:

> org-mode for Emacs can embed maxima code in documents.

You can embed Maxima, or BC, or what-have-you in LaTeX--all that is
needed is file i/o and the \write18 system command. Here is a near
minimal working example of how to do this (the \exec macro in
exec.tex). I use a more elaborate version to write my beamer lecture
slides, course assignments and so on.

My point is that if there were a typesetter written in lisp, we could
construct mathematical objects in maxima, pass these to the typesetter
and vice versa. This kludge accomplishes this by communicating via the
filesystem and shell; org-mode relies on a 3rd language (elisp). You'll
find other variations on this theme out there.

Leo

%% execample.tex

\documentclass{article}
\input{exec.tex}

\newcommand{\maximaresult}[1][maxima.out]{\IfFileExists{#1}{\input{#1}}{\message{File
#1 does not exist, skipping.}}}
\newcommand{\maximasolve}[3][maxima.out]{%
  \exec{maxima --lisp=gcl --init-mac=./maxima-init.mac < \execinput}%
  {s:solve(#2,#3); texout("#1",s);}}
\newcommand{\bcresult}[1][\execoutput]{\IfFileExists{#1}{\input{#1}}{}}

\begin{document}
\exec{bc -l < \execinput}{a(1)}

The $\arctan$ of $1$ is \bcresult.

\def\eqn{x^2-1}
\maximasolve{\eqn}{x}
The solutions to $\eqn$ are \maximaresult

\end{document}

%% exec.tex

\usepackage{verbatim}
\newwrite\execwrite
\def\execoutput{exec.out}
\def\execinput{exec.in}
\def\execerr{exec.err}

\def\exec#1#2{%
\begingroup%
\def\execbin{#1}\def\spacetok{ }%
\immediate\openout\execwrite\execinput%
\immediate\write\execwrite{#2}%
\immediate\closeout\execwrite%
\immediate\write18{\execbin \spacetok 1> \execoutput \spacetok 2>
\execerr}%
\endgroup%
}

%% maxima-init.mac
file_output_append:false $
texout(f,x) := (with_stdout(f,tex(x)), file_output_append:true);


-- 
Leo Butler                <l_butler at users.sourceforge.net>
SDF Public Access UNIX System -   http://sdf.lonestar.org