8
$\begingroup$

I am trying to implement a way in Mathematica to export graphics to PDF and then use Inkscape from within Mathematica to post process the resulting output with the pdf-latex export option in Inkscape. In this way, one can have a nice figure made in Mathematica, with labels generated by your latex file.

I have managed to get this working almost with the following code:

Module[{fig, str = NotebookDirectory[]},
 fig = Plot[Cos[2 x], {x, 0, 2 Pi}, AxesLabel -> {"$x$", "$\\cos{2x}$"}];
 Export[str <> "in.pdf", fig];
 RunProcess[{"inkscape", "-z", "-D",
  "--file=" <> str <> "in.pdf", "--export-pdf=" <> str <> "out.pdf","--export-latex"},
  ProcessEnvironment -> Association[DeleteCases[GetEnvironment[All], "LD_LIBRARY_PATH" -> _]]];
]

Incidentally, this was a major pain in itself because Mathematica changes the PATH variable.

Unfortunately, this still does not work because for some reason Mathematica creates individual text fields for every part of a string that is separated by a space or some funny symbol. In any case, in the example above the x-axis label is processed fine, but the y-axis label is separated in five different text fields:

"$\cos", "{", "2x", "}", "$"

In this example, I could have given $\\cos\\,2x$ as the y-axis label instead, and this would have worked, but for more complicated formula this fix does not work and the .tex file that is created by Inkscape is worthless. Moreover, any negative number on the ticks is also broken in this way because the minus sign is split off from the magnitude.

I have also tried exporting as a .svg file but that does not work at all, because Mathematica includes text as a graphic in the .svg file.

My OS is Ubuntu 14.04 LTS and my Mathematica version is 10.4.1.0

Question:

Is there a way to force Mathematica to export a pdf in such a way that strings are included as a single text field in the pdf?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.