texBreak method

BreakResult<SyntaxTree> texBreak({
  1. int relPenalty = 500,
  2. int binOpPenalty = 700,
  3. bool enforceNoBreak = true,
})

Line breaking results using standard TeX-style line breaking.

This function will return a list of SyntaxTree along with a list of line breaking penalties.

This function will break the equation into pieces according to TeX spec as much as possible (some exceptions exist when enforceNoBreak: true ). Then, you can assemble the pieces in whatever way you like. The most simple way is to put the parts inside a Wrap.

If you wish to implement a custom line breaking policy to manage the penalties, you can access the penalties in BreakResult.penalties. The values in BreakResult.penalties represent the line-breaking penalty generated at the right end of each BreakResult.parts. Note that \nobreak or \penalty<number>=10000> are left unbroken by default, you need to supply enforceNoBreak: false into Math.texBreak to expose those break points and their penalties.

Implementation

BreakResult<SyntaxTree> texBreak({
  int relPenalty = 500,
  int binOpPenalty = 700,
  bool enforceNoBreak = true,
}) {
  final eqRowBreakResult = greenRoot.texBreak(
    relPenalty: relPenalty,
    binOpPenalty: binOpPenalty,
    enforceNoBreak: true,
  );
  return BreakResult(
    parts: eqRowBreakResult.parts
        .map((part) => SyntaxTree(greenRoot: part))
        .toList(growable: false),
    penalties: eqRowBreakResult.penalties,
  );
}