Quick
index
main
eev
eepitch
maths
angg
blogme
dednat6
littlelangs
PURO
(C2,C3,C4,
 λ,ES,
 GA,MD,
 Caepro,
 textos,
 Chapa 1)

emacs
lua
(la)tex
maxima
 qdraw
git
lean4
agda
forth
squeak
icon
tcl
tikz
fvwm
debian
irc
contact

An (eev-based) alternative to emaxima.sty

Long story short, in an image...
In this page I explain how I convert Maxima logs to LaTeX -
and how I generate things that look like this (click to go to the PDF):

My main page on Maxima is here.


1. Introduction: emaxima.sty
2. `emaxima.lisp'
3. Maxima2.lua
4. Maxima2.lua: a demo
5. `find-Maxima2-links'


1. Introduction: emaxima.sty

Maxima comes with something called "EMaxima", whose main files - for me - are these ones:

(find-maximagitfile "doc/emaxima/")
(find-maximagitfile "doc/emaxima/EMaximaIntro.tex")
(find-maximagitfile "interfaces/emacs/emaxima/")
(find-maximagitfile "interfaces/emacs/emaxima/emaxima.lisp")
(find-maximagitfile "interfaces/emacs/emaxima/emaxima.sty")
(find-maximagitfile "interfaces/emacs/emaxima/maxima-font-lock.el")
(find-maximagitfile "interfaces/emacs/emaxima/maxima.el")

I was mainly interested in one feature of emaxima.sty - the one that is explained in page 10 of its manual, that typesets LaTeX blocks like this one,

\begin{maximasession}
diff(sin(x),x);
integrate(cos(x),x);
\maximaoutput*
\i5. diff(sin(x),x); \\
\o5. \cos x \\
\i6. integrate(cos(x),x); \\
\o6. \sin x \\
\end{maximasession}
    as:    

The definition of the environment `maximasession' in emaxima.sty uses catcodes heavily, and so I couldn't put "\begin{maximasession} ... \end{maximasession}" blocks inside "\vbox"es or "\scalebox"es - it would by better to reimplement `maximasession' in another way.

The package `emaxima.sty' is a bit hard to use.

What I am going to explain in this page is an alternative to `emaxima.sty' that is much harder to use - and almost impossible to use if you are not me - but that has some ideas that I think that are worth documenting.


2. `emaxima.lisp'

If we run this

* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
load("/usr/share/emacs/site-lisp/maxima/emaxima.lisp")$
:lisp (setf (get '$display2d 'assign) nil)
display2d:'emaxima$
linenum:0;
diff(sin(x),x);
integrate(cos(x),x);

the last part of the log is:

(%i1) diff(sin(x),x);
(%o1) \cos x
(%i2) integrate(cos(x),x);
(%o2) \sin x
(%i3) 

that is similar to the syntax that `maximasession' understands.
Here is the reason for the `setf':

(find-es "maxima" "emaxima-bug-2024jul20")
(find-maximamsg "58797458 202407 21" "Edrx: display2d:'emaxima; fails in a recent Maxima")
(find-maximamsg "58797475 202407 21" "RDodier: :lisp (setf (get '$display2d 'assign) nil)")


3. Maxima2.lua

Dednat6 is a LaTeX package that I wrote, and that I use to typeset many kinds of diagrams. It very unpopular: I only know one person who uses, or who has used it, besides me - a friend of mine called Fernando Lucatelli - but Dednat6 is very easy to extend, and sometimes I write new extensions for it as quick hacks.

One of these extensions is Maxima2.lua. If I put this in a LaTeX file at any point after the part that loads Dednat6,

%L dofile "Maxima2.lua"
\pu

%M (%i1) diff(sin(x),x);
%M (%o1) \cos x
%M (%i2) integrate(cos(x),x);
%M (%o2) \sin x
%M (%i3)
%L maximahead:sa("sin-cos", "")
\pu

\def\hboxthreewidth {14cm}
\ga{sin-cos}

the "dofile" loads Maxima2.lua, that defines "%M" as a new "head"; the code for that is here. Then when Dednat6 processes the "%M"-block it simply puts the lines after the "%M"s into the global variable maxima_lines as a multi-line string, and when Dednat6 processes this line

%L maximahead:sa("sin-cos", "")

it "output"s this LaTeX code:

\sa{sin-cos}{%
  \vbox{%
    \maximablue{(\%i1)\ diff(sin(x),x);}%
    \maximared{(\%o1)\ }{}%
    \maximared{}{\cos x}%
    \maximared{}{}%
    \maximablue{(\%i2)\ integrate(cos(x),x);}%
    \maximared{(\%o2)\ }{}%
    \maximared{}{\sin x}%
    \maximared{}{}%
    \maximablue{(\%i3)}%
  }%
}

The definitions for "\sa", "\ga", "\maximablue", and "\maximared" are here:

(find-LATEX "edrx21.sty" "sa-and-ga")
(find-LATEX "edrx21.sty" "maximablue-red")

The "%M"-block is easy to tweak by hand. The "output" sends some (ugly!) TeX code both to the TeX part of lualatex and to stdout - it appears in the log, but I usually don't look at it.

Note that the " "s and the "%"s in the "(%i)" lines of the "%M"-block were converted to "\%"s and "\ "s. This was done by Co1.lua, as a trick to quote certain characters without needing to change catcodes.

The "\sa{sin-cos}" is a kind of "\def". I can expand its definition using "\ga{sin-cos}" - and I can do that inside the macros that I use for scaled multicolumn output.


4. Maxima2.lua: a demo

You can see a non-trivial example in this PDF. Note that it has a page that has two matrices with diagrams in its entries, that looks like this:

See my page on Qdraw and MyQdraw for some explanations - but they are very incomplete at this moment. Links:

(find-LATEX "2024-2-C3-maxima-conics.tex" "M-blocks")
(find-es "qdraw" "some-conics")

To download the source of that PDF and compile it on your machine, run this:

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
rm -rfv  /tmp/edrx-latex/
rm -rfv  /tmp/2024-2-C3-maxima-conics.zip
wget -P  /tmp/ http://anggtwu.net/LATEX/2024-2-C3-maxima-conics.zip
mkdir    /tmp/edrx-latex/
unzip -d /tmp/edrx-latex/ /tmp/2024-2-C3-maxima-conics.zip
cd       /tmp/edrx-latex/
lualatex 2024-2-C3-maxima-conics.tex
# (find-fline    "/tmp/edrx-latex/")
# (find-pdf-page "/tmp/edrx-latex/2024-2-C3-maxima-conics.pdf")


5. `find-Maxima2-links'

To generate an "%M"-block from a Maxima program I use `M-x find-Maxima2-links' - where find-Maxima2-links is a very messy 5-minute hack.