Ratex (Ratex v0.1.0)

Copy Markdown View Source

This library provides an Elixir wrapper around the Rust RaTeX library. This allows you render SVGs and PNGs of mathematical expressions right in Elixir.

Summary

Functions

Generate a PNG binary from a given LaTeX math expression.

Same as render_png/2 but raises on error.

Generate an SVG from a given LaTeX math expression.

Same as render_svg/2 but raises on error.

Types

png_opts()

@type png_opts() ::
  {:font_size, float()}
  | {:pixel_ratio, float()}
  | {:color, binary()}
  | {:inline, boolean()}
  | {:unicode_font_path, binary()}

svg_opts()

@type svg_opts() ::
  {:font_size, float()}
  | {:color, binary()}
  | {:inline, boolean()}
  | {:unicode_font_path, binary()}

Functions

render_png(expression, opts \\ [])

@spec render_png(expression :: String.t(), opts :: png_opts()) ::
  {:ok, binary()} | {:error, term()}

Generate a PNG binary from a given LaTeX math expression.

Options

  • :font_size (float/0) - The base font size in pixels. The default value is 32.0.

  • :pixel_ratio (float/0) - The device pixel ratio for retina rasters. The default value is 2.0.

  • :color (String.t/0) - The color of the glpyhs as hexadecimal (e.g. #112233). The default value is "#000000".

  • :inline (boolean/0) - Render the expression as inline text as opposed to display. The default value is false.

  • :unicode_font_path (String.t/0) - The absolute path to a TTF font file for non-ASCII text that may be used inside of an \\text{...} expression. If a font path is not provided the underlying RaTeX Rust library will attempt to use the platform fallback.

render_png!(expression, opts \\ [])

@spec render_png!(expression :: String.t(), opts :: png_opts()) :: binary()

Same as render_png/2 but raises on error.

render_svg(expression, opts \\ [])

@spec render_svg(expression :: String.t(), opts :: svg_opts()) ::
  {:ok, binary()} | {:error, term()}

Generate an SVG from a given LaTeX math expression.

Options

  • :font_size (float/0) - The base font size in pixels. The default value is 32.0.

  • :color (String.t/0) - The color of the glpyhs as hexadecimal (e.g. #112233). The default value is "#000000".

  • :inline (boolean/0) - Render the expression as inline text as opposed to display. The default value is false.

  • :unicode_font_path (String.t/0) - The absolute path to a TTF font file for non-ASCII text that may be used inside of an \\text{...} expression. If a font path is not provided the underlying RaTeX Rust library will attempt to use the platform fallback.

render_svg!(expression, opts \\ [])

@spec render_svg!(expression :: String.t(), opts :: svg_opts()) :: binary()

Same as render_svg/2 but raises on error.