PaperForge.Math (PaperForge v1.4.2)

Copy Markdown View Source

Math AST and native PDF renderer for scientific expressions.

The AST is independent from any input notation and can represent symbols, rows, fractions, roots, matrices, superscripts, subscripts, and integrals.

Summary

Types

ast()

@type ast() ::
  {:symbol, binary()}
  | {:row, [ast()]}
  | {:fraction, ast(), ast()}
  | {:root, ast(), ast() | nil}
  | {:matrix, [[ast()]]}
  | {:superscript, ast(), ast()}
  | {:subscript, ast(), ast()}
  | {:integral, ast() | nil, ast() | nil, ast(), binary()}

Functions

fraction(numerator, denominator)

@spec fraction(ast(), ast()) :: ast()

integral(lower, upper, body, variable \\ "x")

@spec integral(ast() | nil, ast() | nil, ast(), binary()) :: ast()

matrix(rows)

@spec matrix([[ast()]]) :: ast()

measure(ast, options \\ [])

@spec measure(
  ast(),
  keyword()
) :: {number(), number()}

Returns the measured width and height of an expression.

render(page, ast, options)

@spec render(PaperForge.Page.t(), ast(), keyword()) :: PaperForge.Page.t()

Renders a Math AST at top-left page coordinates.

root(value, index \\ nil)

@spec root(ast(), ast() | nil) :: ast()

row(items)

@spec row([ast()]) :: ast()

subscript(base, subscript)

@spec subscript(ast(), ast()) :: ast()

superscript(base, exponent)

@spec superscript(ast(), ast()) :: ast()

symbol(value)

@spec symbol(term()) :: ast()