'Match Beamer equation size with animated Manim equation
I am trying to animate several equations in a Beamer presentation using the Manim library. After I generate the animations, I want to include them in the presentation with exactly the same size as if I had simply generated the equation in LaTex.
For example, I might want the text This is the Pythagorean theorem: $a^2 + b^2 = c^2$ but instead of a static equation, a^2 + b^2 = c^2 would be animated.
As I see it, there are two steps necessary that I don't know how to do yet:
- Generate the Manim animation with dimensions that exactly match the size of "a^2 + b^2 = c^2" within the frame. This requires cropping the animation to match the size of the equation.
- Rescale the animation when it is included in LaTeX such that the size matches the size of "a^2 + b^2 = c^2" generated by LaTeX.
For no. 2, my idea is to include \phantom{$a^2 + b^2 = c^2$} in LaTeX to create an empty space of the correct size for the animation, but I don't know how to get the size of the space touse as the width of the animation.
Minimum Working Example:
I have an Manim animation defined in a file named main.py:
from manim import *
class EquationScene(Scene):
def construct(self):
eq = MathTex('a^2 + b^2 = c^2', font_size=120)
self.play(Write(eq))
To generate the animation, I call manim main.py EquationScene --format=png. I then move the PNG files into a directory named animation in the same directory as my TeX document, animation.tex:
\documentclass{beamer}
\usepackage{animate}
\begin{document}
\begin{frame}
\begin{center}
This is the Pythagorean theorem: $a^2 + b^2 = c^2$.
% This needs to match the size of the equation above,
% but the scaling is wrong and there is extra whitespace
% around the equation. The choice "width=\linewidth" is
% obviously wrong, but ensures the animation at least
% fits in the frame.
\animategraphics[autoplay,width=\linewidth]{30}{animation/EquationScene}{0000}{0029}
\end{center}
\end{frame}
\end{document}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
