# Mathematica PDF import and fonts

I am trying to put nice LaTeX labels on my Mathematica plots. I can do this manually, or by introducing an extra GNUPlot step into my workflow, but it would streamline the process considerably if everything could be done within Mathematica--yielding a publication ready figure, ideally one that is resolution independent.

My solution so far has been to put a call to sciencesoft's LaTeX CGI routine as follows:

Import["http://sciencesoft.at/image/latexurl/?dev=png&template=math&src=\gamma_2"]


which yields a nicely typeset gamma like so: $$\gamma_2.$$ However, this produces a png and my preference would be to use a PDF version that is resolution independent so that I don't have to fiddle with getting the resolution on the PNG correct to match my output.

Entering the URL http://sciencesoft.at/image/latexurl/?dev=pdfwrite&template=math&src=\gamma_2 into my browser produces the kind of PDF that I am looking for and I can view said PDF in Acrobat and check that it has the fonts embedded. However, when I try to import this into Mathematica with

Import["http://sciencesoft.at/image/latexurl/?dev=pdfwrite&template=math&src=\gamma_2"][[1]]


I get something that looks like this (sorry for the ASCII rendition: as a new user I can't post images)

#         #
#         #
#         #  ##
#         #   #
#         #   #
#         #   #
###########   #
#
#


which appears to be the product of some kind of missing font problem. Does anyone know if/how I can get the PDF properly imported into Mathematica?

-
What version of Mathematica are you using? Your last Import renders as a nice graphic in 8.0.0. !Mathematica graphics –  belisarius Aug 2 '12 at 15:39
@belisarius I have version 7.0.0. I will try to get access to an 8.0.0 machine and check whether it works there. –  Ubiquitous Aug 2 '12 at 15:54
@belisarius Same here. The reason the PDF renders fine is that it does not contain any text characters. All you see is outlined curves (check by double-clicking the elements). So this issue is not font related. –  Jens Aug 2 '12 at 15:58
Maybe you can avoid all this Import trouble by using the built-in capabilities for formula creation inside your plots directly: see e.g. my answer to Create complicated text formulas in graphics and the links at the bottom there. –  Jens Aug 2 '12 at 16:02
I get proper typesetting on a colleagues Mathematica 8.0.0 machine, but not in version 7.0.0.The object imported by Mathematica is indeed a set of outlined curves, but I think that is because Mathematica is creating the paths from the embedded computer modern fonts in v8. –  Ubiquitous Aug 2 '12 at 16:22

It's true that there is a problem in Mathematica version 7. I just remembered that I noted this here: outlining of glyphs on import as PDF is buggy in version 7. The confusing thing is that Import sets the option "TextOutlines" -> True so that outlines are indeed produced unless I specify "TextOutlines" -> False in the Import command.

For example, try (note that I corrected the single backslash to a double backslash inside the Mathematica string):

Import["http://sciencesoft.at/image/latexurl/?dev=pdfwrite&template=math&src=\\frac{a}{b}", "PDF", "TextOutlines" -> False][[1]]


which for me leads to a PDF graphic with actual text glyphs. Unfortunately, this fails when the characters are in a font not recognized by Mathematica, and in particular this is true for the Greek symbols.

Therefore, if I do the above command with $\gamma_2$, I see only the 2 and not the $\gamma$. This is a problem to which there is no general solution especially if you plan to import from web sources whose fonts you may or may not know.

The outlining technique is the best approach, but it simply doesn't work properly in version 7.

Therefore, I would still suggest trying to do the formula typesetting entirely in Mathematica instead of going via the online $\LaTeX$ detour.

-
Thanks for clearing that up. Since I can get access to a Mathematica 8.00 machine here I think I will execute my notebook there as I am quite keen to get my labels typeset in LaTeX. –  Ubiquitous Aug 3 '12 at 8:53