typst¶
- class janim.items.svg.typst.TypstDoc(text: str, *, vars: dict[str, TypstVar] | None = None, vars_size_unit: Literal['pt', 'mm', 'cm', 'in'] | None = None, sys_inputs: dict[str, str] = {}, scale: float = 1.0, shared_preamble: str | None = None, additional_preamble: str | None = None, **kwargs)¶
Bases:
SVGItemTypst document
- group_key: str | None = 'data-typst-label'¶
- move_into_position() None¶
- classmethod typstify(obj: TypstPattern) TypstDoc¶
Convert a string to a Typst object, if it already is one, return it directly
- static vars_str(vars: dict[str, TypstVar], unit_or_scale: str | float) tuple[str, dict[str, Points]]¶
- static var_str(var: TypstVar, label: str, unit_or_scale: str | float, mapping: dict[str, Points]) str¶
- static length_str(length: float, unit_or_scale: str | float) str¶
- match_pattern(target: TypstDoc, pattern: TypstPattern, ordinal: int = 0, target_ordinal: int | None = None) Self¶
Match and transform so that the matched parts coincide
For example
t1 = TypstMath('x^2 + y^2') t2 = TypstMath('x + y') t2.points.match_pattern(t1, '+')
Will transform
t2so that the plus signs of both coincide
- patterns(*patterns: SingleMatchPattern) Group[VItem | BasepointVItem]¶
- patterns(*patterns: MultiMatchPattern) Group[Group[VItem | BasepointVItem]]
- patterns(*patterns: SingleMatchPattern | MultiMatchPattern) Group[VItem | BasepointVItem] | Group[Group[VItem | BasepointVItem]]
Get multiple pattern match results at once, returning a
Groupe.g.
typ.patterns(A, B, ...)is equivalent toGroup(typ[A], typ[B], ...)
- get(slices, gapless: bool = False)¶
Get sliced sub-items based on slices
By default,
gapless=False:Means directly slicing sub-items through the given
slices, for exampleitem.get(slice(1, 3)) == item[1:3]Supports using lists to get a batch of sub-items, for example
item.get([slice(1, 3), slice(4, 7)]) == [item[1:3], item[4:7]]Lists support nesting, and results maintain the original nested structure, for example
item.get([slice(1, 3), [slice(4, 6), slice(10, 12)]]) == [item[1:3], [item[4:6], item[10:12]]]
If
gapless=True:Means splitting all sub-items at all start and end positions of the given
slicesand returning them together, for exampleitem.get(slice(1, 3), gapless=True) == [item[:1], item[1:3], item[3:]]Also supports lists and nested lists, for example
item.get([slice(1, 3), slice(5, 7)], gapless=True) == [item[:1], item[1:3], item[3:5], item[5:7], item[7:]]Note: In this case, all nested structures will be flattened first before processing
- MultiMatchPattern = MultiMatchPattern¶
- SingleMatchPattern = SingleMatchPattern¶
- slice(pattern: TypstPattern, ordinal: int) slice¶
- slice(pattern: TypstPattern, ordinal: Iterable[int] | EllipsisType) list[slice]
Get the slice where the specified
patternmatches in shape in this itemBy default returns the first match (i.e.,
ordinal=0)Passing other indices to
ordinalcan get specific parts of subsequent matchesPassing an index list to
ordinalcan get multiple specific parts of matchesPassing ellipsis
...toordinalcan get all matching parts
- indices(pattern: TypstPattern) list[int]¶
Find all positions where
patternappears in this formulapatternsupports using strings or Typst objects
- lps_map: dict[str, list[int]] = {}¶
- property lps: list[int]¶
Partial match table used in the KMP algorithm