5

Recently I ran into this problem when trying to use EPS-images produced by Mathematic in my TeX-documents.

The friendly people at TeX.SE took a look at my eps, and discovered the following "feature" of the eps-file produced by version 11. My image had a text string on a monocolor pink background. This was apparently included into the eps both as a string as well as outlined in some "purely" graphical form. I don't see it with GhostView, apparently the people at TeX.SE used more powerful methods. Anyway, when I used the psfrag package to substitute the string with a snippet of TeX, the literal string was substituted all right, but graphical "copy" stayed. Resulting in a less than pleasing image in my document.

Q: How do I coerce Mathematica to save a piece of Graphics in an EPS-file in such a way that a textual component on colored background is only saved as a string and not also as outlined graphics? I don't care if the colored component obscures the text in, for example GhostView, as long as psfrag can find the text string.

This could be a feature, but...

  • Two years ago I had produced a very similar eps with Mathematica v.9. Back then this graphical ghost was not there. I looked at that eps-file in GhostView, and the black text on pink background was nowhere to be seen - except that the literal string was part of the eps code because psfrag could replace it all right!
  • When I regenerated that two year old image using the version 9 notebook/source, things changed. Now I can see the black text in GhostView, psfrag leaves that part, and my typeset document is not so nice.

Below please find a minimal set of Mathematica commands to create the problem.

pinkki2 = ParametricPlot[u {Cos[t], Sin[t]}, {u, 1.8, 2.2},
   {t, 0.35, 0.7}, Mesh -> False, PlotStyle -> Pink];
pinkki1 = ParametricPlot[u {Cos[t], Sin[t]}, {u, 0.8, 1.2},
   {t, 0.35, 0.7}, Mesh -> False, PlotStyle -> Pink];
tekstit = Graphics[{
        Text["df", {0.4, 0.23}],
        Text["dr", {1.5, 1.35}], Text["dr", {0.75, 0.7}],
        Text["r1df", {0.6, 0.32}], Text["r2df", {1.43, 0.85}],
        Text["A", {0.82, 0.5}], Text["B", {1.68, 1.0}]}
        ];
Show[{tekstit, pinkki1, pinkki2}, AspectRatio -> Automatic, 
 Ticks -> None, AxesLabel -> {"X", "Y"}]

What changed in Mathematica's handling of eps from version 9 to version 11?

How can I go back to version 9 behavior?

I have tried tinkering with the order of the graphics-components in Show. If I use Show[{pinkki1,pinkki2,tekstit}] instead, then psfrag will not find the string, and won't do the substitution at all.

Below you see what it looks like psfrag+LaTeX have replaced one of the "A" strings with $dA_1$ and one of the "B"-strings with $dA_2$. The non-textual version of the string shows through - see the part with a magnifying glass.

enter image description here

Jyrki Lahtonen
  • 1,059
  • 7
  • 15
  • 2
    Where is the code used to produce the graphs then and now? How can we detect the presence of the undesirable feature? I'm afraid that asking "What changed in Mathematica's handling of eps from version 9 to version 11?" is too broad of a question. And should be constrained to your particular problem, of which you haven't provided enough information to reproduce it. – rhermans Jul 30 '18 at 07:53
  • Very sorry about that @rhermans. Mathematica commands now included. The eps-file was created by selecting the appropriate cell and using the Save Graphics as -interface. – Jyrki Lahtonen Jul 30 '18 at 08:55
  • 1
    There is too much noise in that code. Please provide a minimal working example. You are combining 15 plots. Do the following: create the image with the first 8 plots. Export it and check if the error persist. If it does, pick the first 4 plots. If it does not, pick the last 8 plots … you get the idea … do a binary search. Once you got the absolute minimum to reproduce the error, post again. – Hector Jul 30 '18 at 10:14
  • @Hector Now only the necessary three commands are listed. Sorry about the clutter earlier. I also added a link to the generated eps-file as well as the psfrag+LaTeX output. – Jyrki Lahtonen Jul 30 '18 at 10:58
  • FWIW, I have created EPS files using your code and right-click "Save Graphics As" in both MMA 9 and 11. After opening in Acrobat and trying to erase the text "A" with Acrobat TouchUp Text Tool, the EPSv11 works as expected: the text is erased and there is nothing behind. The EPSv9 does not allow me to erase because of non-standard fonts. – Hector Jul 30 '18 at 12:38
  • 3
    You might want use MaTeX. That might avoid your trip through psfrag. – Hector Jul 30 '18 at 12:51
  • Some parts of the EPS seem to be rasterized, as people on TeX.SE said. The "AllowRasterization" -> False option (in Export) should be able to prevent this. However, it has not worked for me for several versions (maybe not worked only for some graphics?). You may want to ask Wolfram Support about this. – Szabolcs Sep 17 '18 at 14:21
  • While this is non-ideal, the best solution I can think of is to just use MaTeX (even if this is not a very good solution as it requires you to modify your existing code). Let's assign the output of your Show to the graphics variable. Then (after loading MaTeX), try graphics /. Text[s_String, rest___] :> Text[MaTeX[s], rest]. This will replace any string in Text with its MaTeX-rendered equivalent. I assume these strings are all supposed to contain LaTeX code and that e.g. r2 should have been r_2. http://i.stack.imgur.com/nPoja.png – Szabolcs Sep 17 '18 at 14:26
  • Also, just to be clear: I am not trying to advertise MaTeX (a package written by myself). I simply can't give you a better solution than this. Perhaps someone else can. – Szabolcs Sep 17 '18 at 14:30
  • Thanks, @Szabolcs. – Jyrki Lahtonen Sep 17 '18 at 14:55
  • Thanks for the old tip @Hector. I have, indeed, switched to using MaTeX since. Works like charm, too. – Jyrki Lahtonen Nov 02 '23 at 17:26

1 Answers1

3

This problem is SOLVED by printing the offending text components using white color. In other words, when I use

tekstit = Graphics[{Text["df", {0.4, 0.23}],
        Text["dr", {1.5, 1.35}], Text["dr", {0.75, 0.7}],
        Text["r1df", {0.6, 0.32}], Text["r2df", {1.43, 0.85}],
        Text[Style["A", White], {0.82, 0.5}], 
   Text[Style["B", White], {1.68, 1.0}]}
        ]

instead of black text as in the question, the end result (after LaTeX and psfrag have done their parts) is as expected. The ghost text is no longer visible. And, psfrag still finds the literal string in the eps source code as long as in the show command tekstit is listed before the pink regions.

Jyrki Lahtonen
  • 1,059
  • 7
  • 15
  • I'm still interested in learning about what changed from version 9 to version 11. This thread may be related, but I cannot tell for sure. A step backwards by Wolfram if you ask me, but I guess they know something I don't. – Jyrki Lahtonen Sep 17 '18 at 15:42