Skip to content

Text() color must be keyword argument — positional arg causes cryptic ValueError #9

@jmjava

Description

@jmjava

Context

Discovered during Course Builder Manim scene development. Passing a hex color string as the second positional argument to Text() causes a deep Manim stack trace.

Problem

This code:

Text("Some label", C_BLUE, font_size=14)

Produces:

ValueError: could not convert string to float: '#2979ff'

The traceback points deep into vectorized_mobject.pygenerate_rgbas_arrayto_rgba_with_alpha, which is extremely confusing. The actual issue is that Text()'s second positional parameter is NOT color — it's something else in Manim's API.

The correct syntax is:

Text("Some label", font_size=14, color=C_BLUE)

Impact

This is easy to write by accident, especially when copying patterns from other Manim objects where color IS a positional arg. The error message gives no indication that the problem is a positional vs keyword argument issue.

Recommendations for docgen auto-scene generation

  • When generating Manim code, always use keyword arguments for Text(): Text("...", font_size=N, color=C)
  • Add a lint rule to docgen validate that flags Text(string_literal, "#hex") patterns
  • Document this gotcha in the Manim lessons issue (Manim generation lessons: font, layout, rendering, and sync #3) or in the docgen scaffold README
  • Consider wrapping Text() in a helper function in the _TimedScene base class that enforces keyword-only color

Severity

Low — easy fix once you know the cause, but the error message is deeply misleading and wastes debugging time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions