Commands
This reference documents a custom command corresponding to the Typst compiler and its implementation of the Cmd
interface.
Typstry
Typstry.Commands.TypstCommand
— TypeTypstCommand(::AbstractVector{<:AbstractString})
TypstCommand(::TypstCommand; kwargs...)
The Typst compiler and its parameters.
Keyword parameters have the same semantics as for a Cmd
.
This type implements the Cmd
interface. However, the interface is undocumented, which may result in unexpected behavior.
Examples
julia> help = TypstCommand(["help"])
typst`help`
julia> TypstCommand(help; ignorestatus = true)
typst`help`
Typstry.Commands.TypstError
— TypeTypstError <: Exception
TypstError(::TypstCommand)
An Exception
indicating a failure to run
a TypstCommand
.
Examples
julia> TypstError(typst``)
TypstError(typst``)
Typstry.Commands.@typst_cmd
— Macro@typst_cmd("s")
typst`s`
Construct a TypstCommand
where each parameter is separated by a space.
This does not support interpolation; use the constructor instead.
Examples
julia> typst`help`
typst`help`
julia> typst`compile input.typ output.typ`
typst`compile input.typ output.typ`
Typstry.Commands.julia_mono
— Constantjulia_mono
A constant String
file path to the JuliaMono typeface.
Use with a TypstCommand
and one of addenv
, setenv
, or the font-path
Typst command-line option.
Typstry.Commands.preamble
— Constantpreamble
A constant TypstString
used at the beginning of Typst source files generated by render
and some show
methods.
May be configured using set_preamble
.
Examples
julia> preamble
TypstString(TypstText("#set page(margin: 1em, height: auto, width: auto, fill: white)\n#set text(16pt, font: \"JuliaMono\")\n"))
Typstry.Commands.render
— Functionrender(value;
input = "input.typ",
output = "output.pdf",
open = true,
ignorestatus = true,
preamble = preamble,
context...)
Render to a document using show(::IO, ::MIME"text/typst", ::Typst)
.
This first generates the input
file containing the preamble
and formatted value
. Then it is compiled to the output
document, whose format is inferred by its file extension to be pdf
, png
, or svg
. The document may be automatically open
ed by the default viewer. The ignorestatus
flag may be set. This supports using the julia_mono
typeface.
Examples
julia> render(Any[true 1; 1.2 1 // 2]);
Typstry.Commands.set_preamble
— Functionset_preamble()
set_preamble(::TypstString)
Use Preferences.jl such that after restarting Julia, the preamble
is initialized to the given TypstString
.
If the TypstString
is not provided, reset the preamble
to it's default value.
Typstry.Commands.typst
— Functiontypst(::AbstractString; catch_interrupt = true, ignorestatus = true)
Convenience function intended for interactive use, emulating the typst command line interface. Be aware, however, that it strictly splits on spaces and does not provide any shell-style escape mechanism, so it will not work if there are, e.g., filenames with spaces.
When catch_interrupt
is true, CTRL-C quietly quits the command. When ignorestatus
is true, a Typst failure will not imply a julia error.
If the "TYPST_FONT_PATHS"
environment variable is not set, it is temporarily set to julia_mono
.
Base
Base.:==
— Function==(::TypstCommand, ::TypstCommand)
See also TypstCommand
.
Examples
julia> TypstCommand(["help"]) == @typst_cmd("help") == typst`help`
true
julia> typst`help` == ignorestatus(typst`help`)
false
Base.addenv
— Functionaddenv(::TypstCommand, args...; kwargs...)
See also TypstCommand
and julia_mono
.
Examples
julia> addenv(typst`compile input.typ output.pdf`, "TYPST_FONT_PATHS" => julia_mono)
typst`compile input.typ output.pdf`
Base.detach
— FunctionBase.eltype
— FunctionBase.firstindex
— FunctionBase.getindex
— FunctionBase.hash
— Functionhash(::TypstCommand, ::UInt)
See also TypstCommand
.
Base.ignorestatus
— Functionignorestatus(::TypstCommand)
Return a TypstCommand
that does not throw a TypstError
if the Typst compiler throws an error.
Errors thrown by the Typst compiler are printed to stderr
regardless.
Examples
julia> ignorestatus(typst`help`)
typst`help`
Base.iterate
— Methoditerate(::TypstCommand)
iterate(::TypstCommand, i)
See also TypstCommand
.
Examples
julia> iterate(typst`help`, 2)
("help", 3)
julia> iterate(typst`help`, 3)
Base.keys
— Functionkeys(::TypstCommand)
See also TypstCommand
.
Examples
julia> keys(typst`help`)
2-element LinearIndices{1, Tuple{Base.OneTo{Int64}}}:
1
2
Base.lastindex
— FunctionBase.length
— FunctionBase.read
— Functionread(::TypstCommand, ::Type{String})
read(::TypstCommand)
See also TypstCommand
.
Base.run
— Functionrun(::TypstCommand, args...; kwargs...)
See also TypstCommand
.
Errors thrown by the Typst compiler will be printed to stderr
. Then, a Julia TypstError
will be thrown unless the ignorestatus
flag is set.
Base.setcpuaffinity
— Functionsetcpuaffinity(::TypstCommand, cpus)
See also TypstCommand
.
Examples
julia> setcpuaffinity(typst`help`, nothing)
typst`help`
Base.setenv
— Functionsetenv(::TypstCommand, args...; kwargs...)
See also TypstCommand
and julia_mono
.
Examples
julia> setenv(typst`compile input.typ output.pdf`, "TYPST_FONT_PATHS" => julia_mono)
typst`compile input.typ output.pdf`
Base.show
— Methodshow(::IO, ::MIME"text/plain", ::TypstCommand)
See also TypstCommand
.
Examples
julia> show(stdout, "text/plain", typst`help`)
typst`help`
Base.show
— Methodshow(::IO, ::MIME"text/plain", ::TypstError)
Examples
julia> show(stdout, "text/plain", TypstError(typst``))
TypstError(typst``)
Base.show
— Methodshow(::IO, ::Union{
MIME"application/pdf", MIME"image/png", MIME"image/svg+xml"
}, ::Union{Typst, TypstString, TypstText})
Print the Portable Document Format (PDF), Portable Network Graphics (PNG), or Scalable Vector Graphics (SVG) format.
The preamble
keyword parameter used by render
may be specified in an IOContext
. Environments, such as Pluto.jl notebooks, may use these methods to display
values of type Typst
, TypstString
, and TypstText
. This supports using the julia_mono
typeface.
Examples
julia> show(IOContext(devnull, :preamble => typst""), "image/svg+xml", Typst(1))
Base.showerror
— Methodshowerror(::IO, ::TypstError)
Print a TypstError
when failing to run
a TypstCommand
.
Examples
julia> showerror(stdout, TypstError(typst``))
TypstError: failed to `run` a `TypstCommand(String[])`