Legend Position in Maxima Plots

Here’s something I just learned and want to share with others and record for my use the next time I need to do this and have already forgotten!

The position and appearance of the figure legend in Maxima plots drawn with plot() (by setting gnuplot_preamble) and in draw() (by setting user_preamble),  can be manipulated to any of the gnuplot options listed here.

Here are some examples:





My Two Favorite wxMaxima Keyboard Shortcuts

Alt Up to recall previous commands to the current input line

In Matlab and RStudio, I love the ability to recall a command I’ve already typed using the up arrow key.  Today I discovered alt up arrow to do the same in wxMaxima!

Ctrl Shift K  for autocompletion and function template

This is really the best implementation of function templates I’ve seen in an IDE:

In wxMaxima, if I type inte  and then ctrl shift k, I see a popup menu of possible completions.  Choosing integrate results in an input cell template that looks like:


Pressing Tab highlights <expr> and I simply type the expression to be integrated.   A second press of Tab key highlights <x> and I type the name of the independent variable.

But wait, there’s more:  this works for any currently defined function—including user defined functions.

**UPDATE**  In the newer versions  of wxMaxima (since v15.10)   Ctrl+Tab and Shift+Ctrl+Tab also trigger autocompletion.

Maxima Language Syntax Highlighting in Notepad++


Notepad++ is lots of people’s favorite text editor for Windows.  I use it every day.

A little googling around led me to a Notepad++ user-defined syntax highlighting  file for the Maxima language, written by David Scherfgen and shared at the Maxima-Discuss list.

I made a little change to the file that overcame a nagging difficulty —  I found that .mac file extensions weren’t automatically being recognized upon opening.

Here’s a link to my modifed file.

To include Maxima syntax highlighting in Notepad++ do this:

  1. unzip the downloaded file MaximaNotepadDS.zip
  2. in Notepad++, go to Language –> Define your language…
  3. Press Import and navigate to the file MaximaNotepadDS.xml
  4. Quit Notepad++ and then start the program again.
  5. Now in Language menu, you’ll see Maxima in the list of languages at the bottom of the drop-down menu
  6. A  .mac file already open won’t display with the new syntax highlighting, but any .mac file you open or save from new will automatically show with syntax highlighting.

How to fix the \tag{}\label{} glitch in the wxMaxima “export to HTML” output


**Update:   This seems to be fixed in  wxMaxima versions > 16.04, but it remains an issue for MacOS users, who for the moment are stuck with an older version of wxMaxima.*****

The work flow in some of my classes involves:

  1. students doing work in wxMaxima
  2. exporting to HTML
  3. printing as PDF
  4. submitting the resulting document to a Dropbox link

The process is usually very slick, with only a few headaches.  Here is one such pain:  occasionally the result of a Maxima command will be displayed in the HTML document like as


That seems to happen if the expression name (here the matrix A) has been used before in the same session and the mathjax  latex-ish tag labeling gets confused by a multiply-defined tag.

To work around that, unselect the “Show user-defined labels instead of (%oxx)” option in Configure/Preferences.  That way, unless an exported document is the result non-re-evaluated cells between several Maxima sessions, the labels should be unique.


And one last thing:  If the work has been done (and saved) between several wxMaxima seesions, it’s possible that the number output lines like %o23 etc  might not be unique, so before exporting, I suggest Cell –> Evaluate All Cells.

An odd gnuplot error and a work-around using maxima_tempdir


I also have this problem in the latest windows installation—on the same machine that long filenames were never a problem before in Maxima.  To fix it choose the sbcl version of maxima, as described at My Windows Installation.


I have a student running wxMaxima on his windows laptop.  He has partitioned his hard drive so he can run Windows 10 as well as other operating systems.

When he attempts any plotting command, he gets an error:


The part of the error message with directory name TANUSH~1 says to me that there is some problem with the long directory name, possibly also a problem caused by a space in that directory name, possibly due to the way those new partitions are formatted.

