Writing Maxima expression to text file in TeX format (for LaTeX)

You want to write an Maxima expression to a file which can be read by other application e.g. LaTeX.

Lets say the expression is sys which contains variable RM. You first want to replace RM by R_m .  Be sure to load mactex-utilities if you have matrix. Without loading this module, the tex command generates TeX output, not LaTeX.

load( "mactex-utilities" )$ 
sys : RM * a / b * log( 10 )$
texput( RM, "R_m")$
sysTex : tex( sys, false)$
with_stdout( "outout.txt", display( sysTex ) )$

Other methods such as stringout, save and write put extra non-TeX characters in file.

I get the following in file outout.txt after executing the above.

{{\log 10\,R_m\,a}\over{b}}

Fix “unknown script ‘context.lua’ or ‘mtx-context.lua'”

  • `$ locate mtx-context.lua` in linux-shell. If it is found, then you probably need to export `TEXMF` variable.
  • In my case, all I had to do: `$ export TEXMF=/usr/share/texmf` on my system with ` OpenSUSE Leap installed. I installed `texlive-context` package using `zypper`.

Other solutions are here: http://tex.stackexchange.com/questions/53892/texlive-2011-context-problem