smallmatrix LaTeX command support
This commit is contained in:
@@ -791,7 +791,8 @@ public class MTMathAtomFactory {
|
|||||||
"bmatrix": ["[", "]"],
|
"bmatrix": ["[", "]"],
|
||||||
"Bmatrix": ["{", "}"],
|
"Bmatrix": ["{", "}"],
|
||||||
"vmatrix": ["vert", "vert"],
|
"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
|
/** 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 {
|
} else if let env = env {
|
||||||
if let delims = matrixEnvs[env] {
|
if let delims = matrixEnvs[env] {
|
||||||
table.environment = "matrix"
|
table.environment = "matrix"
|
||||||
|
|
||||||
|
// smallmatrix uses script style and tighter spacing for inline use
|
||||||
|
let isSmallMatrix = (env == "smallmatrix")
|
||||||
|
|
||||||
table.interRowAdditionalSpacing = 0
|
table.interRowAdditionalSpacing = 0
|
||||||
table.interColumnSpacing = 18
|
table.interColumnSpacing = isSmallMatrix ? 6 : 18
|
||||||
|
|
||||||
let style = MTMathStyle(style: .text)
|
let style = MTMathStyle(style: isSmallMatrix ? .script : .text)
|
||||||
|
|
||||||
for i in 0..<table.cells.count {
|
for i in 0..<table.cells.count {
|
||||||
for j in 0..<table.cells[i].count {
|
for j in 0..<table.cells[i].count {
|
||||||
table.cells[i][j].insert(style, at: 0)
|
table.cells[i][j].insert(style, at: 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if delims.count == 2 {
|
if delims.count == 2 {
|
||||||
let inner = MTInner()
|
let inner = MTInner()
|
||||||
inner.leftBoundary = Self.boundary(forDelimiter: delims[0])
|
inner.leftBoundary = Self.boundary(forDelimiter: delims[0])
|
||||||
|
|||||||
@@ -2369,15 +2369,41 @@ final class MTMathListBuilderTests: XCTestCase {
|
|||||||
]
|
]
|
||||||
|
|
||||||
for (latex, desc) in testCases {
|
for (latex, desc) in testCases {
|
||||||
|
print("Testing: \(desc)")
|
||||||
|
print(" LaTeX: \(latex)")
|
||||||
var error: NSError? = nil
|
var error: NSError? = nil
|
||||||
let list = MTMathListBuilder.build(fromString: latex, error: &error)
|
let list = MTMathListBuilder.build(fromString: latex, error: &error)
|
||||||
|
|
||||||
if list == nil || error != nil {
|
if let err = error {
|
||||||
throw XCTSkip("\\smallmatrix not implemented: \(desc). Error: \(error?.localizedDescription ?? "nil result")")
|
print(" ERROR: \(err.localizedDescription)")
|
||||||
|
} else if list == nil {
|
||||||
|
print(" List is nil but no error")
|
||||||
|
} else {
|
||||||
|
print(" SUCCESS: Got \(list!.atoms.count) atoms")
|
||||||
}
|
}
|
||||||
|
|
||||||
let unwrappedList = try XCTUnwrap(list, "Should parse: \(desc)")
|
let unwrappedList = try XCTUnwrap(list, "Should parse: \(desc)")
|
||||||
|
XCTAssertNil(error, "Should not error on \(desc): \(error?.localizedDescription ?? "")")
|
||||||
XCTAssertTrue(unwrappedList.atoms.count >= 1, "\(desc) should have atoms")
|
XCTAssertTrue(unwrappedList.atoms.count >= 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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user