I am playing with MaTeX to include an image. It works but it also displays the path of the image in the output which messes things out.

Here is a MWE (on windows with 11.3)

<< MaTeX`
SetOptions[MaTeX, "Preamble" -> {"\\usepackage{graphicx}"}];
MaTeX["This is a test \\includegraphics[width=.5\\textwidth]{C:/Program Files/Wolfram Research/Mathematica/11.3/Documentation/English/System/ExampleData/pearls.png} with data"]

which gives

Mathematica graphics

I'd like the path of the images not to show in the text output.

Mathematica graphics

Is there a way to do that?

MaTeX Version 1.7.4, Mathematica 11.3 on windows 10.

Could someone on windows 10 please try to see if they can reproduce this?


I also tried using \text{}

MaTeX["\\text{Test \\includegraphics[width=.5\\textwidth]{C:/Program Files/Wolfram Research/Mathematica/11.3/Documentation/English/System/ExampleData/pearls.png} image}","Preamble"->{"\\usepackage{graphicx}"}]

Mathematica graphics

  • $\begingroup$ I just tried this on macOS with MacTeX 2018 and I cannot reproduce the problem. I see only the images, not the path. I don't know why the path appears for you. i.stack.imgur.com/U8Bw2.png $\endgroup$
    – Szabolcs
    Jan 27, 2019 at 18:39
  • $\begingroup$ @Szabolcs thanks for trying. It might be a Platform related then? There are no errors or warning generated also. $\endgroup$
    – Nasser
    Jan 27, 2019 at 18:49
  • $\begingroup$ Can you try putting it in \text{}? Does it work then? $\endgroup$
    – Szabolcs
    Jan 27, 2019 at 19:19
  • $\begingroup$ @Szabolcs I did. I tried exactly your example. It did not work. I will now post that as well. $\endgroup$
    – Nasser
    Jan 27, 2019 at 19:24
  • $\begingroup$ I suggest you create a TeX-only minimal example and ask on TeX.SE. Do let me know if you found out why it happens or if you have a solution! To create a minimal example, do ClearMaTeXCache[] before the MaTeX call and add the option "TeXFileFunction" -> Print. This will show you the TeX source that MaTeX generates. As a first simplification, replace the \MaTeX{ ... } with simply $ ... $. Then you can remove most of the preamble (which just serves to define \MaTeX). $\endgroup$
    – Szabolcs
    Jan 27, 2019 at 19:43

1 Answer 1


This happens because the file path that you provided contains spaces. Everything after the first space is interpreted as text. This is discussed in this TeX.SE thread:

As mentioned there, the solution is to use grffile package.

Thus, use

"Preamble" -> {"\\usepackage{graphicx}", "\\usepackage{grffile}"}

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.