Strings

This reference documents formatting Julia values into Typst source text.

Typstry.Strings.AbstractTypsts.TypstFunctionType
TypstFunction{P <: Tuple}(
    typst_context::TypstContext,
    callable::Symbol,
    parameters::P...;
    keyword_parameters...
) <: AbstractTypst

A wrapper representing a Typst function.

This uses the depth::Int, mode::Mode, and tab_size::Int keys from the TypstContext.

Subtype of AbstractTypst.

See also Mode.

Interface

  • ==(::TypstFunction, ::TypstFunction)
  • show_typst(::IO, ::TypstContext, ::TypstFunction)
  • show(::IO, ::TypstFunction)

Examples

julia> show_typst(TypstFunction(context, typst"arguments", 1, 2; a = 3, b = 4))
#arguments(
  1,
  2,
  a: 3,
  b: 4
)
source
Typstry.Strings.TypstStrings.TypstStringType
TypstString <: AbstractString
TypstString(::TypstContext, ::Any)
TypstString(::Any; context...)

A Typst formatted string.

The TypstContext is combined with additional context and passed to show_typst.

Interface

This type implements the String interface. However, the interface is undocumented, which may result in unexpected behavior.

  • *(::TypstString, ::TypstString)
  • IOBuffer(::TypstString)
  • codeunit(::TypstString, ::Integer)
  • codeunit(::TypstString)
  • isvalid(::TypstString, ::Integer)
  • iterate(::TypstString, ::Integer)
  • iterate(::TypstString)
  • ncodeunits(::TypstString)
  • pointer(::TypstString)
  • repr(::MIME"text/typst ::TypstString; context = nothing)
  • repr(::MIME, ::TypstString; context = nothing)
    • This method patches incorrect output from the assumption in repr that the parameter is already in the requested MIME type when the MIME type satisfies istextmime and the parameter is an AbstractString.
  • show_typst(::IO, ::TypstContext, ::TypstString)
  • show(::IO, ::MIME"text/plain", ::TypstString)
    • Print in typst"" format if each character satisfies isprint. Otherwise, print with show(::IO, ::TypstString).
  • show(::IO, ::MIME"text/typst", ::TypstString)
    • Accepts a IOContext(::IO, ::TypstContext).
  • show(::IO, ::Union{MIME"application/pdf", MIME"image/png", MIME"image/svg+xml"}, ::TypstString)
    • Accepts a IOContext(::IO, ::TypstContext).
    • Supports the julia_mono typeface.
    • The generated Typst source text contains the context's preamble and the formatted value.
  • show(::IO, ::TypstString)
    • Print in TypstString(TypstText(::String)) format.

Examples

julia> TypstString(1)
typst"$1$"

julia> TypstString(TypstContext(; mode = math), π)
typst"π"

julia> TypstString(1 + 2im; mode = math)
typst"(1 + 2i)"
source
Typstry.Strings.AbstractTypsts.TypstType
Typst{T}(::T) <: AbstractTypst
Typst(::T)

A wrapper used to pass values to show, whose show_typst method formats the wrapped value.

Subtype of AbstractTypst.

Interface

  • ==(::Typst{T}, ::Typst{T}) where T
  • show_typst(::IO, ::TypstContext, ::Typst)

Examples

julia> show_typst(Typst(1))
$1$
source
Typstry.Strings.TypstStrings.@typst_strMacro
typst""
@typst_str(::String)

Construct a TypstString.

Control characters are escaped, except double quotation marks and backslashes in the same manner as @raw_str. Values may be interpolated by calling the TypstString constructor, except using a backslash instead of the type name. Interpolation syntax may be escaped in the same manner as quotation marks.

Tip

Print directly to an IO using show_typst.

See also the performance tip to Avoid string interpolation for I/O.

Examples

julia> x = 1;

julia> typst"$ \(x; mode = math) / \(x + 1; mode = math) $"
typst"$ 1 / 2 $"

julia> typst"\(x//2)"
typst"$1 / 2$"

julia> typst"\(x // 2; mode = math)"
typst"(1 / 2)"

julia> typst"\\(x)"
typst"\\(x)"
source
Typstry.Strings.show_typstFunction
show_typst(::IO, ::TypstContext, ::Any)::Nothing
show_typst(::IO, ::Any; context...)::Nothing
show_typst(::TypstContext, ::Any)::Nothing
show_typst(::Any; context...)::Nothing

Print in Typst format with Julia settings and Typst parameters provided by the TypstContext.

Implement the three-parameter form of this function for a custom type to specify its Typst formatting. A setting is a value used in Julia, whose type varies across settings. A parameter is passed directly to a Typst function and must be a TypstString with the same name as in Typst, except that dashes are replaced with underscores. Some settings, such as block, correspond with a parameter but may also be used in Julia.

See also the Typst Formatting Examples.

Tip

Please create an issue or pull-request to implement new methods.

source