Serialization and output
Serialization is a lossless interchange format for supported mathematical objects. Rendering is a presentation operation and does not change the object.
Output and serialization#
to_latex#
Default context
to_latex(input_expression: ExpressionLike) -> strCalling forms and variants
Explicit context: Context.to_latex
to_latex(input_expression: ExpressionLike) -> strExpression method: Expression.to_latex
to_latex() -> strVariant for this object — Circle2d method: Circle2d.to_latex
to_latex() -> strVariant for this object — Matrix method: Matrix.to_latex
to_latex() -> strVariant for this object — Point2d method: Point2d.to_latex
to_latex() -> strVariant for this object — Polygon2d method: Polygon2d.to_latex
to_latex() -> strVariant for this object — Segment2d method: Segment2d.to_latex
to_latex() -> strVariant for this object — Triangle2d method: Triangle2d.to_latex
to_latex() -> strRender an expression as LaTeX. Matrices and geometry objects have their own
to_latex methods.
to_latex_with_options#
Default context
to_latex_with_options(
input_expression: ExpressionLike,
exponential_style: str,
natural_logarithm_style: str,
multiletter_symbol_style: str,
) -> strCalling forms
Explicit context: Context.to_latex_with_options
to_latex_with_options(
input_expression: ExpressionLike,
exponential_style: str,
natural_logarithm_style: str,
multiletter_symbol_style: str,
) -> strExpression method: Expression.to_latex_with_options
to_latex_with_options(
exponential_style: str,
natural_logarithm_style: str,
multiletter_symbol_style: str,
) -> strRender an expression as LaTeX with presentation flags. Each argument is a string
naming the choice for one flag; an unrecognized name falls back to that flag's
canonical default (so to_latex_with_options(e, "", "", "") equals
to_latex(e)):
exponential_style:"exp_function"(default,\exp(u)) or"e_caret"(e^{u}, the form the LaTeX parser reads back as exponentiation).natural_logarithm_style:"log"(default,\log) or"ln"(\ln).multiletter_symbol_style:"italic"(default,\mathit{name}) or"upright"(\mathrm{name}).
The defaults are fixed, content-independent canonical choices. Readability
heuristics (for example, switching a tall exponent to \exp) belong in the
caller, via the render-twice pattern: render with the default, test the result,
and re-render with the other flag value if it violates the heuristic.
serialize_object#
Default context
serialize_object(object: Any) -> strSerialize an expression, matrix, or geometry object to the stable Symi
serialization format, round-trippable via parse_serialized_object.
Notes: in WASM this is a per-object method because a single polymorphic context method cannot downcast a JsValue back to an exported Rust type.
parse_serialized_object#
Default context
parse_serialized_object(text: str) -> AnyCalling forms
Explicit context: Context.parse_serialized_object
parse_serialized_object(text: str) -> AnyInverse of serialize_object; returns the matching surface class.
Example#
Round-trip an expression through the serialized form and render it as LaTeX.
import symi
x = symi.symbol("x")
target = symi.integrate(symi.sin(x), "x")
serialized = symi.serialize_object(target)
print(serialized)
print(symi.parse_serialized_object(serialized))
print(symi.to_latex(target))