# How to force xelatex to convert eps into pdf? speed issue with slow compilation of xelatex

I run a few simple tests to compare the compilation speed of pdflatex and xelatex. As most people said, I also found that xelatex is always much slower than pdflatex.

The reason for the slowness of xelatex I figured out is eps conversion process in xelatex.

I use eps image files created by Adobe Illustrator, and the average size of the eps file is 1MB. It seems that very time I compiled using xelatex, it will spend considerable time to convert the eps file. But pdflatex convert eps to pdf using "epstopdf" package only once in the first compilation. After the first compilation, pdflatex just use the converted pdf image file. The good thing is those converted pdf image file is significantly smaller than the original eps file, just around 20K.

I tried to use the pdf image file that generated by pdflatex in xelatex, it does speed up the compilation process significantly, though still not as fast as pdflatex, but made a big progress.

But "epstopdf" is not working in xelatex. Is there any other method to force xelatex to convert eps image into pdf file on the fly, so it can use pdf image file ever since the first compilation just as "epstopdf" does in pdflatex?

Why don't you simply call once epstopdf file.eps to convert your eps before running xelatex?

Beside this: Converting the file on the fly when it doesn't exist is not so difficult. E.g. compile this with xelatex --shell-escape:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\IfFileExists{testeps1.pdf}{}{\immediate\write18{epstopdf testeps1.eps}}
\includegraphics{testeps1}
\end{document}


But epstopdf doesn't convert only when the file doesn't exist but also compares file dates and updates the file if the eps has been changed and this is more difficult to implement in xelatex as some of the primitives used seem not to exist. So when you change the eps you must ensure that you trigger the conversion again.

• Thank you. So is it impossible to write latex code to compare file dates? I just feel that there should be a way to do this, because the package "epstopdf" can do this. – user15964 May 13 '15 at 7:34
• By the way, how to convert all eps files in the same directory in a single command line using "epstopdf"? – user15964 May 13 '15 at 7:39
• Depending on your shell for i in *.eps; do epstopdf $i; done would work. – DG' May 13 '15 at 7:57 • If you have several file dependencies and multiple working steps that should be date aware there is a simple solution, use make – MaxNoe May 13 '15 at 8:48 • @user15964 You have spaces in your file name (bad idea), so you must use quotes: for %i in (*.eps) do epstopdf "%i" – Ulrike Fischer May 13 '15 at 15:20 If your document becomes more and more complex, you should think about automating things. A great tool for this is Make: http://gnuwin32.sourceforge.net/packages/make.htm You have to write a Makefile, which is a simple text file (but without ending). A Makefile is a set of rules which describe how a target is made and which dependencies it has. All rules look similiar to this: target: dependecy1 dependency2 ... command1 command2  When you call a simple make in a directory with a Makefile in it, make runs the first rule it encounters. It builds a tree of the dependencys and processes them from top to bottom. It ckecks which files are dependencies are newer than the last target version und just runs the commands if it is necessary. By convention the first rule should be all, which should build your final targets. So for a LaTeX case with bibliography with biblatex/biber this would maybe look like this: all: mydocument.pdf mydocument.pdf: mydocument.tex myreferences.tex xelatex mydocument.tex biber mydocument.bcf xelatex mydocument.tex xelatex mydocument.tex  If you need to convert figures from eps to pdf it would make sense to put them into their own folders and define a rule that converts them to pdf. This would look like this: all: mydocument.pdf mydocument.pdf: mydocument.tex converted/fig1.pdf converted/fig2.pdf xelatex mydocument.tex converted/%.pdf: epsfigures/%.pdf epstopdf$< --outfile=$@  $@ is the name of the target file and $< is the first dependency, see https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html. The % matches all files with the patterns around it. However, this requires the converted directory to exist. Sou one should add a rule that creates the directory and add it as a static dependency (static dependencys are not checked for a date, they just have to exist.). These dependencies come after the regular ones, separated by a pipe |: all: mydocument.pdf mydocument.pdf: mydocument.tex converted/fig1.pdf converted/fig2.pdf xelatex mydocument.tex converted/%.pdf: epsfigures/%.pdf | converted epstopdf$< --outfile=$@ converted: mkdir -p converted  Another handy convention is, that there should be a rule named clean which deletes all output that the Makefile created. Here the tex option --output-directory=<dir> comes in handy. If we use a directory build for the LaTeX output, the clean method just has to delete build and converted. Also TeX usually should not stop if an error occured if you use automatic build system like make. To show you how a Makefile handles variables, i put the texoption in a variable: texoptions = --interaction=nonstopmode --output-directory=build all: build/mydocument.pdf build/mydocument.pdf: mydocument.tex converted/fig1.pdf converted/fig2.pdf | build xelatex$(texoptions) mydocument.tex

converted/%.pdf: epsfigures/%.pdf | converted
epstopdf $< --outfile=$@

converted:
mkdir -p converted

build:
mkdir -p build

clean:
rm -rf build
rm -rf converted


You can call a single rule by make <rule>. So make clean would delete all your created files for a clean start, e.g. after an error occured.

• Hi, MaxNoe! I figure out a way using pure cmd batch and posted it as an answer. Any suggestions is welcome. Especially, I want to know if there is a way to embed the bat code into latex, so I won't need external bat files. – user15964 May 15 '15 at 12:06
• you could do it with a filecontents environment – MaxNoe May 15 '15 at 12:15
• But there are many "%" symbol – user15964 May 15 '15 at 12:16
• and what is more, filecontents can't write .bat file directly. – user15964 May 15 '15 at 12:37
• why not? And a filecontents environment is put out verbatim no need to escape LaTeX symbols. – MaxNoe May 15 '15 at 13:31

I figure out a way myself, and found it working pretty good. So I answer my own question here. It is a method of using external .bat in Three steps.

First, create a bat file named conversion.bat in the latex directory with the contents as below

SETLOCAL ENABLEDELAYEDEXPANSION

for %%G in (*.eps) do @if not exist "%%~nG.pdf" (epstopdf "%%G") else (
(for /f "delims=" %%i in ('dir /B /O:D "%%G" "%%~nG.pdf"') do set newest=%%~xi) & (
if !newest!==.eps echo "%%G" modification time is newer & (epstopdf "%%G") else (
(for /f "delims=" %%i in ('dir /B /T:C /O:D "%%G" "%%~nG.pdf"') do set newest=%%~xi) & (
if !newest!==.eps echo "%%G" creation time is newer & (epstopdf "%%G")))))


Explanation: The above cmd batch code will first compare the modification time of .eps and .pdf, if there are .eps files which modification time is newer then run epstopdf to convert them. Then compare the creation time of .eps and .pdf, also convert the newer .eps file.

\begin{document}
\immediate\write18{conversion.bat}

text here

\end{document}


Third, if you are using winedt set option-->excution modes-->console application-->xelatex-->switches as --shell-escape.

Now compile your document. The external conversion.bat will automatically handle .eps conversion to .pdf