[Tex/LaTex] “Undefined control sequence.” when using animate package (animateinline)

animate

\documentclass[11pt,a4paper,fleqn,final]{article}
%\usepackage{tikz}
\usepackage[tikz]{ocgx2}
\usepackage[dvipdfmx,loop,palindrome,autoplay]{animate}
\usepackage{chemfig}

\begin{document}
\begin{center}
\begin{animateinline}{1}
        \setatomsep{3em}\chemfig{O=C=O}
        \newframe
        \setatomsep{2.5em}\chemfig{O=C=O}
        \newframe
        \setatomsep{2em}\chemfig{O=C=O}
        \newframe
        \setatomsep{1.5em}\chemfig{O=C=O}
        \newframe
        \setatomsep{1em}\chemfig{O=C=O}
\end{animateinline}
\end{center}
\end{document}

When I compile this I get the following warning + nothing on the page.

! Undefined control sequence.
<argument> \LaTeX3 error: 
                           Erroneous variable \origin:pbs@obj16 used!
l.20 \end{animateinline}

The same goes with "\newframe". My suspicion is that its the pdfbase.sty that is throwing the error.

EDIT:

\documentclass[dvipdfmx,11pt,a4paper,fleqn,final]{article}
\usepackage[loop,palindrome,autoplay]{animate}

\begin{document}

\begin{center}
\begin{animateinline}{1}
        a
        \newframe
        b
        \newframe
        c
        \newframe
        d
        \newframe
        e
\end{animateinline}
\end{center}
\end{document}

This render: animate render

Best Answer

The driver dvipdfmx cannot be auto-detected and must be passed as an option to all packages which contain dvipdfmx-specific code. In the code example, these are animate and ocgx2 (not used, currently). (Another popular package is hyperref.)

Therefore, driver options are usually set globally with the documentclass as in:

\documentclass[dvipdfmx,11pt,a4paper,fleqn,final]{article}
%\usepackage{tikz}
\usepackage[tikz]{ocgx2}
\usepackage[loop,palindrome,autoplay]{animate}
\usepackage{chemfig}

\begin{document}
\begin{center}
\begin{animateinline}{1}
        \setatomsep{3em}\chemfig{O=C=O}
        \newframe
        \setatomsep{2.5em}\chemfig{O=C=O}
        \newframe
        \setatomsep{2em}\chemfig{O=C=O}
        \newframe
        \setatomsep{1.5em}\chemfig{O=C=O}
        \newframe
        \setatomsep{1em}\chemfig{O=C=O}
\end{animateinline}
\end{center}
\end{document}

Note that the animation widget size is defined by the first frame's dimensions and that the frames to follow are stretched or squeezed to fit into this widget. Consider putting all frames into a box with the same pre-defined width together with a \strut to also extend the box vertically, e. g.

\makebox[8em][c]{\strut\setatomsep{3em}\chemfig{O=C=O}}
Related Question