typst/typst · error · SourceDiagnostic

cannot draw a horizontal line at offset {offset} in a matrix

Error message

cannot draw a horizontal line at offset {offset} in a matrix with {nrows} rows

What it means

Raised in resolve_mat while resolving matrix augmentation: an `hline` offset in the augment dictionary is out of range for the matrix's number of rows (positive offsets must be ≤ rows, negative ones within bounds counting from the end).

Source

Thrown at crates/typst-library/src/math/ir/resolve.rs:1045

/// Resolves a matrix element.
fn resolve_mat<'a>(
    elem: &'a Packed<MatElem>,
    ctx: &mut MathResolver<'a, '_, '_>,
    styles: StyleChain<'a>,
) -> SourceResult<()> {
    let span = elem.span();

    let rows: Vec<Vec<&Content>> =
        elem.rows.iter().map(|row| row.iter().collect()).collect();
    let nrows = rows.len();
    let ncols = rows.first().map_or(0, |row| row.len());

    let augment = elem.augment.resolve(styles);
    if let Some(aug) = &augment {
        for &offset in &aug.hline.0 {
            if offset > nrows as isize || offset.unsigned_abs() > nrows {
                bail!(
                    span,
                    "cannot draw a horizontal line at offset {offset} \
                     in a matrix with {nrows} rows",
                );
            }
        }

        for &offset in &aug.vline.0 {
            if offset > ncols as isize || offset.unsigned_abs() > ncols {
                bail!(
                    span,
                    "cannot draw a vertical line at offset {offset} \
                     in a matrix with {ncols} columns",
                );
            }
        }
    }

View on GitHub (pinned to 35417aa769)

Solutions

  1. Use an hline offset between 0 and the number of rows
  2. Use negative offsets to count rows from the bottom
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/typst-library/src/math/ir/resolve.rs:1045 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/2844e5fa52dd52bf. Report an issue: GitHub.