or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

3d-objects.mdadvanced-animations.mdanimation-system.mdboolean-operations.mdcoordinate-systems.mdindex.mdinteractive-controls.mdmathematical-objects.mdmatrix-visualization.mdprobability-stats.mdscene-framework.mdtext-and-latex.mdutilities-and-constants.mdvalue-tracking.mdvector-fields.md

text-and-latex.mddocs/

0

# Text and LaTeX Rendering

1

2

ManimGL provides comprehensive text rendering capabilities including plain text, LaTeX mathematical expressions, code highlighting, and markup support. The text system offers precise typographical control and seamless integration with mathematical content for educational animations.

3

4

## Capabilities

5

6

### Plain Text Rendering

7

8

Advanced text rendering with font control, styling, and positioning.

9

10

```python { .api }

11

class Text(VMobject):

12

def __init__(self, text, **kwargs):

13

"""

14

Render plain text with advanced typography.

15

16

Parameters:

17

- text: str, text content to render

18

- font: str, font family name

19

- font_size: float, text size in points (default: 48)

20

- color: text color

21

- stroke_width: float, outline thickness

22

- stroke_color: outline color

23

- fill_opacity: float, text opacity (0-1)

24

- slant: str, font style ('NORMAL', 'ITALIC', 'OBLIQUE')

25

- weight: str, font weight ('NORMAL', 'BOLD')

26

- t2c: dict, text-to-color mapping for parts of text

27

- t2f: dict, text-to-font mapping for parts of text

28

- t2s: dict, text-to-slant mapping for parts of text

29

- t2w: dict, text-to-weight mapping for parts of text

30

"""

31

32

def get_part_by_text(self, text):

33

"""

34

Get submobject containing specific text.

35

36

Parameters:

37

- text: str, text to find

38

39

Returns:

40

VMobject or None

41

"""

42

43

def set_color_by_text(self, text, color):

44

"""

45

Set color for specific text substring.

46

47

Parameters:

48

- text: str, text to recolor

49

- color: new color

50

51

Returns:

52

Text (self)

53

"""

54

55

class MarkupText(VMobject):

56

def __init__(self, text, **kwargs):

57

"""

58

Text with Pango markup support (HTML-like tags).

59

60

Parameters:

61

- text: str, text with markup tags

62

- color: default text color

63

- font_size: float, default font size

64

- line_spacing: float, spacing between lines

65

- justify: bool, justify text alignment

66

- indent: float, paragraph indentation

67

68

Supported markup:

69

- <b>bold</b>

70

- <i>italic</i>

71

- <u>underline</u>

72

- <s>strikethrough</s>

73

- <span color="red">colored text</span>

74

- <span font_size="24">sized text</span>

75

"""

76

77

class Paragraph(VGroup):

78

def __init__(self, *text, **kwargs):

79

"""

80

Multi-line paragraph with line wrapping.

81

82

Parameters:

83

- text: str or list of str, paragraph content

84

- line_spacing: float, spacing between lines

85

- alignment: str, text alignment ('left', 'center', 'right')

86

"""

87

```

88

89

### LaTeX Mathematical Expressions

90

91

Comprehensive LaTeX rendering for mathematical notation and equations.

92

93

