The problem is that \animategraphics uses LaTeX's \IfFileExists that uses the space as end marker of the file name. Then the result \@filef@und contains the file name including a final space. \animategraphics then removes the space via \zap@space that also kills spaces in between.
The following workaround redefines \animategraphics. It uses package grffile \grffile@IfFileExists instead of \IfFileExists, sets \@filef@und to the file name without the final space and neutralizes \zap@space.
\documentclass{article}
\usepackage{animate}
\usepackage{grffile}
\usepackage{letltxmacro}
\makeatletter
\@ifdefinable{org@animategraphics}{%
\LetLtxMacro\org@animategraphics\animategraphics
\renewcommand*{\animategraphics}{%
\begingroup
\@ifnextchar[{%
\def\anigrf@opt{[}%
\anigrf@animategraphics
}{%
\let\anigrf@opt\@empty
\anigrf@animategraphics
}%
}%
\newcommand{\anigrf@animategraphics}[5][]{%
\renewcommand{\IfFileExists}[3]{%
\grffile@IfFileExists{##1}{%
\let\@filef@und\grffile@file@found
\def\zap@space####1 \@empty{####1}%
##2%
}{##3}%
}%
\ifx\anigrf@opt\@empty
\org@animategraphics{#2}{#3}{#4}{#5}%
\else
\org@animategraphics[{#1}]{#2}{#3}{#4}{#5}%
\fi
\endgroup
}%
}
\makeatother
\begin{document}
\animategraphics[controls,autoplay,loop,scale=1]{10}{heart animation}{}{}%
\end{document}
Update for animate 2013/04/23
Since 2013/04/23 (or before?) package animate supports quoting of file names
(thanks mozartstraße for the hint):
\animategraphics[controls,autoplay,loop,scale=1]{10}{"heart animation"}{}{}%
Thus the patch is not needed.
However, I think, quotes do not belong to the user interface, there are already curly braces to delimit the file name argument. Thus the following updated patch automatically adds quotes, if spaces are detected. If quotes are already given,
then the file name argument is not changed.
\documentclass{article}
\usepackage{animate}
\usepackage{grffile}
\usepackage{letltxmacro}
\makeatletter
\@ifdefinable{org@animategraphics}{%
\LetLtxMacro\org@animategraphics\animategraphics
\renewcommand*{\animategraphics}{%
\begingroup
\@ifnextchar[{%
\def\anigrf@opt{[}%
\anigrf@animategraphics
}{%
\let\anigrf@opt\@empty
\anigrf@animategraphics
}%
}%
\@ifpackagelater{animate}{2013/04/23}{%
\def\anigrf@testspace#1 #2\@nil{%
\def\anigrf@tmp{#2}%
}%
\def\anigrf@testquote#1"#2\@nil{%
\def\anigrf@tmp{#2}%
}%
\newcommand{\anigrf@animategraphics}[3][]{%
% do nothing if the file name contains quotes
\edef\anigrf@file{#3}%
\@onelevel@sanitize\anigrf@file
\expandafter\anigrf@testquote\anigrf@file"\@nil
\ifx\anigrf@tmp\@empty % file name without quote(s)
% test for space in the file name
\@firstofone{\expandafter\anigrf@testspace\anigrf@file} \@nil
\ifx\anigrf@tmp\@empty % file name without space(s)
% do nothing, no spaces found
\expandafter\expandafter\expandafter\@firstoftwo
\else % file name with space(s)
\expandafter\expandafter\expandafter\@secondoftwo
\fi
\else % file name with quote(s)
\expandafter\@firstoftwo
\fi
{\anigrf@@animategraphics{#1}{#2}{#3}}%
{\anigrf@@animategraphics{#1}{#2}{"#3"}}%
}%
\newcommand{\anigrf@@animategraphics}[5]{%
\ifx\anigrf@opt\@empty
\org@animategraphics{#2}{#3}{#4}{#5}%
\else
\org@animategraphics[{#1}]{#2}{#3}{#4}{#5}%
\fi
\endgroup
}%
}{%
\newcommand{\anigrf@animategraphics}[5][]{%
\renewcommand{\IfFileExists}[3]{%
\grffile@IfFileExists{##1}{%
\let\@filef@und\grffile@file@found
\def\zap@space####1 \@empty{####1}%
##2%
}{##3}%
}%
\ifx\anigrf@opt\@empty
\org@animategraphics{#2}{#3}{#4}{#5}%
\else
\org@animategraphics[{#1}]{#2}{#3}{#4}{#5}%
\fi
\endgroup
}%
}%
}
\makeatother
\begin{document}
\animategraphics[controls,autoplay,loop,scale=1]{10}{heart animation}{}{}%
\end{document}
heart_animationbe a solution? – yo' Sep 28 '12 at 11:55.batfile? – egreg Sep 28 '12 at 12:15grffileand then a filename inside quotes:"foo bar"– Sep 28 '12 at 12:19animategraphicsaccepts spaces in a file name enclosed in double quotes, but instead ofheart animationlooks forheartanimation. – egreg Sep 28 '12 at 12:57...{heart\space animation}...– Sep 28 '12 at 13:19