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:



For starters…

The MaximaList: A reason for being

A first post on a new blog ought to do some explaining about motivations and reason-to-exist, and here is mine:  After using and teaching with R, I am increasingly convinced that the availability of a powerful, free, widely-used software tool provides a link for students and professionals between training and practice that unties us from traditional institution-level constraints.  It’s fine to learn statistics using SPSS in college, but unless you go to work at another big institution that owns an SPSS license, you’re faced with (a) convincing them to buy one, or (b) learning a new system from scratch —  a start-up process so formidable that your hard-earned training fades from disuse.  Likewise with Maple and Mathematica for symbolic computation, and MATLAB for numerics.  For statistics, the R language and the portable graphical user interface RStudio provides us with a tool that we can bring with us on our own machines wherever our work takes us, and a community of users that can and does support users at all levels of sophistication.  The tight integration of R Markdown document preparation in RStudio has opened up many possibilities and prepared our students to really make productive use of their statistical training in their careers that span the range of professional fields.

For the last twenty years, I have carried out an annual ritual, making the rounds of free alternatives to MATLAB that are portable and easily-installed on all widely used operating systems.  It is only in the last few years with FreeMat  that I’ve been able to bring students on a large scale to the point that they can learn to use the power of a language like MATLAB in a not-just-in-the-computer-lab way.  “Can I install this on my Mac?” is the question I have to answer with an easy “yes” before I would ever consider integrating a software package into my courses.  That is happily now the case with all the packages I’ve mentioned here.  Add to that the fact that MATLAB is both a language and a proprietary software package allows students to use these free-ware packages while setting the stage for productive work throughout their careers because the’ve learned that widely-used language.

And now Maxima.  I’m relatively new to the program but experienced in the framework:

  • Find a software solution that works for users at all levels of technical expertise and identically on all popular operating systems
  • Build the use of that software into the teaching, learning, and professional workflow
  • Integrate document preparation at every stage so that students and professionals don’t just learn to perform calculations but also see the processes of computation and  effective presentation of their work  as a single thing.

With the graphical user interface wxMaxima, this is all possible.  The MaximaList is dedicated to adding value to the community by advancing those three aims.