From d4a534d404beb29323949e42562d0335cf21e7f3 Mon Sep 17 00:00:00 2001 From: Antonin Peronnet <62420525+rambip@users.noreply.github.com> Date: Thu, 16 Apr 2026 20:45:36 +0200 Subject: [PATCH 01/36] Add font size constants to constants.py --- manim/constants.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/manim/constants.py b/manim/constants.py index ccf99a0293..4d4c8dec80 100644 --- a/manim/constants.py +++ b/manim/constants.py @@ -177,12 +177,19 @@ DEFAULT_POINTWISE_FUNCTION_RUN_TIME = 3.0 DEFAULT_WAIT_TIME = 1.0 +# Font calculation +DEFAULT_TEX_FONT_SIZE_PT = 10 +PT_OVER_PX = 4 / 3 +DEFAULT_FONT_SIZE_IN_WOLRD_SPACE = 0.5 +"""Length occupied by an 'EM' character in manim space, using manim default font size. +An example of an 'EM' character is the em dash: '—'""" + # Misc DEFAULT_POINT_DENSITY_2D = 25 DEFAULT_POINT_DENSITY_1D = 10 DEFAULT_STROKE_WIDTH = 4 DEFAULT_FONT_SIZE = 48 -SCALE_FACTOR_PER_FONT_POINT = 1 / 960 + # Mathematical constants PI = np.pi From 3e8e21e8c50be5125ab42563504ae7fb81b00227 Mon Sep 17 00:00:00 2001 From: Antonin Peronnet <62420525+rambip@users.noreply.github.com> Date: Thu, 16 Apr 2026 21:12:16 +0200 Subject: [PATCH 02/36] Refactor text scaling and font size constants Updated text scaling and font size handling in text_mobject.py. --- manim/mobject/text/text_mobject.py | 34 ++++++++++++++++-------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/manim/mobject/text/text_mobject.py b/manim/mobject/text/text_mobject.py index d484420301..e3b5ab27df 100644 --- a/manim/mobject/text/text_mobject.py +++ b/manim/mobject/text/text_mobject.py @@ -79,10 +79,11 @@ def construct(self): from typing import Self from manim.typing import Point3D - -TEXT_MOB_SCALE_FACTOR = 0.05 + DEFAULT_LINE_SPACING_SCALE = 0.3 -TEXT2SVG_ADJUSTMENT_FACTOR = 4.8 +TEXT_FONT_SIZE_PT = 10 +"""The font size we use to render the unscaled text in the SVG. +Note that the typical EM dash (—) will be 13.333 svg units, since 1pt = 4/3 px""" __all__ = ["Text", "Paragraph", "MarkupText", "register_font"] @@ -590,7 +591,11 @@ def add_line_to(end: Point3D) -> None: each.points = np.array(closed_curve_points, ndmin=2) # anti-aliasing if height is None and width is None: - self.scale(TEXT_MOB_SCALE_FACTOR) + self.scale( + 1 / PT_OVER_PX # convert svg output to "pt" units + / TEXT_FONT_SIZE_PT # then to "fontsize" or "EM" units + * DEFAULT_FONT_SIZE_IN_WORLD_SPACE # then to world space + ) self.initial_height = self.height def __repr__(self) -> str: @@ -601,10 +606,7 @@ def font_size(self) -> float: return ( self.height / self.initial_height - / TEXT_MOB_SCALE_FACTOR - * 2.4 * self._font_size - / DEFAULT_FONT_SIZE ) @font_size.setter @@ -800,7 +802,7 @@ def _text2svg(self, color: ParsableManimColor) -> str: """Convert the text to SVG using Pango.""" size = self._font_size line_spacing = self.line_spacing - size /= TEXT2SVG_ADJUSTMENT_FACTOR + size /= TEXT2SVG_ADJUSTMENT_FACTOR / line_spacing /= TEXT2SVG_ADJUSTMENT_FACTOR dir_name = config.get_dir("text_dir") @@ -1302,7 +1304,11 @@ def add_line_to(end: Point3D) -> None: ) # anti-aliasing if height is None and width is None: - self.scale(TEXT_MOB_SCALE_FACTOR) + self.scale( + 1 / PT_OVER_PX # convert svg output to "pt" units + / TEXT_FONT_SIZE_PT # then to "fontsize" or "EM" units + * DEFAULT_FONT_SIZE_IN_WORLD_SPACE # then to world space + ) self.initial_height = self.height @@ -1311,10 +1317,7 @@ def font_size(self) -> float: return ( self.height / self.initial_height - / TEXT_MOB_SCALE_FACTOR - * 2.4 * self._font_size - / DEFAULT_FONT_SIZE ) @font_size.setter @@ -1345,10 +1348,9 @@ def _text2hash(self, color: ParsableManimColor) -> str: def _text2svg(self, color: ParsableManimColor | None) -> str: """Convert the text to SVG using Pango.""" color = ManimColor(color) - size = self._font_size - line_spacing: float = self.line_spacing - size /= TEXT2SVG_ADJUSTMENT_FACTOR - line_spacing /= TEXT2SVG_ADJUSTMENT_FACTOR + # scale down so that manim font size becomes a specific target size in pt for pango + size = TEXT_FONT_SIZE_PT * self._font_size / DEFAULT_FONT_SIZE + line_spacing = TEXT_FONT_SIZE_PT * self.line_spacing / DEFAULT_FONT_SIZE dir_name = config.get_dir("text_dir") dir_name.mkdir(parents=True, exist_ok=True) From 9916d45505a139cff114563c175ba6b9623b625f Mon Sep 17 00:00:00 2001 From: Antonin Peronnet <62420525+rambip@users.noreply.github.com> Date: Thu, 16 Apr 2026 21:26:10 +0200 Subject: [PATCH 03/36] Refactor font size management in tex_mobject.py Refactor font size handling in SingleStringMathTex class to use initial font size for calculations. --- manim/mobject/text/tex_mobject.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/manim/mobject/text/tex_mobject.py b/manim/mobject/text/tex_mobject.py index 729fbb158b..5d73286ae5 100644 --- a/manim/mobject/text/tex_mobject.py +++ b/manim/mobject/text/tex_mobject.py @@ -41,7 +41,9 @@ from ..opengl.opengl_compatibility import ConvertToOpenGL MATHTEX_SUBSTRING = "substring" - +TEX_DEFAULT_FONTSIZE_PT = 10 +"""The fontsize used by default by tex: 10pt. +This means that one 'EM' character like '—' will be 13.333 svg units, since 1pt=4/3 px""" class SingleStringMathTex(SVGMobject): """Elementary building block for rendering text with LaTeX. @@ -70,7 +72,7 @@ def __init__( if color is None: color = VMobject().color - self._font_size = font_size + self.initial_font_size = font_size self.organize_left_to_right = organize_left_to_right self.tex_environment = tex_environment if tex_template is None: @@ -97,11 +99,17 @@ def __init__( ) self.init_colors() - # used for scaling via font_size.setter - self.initial_height = self.height - if height is None: - self.font_size = self._font_size + self.scale( + 1 / PT_OVER_PX # convert latex svg output to pt + / TEX_DEFAULT_FONT_SIZE_PT # then to "fontsize" or "em" units + * DEFAULT_FONTSIZE_IN_WORLD_SPACE # then to worldspace + ) + + + # used for scaling via font_size.setter + # we use the initial size in world space + self.initial_height = self.height if self.organize_left_to_right: self._organize_submobjects_left_to_right() @@ -112,7 +120,9 @@ def __repr__(self) -> str: @property def font_size(self) -> float: """The font size of the tex mobject.""" - return self.height / self.initial_height / SCALE_FACTOR_PER_FONT_POINT + return ( + self.height / self.initial_height * self.initial_font_size + ) @font_size.setter def font_size(self, font_val: float) -> None: From de8524c5c188217127f53293fbeaa0b857dbce67 Mon Sep 17 00:00:00 2001 From: Antonin Peronnet <62420525+rambip@users.noreply.github.com> Date: Thu, 16 Apr 2026 21:53:19 +0200 Subject: [PATCH 04/36] Fix DEFAULT_FONT_SIZE_IN_WOLRD_SPACE definition Updated DEFAULT_FONT_SIZE_IN_WOLRD_SPACE value and corrected its description. --- manim/constants.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/manim/constants.py b/manim/constants.py index 4d4c8dec80..f97859b6d2 100644 --- a/manim/constants.py +++ b/manim/constants.py @@ -63,6 +63,7 @@ "DEFAULT_POINT_DENSITY_1D", "DEFAULT_STROKE_WIDTH", "DEFAULT_FONT_SIZE", + "DEFAULT_FONT_SIZE_IN_WOLRD_SPACE", "SCALE_FACTOR_PER_FONT_POINT", "PI", "TAU", @@ -178,18 +179,23 @@ DEFAULT_WAIT_TIME = 1.0 # Font calculation -DEFAULT_TEX_FONT_SIZE_PT = 10 PT_OVER_PX = 4 / 3 -DEFAULT_FONT_SIZE_IN_WOLRD_SPACE = 0.5 -"""Length occupied by an 'EM' character in manim space, using manim default font size. -An example of an 'EM' character is the em dash: '—'""" +DEFAULT_FONT_SIZE_IN_WOLRD_SPACE = 2 / 3 +"""Length occupied by an 'EM' character in manim space, when manim default font size is used. +An example of an 'EM' character is the em dash: '—'. +The chosen value is an arbitrary convention.""" # Misc DEFAULT_POINT_DENSITY_2D = 25 DEFAULT_POINT_DENSITY_1D = 10 DEFAULT_STROKE_WIDTH = 4 DEFAULT_FONT_SIZE = 48 - +SCALE_FACTOR_PER_FONT_POINT = ( # legacy, not used in code anymore + DEFAULT_FONT_SIZE_IN_WOLRD_SPACE + / (10 * PT_OVER_PX) # LaTeX default font size in pixels + / DEFAULT_FONT_SIZE +) +"""Downscale factor from LaTeX pixel to world space, divided by DEFAULT_FONT_SIZE""" # Mathematical constants PI = np.pi From 394d52a82e58ef675082ad1913baad099153cc3d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 16 Apr 2026 20:00:20 +0000 Subject: [PATCH 05/36] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- manim/constants.py | 6 +++--- manim/mobject/text/tex_mobject.py | 17 ++++++++--------- manim/mobject/text/text_mobject.py | 4 ++-- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/manim/constants.py b/manim/constants.py index f97859b6d2..c54f31be26 100644 --- a/manim/constants.py +++ b/manim/constants.py @@ -190,9 +190,9 @@ DEFAULT_POINT_DENSITY_1D = 10 DEFAULT_STROKE_WIDTH = 4 DEFAULT_FONT_SIZE = 48 -SCALE_FACTOR_PER_FONT_POINT = ( # legacy, not used in code anymore - DEFAULT_FONT_SIZE_IN_WOLRD_SPACE - / (10 * PT_OVER_PX) # LaTeX default font size in pixels +SCALE_FACTOR_PER_FONT_POINT = ( # legacy, not used in code anymore + DEFAULT_FONT_SIZE_IN_WOLRD_SPACE + / (10 * PT_OVER_PX) # LaTeX default font size in pixels / DEFAULT_FONT_SIZE ) """Downscale factor from LaTeX pixel to world space, divided by DEFAULT_FONT_SIZE""" diff --git a/manim/mobject/text/tex_mobject.py b/manim/mobject/text/tex_mobject.py index 5d73286ae5..44bc8bd4a8 100644 --- a/manim/mobject/text/tex_mobject.py +++ b/manim/mobject/text/tex_mobject.py @@ -45,6 +45,7 @@ """The fontsize used by default by tex: 10pt. This means that one 'EM' character like '—' will be 13.333 svg units, since 1pt=4/3 px""" + class SingleStringMathTex(SVGMobject): """Elementary building block for rendering text with LaTeX. @@ -101,14 +102,14 @@ def __init__( if height is None: self.scale( - 1 / PT_OVER_PX # convert latex svg output to pt - / TEX_DEFAULT_FONT_SIZE_PT # then to "fontsize" or "em" units - * DEFAULT_FONTSIZE_IN_WORLD_SPACE # then to worldspace + 1 + / PT_OVER_PX # convert latex svg output to pt + / TEX_DEFAULT_FONT_SIZE_PT # then to "fontsize" or "em" units + * DEFAULT_FONTSIZE_IN_WORLD_SPACE # then to worldspace ) - - # used for scaling via font_size.setter - # we use the initial size in world space + # used for scaling via font_size.setter + # we use the initial size in world space self.initial_height = self.height if self.organize_left_to_right: @@ -120,9 +121,7 @@ def __repr__(self) -> str: @property def font_size(self) -> float: """The font size of the tex mobject.""" - return ( - self.height / self.initial_height * self.initial_font_size - ) + return self.height / self.initial_height * self.initial_font_size @font_size.setter def font_size(self, font_val: float) -> None: diff --git a/manim/mobject/text/text_mobject.py b/manim/mobject/text/text_mobject.py index e3b5ab27df..829b71f727 100644 --- a/manim/mobject/text/text_mobject.py +++ b/manim/mobject/text/text_mobject.py @@ -79,7 +79,7 @@ def construct(self): from typing import Self from manim.typing import Point3D - + DEFAULT_LINE_SPACING_SCALE = 0.3 TEXT_FONT_SIZE_PT = 10 """The font size we use to render the unscaled text in the SVG. @@ -802,7 +802,7 @@ def _text2svg(self, color: ParsableManimColor) -> str: """Convert the text to SVG using Pango.""" size = self._font_size line_spacing = self.line_spacing - size /= TEXT2SVG_ADJUSTMENT_FACTOR / + size /= TEXT2SVG_ADJUSTMENT_FACTOR / line_spacing /= TEXT2SVG_ADJUSTMENT_FACTOR dir_name = config.get_dir("text_dir") From 24851f2df1ff76634937c11a117b971db09c92d8 Mon Sep 17 00:00:00 2001 From: Antonin Peronnet <62420525+rambip@users.noreply.github.com> Date: Thu, 16 Apr 2026 22:07:02 +0200 Subject: [PATCH 06/36] Refactor font size handling to use initial_font_size --- manim/mobject/text/text_mobject.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/manim/mobject/text/text_mobject.py b/manim/mobject/text/text_mobject.py index 829b71f727..68cc250dda 100644 --- a/manim/mobject/text/text_mobject.py +++ b/manim/mobject/text/text_mobject.py @@ -467,7 +467,7 @@ def __init__( else: logger.warning(f"Font {font} not in {fonts_list}.") self.font = font - self._font_size = float(font_size) + self.initial_font_size = float(font_size) # needs to be a float or else size is inflated when font_size = 24 # (unknown cause) self.slant = slant @@ -800,10 +800,8 @@ def _text2settings(self, color: ParsableManimColor) -> list[TextSetting]: def _text2svg(self, color: ParsableManimColor) -> str: """Convert the text to SVG using Pango.""" - size = self._font_size - line_spacing = self.line_spacing - size /= TEXT2SVG_ADJUSTMENT_FACTOR / - line_spacing /= TEXT2SVG_ADJUSTMENT_FACTOR + size = TEXT_FONT_SIZE_PT * self.initial_font_size / DEFAULT_FONT_SIZE + line_spacing = TEXT_FONT_SIZE_PT * self.line_spacing / DEFAULT_FONT_SIZE dir_name = config.get_dir("text_dir") dir_name.mkdir(parents=True, exist_ok=True) @@ -1183,7 +1181,7 @@ def __init__( else: logger.warning(f"Font {font} not in {fonts_list}.") self.font = font - self._font_size = float(font_size) + self.initial_font_size = float(font_size) self.slant = slant self.weight = weight self.gradient = gradient @@ -1208,10 +1206,10 @@ def __init__( if self.line_spacing == -1: self.line_spacing = ( - self._font_size + self._font_size * DEFAULT_LINE_SPACING_SCALE + self.initial_font_size + self.initial_font_size * DEFAULT_LINE_SPACING_SCALE ) else: - self.line_spacing = self._font_size + self._font_size * self.line_spacing + self.line_spacing = self.initial_font_size + self.initial_font_size * self.line_spacing parsed_color: ManimColor = ManimColor(color) if color else VMobject().color file_name = self._text2svg(parsed_color) @@ -1317,7 +1315,7 @@ def font_size(self) -> float: return ( self.height / self.initial_height - * self._font_size + * self.initial_font_size ) @font_size.setter @@ -1337,7 +1335,7 @@ def _text2hash(self, color: ParsableManimColor) -> str: + self.weight + ManimColor(color).to_hex().lower() ) # to differentiate from classical Pango Text - settings += str(self.line_spacing) + str(self._font_size) + settings += str(self.line_spacing) + str(self.initial_font_size) settings += str(self.disable_ligatures) settings += str(self.justify) id_str = self.text + settings @@ -1349,7 +1347,7 @@ def _text2svg(self, color: ParsableManimColor | None) -> str: """Convert the text to SVG using Pango.""" color = ManimColor(color) # scale down so that manim font size becomes a specific target size in pt for pango - size = TEXT_FONT_SIZE_PT * self._font_size / DEFAULT_FONT_SIZE + size = TEXT_FONT_SIZE_PT * self.initial_font_size / DEFAULT_FONT_SIZE line_spacing = TEXT_FONT_SIZE_PT * self.line_spacing / DEFAULT_FONT_SIZE dir_name = config.get_dir("text_dir") From bd606886fb4ba8b678f753223aa58f826be97cb8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 16 Apr 2026 20:07:18 +0000 Subject: [PATCH 07/36] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- manim/mobject/text/text_mobject.py | 33 ++++++++++++++---------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/manim/mobject/text/text_mobject.py b/manim/mobject/text/text_mobject.py index 68cc250dda..bf5e8ecf70 100644 --- a/manim/mobject/text/text_mobject.py +++ b/manim/mobject/text/text_mobject.py @@ -592,9 +592,10 @@ def add_line_to(end: Point3D) -> None: # anti-aliasing if height is None and width is None: self.scale( - 1 / PT_OVER_PX # convert svg output to "pt" units - / TEXT_FONT_SIZE_PT # then to "fontsize" or "EM" units - * DEFAULT_FONT_SIZE_IN_WORLD_SPACE # then to world space + 1 + / PT_OVER_PX # convert svg output to "pt" units + / TEXT_FONT_SIZE_PT # then to "fontsize" or "EM" units + * DEFAULT_FONT_SIZE_IN_WORLD_SPACE # then to world space ) self.initial_height = self.height @@ -603,11 +604,7 @@ def __repr__(self) -> str: @property def font_size(self) -> float: - return ( - self.height - / self.initial_height - * self._font_size - ) + return self.height / self.initial_height * self._font_size @font_size.setter def font_size(self, font_val: float) -> None: @@ -1206,10 +1203,13 @@ def __init__( if self.line_spacing == -1: self.line_spacing = ( - self.initial_font_size + self.initial_font_size * DEFAULT_LINE_SPACING_SCALE + self.initial_font_size + + self.initial_font_size * DEFAULT_LINE_SPACING_SCALE ) else: - self.line_spacing = self.initial_font_size + self.initial_font_size * self.line_spacing + self.line_spacing = ( + self.initial_font_size + self.initial_font_size * self.line_spacing + ) parsed_color: ManimColor = ManimColor(color) if color else VMobject().color file_name = self._text2svg(parsed_color) @@ -1303,20 +1303,17 @@ def add_line_to(end: Point3D) -> None: # anti-aliasing if height is None and width is None: self.scale( - 1 / PT_OVER_PX # convert svg output to "pt" units - / TEXT_FONT_SIZE_PT # then to "fontsize" or "EM" units - * DEFAULT_FONT_SIZE_IN_WORLD_SPACE # then to world space + 1 + / PT_OVER_PX # convert svg output to "pt" units + / TEXT_FONT_SIZE_PT # then to "fontsize" or "EM" units + * DEFAULT_FONT_SIZE_IN_WORLD_SPACE # then to world space ) self.initial_height = self.height @property def font_size(self) -> float: - return ( - self.height - / self.initial_height - * self.initial_font_size - ) + return self.height / self.initial_height * self.initial_font_size @font_size.setter def font_size(self, font_val: float) -> None: From bdc693c875f650bbbc830c074ab738dc0fd16d09 Mon Sep 17 00:00:00 2001 From: Antonin Peronnet <62420525+rambip@users.noreply.github.com> Date: Sun, 19 Apr 2026 09:43:24 +0200 Subject: [PATCH 08/36] Update imports in tex_mobject.py for constants --- manim/mobject/text/tex_mobject.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/mobject/text/tex_mobject.py b/manim/mobject/text/tex_mobject.py index 44bc8bd4a8..55695aaa5c 100644 --- a/manim/mobject/text/tex_mobject.py +++ b/manim/mobject/text/tex_mobject.py @@ -31,7 +31,7 @@ from typing import Any, Self from manim import config, logger -from manim.constants import * +from manim.constants import DEFAULT_FONT_SIZE, PT_OVER_PX, DEFAULT_FONTSIZE_IN_WORLD_SPACE from manim.mobject.geometry.line import Line from manim.mobject.svg.svg_mobject import SVGMobject from manim.mobject.types.vectorized_mobject import VGroup, VMobject From 607d8d9cec133844b482d685fa407a2832eeae10 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 19 Apr 2026 07:43:38 +0000 Subject: [PATCH 09/36] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- manim/mobject/text/tex_mobject.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/manim/mobject/text/tex_mobject.py b/manim/mobject/text/tex_mobject.py index 55695aaa5c..d75ef0afcd 100644 --- a/manim/mobject/text/tex_mobject.py +++ b/manim/mobject/text/tex_mobject.py @@ -31,7 +31,11 @@ from typing import Any, Self from manim import config, logger -from manim.constants import DEFAULT_FONT_SIZE, PT_OVER_PX, DEFAULT_FONTSIZE_IN_WORLD_SPACE +from manim.constants import ( + DEFAULT_FONT_SIZE, + DEFAULT_FONTSIZE_IN_WORLD_SPACE, + PT_OVER_PX, +) from manim.mobject.geometry.line import Line from manim.mobject.svg.svg_mobject import SVGMobject from manim.mobject.types.vectorized_mobject import VGroup, VMobject From 28b3835c42c659f7dafb10dbb6c10a29afcf3fa9 Mon Sep 17 00:00:00 2001 From: Antonin Peronnet <62420525+rambip@users.noreply.github.com> Date: Sun, 19 Apr 2026 09:50:30 +0200 Subject: [PATCH 10/36] Refactor constants import in tex_mobject.py Refactor imports in tex_mobject.py to use wildcard import for constants. --- manim/mobject/text/tex_mobject.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/manim/mobject/text/tex_mobject.py b/manim/mobject/text/tex_mobject.py index d75ef0afcd..6e5234c1c5 100644 --- a/manim/mobject/text/tex_mobject.py +++ b/manim/mobject/text/tex_mobject.py @@ -31,11 +31,8 @@ from typing import Any, Self from manim import config, logger -from manim.constants import ( - DEFAULT_FONT_SIZE, - DEFAULT_FONTSIZE_IN_WORLD_SPACE, - PT_OVER_PX, -) +from manim.constants import * +from manim.constants import PT_OVER_PX from manim.mobject.geometry.line import Line from manim.mobject.svg.svg_mobject import SVGMobject from manim.mobject.types.vectorized_mobject import VGroup, VMobject From f1dbcc729e38d44ee37c395068f3538506dd93c4 Mon Sep 17 00:00:00 2001 From: Antonin Peronnet <62420525+rambip@users.noreply.github.com> Date: Sun, 19 Apr 2026 09:51:13 +0200 Subject: [PATCH 11/36] Import PT_OVER_PX constant in text_mobject.py --- manim/mobject/text/text_mobject.py | 1 + 1 file changed, 1 insertion(+) diff --git a/manim/mobject/text/text_mobject.py b/manim/mobject/text/text_mobject.py index bf5e8ecf70..9d5a412bce 100644 --- a/manim/mobject/text/text_mobject.py +++ b/manim/mobject/text/text_mobject.py @@ -69,6 +69,7 @@ def construct(self): from manim import config, logger from manim.constants import * +from manim.constants import PT_OVER_PX from manim.mobject.geometry.arc import Dot from manim.mobject.svg.svg_mobject import SVGMobject from manim.mobject.types.vectorized_mobject import VGroup, VMobject From 378978efc190b0cd8f7e783354e53a80296c926d Mon Sep 17 00:00:00 2001 From: Antonin Peronnet <62420525+rambip@users.noreply.github.com> Date: Sun, 19 Apr 2026 09:58:18 +0200 Subject: [PATCH 12/36] Rename TEX_DEFAULT_FONTSIZE_PT to TEX_DEFAULT_FONT_SIZE_PT --- manim/mobject/text/tex_mobject.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/mobject/text/tex_mobject.py b/manim/mobject/text/tex_mobject.py index 6e5234c1c5..cba4276a10 100644 --- a/manim/mobject/text/tex_mobject.py +++ b/manim/mobject/text/tex_mobject.py @@ -42,7 +42,7 @@ from ..opengl.opengl_compatibility import ConvertToOpenGL MATHTEX_SUBSTRING = "substring" -TEX_DEFAULT_FONTSIZE_PT = 10 +TEX_DEFAULT_FONT_SIZE_PT = 10 """The fontsize used by default by tex: 10pt. This means that one 'EM' character like '—' will be 13.333 svg units, since 1pt=4/3 px""" From 8401941dfebd49000defbf0b97f75661a1e702d6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 19 Apr 2026 08:09:01 +0000 Subject: [PATCH 13/36] test: add em-dash width checks for text and math text Agent-Logs-Url: https://github.com/rambip/manim/sessions/3da47ac5-56e2-4f83-9bea-469050a8cdad Co-authored-by: rambip <62420525+rambip@users.noreply.github.com> --- tests/module/mobject/text/test_texmobject.py | 6 ++++++ tests/module/mobject/text/test_text_mobject.py | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/tests/module/mobject/text/test_texmobject.py b/tests/module/mobject/text/test_texmobject.py index 48297abec6..9a0dca864e 100644 --- a/tests/module/mobject/text/test_texmobject.py +++ b/tests/module/mobject/text/test_texmobject.py @@ -6,6 +6,7 @@ import pytest from manim import MathTex, SingleStringMathTex, Tex, TexTemplate, tempconfig +from manim.constants import DEFAULT_FONT_SIZE_IN_WOLRD_SPACE def test_MathTex(config): @@ -256,6 +257,11 @@ def test_changing_font_size(): assert num.height == Tex("0", font_size=48).height +def test_mathtex_em_dash_width_matches_default_font_size_in_world_space(): + em_dash = MathTex(r"\text{---}") + assert em_dash.width == DEFAULT_FONT_SIZE_IN_WOLRD_SPACE + + def test_log_error_context(capsys): """Test that the environment context of an error is correctly logged if it exists""" invalid_tex = r""" diff --git a/tests/module/mobject/text/test_text_mobject.py b/tests/module/mobject/text/test_text_mobject.py index 2e656b90ae..81ce73570c 100644 --- a/tests/module/mobject/text/test_text_mobject.py +++ b/tests/module/mobject/text/test_text_mobject.py @@ -3,6 +3,7 @@ from contextlib import redirect_stdout from io import StringIO +from manim.constants import DEFAULT_FONT_SIZE_IN_WOLRD_SPACE from manim.mobject.text.text_mobject import MarkupText, Text @@ -32,3 +33,8 @@ def warning_printed(font: str, **kwargs) -> bool: # check random string (should be warning) assert warning_printed("Manim!" * 3, warn_missing_font=True) + + +def test_em_dash_width_matches_default_font_size_in_world_space(): + text_em_dash = Text("—") + assert text_em_dash.width == DEFAULT_FONT_SIZE_IN_WOLRD_SPACE From ef13da666d5c3e0238251e880aece1a00bc4f709 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 19 Apr 2026 08:27:03 +0000 Subject: [PATCH 14/36] fix: rename text font-size internals and add world-space aliases Agent-Logs-Url: https://github.com/rambip/manim/sessions/802ae0bf-ed97-478a-b7eb-923ac4efd2a2 Co-authored-by: rambip <62420525+rambip@users.noreply.github.com> --- manim/constants.py | 4 ++++ manim/mobject/text/text_mobject.py | 11 +++++++---- tests/module/mobject/text/test_texmobject.py | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/manim/constants.py b/manim/constants.py index c54f31be26..be09d9023a 100644 --- a/manim/constants.py +++ b/manim/constants.py @@ -63,6 +63,8 @@ "DEFAULT_POINT_DENSITY_1D", "DEFAULT_STROKE_WIDTH", "DEFAULT_FONT_SIZE", + "DEFAULT_FONT_SIZE_IN_WORLD_SPACE", + "DEFAULT_FONTSIZE_IN_WORLD_SPACE", "DEFAULT_FONT_SIZE_IN_WOLRD_SPACE", "SCALE_FACTOR_PER_FONT_POINT", "PI", @@ -184,6 +186,8 @@ """Length occupied by an 'EM' character in manim space, when manim default font size is used. An example of an 'EM' character is the em dash: '—'. The chosen value is an arbitrary convention.""" +DEFAULT_FONT_SIZE_IN_WORLD_SPACE = DEFAULT_FONT_SIZE_IN_WOLRD_SPACE +DEFAULT_FONTSIZE_IN_WORLD_SPACE = DEFAULT_FONT_SIZE_IN_WOLRD_SPACE # Misc DEFAULT_POINT_DENSITY_2D = 25 diff --git a/manim/mobject/text/text_mobject.py b/manim/mobject/text/text_mobject.py index 9d5a412bce..db7f9d9a67 100644 --- a/manim/mobject/text/text_mobject.py +++ b/manim/mobject/text/text_mobject.py @@ -510,10 +510,13 @@ def __init__( self.text = text_without_tabs if self.line_spacing == -1: self.line_spacing = ( - self._font_size + self._font_size * DEFAULT_LINE_SPACING_SCALE + self.initial_font_size + + self.initial_font_size * DEFAULT_LINE_SPACING_SCALE ) else: - self.line_spacing = self._font_size + self._font_size * self.line_spacing + self.line_spacing = ( + self.initial_font_size + self.initial_font_size * self.line_spacing + ) parsed_color: ManimColor = ManimColor(color) if color else VMobject().color file_name = self._text2svg(parsed_color.to_hex()) @@ -605,7 +608,7 @@ def __repr__(self) -> str: @property def font_size(self) -> float: - return self.height / self.initial_height * self._font_size + return self.height / self.initial_height * self.initial_font_size @font_size.setter def font_size(self, font_val: float) -> None: @@ -657,7 +660,7 @@ def _text2hash(self, color: ParsableManimColor) -> str: "PANGO" + self.font + self.slant + self.weight + str(color) ) # to differentiate Text and CairoText settings += str(self.t2f) + str(self.t2s) + str(self.t2w) + str(self.t2c) - settings += str(self.line_spacing) + str(self._font_size) + settings += str(self.line_spacing) + str(self.initial_font_size) settings += str(self.disable_ligatures) settings += str(self.gradient) id_str = self.text + settings diff --git a/tests/module/mobject/text/test_texmobject.py b/tests/module/mobject/text/test_texmobject.py index 9a0dca864e..873be6d5a9 100644 --- a/tests/module/mobject/text/test_texmobject.py +++ b/tests/module/mobject/text/test_texmobject.py @@ -258,7 +258,7 @@ def test_changing_font_size(): def test_mathtex_em_dash_width_matches_default_font_size_in_world_space(): - em_dash = MathTex(r"\text{---}") + em_dash = MathTex(r"\text{—}") assert em_dash.width == DEFAULT_FONT_SIZE_IN_WOLRD_SPACE From 0c111b3183d9b22dc3fd6b083ee25497e85d2527 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 19 Apr 2026 08:28:58 +0000 Subject: [PATCH 15/36] test: use world-space constant alias in em-dash tests Agent-Logs-Url: https://github.com/rambip/manim/sessions/802ae0bf-ed97-478a-b7eb-923ac4efd2a2 Co-authored-by: rambip <62420525+rambip@users.noreply.github.com> --- tests/module/mobject/text/test_texmobject.py | 4 ++-- tests/module/mobject/text/test_text_mobject.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/module/mobject/text/test_texmobject.py b/tests/module/mobject/text/test_texmobject.py index 873be6d5a9..05ee3cac49 100644 --- a/tests/module/mobject/text/test_texmobject.py +++ b/tests/module/mobject/text/test_texmobject.py @@ -6,7 +6,7 @@ import pytest from manim import MathTex, SingleStringMathTex, Tex, TexTemplate, tempconfig -from manim.constants import DEFAULT_FONT_SIZE_IN_WOLRD_SPACE +from manim.constants import DEFAULT_FONT_SIZE_IN_WORLD_SPACE def test_MathTex(config): @@ -259,7 +259,7 @@ def test_changing_font_size(): def test_mathtex_em_dash_width_matches_default_font_size_in_world_space(): em_dash = MathTex(r"\text{—}") - assert em_dash.width == DEFAULT_FONT_SIZE_IN_WOLRD_SPACE + assert em_dash.width == DEFAULT_FONT_SIZE_IN_WORLD_SPACE def test_log_error_context(capsys): diff --git a/tests/module/mobject/text/test_text_mobject.py b/tests/module/mobject/text/test_text_mobject.py index 81ce73570c..20148d9ffb 100644 --- a/tests/module/mobject/text/test_text_mobject.py +++ b/tests/module/mobject/text/test_text_mobject.py @@ -3,7 +3,7 @@ from contextlib import redirect_stdout from io import StringIO -from manim.constants import DEFAULT_FONT_SIZE_IN_WOLRD_SPACE +from manim.constants import DEFAULT_FONT_SIZE_IN_WORLD_SPACE from manim.mobject.text.text_mobject import MarkupText, Text @@ -37,4 +37,4 @@ def warning_printed(font: str, **kwargs) -> bool: def test_em_dash_width_matches_default_font_size_in_world_space(): text_em_dash = Text("—") - assert text_em_dash.width == DEFAULT_FONT_SIZE_IN_WOLRD_SPACE + assert text_em_dash.width == DEFAULT_FONT_SIZE_IN_WORLD_SPACE From 5a2970239b0110a35fa54450fb7f4908640b5da6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 19 Apr 2026 08:30:28 +0000 Subject: [PATCH 16/36] refactor: make world-space font-size constant name canonical Agent-Logs-Url: https://github.com/rambip/manim/sessions/802ae0bf-ed97-478a-b7eb-923ac4efd2a2 Co-authored-by: rambip <62420525+rambip@users.noreply.github.com> --- manim/constants.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/manim/constants.py b/manim/constants.py index be09d9023a..cc65521796 100644 --- a/manim/constants.py +++ b/manim/constants.py @@ -182,12 +182,12 @@ # Font calculation PT_OVER_PX = 4 / 3 -DEFAULT_FONT_SIZE_IN_WOLRD_SPACE = 2 / 3 +DEFAULT_FONT_SIZE_IN_WORLD_SPACE = 2 / 3 """Length occupied by an 'EM' character in manim space, when manim default font size is used. An example of an 'EM' character is the em dash: '—'. The chosen value is an arbitrary convention.""" -DEFAULT_FONT_SIZE_IN_WORLD_SPACE = DEFAULT_FONT_SIZE_IN_WOLRD_SPACE -DEFAULT_FONTSIZE_IN_WORLD_SPACE = DEFAULT_FONT_SIZE_IN_WOLRD_SPACE +DEFAULT_FONT_SIZE_IN_WOLRD_SPACE = DEFAULT_FONT_SIZE_IN_WORLD_SPACE +DEFAULT_FONTSIZE_IN_WORLD_SPACE = DEFAULT_FONT_SIZE_IN_WORLD_SPACE # Misc DEFAULT_POINT_DENSITY_2D = 25 @@ -195,7 +195,7 @@ DEFAULT_STROKE_WIDTH = 4 DEFAULT_FONT_SIZE = 48 SCALE_FACTOR_PER_FONT_POINT = ( # legacy, not used in code anymore - DEFAULT_FONT_SIZE_IN_WOLRD_SPACE + DEFAULT_FONT_SIZE_IN_WORLD_SPACE / (10 * PT_OVER_PX) # LaTeX default font size in pixels / DEFAULT_FONT_SIZE ) From 511cd8dbb6d3952b6d04448046ea41df63348c23 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 19 Apr 2026 08:35:43 +0000 Subject: [PATCH 17/36] fix: stop scaling tex by PT_OVER_PX and relax em-dash precision Agent-Logs-Url: https://github.com/rambip/manim/sessions/e8302477-8de0-4944-8d6d-bf2a4da1945f Co-authored-by: rambip <62420525+rambip@users.noreply.github.com> --- manim/mobject/text/tex_mobject.py | 4 +--- tests/module/mobject/text/test_texmobject.py | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/manim/mobject/text/tex_mobject.py b/manim/mobject/text/tex_mobject.py index cba4276a10..8bf1efc0aa 100644 --- a/manim/mobject/text/tex_mobject.py +++ b/manim/mobject/text/tex_mobject.py @@ -32,7 +32,6 @@ from manim import config, logger from manim.constants import * -from manim.constants import PT_OVER_PX from manim.mobject.geometry.line import Line from manim.mobject.svg.svg_mobject import SVGMobject from manim.mobject.types.vectorized_mobject import VGroup, VMobject @@ -104,8 +103,7 @@ def __init__( if height is None: self.scale( 1 - / PT_OVER_PX # convert latex svg output to pt - / TEX_DEFAULT_FONT_SIZE_PT # then to "fontsize" or "em" units + / TEX_DEFAULT_FONT_SIZE_PT # convert latex svg output to "fontsize" or "em" units * DEFAULT_FONTSIZE_IN_WORLD_SPACE # then to worldspace ) diff --git a/tests/module/mobject/text/test_texmobject.py b/tests/module/mobject/text/test_texmobject.py index 05ee3cac49..c34c6bdc46 100644 --- a/tests/module/mobject/text/test_texmobject.py +++ b/tests/module/mobject/text/test_texmobject.py @@ -259,7 +259,7 @@ def test_changing_font_size(): def test_mathtex_em_dash_width_matches_default_font_size_in_world_space(): em_dash = MathTex(r"\text{—}") - assert em_dash.width == DEFAULT_FONT_SIZE_IN_WORLD_SPACE + assert round(em_dash.width, 5) == round(DEFAULT_FONT_SIZE_IN_WORLD_SPACE, 5) def test_log_error_context(capsys): From 7474bd7bdd730f14316f1c8f826c25978f6e0838 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 19 Apr 2026 08:37:13 +0000 Subject: [PATCH 18/36] test: relax text em-dash width precision Agent-Logs-Url: https://github.com/rambip/manim/sessions/e8302477-8de0-4944-8d6d-bf2a4da1945f Co-authored-by: rambip <62420525+rambip@users.noreply.github.com> --- tests/module/mobject/text/test_text_mobject.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/module/mobject/text/test_text_mobject.py b/tests/module/mobject/text/test_text_mobject.py index 20148d9ffb..e6ca494a92 100644 --- a/tests/module/mobject/text/test_text_mobject.py +++ b/tests/module/mobject/text/test_text_mobject.py @@ -37,4 +37,4 @@ def warning_printed(font: str, **kwargs) -> bool: def test_em_dash_width_matches_default_font_size_in_world_space(): text_em_dash = Text("—") - assert text_em_dash.width == DEFAULT_FONT_SIZE_IN_WORLD_SPACE + assert round(text_em_dash.width, 5) == round(DEFAULT_FONT_SIZE_IN_WORLD_SPACE, 5) From d4202f69cd4e87f9e1e523a9b58d10552b948988 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 19 Apr 2026 08:38:26 +0000 Subject: [PATCH 19/36] test: simplify em-dash test names Agent-Logs-Url: https://github.com/rambip/manim/sessions/e8302477-8de0-4944-8d6d-bf2a4da1945f Co-authored-by: rambip <62420525+rambip@users.noreply.github.com> --- tests/module/mobject/text/test_texmobject.py | 2 +- tests/module/mobject/text/test_text_mobject.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/module/mobject/text/test_texmobject.py b/tests/module/mobject/text/test_texmobject.py index c34c6bdc46..770b2bf254 100644 --- a/tests/module/mobject/text/test_texmobject.py +++ b/tests/module/mobject/text/test_texmobject.py @@ -257,7 +257,7 @@ def test_changing_font_size(): assert num.height == Tex("0", font_size=48).height -def test_mathtex_em_dash_width_matches_default_font_size_in_world_space(): +def test_mathtex_em_dash_width_default_font_size(): em_dash = MathTex(r"\text{—}") assert round(em_dash.width, 5) == round(DEFAULT_FONT_SIZE_IN_WORLD_SPACE, 5) diff --git a/tests/module/mobject/text/test_text_mobject.py b/tests/module/mobject/text/test_text_mobject.py index e6ca494a92..0405edd223 100644 --- a/tests/module/mobject/text/test_text_mobject.py +++ b/tests/module/mobject/text/test_text_mobject.py @@ -35,6 +35,6 @@ def warning_printed(font: str, **kwargs) -> bool: assert warning_printed("Manim!" * 3, warn_missing_font=True) -def test_em_dash_width_matches_default_font_size_in_world_space(): +def test_em_dash_width_default_font_size(): text_em_dash = Text("—") assert round(text_em_dash.width, 5) == round(DEFAULT_FONT_SIZE_IN_WORLD_SPACE, 5) From 4b2277f6763d5ac48c7da0fb7b36cef9c34eceb2 Mon Sep 17 00:00:00 2001 From: Antonin Peronnet <62420525+rambip@users.noreply.github.com> Date: Sun, 19 Apr 2026 10:46:57 +0200 Subject: [PATCH 20/36] Change default font size in world space to 0.5 --- manim/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/constants.py b/manim/constants.py index cc65521796..31824f1f47 100644 --- a/manim/constants.py +++ b/manim/constants.py @@ -182,7 +182,7 @@ # Font calculation PT_OVER_PX = 4 / 3 -DEFAULT_FONT_SIZE_IN_WORLD_SPACE = 2 / 3 +DEFAULT_FONT_SIZE_IN_WORLD_SPACE = 0.5 """Length occupied by an 'EM' character in manim space, when manim default font size is used. An example of an 'EM' character is the em dash: '—'. The chosen value is an arbitrary convention.""" From 102d45d13d8670a83d80cef9aa553eab3265b7bc Mon Sep 17 00:00:00 2001 From: Antonin Peronnet <62420525+rambip@users.noreply.github.com> Date: Sun, 19 Apr 2026 10:47:26 +0200 Subject: [PATCH 21/36] Fix scaling factor calculation for font size --- manim/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/constants.py b/manim/constants.py index 31824f1f47..9c5f7cb1de 100644 --- a/manim/constants.py +++ b/manim/constants.py @@ -196,7 +196,7 @@ DEFAULT_FONT_SIZE = 48 SCALE_FACTOR_PER_FONT_POINT = ( # legacy, not used in code anymore DEFAULT_FONT_SIZE_IN_WORLD_SPACE - / (10 * PT_OVER_PX) # LaTeX default font size in pixels + / 10 # LaTeX default font size in pixels / DEFAULT_FONT_SIZE ) """Downscale factor from LaTeX pixel to world space, divided by DEFAULT_FONT_SIZE""" From 1883cc39e14d002dc0549909f5aa20783c48f916 Mon Sep 17 00:00:00 2001 From: Antonin Peronnet <62420525+rambip@users.noreply.github.com> Date: Sun, 19 Apr 2026 10:51:29 +0200 Subject: [PATCH 22/36] Fix scaling calculation for font size --- manim/mobject/text/tex_mobject.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/mobject/text/tex_mobject.py b/manim/mobject/text/tex_mobject.py index 8bf1efc0aa..e775781ac9 100644 --- a/manim/mobject/text/tex_mobject.py +++ b/manim/mobject/text/tex_mobject.py @@ -102,7 +102,7 @@ def __init__( if height is None: self.scale( - 1 + font_size / DEFAULT_FONT_SIZE / TEX_DEFAULT_FONT_SIZE_PT # convert latex svg output to "fontsize" or "em" units * DEFAULT_FONTSIZE_IN_WORLD_SPACE # then to worldspace ) From 5963389d7db1a6d41f4127dd31cc8e11c52918d7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 19 Apr 2026 08:54:15 +0000 Subject: [PATCH 23/36] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- manim/mobject/text/tex_mobject.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/manim/mobject/text/tex_mobject.py b/manim/mobject/text/tex_mobject.py index e775781ac9..b801654c09 100644 --- a/manim/mobject/text/tex_mobject.py +++ b/manim/mobject/text/tex_mobject.py @@ -102,7 +102,8 @@ def __init__( if height is None: self.scale( - font_size / DEFAULT_FONT_SIZE + font_size + / DEFAULT_FONT_SIZE / TEX_DEFAULT_FONT_SIZE_PT # convert latex svg output to "fontsize" or "em" units * DEFAULT_FONTSIZE_IN_WORLD_SPACE # then to worldspace ) From e8c7d7ea1c9f7f981875bae424bea77e267d9a91 Mon Sep 17 00:00:00 2001 From: Antonin Peronnet <62420525+rambip@users.noreply.github.com> Date: Mon, 20 Apr 2026 06:49:02 +0200 Subject: [PATCH 24/36] Change precision of width assertion in test --- tests/module/mobject/text/test_text_mobject.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/module/mobject/text/test_text_mobject.py b/tests/module/mobject/text/test_text_mobject.py index 0405edd223..325573fcdd 100644 --- a/tests/module/mobject/text/test_text_mobject.py +++ b/tests/module/mobject/text/test_text_mobject.py @@ -37,4 +37,4 @@ def warning_printed(font: str, **kwargs) -> bool: def test_em_dash_width_default_font_size(): text_em_dash = Text("—") - assert round(text_em_dash.width, 5) == round(DEFAULT_FONT_SIZE_IN_WORLD_SPACE, 5) + assert round(text_em_dash.width, 3) == round(DEFAULT_FONT_SIZE_IN_WORLD_SPACE, 3) From a2210cbdc966c604ec70c4fe2528fdf61ca3a484 Mon Sep 17 00:00:00 2001 From: Antonin Peronnet <62420525+rambip@users.noreply.github.com> Date: Mon, 20 Apr 2026 06:50:22 +0200 Subject: [PATCH 25/36] Update precision in em dash width test Change precision of width assertion for em dash in test. --- tests/module/mobject/text/test_texmobject.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/module/mobject/text/test_texmobject.py b/tests/module/mobject/text/test_texmobject.py index 770b2bf254..764b7721b9 100644 --- a/tests/module/mobject/text/test_texmobject.py +++ b/tests/module/mobject/text/test_texmobject.py @@ -259,7 +259,7 @@ def test_changing_font_size(): def test_mathtex_em_dash_width_default_font_size(): em_dash = MathTex(r"\text{—}") - assert round(em_dash.width, 5) == round(DEFAULT_FONT_SIZE_IN_WORLD_SPACE, 5) + assert round(em_dash.width, 3) == round(DEFAULT_FONT_SIZE_IN_WORLD_SPACE, 3) def test_log_error_context(capsys): From 04a050893225e746b33ef4ed9d1f3346abefd6ff Mon Sep 17 00:00:00 2001 From: Antonin Peronnet <62420525+rambip@users.noreply.github.com> Date: Mon, 20 Apr 2026 07:15:29 +0200 Subject: [PATCH 26/36] Update assertion for em dash width test --- tests/module/mobject/text/test_texmobject.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/module/mobject/text/test_texmobject.py b/tests/module/mobject/text/test_texmobject.py index 764b7721b9..5ecfb2c435 100644 --- a/tests/module/mobject/text/test_texmobject.py +++ b/tests/module/mobject/text/test_texmobject.py @@ -259,7 +259,7 @@ def test_changing_font_size(): def test_mathtex_em_dash_width_default_font_size(): em_dash = MathTex(r"\text{—}") - assert round(em_dash.width, 3) == round(DEFAULT_FONT_SIZE_IN_WORLD_SPACE, 3) + assert abs(em_dash.width - DEFAULT_FONT_SIZE_IN_WORLD_SPACE) < 0.005 def test_log_error_context(capsys): From d790a683747e53bf5d4c50f09b82f8c15de48360 Mon Sep 17 00:00:00 2001 From: Antonin Peronnet <62420525+rambip@users.noreply.github.com> Date: Mon, 20 Apr 2026 07:24:51 +0200 Subject: [PATCH 27/36] Modify em dash width test for Liberation Sans font Update test for em dash width with specific font. --- tests/module/mobject/text/test_text_mobject.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/module/mobject/text/test_text_mobject.py b/tests/module/mobject/text/test_text_mobject.py index 325573fcdd..4c4eb08207 100644 --- a/tests/module/mobject/text/test_text_mobject.py +++ b/tests/module/mobject/text/test_text_mobject.py @@ -36,5 +36,6 @@ def warning_printed(font: str, **kwargs) -> bool: def test_em_dash_width_default_font_size(): - text_em_dash = Text("—") - assert round(text_em_dash.width, 3) == round(DEFAULT_FONT_SIZE_IN_WORLD_SPACE, 3) + # this specific font renders the em dash at full width, like Tex does. + text_em_dash = Text("—", font="Liberation Sans") + assert abs(text_em_dash.width - DEFAULT_FONT_SIZE_IN_WORLD_SPACE) < 0.005 From aba7b5b14532cbec706add96b9b2d45178cc395a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 20 Apr 2026 05:25:06 +0000 Subject: [PATCH 28/36] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/module/mobject/text/test_text_mobject.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/module/mobject/text/test_text_mobject.py b/tests/module/mobject/text/test_text_mobject.py index 4c4eb08207..af709067d2 100644 --- a/tests/module/mobject/text/test_text_mobject.py +++ b/tests/module/mobject/text/test_text_mobject.py @@ -37,5 +37,5 @@ def warning_printed(font: str, **kwargs) -> bool: def test_em_dash_width_default_font_size(): # this specific font renders the em dash at full width, like Tex does. - text_em_dash = Text("—", font="Liberation Sans") + text_em_dash = Text("—", font="Liberation Sans") assert abs(text_em_dash.width - DEFAULT_FONT_SIZE_IN_WORLD_SPACE) < 0.005 From 12b7b061330e10a47888315c1b2530e5a098ab44 Mon Sep 17 00:00:00 2001 From: Antonin Peronnet <62420525+rambip@users.noreply.github.com> Date: Mon, 20 Apr 2026 07:35:10 +0200 Subject: [PATCH 29/36] Move PT_OVER_PX to text_mobject.py (backend-specific) --- manim/constants.py | 1 - 1 file changed, 1 deletion(-) diff --git a/manim/constants.py b/manim/constants.py index 9c5f7cb1de..444ec63b49 100644 --- a/manim/constants.py +++ b/manim/constants.py @@ -181,7 +181,6 @@ DEFAULT_WAIT_TIME = 1.0 # Font calculation -PT_OVER_PX = 4 / 3 DEFAULT_FONT_SIZE_IN_WORLD_SPACE = 0.5 """Length occupied by an 'EM' character in manim space, when manim default font size is used. An example of an 'EM' character is the em dash: '—'. From 0a9bfcad76afab3c1e5cb3fd988492d61c7fe022 Mon Sep 17 00:00:00 2001 From: Antonin Peronnet <62420525+rambip@users.noreply.github.com> Date: Mon, 20 Apr 2026 07:35:19 +0200 Subject: [PATCH 30/36] Add TEX_SVG_UNITS_PER_PT constant with 72 DPI documentation --- manim/mobject/text/tex_mobject.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/manim/mobject/text/tex_mobject.py b/manim/mobject/text/tex_mobject.py index b801654c09..b9fd80fd2b 100644 --- a/manim/mobject/text/tex_mobject.py +++ b/manim/mobject/text/tex_mobject.py @@ -41,6 +41,9 @@ from ..opengl.opengl_compatibility import ConvertToOpenGL MATHTEX_SUBSTRING = "substring" +TEX_SVG_UNITS_PER_PT = 1 +"""Scale factor from TeX SVG output to point units. +TeX outputs 1 svg unit per point (72 DPI).""" TEX_DEFAULT_FONT_SIZE_PT = 10 """The fontsize used by default by tex: 10pt. This means that one 'EM' character like '—' will be 13.333 svg units, since 1pt=4/3 px""" From a876c235be6c439cb954896dfba60bbb5be7e723 Mon Sep 17 00:00:00 2001 From: Antonin Peronnet <62420525+rambip@users.noreply.github.com> Date: Mon, 20 Apr 2026 07:35:27 +0200 Subject: [PATCH 31/36] Add PANGO_SVG_UNITS_PER_PT constant (96 DPI), remove import from constants --- manim/mobject/text/text_mobject.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/manim/mobject/text/text_mobject.py b/manim/mobject/text/text_mobject.py index db7f9d9a67..b45f278d53 100644 --- a/manim/mobject/text/text_mobject.py +++ b/manim/mobject/text/text_mobject.py @@ -69,7 +69,7 @@ def construct(self): from manim import config, logger from manim.constants import * -from manim.constants import PT_OVER_PX +# PANGO_SVG_UNITS_PER_PT moved below with other text-specific constants from manim.mobject.geometry.arc import Dot from manim.mobject.svg.svg_mobject import SVGMobject from manim.mobject.types.vectorized_mobject import VGroup, VMobject @@ -82,6 +82,9 @@ def construct(self): from manim.typing import Point3D DEFAULT_LINE_SPACING_SCALE = 0.3 +PANGO_SVG_UNITS_PER_PT = 4 / 3 +"""Scale factor from Pango SVG output to point units. +Pango outputs 4/3 svg units per point (96 DPI).""" TEXT_FONT_SIZE_PT = 10 """The font size we use to render the unscaled text in the SVG. Note that the typical EM dash (—) will be 13.333 svg units, since 1pt = 4/3 px""" @@ -597,7 +600,7 @@ def add_line_to(end: Point3D) -> None: if height is None and width is None: self.scale( 1 - / PT_OVER_PX # convert svg output to "pt" units + / PANGO_SVG_UNITS_PER_PT # convert svg output to "pt" units / TEXT_FONT_SIZE_PT # then to "fontsize" or "EM" units * DEFAULT_FONT_SIZE_IN_WORLD_SPACE # then to world space ) @@ -1308,7 +1311,7 @@ def add_line_to(end: Point3D) -> None: if height is None and width is None: self.scale( 1 - / PT_OVER_PX # convert svg output to "pt" units + / PANGO_SVG_UNITS_PER_PT # convert svg output to "pt" units / TEXT_FONT_SIZE_PT # then to "fontsize" or "EM" units * DEFAULT_FONT_SIZE_IN_WORLD_SPACE # then to world space ) From df034318ea141fdb578a067ceb37f0901e1a1177 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 20 Apr 2026 05:36:12 +0000 Subject: [PATCH 32/36] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- manim/mobject/text/text_mobject.py | 1 + 1 file changed, 1 insertion(+) diff --git a/manim/mobject/text/text_mobject.py b/manim/mobject/text/text_mobject.py index b45f278d53..6397ac2e9b 100644 --- a/manim/mobject/text/text_mobject.py +++ b/manim/mobject/text/text_mobject.py @@ -69,6 +69,7 @@ def construct(self): from manim import config, logger from manim.constants import * + # PANGO_SVG_UNITS_PER_PT moved below with other text-specific constants from manim.mobject.geometry.arc import Dot from manim.mobject.svg.svg_mobject import SVGMobject From 99bc87eddf68717a295b62c9c54ba51be7cf942c Mon Sep 17 00:00:00 2001 From: Antonin Peronnet <62420525+rambip@users.noreply.github.com> Date: Mon, 20 Apr 2026 07:38:32 +0200 Subject: [PATCH 33/36] Update text_mobject.py --- manim/mobject/text/text_mobject.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/manim/mobject/text/text_mobject.py b/manim/mobject/text/text_mobject.py index 6397ac2e9b..0bcd21f291 100644 --- a/manim/mobject/text/text_mobject.py +++ b/manim/mobject/text/text_mobject.py @@ -70,7 +70,6 @@ def construct(self): from manim import config, logger from manim.constants import * -# PANGO_SVG_UNITS_PER_PT moved below with other text-specific constants from manim.mobject.geometry.arc import Dot from manim.mobject.svg.svg_mobject import SVGMobject from manim.mobject.types.vectorized_mobject import VGroup, VMobject @@ -85,7 +84,7 @@ def construct(self): DEFAULT_LINE_SPACING_SCALE = 0.3 PANGO_SVG_UNITS_PER_PT = 4 / 3 """Scale factor from Pango SVG output to point units. -Pango outputs 4/3 svg units per point (96 DPI).""" +Pango outputs 4/3 svg units per point (72 DPI).""" TEXT_FONT_SIZE_PT = 10 """The font size we use to render the unscaled text in the SVG. Note that the typical EM dash (—) will be 13.333 svg units, since 1pt = 4/3 px""" From ac681f444b2bcfa1ff9d0ff73b360b3cc2b06ccc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 20 Apr 2026 05:38:47 +0000 Subject: [PATCH 34/36] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- manim/mobject/text/text_mobject.py | 1 - 1 file changed, 1 deletion(-) diff --git a/manim/mobject/text/text_mobject.py b/manim/mobject/text/text_mobject.py index 0bcd21f291..16263fc322 100644 --- a/manim/mobject/text/text_mobject.py +++ b/manim/mobject/text/text_mobject.py @@ -69,7 +69,6 @@ def construct(self): from manim import config, logger from manim.constants import * - from manim.mobject.geometry.arc import Dot from manim.mobject.svg.svg_mobject import SVGMobject from manim.mobject.types.vectorized_mobject import VGroup, VMobject From 96d53f04831eddf935d4ee91087754d3d7b84c06 Mon Sep 17 00:00:00 2001 From: Antonin Peronnet <62420525+rambip@users.noreply.github.com> Date: Mon, 20 Apr 2026 07:50:07 +0200 Subject: [PATCH 35/36] Refactor em dash width test to check available fonts Updated test for em dash width to select available fonts dynamically. --- tests/module/mobject/text/test_text_mobject.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/module/mobject/text/test_text_mobject.py b/tests/module/mobject/text/test_text_mobject.py index af709067d2..a6c82bb6d7 100644 --- a/tests/module/mobject/text/test_text_mobject.py +++ b/tests/module/mobject/text/test_text_mobject.py @@ -34,8 +34,15 @@ def warning_printed(font: str, **kwargs) -> bool: # check random string (should be warning) assert warning_printed("Manim!" * 3, warn_missing_font=True) - -def test_em_dash_width_default_font_size(): - # this specific font renders the em dash at full width, like Tex does. - text_em_dash = Text("—", font="Liberation Sans") - assert abs(text_em_dash.width - DEFAULT_FONT_SIZE_IN_WORLD_SPACE) < 0.005 +def test_em_dash_width_default_font_size(): + from manimpango import list_fonts + + available = list_fonts() + # Fonts that render em dash at full font size width + candidates = ["Arial", "Liberation Sans"] + + font = next((f for f in candidates if f in available), None) + assert font is not None, f"No suitable font found. Available: {available}" + + text_em_dash = Text("—", font=font) + assert abs(text_em_dash.width - DEFAULT_FONT_SIZE_IN_WORLD_SPACE) < 0.01 From c3cc5023d01ae461c3fb09003b1faa4f075f5606 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 20 Apr 2026 05:50:32 +0000 Subject: [PATCH 36/36] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../module/mobject/text/test_text_mobject.py | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/tests/module/mobject/text/test_text_mobject.py b/tests/module/mobject/text/test_text_mobject.py index a6c82bb6d7..d6b1725178 100644 --- a/tests/module/mobject/text/test_text_mobject.py +++ b/tests/module/mobject/text/test_text_mobject.py @@ -34,15 +34,16 @@ def warning_printed(font: str, **kwargs) -> bool: # check random string (should be warning) assert warning_printed("Manim!" * 3, warn_missing_font=True) -def test_em_dash_width_default_font_size(): - from manimpango import list_fonts - - available = list_fonts() - # Fonts that render em dash at full font size width - candidates = ["Arial", "Liberation Sans"] - - font = next((f for f in candidates if f in available), None) - assert font is not None, f"No suitable font found. Available: {available}" - - text_em_dash = Text("—", font=font) - assert abs(text_em_dash.width - DEFAULT_FONT_SIZE_IN_WORLD_SPACE) < 0.01 + +def test_em_dash_width_default_font_size(): + from manimpango import list_fonts + + available = list_fonts() + # Fonts that render em dash at full font size width + candidates = ["Arial", "Liberation Sans"] + + font = next((f for f in candidates if f in available), None) + assert font is not None, f"No suitable font found. Available: {available}" + + text_em_dash = Text("—", font=font) + assert abs(text_em_dash.width - DEFAULT_FONT_SIZE_IN_WORLD_SPACE) < 0.01