Skip to content

fix: normalize Code baseline alignment in Paragraph#4692

Open
Croustit wants to merge 2 commits intoManimCommunity:mainfrom
Croustit:adjust_code_alignment
Open

fix: normalize Code baseline alignment in Paragraph#4692
Croustit wants to merge 2 commits intoManimCommunity:mainfrom
Croustit:adjust_code_alignment

Conversation

@Croustit
Copy link
Copy Markdown
Contributor

@Croustit Croustit commented Apr 14, 2026

Fixes #4626

Overview: What does this pull request change?

Fixes a vertical alignment issue with Code mobjects when arranged in a VGroup. When a code snippet contains only characters without ascenders (e.g. "pass"), the resulting mobject has a smaller bounding box than a snippet containing ascenders (e.g. "pass b"), causing inconsistent positioning when using arrange(DOWN).

This fix adds a hidden reference line containing characters with ascenders ("A") when building the Paragraph inside Code, so that Pango always computes metrics to align the text with line numbers. The reference line and its line number are then removed from the rendered output.

Motivation and Explanation: Why and how do your changes improve the library?

Links to added or changed documentation pages

Further Information and Comments

Reproduction case (from issue #4626):

from manim import *

class CodeBug(Scene):
    def construct(self):
        code = Code(code_string="pass")
        code2 = Code(code_string="pass b")
        group = VGroup(code, code2).arrange(DOWN)
        self.add(group)

Before this fix, code was misaligned vertically. After this fix, both blocks are consistently positioned.

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Baseline alignment issue of Code

1 participant