```python { .api }

94

class Tex(VMobject):

95

def __init__(self, *tex_strings, **kwargs):

96

"""

97

Render LaTeX mathematical expressions.

98

99

Parameters:

100

- tex_strings: str arguments, LaTeX code to render

101

- arg_separator: str, separator between arguments (default: " ")

102

- substrings_to_isolate: list, LaTeX parts to isolate as submobjects

103

- font_size: float, text size

104

- color: default color

105

- stroke_width: float, outline thickness

106

- background_stroke_width: float, background outline thickness

107

- background_stroke_color: background outline color

108

- tex_environment: str, LaTeX environment ('align*', 'equation*', etc.)

109

- tex_template: TexTemplate, custom LaTeX template

110

"""

111

112

def get_part_by_tex(self, tex, substring=True):

113

"""

114

Get submobject containing specific LaTeX code.

115

116

Parameters:

117

- tex: str, LaTeX code to find

118

- substring: bool, allow partial matches

119

120

Returns:

121

VMobject or None

122

"""

123

124

def get_parts_by_tex(self, tex, substring=True):

125

"""

126

Get all submobjects containing specific LaTeX code.

127

128

Parameters:

129

- tex: str, LaTeX code to find

130

- substring: bool, allow partial matches

131

132

Returns:

133

VGroup

134

"""

135

136

def set_color_by_tex(self, tex, color, **kwargs):

137

"""

138

Set color for specific LaTeX substring.

139

140

Parameters:

141

- tex: str, LaTeX code to recolor

142

- color: new color

143

- substring: bool, allow partial matches

144

145

Returns:

146

Tex (self)

147

"""

148

149

def set_color_by_tex_to_color_map(self, tex_to_color_map, **kwargs):

150

"""

151

Set colors using tex-to-color mapping.

152

153

Parameters:

154

- tex_to_color_map: dict, mapping from LaTeX to colors

155

156

Returns:

157

Tex (self)

158

"""

159

160

class MathTex(Tex):

161

def __init__(self, *tex_strings, **kwargs):

162

"""

163

LaTeX math mode expressions (automatically wrapped in $...$).

164

165

Parameters:

166

- tex_strings: str arguments, mathematical expressions

167

"""

168

169

class TexText(Tex):

170

def __init__(self, *tex_strings, **kwargs):

171

"""

172

Mixed text and math LaTeX rendering.

173

174

Parameters:

175

- tex_strings: str arguments, text with embedded math ($...$)

176

- arg_separator: str, separator between arguments

177

- tex_environment: str, LaTeX environment (default: plain text)

178

"""

179

180

class BulletedList(TexText):

181

def __init__(self, *items, **kwargs):

182

"""

183

Bulleted list with LaTeX rendering.

184

185

Parameters:

186

- items: str arguments, list items

187

- bullet: str, bullet character (default: "\\cdot")

188

- buff: float, spacing after bullet

189

- dot_scale_factor: float, bullet size scaling

190

"""

191

192

class Title(TexText):

193

def __init__(self, *text_parts, **kwargs):

194

"""

195

Title text with larger font and positioning.

196

197

Parameters:

198

- text_parts: str arguments, title content

199

- scale_factor: float, title scaling (default: 1.5)

200

- include_underline: bool, add underline

201

- underline_width: float, underline thickness

202

"""

203

```

204

205

### Code Display and Highlighting

206

207

Syntax-highlighted code display with language support.

208

209

```python { .api }

210

class Code(Text):

211

def __init__(self, code_string, **kwargs):

212

"""

213

Syntax-highlighted code display.

214

215

Parameters:

216

- code_string: str, source code to display

217

- language: str, programming language ('python', 'javascript', 'c++', etc.)

218

- font: str, monospace font name (default: "Consolas")

219

- font_size: float, code font size

220

- line_spacing: float, spacing between code lines

221

- tab_width: int, spaces per tab character

222

- background: str, background style ('rectangle', 'window')

223

- background_stroke_width: float, background border width

224

- background_stroke_color: background border color

225

- corner_radius: float, background corner rounding

226

- style: str, syntax highlighting style ('default', 'monokai', etc.)

227

- generate_html_string: bool, generate HTML representation

228

"""

229

230

def set_language(self, language):

231

"""

232

Change syntax highlighting language.

233

234

Parameters:

235

- language: str, new language name

236

237

Returns:

238

Code (self)

239

"""

240

```

241

242

### Special Text Objects

243

244

Specialized text objects for mathematical and educational content.

245

246

```python { .api }

247

class Integer(VMobject):

248

def __init__(self, number=0, **kwargs):

249

"""

250

Integer number display that can be animated.

251

252

Parameters:

253

- number: int, number to display

254

- number_config: dict, Text configuration for number

255

- show_ellipsis: bool, show ellipsis for large numbers

256

- group_with_commas: bool, add comma separators

257

"""

258

259

def set_value(self, number):

260

"""

261

Change displayed number.

262

263

Parameters:

264

- number: int, new number to display

265

266

Returns:

267

Integer (self)

268

"""

269

270

def get_value(self):

271

"""

272

Get current displayed number.

273

274

Returns:

275

int

276

"""

277

278

def increment_value(self, delta=1):

279

"""

280

Increment displayed number.

281

282

Parameters:

283

- delta: int, amount to add

284

285

Returns:

286

Integer (self)

287

"""

288

289

class DecimalNumber(VMobject):

290

def __init__(self, number=0, **kwargs):

291

"""

292

Decimal number display that can be animated.

293

294

Parameters:

295

- number: float, number to display

296

- num_decimal_places: int, decimal places to show

297

- include_sign: bool, show + for positive numbers

298

- group_with_commas: bool, add comma separators

299

- digit_buff_per_font_unit: float, spacing between digits

300

- show_ellipsis: bool, show ellipsis for rounding

301

- unit: str, unit suffix (e.g., "m", "kg")

302

- include_background_rectangle: bool, add background

303

- edge_to_fix: np.array, edge to keep fixed during updates

304

"""

305

306

def set_value(self, number):

307

"""

308

Change displayed number.

309

310

Parameters:

311

- number: float, new number to display

312

313

Returns:

314

DecimalNumber (self)

315

"""

316

317

def get_value(self):

318

"""

319

Get current displayed number.

320

321

Returns:

322

float

323

"""

324

325

def increment_value(self, delta):

326

"""

327

Increment displayed number.

328

329

Parameters:

330

- delta: float, amount to add

331

332

Returns:

333

DecimalNumber (self)

334

"""

335

```

