17
$\begingroup$

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.

$\endgroup$
8
  • $\begingroup$ 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 $\endgroup$
    – Szabolcs
    Apr 14, 2015 at 14:17
  • $\begingroup$ Afraid not. UK, Mac OS X. $\endgroup$
    – Tom
    Apr 14, 2015 at 14:47
  • $\begingroup$ Not sure why I thought you were from Hong Kong ... $\endgroup$
    – Szabolcs
    Apr 14, 2015 at 14:48
  • $\begingroup$ Interesting assumption! haha $\endgroup$
    – Tom
    Apr 14, 2015 at 14:50
  • $\begingroup$ You are still on version 9 and have no opportunity to upgrade to 10? $\endgroup$
    – Szabolcs
    Dec 8, 2015 at 11:49

1 Answer 1

22
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ 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 :) $\endgroup$
    – Tom
    Apr 15, 2015 at 21:16
  • $\begingroup$ @Tom Maybe you shouldn't accept my answer. Someone might start working on this and post a more complete answer. $\endgroup$
    – Szabolcs
    Apr 15, 2015 at 23:22
  • $\begingroup$ Sounds like it would be easier to just upgrade to Mathematica 10.0. $\endgroup$ Dec 12, 2015 at 1:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.