diff --git a/Sources/SwiftMath/MathRender/MTMathAtomFactory.swift b/Sources/SwiftMath/MathRender/MTMathAtomFactory.swift index 321a037..6372627 100644 --- a/Sources/SwiftMath/MathRender/MTMathAtomFactory.swift +++ b/Sources/SwiftMath/MathRender/MTMathAtomFactory.swift @@ -791,7 +791,8 @@ public class MTMathAtomFactory { "bmatrix": ["[", "]"], "Bmatrix": ["{", "}"], "vmatrix": ["vert", "vert"], - "Vmatrix": ["Vert", "Vert"] + "Vmatrix": ["Vert", "Vert"], + "smallmatrix": [] ] /** Builds a table for a given environment with the given rows. Returns a `MTMathAtom` containing the @@ -821,17 +822,21 @@ public class MTMathAtomFactory { } else if let env = env { if let delims = matrixEnvs[env] { table.environment = "matrix" + + // smallmatrix uses script style and tighter spacing for inline use + let isSmallMatrix = (env == "smallmatrix") + table.interRowAdditionalSpacing = 0 - table.interColumnSpacing = 18 - - let style = MTMathStyle(style: .text) - + table.interColumnSpacing = isSmallMatrix ? 6 : 18 + + let style = MTMathStyle(style: isSmallMatrix ? .script : .text) + for i in 0..= 1, "\(desc) should have atoms") + + // Verify we have a table structure + var foundTable = false + for atom in unwrappedList.atoms { + if atom.type == .table { + foundTable = true + break + } + // Check inside inner atoms (for matrices with delimiters) + if atom.type == .inner, let inner = atom as? MTInner, let innerList = inner.innerList { + for innerAtom in innerList.atoms { + if innerAtom.type == .table { + foundTable = true + break + } + } + } + } + XCTAssertTrue(foundTable, "\(desc) should contain a table structure") } }