Guidedog Handbuch 1.0.0-beta.16
Sprache
Auf dieser Seite
Guidedog / Dokumentation 1.0.0-beta.16

guidedoc_typst

The Typst-source renderer of Guidedoc: a validated document becomes one Typst source file. It writes text, not PDF; gd-typst compiles it.

The output is a fixed, trusted preamble of gd- helper definitions (PREAMBLE) followed by the body. Source text never becomes executable Typst: markup text escapes every ASCII punctuation character, and code, URLs, labels, and paths are string literals. Raw Typst is written only under ContentPolicy::Allow; LaTeX math goes through a bounded adapter (translate_math) whose failures follow the math policy, and MathML through a bounded translator (translate_mathml) whose output is generated markup, written under every policy.

use guidedoc::Registry;
let registry = Registry { readers: vec![], renderers: vec![guidedoc_typst::RENDERER] };
assert!(registry.find_renderer("typst").is_some());
assert!(guidedoc_typst::PREAMBLE.contains("#let gd-link"));

Structs

pub struct guidedoc_typst::MathError<'a>

The first construct of a formula the adapter cannot translate: a command such as \color, borrowed from the formula, or a description such as „an unclosed {„.

Fields

pub construct: &'a str

The command or the description of the construct.

Trait Implementations

impl fmt::Display for MathError<'_>
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
impl std::error::Error for MathError<'_>
pub struct guidedoc_typst::MathMlMath

What the translator found out about a formula it wrote.

Fields

pub block: bool

The root says display="block": the formula is meant to stand on its own line.

pub struct guidedoc_typst::MathMlUnsupported

The first construct of a MathML formula the translator cannot write as Typst math: an element such as <menclose>, or a description such as „more than 4096 elements“.

Fields

pub construct: String

The element or the description of the construct.

Trait Implementations

impl fmt::Display for MathMlUnsupported
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
impl std::error::Error for MathMlUnsupported

Functions

pub fn guidedoc_typst::is_label_safe(name: &str) -> bool

Tells whether name can be written as a Typst label literal <name>: non-empty, made of letters, digits, non-ASCII characters, and -, _, ., :.

pub fn guidedoc_typst::write_markup_text(out: &mut (impl TextSink + ?Sized), text: &str)

Writes text as inert Typst markup. Every ASCII punctuation character is escaped with a backslash, which Typst accepts for all of them, so no markup (#, $, *, _, , <, @, [, =, -, +, /, ~, quotes, // comments, list and heading markers, shorthands such as -- or ..., URL autolinks) can arise from text. Line breaks are white space; control characters are dropped. It never fails.

pub fn guidedoc_typst::write_string_literal(out: &mut (impl TextSink + ?Sized), s: &str)

Writes s as a Typst string literal, quotes included. It never fails.

pub fn guidedoc_typst::translate_math<'a>(latex: &'a str, out: &mut String) -> Result<(), MathError<'a>>

Appends the Typst math form of latex (without $ delimiters) to out. On failure it returns the first unsupported construct; out then holds an incomplete translation the caller should discard. It never panics, for any input.

pub fn guidedoc_typst::translate_mathml(mathml: &str, out: &mut String) -> Result<MathMlMath, MathMlUnsupported>

Appends the Typst math form of mathml (one math element, without $ delimiters) to out. It borrows both for the call. The output may name gd-math-font, as the output of crate::translate_math does. On failure it returns the first construct it cannot translate, and out is as it was. It never panics, for any input.

pub fn guidedoc_typst::renderer() -> Renderer

Returns RENDERER, the Typst renderer descriptor.

pub fn guidedoc_typst::emit_preamble(out: &mut Emitter<'_>)

Writes PREAMBLE. A host composing a book from body-only chapters (RenderOptions::standalone = false) writes it once, before the chapters.

pub fn guidedoc_typst::render(ctx: &mut RenderContext<'_>) -> Result<(), Fail>

Writes ctx.doc as Typst source through ctx.out: the preamble, the document and page settings, and the body when ctx.options.standalone, else the body alone. It borrows the context for the call. Problems go to ctx.reports(); it fails with the first error (raw content the policy refuses, an unresolved reference, untranslatable math under the refuse policy, nesting past the limits), or Capacity when the per-node marks cannot be allocated.

Constants

pub const guidedoc_typst::SOURCE_LABEL: &str = "gd-source"

The label of the metadata that carries block source positions in a book’s Typst (see RenderOptions::source_positions).

pub const guidedoc_typst::MAX_MATHML_ELEMENTS: usize = 4096

The most elements of one formula the translator reads.

pub const guidedoc_typst::MAX_MATHML_NESTING: usize = 48

The deepest element nesting the translator follows. Typst nests one call for each level, so the bound is lower than the filter’s.

pub const guidedoc_typst::CITATION_MISSING: Message

A citation reference without a citation.

pub const guidedoc_typst::DEPTH_LIMIT: Message

Rendering recursion past the depth bound.

pub const guidedoc_typst::DIMENSION_IGNORED: Message

An image size that is not a length.

pub const guidedoc_typst::FOOTNOTE_MISSING: Message

A footnote reference without a footnote.

pub const guidedoc_typst::IMAGE_REMOTE: Message

A remote image, which Typst cannot embed.

pub const guidedoc_typst::LANGUAGE_INVALID: Message

RenderOptions::language is not a language tag.

A reference nothing resolved.

pub const guidedoc_typst::MATH_MATHML: Message

A formula written as MathML that the translator cannot write as Typst math.

pub const guidedoc_typst::MATH_OMITTED: Message

Math the adapter cannot translate, under the omit policy.

pub const guidedoc_typst::MATH_UNSUPPORTED: Message

Math the adapter cannot translate, under the refuse policy. One code, three severities: the conversion policy decides whether the formula fails the conversion, is omitted, or is kept as source.

pub const guidedoc_typst::MATH_VERBATIM: Message

Math the adapter cannot translate, under the allow policy: kept as LaTeX source.

pub const guidedoc_typst::RAW_FOREIGN: Message

Raw content for another format, under the refuse policy.

pub const guidedoc_typst::RAW_FOREIGN_OMITTED: Message

Raw content for another format, under the omit or allow policy: never written.

pub const guidedoc_typst::RAW_OMITTED: Message

Raw Typst under the omit policy.

pub const guidedoc_typst::RAW_REFUSED: Message

Raw Typst under the refuse policy.

pub const guidedoc_typst::SUBSTITUTION_MISSING: Message

A substitution without a definition, or one that refers to itself.

pub const guidedoc_typst::URL_OMITTED: Message

An unsafe link under the omit policy: only its text is kept.

pub const guidedoc_typst::URL_UNSAFE: Message

A javascript:, vbscript:, or non-image data: link under the refuse policy.

pub const guidedoc_typst::VERSION: &str = env!("CARGO_PKG_VERSION")

The renderer’s version: the project version.

pub const guidedoc_typst::CONFORMANCE: Conformance = Conformance::Partial

How completely the renderer covers the document model.

pub const guidedoc_typst::RENDERER: Renderer

The „typst“ renderer descriptor, for a guidedoc::Registry. It has no state.

pub const guidedoc_typst::PREAMBLE: &str = include_str!("preamble.typ")

The helper definitions every body relies on: fixed, trusted Typst into which no document data is ever interpolated.