Add array environment parsing
Agent-Logs-Url: https://github.com/wesleyel/swiftui-math/sessions/56436444-e15b-4dd0-8a70-c87df1e3dc4e Co-authored-by: wesleyel <48174882+wesleyel@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
8201156af8
commit
f8f668f649
@@ -1052,6 +1052,43 @@ struct ParserTests {
|
||||
#expect(latex == "\\left( \\begin{matrix}x&y\\\\ z&w\\end{matrix}\\right) ")
|
||||
}
|
||||
|
||||
@Test
|
||||
func array() throws {
|
||||
let str = "\\left\\{\\begin{array}{ll}1,&|x|\\leq1,\\\\0,&|x|>1,\\end{array}\\right."
|
||||
let list = try #require(Math.Parser.build(fromString: str))
|
||||
#expect(list.atoms.count == 1)
|
||||
|
||||
let inner = try #require(list.atoms[0] as? Math.Inner)
|
||||
let leftBoundary = try #require(inner.leftBoundary)
|
||||
#expect(leftBoundary.type == .boundary)
|
||||
#expect(leftBoundary.nucleus == "{")
|
||||
#expect(inner.rightBoundary == nil)
|
||||
|
||||
let innerList = try #require(inner.innerList)
|
||||
#expect(innerList.atoms.count == 1)
|
||||
|
||||
let table = try #require(innerList.atoms[0] as? Math.Table)
|
||||
#expect(table.environment == "array")
|
||||
#expect(table.columnFormat == "ll")
|
||||
#expect(table.interRowAdditionalSpacing == 0)
|
||||
#expect(table.interColumnSpacing == 18)
|
||||
#expect(table.numberOfRows == 2)
|
||||
#expect(table.numberOfColumns == 2)
|
||||
#expect(table.alignment(forColumn: 0) == .left)
|
||||
#expect(table.alignment(forColumn: 1) == .left)
|
||||
|
||||
for row in 0..<table.numberOfRows {
|
||||
for column in 0..<table.numberOfColumns {
|
||||
let style = try #require(table.cells[row][column].atoms.first as? Math.Style)
|
||||
#expect(style.level == .text)
|
||||
}
|
||||
}
|
||||
|
||||
let latex = Math.Parser.atomListToString(list)
|
||||
#expect(latex.contains("\\begin{array}{ll}"))
|
||||
#expect(latex.contains("\\right."))
|
||||
}
|
||||
|
||||
@Test
|
||||
func defaultTable() throws {
|
||||
let str = "x \\\\ y"
|
||||
|
||||
Reference in New Issue
Block a user