typst/typst · error

tag must be one to four characters in length

Error message

tag must be one to four characters in length

What it means

Raised while casting a string to an OpenType Tag: OpenType tags are fixed at one to four bytes, but the string had zero or more than four characters.

Source

Thrown at crates/typst-library/src/text/font/tag.rs:99

// Tags must: https://learn.microsoft.com/en-us/typography/opentype/spec/otff#data-types
// - be one to four bytes in length
// - be representable as printable ASCII (0x20..=0x7E)
// - contain at least one character that isn't padding (0x20, space)
// - padding may only appear at the end of a tag
cast! {
    Tag,
    v: Str => {
        if let Some(cluster) = v.graphemes(true).find(|v| {
            !v.as_bytes().iter().all(|v| (0x20..=0x7E).contains(v))
        }) {
            bail!(
                "tag may contain only printable ASCII characters";
                hint: "found invalid cluster `{}`", cluster.repr();
            )
        }

        if !(1..=4).contains(&v.len()) {
            bail!(
                "tag must be one to four characters in length";
                hint: "found {} characters", v.len();
            );
        }

        let mut within_padding = false;
        for (i, &v) in v.as_bytes().iter().enumerate() {
            if (within_padding && v != b' ') || (i == 0 && v == b' ') {
                bail!("spaces may only appear as padding following a tag")
            }
            within_padding |= b' ' == v;
        }

        Self::from_bytes_lossy(v.as_bytes())
    }
}

impl From<Tag> for ttf_parser::Tag {

View on GitHub (pinned to 35417aa769)

Solutions

  1. Shorten the tag to at most four characters, e.g. `"kern"`
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/typst-library/src/text/font/tag.rs:99 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of typst/typst@35417aa769 (2026-08-17). Data as JSON: /api/errors/02fb34f411cbc6be. Report an issue: GitHub.