I want to make use of Maxima as the backend to solve some computations used in my LaTeX input file. I did the following steps.
Download and install Maxima.
Create a batch file named cas.bat
(for example) as follows.
rem cas.bat
echo off
set PATH=%PATH%;"C:\Program Files (x86)\Maxima-5.31.2\bin"
maxima --very-quiet -r %1 > solution.tex
Save the batch in the same directory in which your input file below exists. It is just for the sake of simplicity.
Create the input file named main.tex
(for example) as follows.
% main.tex
\documentclass[preview,border=12pt,12pt]{standalone}
\usepackage{amsmath}
\def\f(#1){(#1)^2-5*(#1)+6}
\begin{document}
\section{Problem}
Evaluate $\f(x)$ for $x=\frac 1 2$.
\section{Solution}
\immediate\write18{cas "x: 1/2;tex(\f(x));"}
\input{solution}
\end{document}
Compile the input file with pdflatex -shell-escape main
and you will get a nice output as follows.
!
Done.
Apparently the output of Maxima is as follows. I don't know how to make it cleaner.
solution.tex
1
-
2
$${{15}\over{4}}$$
false
Now, my question are
\frac{15}{4}
without $$...$$
?(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. I'm pretty sure there have been several attempts to create a system such as the one you describe. You can also look at the documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With