# Asymptote package: works with pdflatex and xelatex, but problems with lualatex

I would like to compile the following using the command sequence:

lualatex document.tex
asy document-1.asy
lualatex document.tex


However, this fails with the message:

! error:  (file "document-1".pdf) (pdf backend): cannot find image file '"document-1".pdf'
!  ==> Fatal error occurred, no output PDF file produced!


If I replace lualatex with pdflatex or xelatex the code works just fine. This is with mactex 2017. The test doc is the following:

\documentclass{article}
\usepackage{graphicx}
\usepackage{asymptote}
\begin{document}
Hello.
I like to make pics with Asymptote like this one:
\begin{figure}[h]
\begin{asy}
include graph;
size(1inch);
filldraw(circle((0,0),1),yellow,black);
fill(circle((-.3,.4),.1),black);
fill(circle((.3,.4),.1),black);
draw(arc((0,0),.5,-140,-40));
\end{asy}
\end{figure}
\par It makes me happy,
since I can still type my normal LaTeX stuff around it:
$$\int_0^{\pi}{\sin{x}}\,dx=2$$
\end{document}


My question is: how can I make this work with lualatex (which I am using for my main document)?

• The asymptote package tells the TeX engine to look at "document-1".pdf (literally with quotes), and LuaTeX does just that (it doesn't strip them like the other two engines). So, if you do mv document-1.pdf \"document-1\".pdf after the asy run, you'll get the desired result. I don't know which program is to blame though. – Sergei Golovan Jun 23 '17 at 3:42
• @SergeiGolovan This way pdf is produced, but with no graphics. The answer provided by @AkiraKakuto works though. Seems like asymptote package writers should adapt the package. – balcinus Jun 23 '17 at 6:57

I tried to rewrite several lines in asymptote.sty:

\documentclass{article}
\usepackage{graphicx}
\usepackage{asymptote}
\usepackage{ifluatex}
\ifluatex
\makeatletter
\def\asy@input@graphic{%
\ifASYinline
\IfFileExists{"\AsyFile.tex"}{%
\catcode:=12\relax
\@@input"\AsyFile.tex"\relax
}{%
}%
\else
\IfFileExists{"\AsyFile.\AsyExtension"}{%
\ifASYattach
\ifASYPDF
\IfFileExists{"\AsyFile+0.pdf"}{%
\setbox\ASYbox=\hbox{\includegraphics[hiresbb]{\AsyFile+0.pdf}}%
}{%
\setbox\ASYbox=\hbox{\includegraphics[hiresbb]{\AsyFile.pdf}}%
}%
\else
\setbox\ASYbox=\hbox{\includegraphics[hiresbb]{\AsyFile.eps}}%
\fi
\textattachfile{\AsyFile.\AsyExtension}{\phantom{\copy\ASYbox}}%
\vskip-\ht\ASYbox
\indent
\box\ASYbox
\else
\ifASYPDF
\includegraphics[hiresbb]{\AsyFile.pdf}%
\else
\includegraphics[hiresbb]{\AsyFile.eps}%
\fi
\fi
}{%
\IfFileExists{"\AsyFile.tex"}{%
\catcode:=12
\@@input"\AsyFile.tex"\relax
}{%
\PackageWarning{asymptote}{%
}%
}%
}%
\fi
}
\makeatother
\fi
\begin{document}
Hello.
I like to make pics with Asymptote like this one:
\begin{figure}[h]
\begin{asy}
include graph;
size(1inch);
filldraw(circle((0,0),1),yellow,black);
fill(circle((-.3,.4),.1),black);
fill(circle((.3,.4),.1),black);
draw(arc((0,0),.5,-140,-40));
\end{asy}
\end{figure}
\par It makes me happy,
since I can still type my normal LaTeX stuff around it:
$$\int_0^{\pi}{\sin{x}}\,dx=2$$
\end{document}

• I was having this same bug in ShareLaTeX, and copying and pasting your preamble code fixed it! Thanks so much! – Twiffy Aug 2 '18 at 18:51

The quotes are necessary in order to handle file names containing spaces, which many users unfortunately insist on. If you remove the quotes, lualatex will work, but only with file names that do not contain spaces. I will check to see if lualatex in TeXLive 2017 has been fixed to discard quotation marks.

• I am already running MacTeX 2017, which should have the same version of lualatex. – balcinus Jun 23 '17 at 16:31
• @John Bowman: Not fixed in TeX Live 2017. The quotes are in general necessary, so I enclosed by \ifluatex and \fi. – Akira Kakuto Jun 24 '17 at 7:52

That should be

asy document-1.asy


asy document-1.tex