336

337

### Text Utilities and Layout

338

339

Utilities for text alignment, layout, and organization.

340

341

```python { .api }

342

class VGroup(VMobject):

343

def arrange(self, direction=RIGHT, **kwargs):

344

"""

345

Arrange submobjects in specified direction.

346

347

Parameters:

348

- direction: np.array, arrangement direction

349

- buff: float, spacing between objects

350

- center: bool, center the arrangement

351

- aligned_edge: np.array, edge to align

352

353

Returns:

354

VGroup (self)

355

"""

356

357

def arrange_in_grid(self, rows=None, cols=None, **kwargs):

358

"""

359

Arrange submobjects in grid layout.

360

361

Parameters:

362

- rows: int, number of rows

363

- cols: int, number of columns

364

- buff: float, spacing between objects

365

- cell_alignment: np.array, alignment within cells

366

367

Returns:

368

VGroup (self)

369

"""

370

371

def text_alignment_functions():

372

"""Text alignment utility functions."""

373

374

def align_text_left(text_mobject):

375

"""Align text to left edge."""

376

377

def align_text_right(text_mobject):

378

"""Align text to right edge."""

379

380

def align_text_center(text_mobject):

381

"""Center align text."""

382

383

class Underline(Line):

384

def __init__(self, mobject, **kwargs):

385

"""

386

Underline for text objects.

387

388

Parameters:

389

- mobject: Text object to underline

390

- buff: float, distance below text

391

"""

392

393

class Cross(VGroup):

394

def __init__(self, mobject, **kwargs):

395

"""

396

Cross/strikethrough for text objects.

397

398

Parameters:

399

- mobject: Object to cross out

400

- stroke_color: Cross line color

401

- stroke_width: Cross line thickness

402

"""

403

```

404

405

## Usage Examples

406

407

### Basic Text

408

409

```python

410

from manimgl import *

411

412

class TextExample(Scene):

413

def construct(self):

414

# Create various text objects

415

plain_text = Text("Hello World", font_size=48)

416

styled_text = Text(

417

"Styled Text",

418

font="Arial",

419

color=BLUE,

420

stroke_width=2,

421

stroke_color=WHITE

422

)

423

424

# Position text

425

plain_text.shift(UP)

426

styled_text.shift(DOWN)

427

428

# Animate

429

self.play(Write(plain_text))

430

self.play(Write(styled_text))

431

self.wait()

432

```

433

434

### LaTeX Mathematics

435

436

```python

437

class MathExample(Scene):

438

def construct(self):

439

# Mathematical expressions

440

equation = MathTex(

441

"E", "=", "m", "c^2"

442

).set_color_by_tex_to_color_map({

443

"E": YELLOW,

444

"m": RED,

445

"c": BLUE

446

})

447

448

# Complex equation

449

integral = MathTex(

450

r"\int_0^{\infty} x^2 e^{-x} dx = 2"

451

)

452

453

self.play(Write(equation))

454

self.wait()

455

self.play(Transform(equation, integral))

456

self.wait()

457

```

458

459

### Code Display

460

461

```python

462

class CodeExample(Scene):

463

def construct(self):

464

code = Code(

465

"""

466

def fibonacci(n):

467

if n <= 1:

468

return n

469

return fibonacci(n-1) + fibonacci(n-2)

470

""",

471

language="python",

472

font_size=36,

473

background="rectangle",

474

background_stroke_color=WHITE

475

)

476

477

self.play(ShowCreation(code))

478

self.wait()

479

```

480

481

### Mixed Text and Math

482

483

```python

484

class MixedExample(Scene):

485

def construct(self):

486

mixed = TexText(

487

"The quadratic formula is ",

488

"$x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}$",

489

" for $ax^2 + bx + c = 0$"

490

)

491

492

# Color the math parts

493

mixed.set_color_by_tex("$", YELLOW)

494

495

self.play(Write(mixed))

496

self.wait()

497

```

498

499

### Animated Numbers

500

501

```python

502

class NumberExample(Scene):

503

def construct(self):

504

# Animated decimal

505

number = DecimalNumber(0, num_decimal_places=2)

506

number.add_updater(lambda m, dt: m.increment_value(dt))

507

508

self.add(number)

509

self.wait(5) # Number will count up automatically

510

```