Typst (Typst v0.2.2)
View SourceThis module provides the core functions for interacting with
the typst markup language compiler.
Note that when using the formatting directives, they are exactly the same as
EEx, so all of its constructs are supported.
See Typst's documentation for a quickstart.
Summary
Functions
Converts a given piece of typst markup to a PDF binary.
Same as render_to_pdf/3, but raises if the rendering fails.
Converts a given piece of typst markup to a PNG binary, one per each page. #
Same as render_to_png/3, but raises if the rendering fails.
Formats the given markup template with the given bindings, mostly useful for inspecting and debugging.
Types
Functions
@spec render_to_pdf(String.t(), [formattable()], [typst_opt()]) :: {:ok, binary()} | {:error, String.t()}
Converts a given piece of typst markup to a PDF binary.
Options
This function takes the following options:
:extra_fonts- a list of directories to seatch for fonts:root_dir- the root directory for typst, where all filepaths are resolved from. defaults to the current directory:assets- a list of{"name", binary()}or enumerable to store blobs in the typst virtual file system
Examples
iex> {:ok, pdf} = Typst.render_to_pdf("= test\n<%= name %>", name: "John")
iex> is_binary(pdf)
true
iex> svg = ~S|<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="m19.5 8.25-7.5 7.5-7.5-7.5" /></svg>|
iex> {:ok, pdf} = Typst.render_to_pdf(~S|#image(read("logo", encoding: none), width: 6cm)|, [], assets: [logo: svg])
iex> is_binary(pdf)
true
@spec render_to_pdf!(String.t(), [formattable()], [typst_opt()]) :: binary()
Same as render_to_pdf/3, but raises if the rendering fails.
@spec render_to_png(String.t(), [formattable()], [typst_opt()]) :: {:ok, [binary()]} | {:error, String.t()}
Converts a given piece of typst markup to a PNG binary, one per each page. #
Options
This function takes the following options:
:extra_fonts- a list of directories to seatch for fonts:root_dir- the root directory for typst, where all filepaths are resolved from. defaults to the current directory:pixels_per_pt- specifies how many pixels represent one pt unit:assets- a list of{"name", binary()}or enumerable to store blobs in the typst virtual file system
Examples
iex> {:ok, pngs} = Typst.render_to_png("= test\n<%= name %>", name: "John")
iex> is_list(pngs)
true
@spec render_to_png!(String.t(), [formattable()], [typst_opt()]) :: [binary()]
Same as render_to_png/3, but raises if the rendering fails.
@spec render_to_string(String.t(), [formattable()]) :: String.t()
Formats the given markup template with the given bindings, mostly useful for inspecting and debugging.
Examples
iex> Typst.render_to_string("= Hey <%= name %>!", name: "Jude")
"= Hey Jude!"