4
$\begingroup$

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?

$\endgroup$
5
  • $\begingroup$ What version of Mathematica are you using? Your last Import renders as a nice graphic in 8.0.0. !Mathematica graphics $\endgroup$ Aug 2, 2012 at 15:39
  • $\begingroup$ @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. $\endgroup$
    – Ubiquitous
    Aug 2, 2012 at 15:54
  • $\begingroup$ @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. $\endgroup$
    – Jens
    Aug 2, 2012 at 15:58
  • $\begingroup$ 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. $\endgroup$
    – Jens
    Aug 2, 2012 at 16:02
  • $\begingroup$ 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. $\endgroup$
    – Ubiquitous
    Aug 2, 2012 at 16:22

1 Answer 1

5
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – Ubiquitous
    Aug 3, 2012 at 8:53

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.