subtitles

class janim.timeline.subtitles.SubtitleInfo(text: str, range: TimeRange, kwargs: dict, subtitle: Text | TypstText)

Bases: object

Parameter information for calling subtitle()

text: str
range: TimeRange
kwargs: dict
subtitle: Text | TypstText
class janim.timeline.subtitles.SubtitlesMixin(*args, **kwargs)

Bases: TimelineCore

Provides the ability to add subtitles to Timeline

Hint

All methods in this class can be used directly in Timeline

subtitle(text: str | Iterable[str], duration: float = 1, *, delay: float = 0, scale: float | Iterable[float] = 0.8, use_typst_text: bool | Iterable[bool] = False, surrounding_color: JAnimColor = BLACK, surrounding_alpha: float = 0.5, font: str | Iterable[str] = [], depth: float = -100000.0, **kwargs) TimeRange
subtitle(text: str | Iterable[str], range: TimeRange, **kwargs) TimeRange

Add subtitle

  • Text can be passed as a list, displayed vertically

  • You can specify that the subtitle appears delay seconds after the current position

  • duration represents the duration

  • scale represents the scaling of text. You can pass a list to specify scaling for each text

  • use_typst_text indicates whether to use TypstText. You can pass a list to specify whether each text uses it

  • Set surrounding_alpha to 0 to disable the background box

Config also provides some configurable parameters:

  • subtitle_font globally configures the font used for subtitles

  • subtitle_to_edge_buff configures the distance from the subtitle to the bottom edge; defaults to DEFAULT_ITEM_TO_EDGE_BUFF

Return value represents the display time range

place_subtitle(subtitle: Text | TypstText, range: TimeRange) None

Called by subtitle() to place subtitles in appropriate positions:

  • For subtitles added in the same batch [a, b], a is placed above b

  • If [a, b] mentioned above still exists and a c is added, then c is placed at the top

has_subtitle() bool