Contexts
This reference documents how to specify formatting data.
Typstry.ContextErrors.ContextError
— TypeContextError <: Exception
ContextError(::Type, ::Type, ::Symbol)
An Exception
indicating that a context key returned a value of an incorrect type.
Interface
Implements the Exception
interface.
showerror(::IO, ::ContextError)
show(::IO, ::MIME"text/plain", ::ContextError)
Examples
julia> ContextError(Mode, String, :mode)
ContextError(Mode, String, :mode)
Typstry.DefaultIOs.DefaultIO
— TypeDefaultIO
DefaultIO()
A type used to initialize the default io
in context
.
Examples
julia> io = context[:io]::DefaultIO
(() -> IOContext(stdout, :compact => true))::DefaultIO
julia> io == DefaultIO()() == IOContext(stdout, :compact => true)
true
Typstry.TypstContext
— TypeTypstContext <: AbstractDict{Symbol, Any}
TypstContext(::Any)
TypstContext(; kwargs...)
Provide formatting data for show_typst
.
Implement a method of this constructor for a custom type to specify its custom settings and parameters.
Calls to show_typst
from the following methods:
TypstString
render
show_typst(::IO, ::TypstContext, x)
show
with theapplication/pdf
,image/png
,image/svg+xml
, andtext/typst
MIME
types and aTypstString
,TypstText
, andTypst
value
specify the TypstContext
by combining the following contexts:
- The context given by a
TypstContext
or keyword parameters, which are mutually exclusive - The context given by
IOContext(::IO, ::TypstContext)
- The
context
implicitly set when callingshow_typst
withinshow_typst
- The type's default context, specified by implementing the
TypstContext
constructor - The global default
context
Duplicate keys are handled such that each context is prioritized in order as listed. In other words, keyword parameters and TypstContext
parameters have the highest priority while the default context
has the lowest priority.
Interfaces
This type implements the dictionary and iteration interfaces. However, it does not support removing mappings except through reset_context
.
IOContext(::IO, ::TypstContext)
- Equivalent to
IOContext(::IO, :typst_context => ::TypstContext)
- Equivalent to
copy(::TypstContext)
eltype(::TypstContext)
getkey(::TypstContext, ::Any, ::Any)
get(::TypstContext, ::Any, ::Any)
get(::Union{Function, Type}, ::TypstContext, ::Any)
iterate(::TypstContext, state)
iterate(::TypstContext)
length(::TypstContext)
mergewith(::Any, ::TypstContext, ::AbstractDict...)
merge!(::TypstContext, ::AbstractDict...)
merge(::TypstContext, ::AbstractDict...)
setindex!(::TypstContext, ::Any, ::Any)
show(::IO, ::TypstContext)
sizehint!(::TypstContext, ::Any; kwargs...)
Typstry.context
— Constantcontext
A const
ant TypstContext
used to provide default formatting data when calling show_typst
.
See also reset_context
.
Set mappings in this dictionary to customize the default formatting in other packages and environments.
Setting | Type | Description |
---|---|---|
backticks | Int | The number of backticks to enclose raw text markup, which may be increased to disambiguiate nested raw text. |
block | Bool | When mode = math , specifies whether the enclosing dollar signs are padded with a space to render the element inline or its own block. |
context | TypstContext | This is set implicitly by combining the context given by a TypstContext or keyword parameters with that given by an IO . It is used when calling show_typst from within show_typst . For example, formatting values in containers or changing the type of the input. This is necessary to construct a new combined context with the nested type-level default values, rather than the root type-level default values. |
depth | Int | The current level of nesting within container types to specify the degree of indentation by repeating the tab_size . |
io | DefaultIO | A function with the signature io()::IO , which is used by show_typst when an IO is not otherwise specified. This is implemented as a function to avoid initialization errors. |
mode | Mode | The current Typst syntactical context where code follows the number sign, markup is at the top-level and enclosed in square brackets, and math is enclosed in dollar signs. |
parenthesize | Bool | Whether to enclose some mathematical elements in parentheses to specify their operator precedence and avoid ambiguity. |
preamble | TypstString | Used at the beginning of Typst source files generated by render and some show methods. |
tab_size | Int | The number of spaces used by some elements with multi-line Typst formatting, which is repeated for each level of depth |
Examples
julia> context
TypstContext with 8 entries:
:mode => markup
:parenthesize => true
:block => false
:preamble => TypstString(TypstText("#set page(margin: 1em, height: auto, …
:io => (() -> IOContext(stdout, :compact => true))::DefaultIO
:tab_size => 2
:backticks => 3
:depth => 0
Typstry.reset_context
— Functionreset_context()
Remove any custom mappings from the context
such that it is returned to its default state.
Examples
julia> reset_context()
TypstContext with 8 entries:
:mode => markup
:parenthesize => true
:block => false
:preamble => TypstString(TypstText("#set page(margin: 1em, height: auto, …
:io => (() -> IOContext(stdout, :compact => true))::DefaultIO
:tab_size => 2
:backticks => 3
:depth => 0