# Epstopdf package not working with XeLaTeX in knitr ONLY

Background

I regularly use knitr in RStudio to typeset LaTeX documents using XeLaTeX with R chunks in them. This had worked fine up until this morning when RStudio stopped recognising that MiKTeX/Texworks was installed so would not compile the LaTeX into a PDF anymore. Uninstalling and reinstalling MiKTeX/Texworks solved the problem.

Problem

However, after reinstalling all of my LaTeX packages that I regularly use, I realised that one of them had stopped working : epstopdf. My EPS files were no longer appearing in the document. This still happens even after including --enable-write18 in the arguments for PDFLaTeX and XeLaTeX in the Texworks preferences.

This problem only occurs when using XeLaTeX in RStudio.

When using Texworks directly, epstopdf works fine. And when using PDFLaTeX in RStudio, it also works fine.

Can anybody tell me what I am doing wrong or why this has suddenly started happening?

MWE

\documentclass{article}
\usepackage{graphicx}
\usepackage{epstopdf}
\begin{document}
\begin{figure}
\centering
\includegraphics[width=1.1\linewidth]{example1.eps}
\caption{Example1}
\end{figure}
Copy and paste the following code to convert more images at the same time:
\begin{figure}
\centering
\includegraphics[width=1.1\linewidth]{example2.eps}
\caption{Example2}
\end{figure}
\end{document}

• Can you provide some sample code that one can use in R under knitr? Is this specific to a single image, or all of them? – Werner Aug 2 '16 at 16:06
• HI Werner, sure thing. It happens with all of my eps images. Here is some sample code which doesn't work with knitr using xelatex but works in every other way \documentclass{article} \usepackage{graphicx} \usepackage{epstopdf} \begin{document} \begin{figure} \centering \includegraphics[width=1.1\linewidth]{example1.eps} \caption{Example1} \end{figure} Copy and paste the following code to convert more images at the same time: \begin{figure} \centering \includegraphics[width=1.1\linewidth]{example2.eps} \caption{Example2} \end{figure} \end{document} – daj23 Aug 2 '16 at 16:29
• You shouldn't need to load epstopdf explicitly or use shell escape. But you may need to tell graphicx the driver you want to use since this is XeLaTeX and I don't think graphicx can always figure it out. (But I'm not certain of this - I might be thinking of something else.) – cfr Aug 2 '16 at 21:57
• Don't include the extension when loading the image with \includegraphics unless you are certain you need to do so for special reasons and why. – cfr Aug 2 '16 at 22:00
• Unfortunately removing the .eps and/or specifying it is XeLateX to graphicx didn't work – daj23 Aug 3 '16 at 16:13