# 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: