I am interested to use LaTeX like labels in the plots that I prepare in Mathematica, and hence, I downloaded the MathPSfrag package from this website http://wwwth.mpp.mpg.de/members/jgrosse/mathpsfrag/ . Since I cannot attach any file here, I request anyone who is interested to help me, to download the package and run the MathPsfrag-Test.nb notebook. I apologize if the manner in which I am asking the question violates any code of conduct, but since I am new to this group, and because there are multiple files involved with long codes, I am not entirely sure about how else to ask.

This package has been tested only up to version 6, and I am using Mathematica 10 on Windows 7 machine. Unfortunately the package does not work, and I tried finding the problem and any solution to it myself, but without much success. Here is a summary of what I have found.

After unzipping the contents on the package, I followed the instructions and tried running the MathPSfrag-Test.nb notebook line by line. First and foremost I realized that the Windows 7 has a space in their folder names like Program Files, where all programs are installed, and hence, I gave the absolute path to the GhostScript executable, after which the MathPSfragConfigurationTest[] was successful. After that I started executing the notebook step-by-step, and got stuck at the command:


I tried investigating a bit into MathPSfrag.m file, and found the following:

  1. The UtilitiesFilterOptions is replaced by FilterRules in version 10. Hence, I replaced all the commands with FilterOptions functions with the FilterRules function, but with the right syntax.

  2. Despite the above step, I get an error saying that FilterRules function needs two arguments. So I checked the HandleAutomaticPSfrag function defined in the package file, which is defined as HandleAutomaticPSfrag[gr_Graphics,opts___Rule]:= ... and realized that there is a opts___ argument that denotes a BlankNullSequence. The FilterRules as an example is used within this function as as

    FilterRules[opts, Options @ HandleAutomaticPSfrag]

    By using the HandleAutomaticPSfrag[exampleplot] command in the Test notebook, there seem to be no opts provided as a second argument, and this is where I think the FilterRules gets stuck.

However, if my explanation of the opts___ above is correct, then I do not understand how the old versions of Mathematica were able to run the package. This makes me feel that I am missing something obvious. Could someone please help me changing the package so that I can also use it with version 10?


  • 1
    $\begingroup$ You could instead look at LevelScheme and/or SciDraw $\endgroup$ Commented Aug 6, 2014 at 17:10
  • $\begingroup$ Thank you Blochwave! I downloaded the packages and skimmed through the user guides. It looks promising, but before I dig into more details of these packages and start using them, could you please tell me if the text formatting of the labels have Computer Modern fonts as used by Latex with the default font encoding, family and series used for the text and Math symbols respectively in LaTeX? $\endgroup$
    – Ameya
    Commented Aug 6, 2014 at 17:48
  • $\begingroup$ I'm afraid I don't know, you'll have to check yourself. $\endgroup$ Commented Aug 6, 2014 at 17:51
  • $\begingroup$ Well, this is a pretty cool package and I didn't know about it. I just published an alternative package, MaTeX, which also makes it easy to use LaTeX labels. $\endgroup$
    – Szabolcs
    Commented Mar 7, 2015 at 0:01

1 Answer 1


The following was supposed to be a comment, but since I'm new here, I have to put it into an answer.

I used the MathPSfrag package already in Mathematica versions 6, 7, 8 and 9, and everything worked fine (under Windows 7 and 8). Now, with Mathematica 10, the package is indeed no longer working. However, the problem is more serious than just an outdated FilterOptions package, but let me first comment on your question.

The correct way to replace the FilterOptions functionality is the following: Find all appearances of FilterOptions in MathPSfrag (here exemplified by application of FilterOptions to Export) and replace

FilterOptions[Export, opts]



This solves the problem of wrong number of arguments.

Then there is another issue due to a known bug in the AbsoluteOptions function. At least on my system (Win 8.1, Mathematica 10) Mathematica insists in producing error messages when evaluating AbsoluteOptions, even for harmless examples like AbsoluteOptions[Plot[Sin[x], {x, -2 Pi, 2 Pi}]]. In my case one can safely ignore these error messages. I did this with brute force by simply replacing each appearance of AbsoluteOptions[...,...] with Quiet[AbsoluteOptions[...,...]] in the MathPSfrag file. The same has to be done for the FullGraphics command.

The real problem with Mathematica 10 and MathPSfrag package resides in the fact that EPS files are exported differently (compared to older Mathematica versions), in particalur text labels. Usually, if an EPS file contains a text label this label is stored as cleartext: when opening an EPS (that contains text) with a text editor you can find all text strings in round brackets. MathPSfrag, or more precisely, the LaTeX PSfrag package, searches these strings and replaces them with TeX labels. Unfortunately, for some reason the way of storing EPS files in Mathematica 10 was changed. Text labels do no longer appear as cleartext but rather in an encrypted form, so PSfrag cannot replace them anymore. I suppose the problem is how fonts are embedded. As Verbeia noted in this post the export functionality in Mathematica 10 is now based on the Cairo library.

I'm afraid there's no easy solution to this problem (apart from using older Mathematica versions...), although I know that users of Inkscape encountered related problems but the Inkscape developers seem to have found a workaround in the current version.

Does anyone know if it is possible to change the way of EPS exporting in Mathematica 10?

  • $\begingroup$ Your last question needs to be submitted as a separate concise questions on Mathematica.SE. Both MathPSFrag and PSFrag seem to fail on Mathematica-generated EPS files. Did you possibly manage to find a workaround? $\endgroup$ Commented Sep 22, 2014 at 14:28
  • $\begingroup$ Not yet, unfortunately. In the EPS files the extensive use of shortcuts (bind def), letter spacing (kerning) and the new way of font embedding make it impossible to replace text labels. So far, I was not able to tell the Export function to use the old behavior. Thus, working with version 10 while exporting graphics with version 8 or 9 is the only option for me. $\endgroup$
    – Liouville
    Commented Oct 2, 2014 at 8:47

Your Answer

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

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