Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In the animate package, using \multiframe, how to deal with zero padding? For example if I have 101 pictures from pic0000.jpg to pic0100.jpg and I want to do something like that:

\documentclass{article}
\usepackage{animate}
\usepackage[demo]{graphicx}
\begin{document}
\begin{animateinline}[controls]{6}
\multiframe{101}{i=0+1}{
  The pic \i
  \includegraphics[height=.45\textheight]{pic\i}
 }
\end{animateinline}
\end{document}

but with the variable I varying from 0000 to 0100.

share|improve this question
    
animate has an internal macro for zero-padding you could use. See my answer below. –  AlexG Dec 12 '12 at 13:19
    
Tricky but that look the more straightforward. –  aberration Dec 12 '12 at 16:32
    
It's versatile, as you can specify any number of digits as the template string without modifying/extending the macro. –  AlexG Dec 12 '12 at 16:35

3 Answers 3

up vote 0 down vote accepted

Internally, animate defines the macro \@anim@pad{<template>}{<number>} for zero-padding numbers according to a template which is a string of arbitrary digits of the desired width.

In the example below \i is formatted (zero-padded) to four digits width (0000...0100):

\documentclass{article}
\usepackage{animate}
\usepackage[demo]{graphicx}

\makeatletter
\let\zeropad\@anim@pad
\makeatother

\begin{document}
\begin{animateinline}[controls]{6}
\multiframe{101}{i=0+1}{%
  The pic \i
  \includegraphics[height=.45\textheight]{pic\zeropad{1234}{\i}}%
}
\end{animateinline}
\end{document}
share|improve this answer

Prepend the zeros as you go based on a condition:

\multiframe{101}{i=1+1}{%
  \includegraphics[height=50pt]{pic0\ifnum\number\i<100 0\fi\ifnum\number\i<10 0\fi\i}%
}

The first condition

\ifnum\number\i<100 0\fi

inserts a 0 if \i is less than 100. The second condition

\ifnum\number\i<10 0\fi

inserts a 0 if \i is less than 10. This establishes the correct formatting for your external files.

share|improve this answer

Here is one way to pad the numbers so that they are always four digits:

enter image description here


Code: Test \PadDigits Macro:

\documentclass{article}
\usepackage{pgffor}

\newcommand*{\PadDigits}[1]{%
    % #1 = number to pad
    \ifnum#1<10 
        000#1%
    \else
        \ifnum#1<100
            00#1%
        \else
        \ifnum#1<1000
            0#1%
        \else
            #1%
    \fi\fi\fi
}%
\begin{document}

\foreach \x in {0,9,99,999,1000} {%
    \par\noindent
    Padding \x = "\PadDigits{\x}"
}
\end{document}

Code: Use with \includegraphics:

\documentclass{article}
\usepackage{animate}
\usepackage[demo]{graphicx}

\newcommand*{\PadDigits}[1]{%
    % #1 = number to pad
    \ifnum#1<10 
        000#1%
    \else
        \ifnum#1<100
            00#1%
        \else
        \ifnum#1<1000
            0#1%
        \else
            #1%
    \fi\fi\fi
}%

\begin{document}
\begin{animateinline}[controls]{6}
\multiframe{101}{i=0+1}{%
  The pic \i
  \includegraphics[height=.45\textheight]{pic\PadDigits{\i}}%
 }
\end{animateinline}
share|improve this answer
    
Just did a test with the animate package and it's work well, do you want that I post the MWE as an answer? –  aberration Dec 12 '12 at 3:12
    
@aberration: Done. Note the addition of the trailing % -- just in case there was any shifting in the animation as you may have spurious spaces without those chars. –  Peter Grill Dec 12 '12 at 3:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.