Update app.py
Browse files
app.py
CHANGED
|
@@ -538,30 +538,47 @@ class GeneratedMathScene(Scene):
|
|
| 538 |
|
| 539 |
# Split by # separator
|
| 540 |
segments = content.split("#")
|
| 541 |
-
|
|
|
|
|
|
|
| 542 |
|
| 543 |
for segment in segments:
|
| 544 |
segment = segment.strip()
|
| 545 |
if not segment:
|
| 546 |
continue
|
| 547 |
|
| 548 |
-
#
|
| 549 |
if segment.startswith("%"):
|
| 550 |
-
# Remove % from start
|
| 551 |
latex_content = segment[1:]
|
| 552 |
mob = MathTex(latex_content, color=color, font_size=equation_size)
|
| 553 |
else:
|
| 554 |
-
# Regular text
|
| 555 |
mob = Text(segment, color=color, font=font, font_size=text_size)
|
| 556 |
|
| 557 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 558 |
|
| 559 |
-
if not
|
| 560 |
return VGroup()
|
| 561 |
|
| 562 |
-
#
|
| 563 |
-
|
| 564 |
-
return
|
| 565 |
|
| 566 |
def make_wrapped_paragraph(content, color, font, font_size, line_spacing=0.2):
|
| 567 |
lines = []
|
|
|
|
| 538 |
|
| 539 |
# Split by # separator
|
| 540 |
segments = content.split("#")
|
| 541 |
+
all_lines = [] # Store all lines
|
| 542 |
+
current_line = [] # Current line being built
|
| 543 |
+
current_width = 0
|
| 544 |
|
| 545 |
for segment in segments:
|
| 546 |
segment = segment.strip()
|
| 547 |
if not segment:
|
| 548 |
continue
|
| 549 |
|
| 550 |
+
# Create the mobject (Text or MathTex)
|
| 551 |
if segment.startswith("%"):
|
|
|
|
| 552 |
latex_content = segment[1:]
|
| 553 |
mob = MathTex(latex_content, color=color, font_size=equation_size)
|
| 554 |
else:
|
|
|
|
| 555 |
mob = Text(segment, color=color, font=font, font_size=text_size)
|
| 556 |
|
| 557 |
+
# Calculate what width would be if we add this segment
|
| 558 |
+
test_line = current_line + [mob]
|
| 559 |
+
test_group = VGroup(*test_line).arrange(RIGHT, buff=0.05)
|
| 560 |
+
|
| 561 |
+
# Check if adding this segment exceeds wrap_width
|
| 562 |
+
if test_group.width > wrap_width and len(current_line) > 0:
|
| 563 |
+
# Save current line and start new line
|
| 564 |
+
line_group = VGroup(*current_line).arrange(RIGHT, buff=0.05)
|
| 565 |
+
all_lines.append(line_group)
|
| 566 |
+
current_line = [mob] # Start new line with current segment
|
| 567 |
+
else:
|
| 568 |
+
# Add to current line
|
| 569 |
+
current_line.append(mob)
|
| 570 |
+
|
| 571 |
+
# Add the last line
|
| 572 |
+
if current_line:
|
| 573 |
+
line_group = VGroup(*current_line).arrange(RIGHT, buff=0.05)
|
| 574 |
+
all_lines.append(line_group)
|
| 575 |
|
| 576 |
+
if not all_lines:
|
| 577 |
return VGroup()
|
| 578 |
|
| 579 |
+
# Stack all lines vertically
|
| 580 |
+
final_group = VGroup(*all_lines).arrange(DOWN, aligned_edge=LEFT, buff=0.2)
|
| 581 |
+
return final_group
|
| 582 |
|
| 583 |
def make_wrapped_paragraph(content, color, font, font_size, line_spacing=0.2):
|
| 584 |
lines = []
|