[MTMathAtomFactory] add support for /mod and /pmod

This commit is contained in:
Nicolas Guillot
2025-09-30 09:35:29 +02:00
parent 7f6cb02371
commit 4dcc7800d5
2 changed files with 25 additions and 0 deletions

View File

@@ -310,6 +310,7 @@ public class MTMathAtomFactory {
"hom" : MTMathAtomFactory.operatorWithName( "hom", limits: false),
"exp" : MTMathAtomFactory.operatorWithName( "exp", limits: false),
"deg" : MTMathAtomFactory.operatorWithName( "deg", limits: false),
"mod" : MTMathAtomFactory.operatorWithName("mod", limits: false),
// Limit operators
"lim" : MTMathAtomFactory.operatorWithName( "lim", limits: true),

24
Sources/SwiftMath/MathRender/MTMathListBuilder.swift Executable file → Normal file
View File

@@ -620,6 +620,30 @@ public struct MTMathListBuilder {
mathColorbox.colorString = color!
mathColorbox.innerList = self.buildInternal(true)
return mathColorbox
} else if command == "pmod" {
// A pmod command has 1 argument - creates (mod n)
let inner = MTInner()
inner.leftBoundary = MTMathAtomFactory.boundary(forDelimiter: "(")
inner.rightBoundary = MTMathAtomFactory.boundary(forDelimiter: ")")
let innerList = MTMathList()
// Add the "mod" operator (upright text)
let modOperator = MTMathAtomFactory.atom(forLatexSymbol: "mod")!
innerList.add(modOperator)
// Add medium space between "mod" and argument (6mu)
let space = MTMathSpace(space: 6.0)
innerList.add(space)
// Parse the argument from braces
let argument = self.buildInternal(true)
if let argList = argument {
innerList.append(argList)
}
inner.innerList = innerList
return inner
} else {
let errorMessage = "Invalid command \\\(command)"
self.setError(.invalidCommand, message:errorMessage)