From 4dcc7800d5b06e582e4c438117dee1059577f054 Mon Sep 17 00:00:00 2001 From: Nicolas Guillot Date: Tue, 30 Sep 2025 09:35:29 +0200 Subject: [PATCH] [MTMathAtomFactory] add support for /mod and /pmod --- .../MathRender/MTMathAtomFactory.swift | 1 + .../MathRender/MTMathListBuilder.swift | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) mode change 100755 => 100644 Sources/SwiftMath/MathRender/MTMathListBuilder.swift diff --git a/Sources/SwiftMath/MathRender/MTMathAtomFactory.swift b/Sources/SwiftMath/MathRender/MTMathAtomFactory.swift index c9c678c..01fa3ba 100644 --- a/Sources/SwiftMath/MathRender/MTMathAtomFactory.swift +++ b/Sources/SwiftMath/MathRender/MTMathAtomFactory.swift @@ -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), diff --git a/Sources/SwiftMath/MathRender/MTMathListBuilder.swift b/Sources/SwiftMath/MathRender/MTMathListBuilder.swift old mode 100755 new mode 100644 index d71d522..6ac754f --- a/Sources/SwiftMath/MathRender/MTMathListBuilder.swift +++ b/Sources/SwiftMath/MathRender/MTMathListBuilder.swift @@ -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)