MaTeX for Mathematica 9

17

6

There's a great package called MaTeX that @Szabolcs wrote which allows one to easily use LaTeX within Mathematica for things like axes labels. After hours trying out various other solutions I downloaded a Mathematica 10 trial and the MaTeX package. So easy, you should give it a try if you haven't.

Anyway, it's not compatible with Mathematica 9 and I hoped somebody might have already tweaked the code for themselves to allow compatibility with their version 9? Maybe not, but you never know.

Tom

Posted 2015-04-14T09:23:00.017

Reputation: 3 096

Do you by any chance use a Chinese version of Windows so you could help me test this with your v10 trial? I should come back to this question later today

– Szabolcs – 2015-04-14T14:17:41.767

Afraid not. UK, Mac OS X. – Tom – 2015-04-14T14:47:46.540

Not sure why I thought you were from Hong Kong ... – Szabolcs – 2015-04-14T14:48:41.833

Interesting assumption! haha – Tom – 2015-04-14T14:50:39.647

You are still on version 9 and have no opportunity to upgrade to 10? – Szabolcs – 2015-12-08T11:49:44.037

My supervisor only has licenses for v9 and upgrading would cost thousands I think. A master's student just asked me how to use LaTeX with Mathematica and it reminded me of this post so I came back to check and thought I'd give it a bounty whilst I'm here just in case. – Tom – 2015-12-08T11:52:57.397

Sorry, I really don't have time to rewrite it for M9. You could also try this package: http://packagedata.net/index.php/#package-86 It solves much the same problem and I believe it works with earlier Mathematica versions. I have never used it because I was not aware of it when I started MaTeX.

– Szabolcs – 2015-12-08T12:48:55.823

Yeah sure totally I understand. Ok will check it out. Thank you – Tom – 2015-12-08T13:33:44.310

Answers

22

I am not willing to make MaTeX compatible with Mathematica 9 for the simple reason that it would create too much of a maintenance burden, and I already don't have time to properly respond to all support requests.


If anyone is willing to hack MaTeX to work with Mathematica 9, here's what needs to be done.

The primary reason why Mathematica 10 is required is RunProcess, which makes it much easier to call external commands than it was possible before. It lifts the burden of assembling command lines with proper handling of spaces in paths, escaped characters, etc., in a cross platform way. It can also capture standard output easily, and it doesn't cause a command window to pop up on Windows every time it is used, like Run does.

  1. In the iMaTeX function, RunProcess needs to be replaced with Run. You need to make sure spaces in paths are handled correctly. Note that on Windows, there's typically in a space in the path to either Ghostscript of pdflatex and there's also a space in the path to the temporary directory, where MaTeX creates temporary files.

    The most important place where I used RunProcess to capture standard output is when running pdflatex. Instead of capturing standard output (not easily possible with Run), you can just read in the TeX log file. See the logfile = ... line in iMaTeX.

    MaTeX also uses the exit code of processes, but that is already returned by Run.

  2. I used Associations for storing and handling various permanent settings, including the paths to Ghostscript and pdflatex. As a simplest solution, I would recommend ripping out the whole configuration system and instead hard-coding these settings as DownValues of $config inside MaTeX.m. This will get rid of some uses of associations and the remaining uses of RunProcess. Everything from the comment (* Load and check persistent configuration *) up to and including the definition of ConfigurMaTeX can be removed and replaced with something like $config["Ghostscript"] = "...hardcoded path to Ghostscript...".

  3. I also used Associations for caching results, which speeds up things and significantly improves the user experience. There are three choices here: (a) either remove the caching functionality entirely or (b) use plain memoization, without any bound on how many results are cached, and without the possibility to clear the cache, or (c) implement limited caching using DownValues using something similar to what I wrote here many many years ago...

I hope this information will help anyone who would like to try to make MaTeX work with Mathematica 9 on their own machine. Making it compatible with M9 and work robustly on all platforms, for everyone, without hard-coding settings, would take more work.

Szabolcs

Posted 2015-04-14T09:23:00.017

Reputation: 213 047

Thank you @Szabolcs I appreciate the guide. I have very little Mathematica expertise but I might manage. I'll report back if I have any success :) – Tom – 2015-04-15T21:16:25.167

@Tom Maybe you shouldn't accept my answer. Someone might start working on this and post a more complete answer. – Szabolcs – 2015-04-15T23:22:36.670

Sounds like it would be easier to just upgrade to Mathematica 10.0. – David G. Stork – 2015-12-12T01:43:53.090