As a workaround, we set the maxima option maxima_tempdir to point to another directory and all worked as expected:


Of course, that new directory will now fill up with files with names like maxout_xxxx.dat and maxout_xxxx.gnuplot, but that was already happening in the default directory.  A natural feature for wxMaxima to include in future releases would be to clean up the directory by deleting all those files when the program is stopped…

Maxima Language Code Translations

Have you seen these sites?

Hyperpolyglot.org  and Rosettacode.org  provide a valuable help for users who need to solve a problem in a new language:  Line-by-line comparisons  with lots of other languages.

For Maxima users, Hyperpolyglot’s computer-algebra system section  has side-by-side tables of comparisons with Mathematica, Maple, Sage and Numpy.

Rosettacode is arranged by task, with user-contributed solutions to common tasks in lots of languages.  I was motivated to write this post while working on a new Maxima version of an ordinary differential equations course I’ve taught for years using MATLAB.

 Here is Rosettacode’s section on the Euler Method  — a method for numerical approximation to the solution of a first order ordinary differential equation.

For the record, this is the version I decided to teach in my course:

(    /* Euler Method for  initial value problem
          y'=xy ,  y(0)=0.5   */ 
for i:1 thru nsteps do (

:=, ”(), define and div, grad, curl

I recently posted about : and :=  for defining functional expressions.  I’m starting to enjoy these emoji-like constructions 😉

This is another  colon-equals post.  This time for defining functions involving the maxima differentiation command diff.

Notice below that if we define a function with :=, the naive use of :=diff doesn’t produce a derivative with the expected results upon evaluation.


In fact, it’s a good thing that :=diff works like that.  The error with fp(3) above comes from the fact that we’ve actually defined an operator that differentiates the function with respect to the argument we pass…in the case above, differentiating with respect to the symbol u makes sense, while differentiating with respect to the constant 3 doesn’t.

So how to make the derivative function do what we want?  Two ways, that are subtly different, in ways I’m not completely sure of.  More about that when I learn more :-).

First is define,


Also you can use    ”()       quote-quote with parens around the whole right hand side:


I used define to write functions for vector valued 3D curves in an earlier post.   In figuring this out, I also learned that the :=diff form is really useful.  Below are three little functions in which I use :=diff to define the vector calculus operators grad, div and curl.  Notice that we pass the function f as an argument, and the :=diff form allows Maxima to differentiate them behind the scenes and return the results of the grad, div, and curl operators as you’d expect. These versions of div, grad and curl behave differently, and for me more as expected, than the functions of those names included in the Maxima vect package.  You can download the .mac file here.

/* Three Maxima functions for the multivariable calculus operators  grad, div, and curl
TheMaximaList.org, 2016



curl(f,x,y,z):=[ diff(f[3],y)-diff(f[2],z),
diff(f[2],x)-diff(f[1],y) ]$

Here is a screenshot showing how to call these functions:


$latex \int x^2 dx$

I’m testing the latex math-mode utility in WordPress.com.  The first thing to know is that based on the way the title of this post appears, the latex utility doesn’t work in post titles.

The rub here is that MathJax would be the natural solution, but WordPress.com isn’t compatible with JavaScript.  

That leaves us with $, followed by the word latex, followed by my latex markup, followed by a closing $ , which I illustrate  below with a screenshot because I don’t know how to quote a string verbatim in WordPress:


This works OK as inline style math \int x^2 dx and I think we could simulate display math mode like this with manual paragraph centering and with the optional size argument &s=1 inside the dollar signs (the default size is 0)

\int x^2 dx

and then back to inline for f(x).

And there it is.

The official guide to the  WordPress \LaTeX utility  can be found here.

Functions, :, and :=

I’m really posting this for myself to act as a big paperweight.  Whenever I forget about :=  and : for functions in Maxima, I can refer to this page.

The gist:

  • g(x):=x^2  results in a function you can evaluate as g(3)
  • f: x^2 results in an expression you can evaluate with ev(f,x=3)
  • ev works with both:  ev(g(x),x=3)  or ev(f,x=3)
  • also subst(x=3,f) and subst(x=3,g(x))
  • based on our definition, g doesn’t have a meaning…only  g(x) does
  • likewise, f(3) doesn’t have a meaning here…only the symbol f does
  • finally h:=x^2 gives an error — explicit dependent variable needed with :=




A few notes about exporting to .tex in Windows

23 March, 2016 Update!  The following was true for my windows installation of version wxMaxima 15.8.1-git.  I’ve just updated to wxMaxima 15.8.2 64 bit windows version and all is as expected — put TeX: at the beginning of the each text cell, then write latex like a boss.  I’m still not using dollar signs, for compatibility with mathJax when I export to html format 🙂

I really became a believer in the usefuless of Maxima as a productive part of my (and my students) workflow because of the easy way wxMaxima allows the user to document their work in an html or pdf (via pdflatex) document that include LaTeX markup for beautiful mathematical notation.

On my linux machine (Ubuntu 14.04) exporting my wxMaxima session to .tex behaves pretty nicely — maybe I’ll make a future post about that.  In particular, simply putting the string “TeX:” at the beginning of the document allows free use of LaTeX markup to be correctly rendered in the exported .tex document.  This doesn’t work in my Windows version, as well as a few other things described here.

In this post, I’ll describe what I’ve been doing to work around the problems in .tex export in Windows while being consistent with typesetting markups that make for good-looking HTML exports as well.

Goodbye dollar signs

After 25 years of using $…$ for inline math mode and $$…$$ for basic display math mode in LaTeX, I’ve begun using \( … \)  and \[ … \] respectively, because MathJax  (which can be a part of a delicious HTML export from wxMaxima) doesn’t respond to $…$, probably because the dollar sign has other non-LaTeX uses (!)   Another good reason to avoid $…$ in writing  wxMaxima documents is that dollar sign has a specific purpose of suppressing output for a Maxima command, although that problem goes away after the second of the fixes I describe below.

While avoiding $ for LaTeX math mode in wxMaxima documents doesn’t solve all the problems with export to .tex, it does reduce the number of post-processing fixes I need to do to the .tex file to get it to properly compile.

First, my wxMaxima document, with text cells that contain math formulas is shown in this screenshot:


After export to .tex , I get a file that includes the following latex source snippet.  Notice where I’d like inline math, there is in every case \ensuremath{\backslash}.


What is \ensuremath{\backslash} and why does wxMaxima insist on it?

I don’t have an answer for what or why, but it turns out all those \ensuremath{\backslash} statements don’t compile in pdfLaTeX.  A lot of error messages emanate from pdfLaTeX.  The resulting pdf is given below.  Notice the \( isn’t recognized as the start of LaTeX inline math.  The compiler gets the hint about math mode when it sees the superscript, but the \ensuremath{\backslash} gets in the way again and again:


Yuck!  And all I really wanted in that latex source was \(  and \)…

Find and Replace All

I edited the .tex source with a find-replace-all every occurrence of \ensuremath{\backslash} with \    and the result is much nicer:


However, there are still a bunch of pdflatex errors from the lines corresponding to the maxima input and output. Turns out anything that LaTeX finds in the maxima that wants to be in math mode, in this case the superscript x^2, results in an “inserted missing $”, kind of error.  Lots of them, in fact.

You can see that in the blue text in the graphic above:  the first occurrence of the variable x is not in math mode, then everything after the ^ is, which then makes the sin(x) appear incorrectly because latex would have wanted \sin, which wouldn’t make sense as a Maxima command.

Maxima input looks better verbatim

To remedy the compiler errors and, in my opinion, make the maxima input clearer for the reader than it would have been if the LaTeX would have somehow known what to make of it, I further edited the latex code, inserting the LaTeX “verbatim” command \verb in each occurrence of maxima input:


And the resulting pdfLaTeX compiled pdf looks great: