Added new command \lbar to show \u{019B} or lambda bar.

Made displayErrorInline and error visible.
Code clean up.
This commit is contained in:
Michael Griebling
2023-01-17 13:52:48 -05:00
parent 10b44d5258
commit e4ba232a5f
3 changed files with 12 additions and 34 deletions

View File

@@ -351,6 +351,7 @@ public class MTMathAtomFactory {
"ldots" : MTMathAtom(type: .ordinary, value: "\u{2026}"),
"prime" : MTMathAtom(type: .ordinary, value: "\u{2032}"),
"hbar" : MTMathAtom(type: .ordinary, value: "\u{210F}"),
"lbar" : MTMathAtom(type: .ordinary, value: "\u{019B}"), // NEW ƛ
"Im" : MTMathAtom(type: .ordinary, value: "\u{2111}"),
"ell" : MTMathAtom(type: .ordinary, value: "\u{2113}"),
"wp" : MTMathAtom(type: .ordinary, value: "\u{2118}"),
@@ -468,48 +469,41 @@ public class MTMathAtomFactory {
// Return an atom for times sign \times or *
public static func times() -> MTMathAtom {
return MTMathAtom(type: .binaryOperator, value: UnicodeSymbol.multiplication)
MTMathAtom(type: .binaryOperator, value: UnicodeSymbol.multiplication)
}
// Return an atom for division sign \div or /
public static func divide() -> MTMathAtom {
return MTMathAtom(type: .binaryOperator, value: UnicodeSymbol.division)
MTMathAtom(type: .binaryOperator, value: UnicodeSymbol.division)
}
// Return an atom aka placeholder square
public static func placeholder() -> MTMathAtom {
return MTMathAtom(type: .placeholder, value: UnicodeSymbol.whiteSquare)
MTMathAtom(type: .placeholder, value: UnicodeSymbol.whiteSquare)
}
public static func placeholderFraction() -> MTFraction {
let frac = MTFraction()
frac.numerator = MTMathList()
frac.numerator?.add(placeholder())
frac.denominator = MTMathList()
frac.denominator?.add(placeholder())
return frac
}
public static func placeholderSquareRoot() -> MTRadical {
let rad = MTRadical()
rad.radicand = MTMathList()
rad.radicand?.add(placeholder())
return rad
}
public static func placeholderRadical() -> MTRadical {
let rad = MTRadical()
rad.radicand = MTMathList()
rad.degree = MTMathList()
rad.radicand?.add(placeholder())
rad.degree?.add(placeholder())
return rad
}
@@ -525,7 +519,7 @@ public class MTMathAtomFactory {
*/
public static func atom(forCharacter ch: Character) -> MTMathAtom? {
let chStr = String(ch)
switch chStr {
switch chStr {
case "\u{0410}"..."\u{044F}":
return MTMathAtom(type: .ordinary, value: chStr)
case _ where ch.utf32Char < 0x0021 || ch.utf32Char > 0x007E:
@@ -564,13 +558,11 @@ public class MTMathAtomFactory {
convert the characters to atoms. Any character that cannot be converted is ignored. */
public static func atomList(for string: String) -> MTMathList {
let list = MTMathList()
for character in string {
if let newAtom = atom(forCharacter: character) {
list.add(newAtom)
}
}
return list
}
@@ -579,15 +571,12 @@ public class MTMathAtomFactory {
*/
public static func atom(forLatexSymbol name: String) -> MTMathAtom? {
var name = name
if let canonicalName = aliases[name] {
name = canonicalName
}
if let atom = supportedLatexSymbols[name] {
return atom.copy()
}
return nil
}
@@ -603,7 +592,6 @@ public class MTMathAtomFactory {
if atom.nucleus.count == 0 {
return nil
}
return sharedInstance.textToLatexSymbolName[atom.nucleus]
}
@@ -620,7 +608,7 @@ public class MTMathAtomFactory {
/** Returns a large opertor for the given name. If limits is true, limits are set up on
the operator and displayed differently. */
public static func operatorWithName(_ name: String, limits: Bool) -> MTLargeOperator {
return MTLargeOperator(value: name, limits: limits)
MTLargeOperator(value: name, limits: limits)
}
/** Returns an accent with the given name. The name of the accent is the LaTeX name
@@ -637,7 +625,7 @@ public class MTMathAtomFactory {
/** Returns the accent name for the given accent. This is the reverse of the above
function. */
public static func accentName(_ accent: MTAccent) -> String? {
return accentValueToName[accent.nucleus]
accentValueToName[accent.nucleus]
}
/** Creates a new boundary atom for the given delimiter name. If the delimiter name
@@ -820,8 +808,6 @@ public class MTMathAtomFactory {
table.set(alignment: .left, forColumn: 1)
let style = MTMathStyle(style: .text)
for i in 0..<table.cells.count {
for j in 0..<table.cells[i].count {
table.cells[i][j].insert(style, at: 0)

View File

@@ -61,7 +61,7 @@ public class MTMathUILabel : MTView {
set {
_mathList = newValue
error = nil
_latex = MTMathListBuilder.mathListToString(mathList)
_latex = MTMathListBuilder.mathListToString(newValue)
self.invalidateIntrinsicContentSize()
self.setNeedsLayout()
}
@@ -80,7 +80,7 @@ public class MTMathUILabel : MTView {
_latex = newValue
self.error = nil
var error : NSError? = nil
_mathList = MTMathListBuilder.build(fromString: latex, error: &error)
_mathList = MTMathListBuilder.build(fromString: newValue, error: &error)
if error != nil {
_mathList = nil
self.error = error
@@ -97,10 +97,10 @@ public class MTMathUILabel : MTView {
}
/** This contains any error that occurred when parsing the latex. */
var error:NSError?
public var error:NSError?
/** If true, if there is an error it displays the error message inline. Default true. */
var displayErrorInline = true
public var displayErrorInline = true
/** The MTFont to use for rendering. */
var font = MTFontManager.fontManager.defaultFont {
@@ -220,7 +220,7 @@ public class MTMathUILabel : MTView {
override public func layoutSubviews() { _layoutSubviews() }
#endif
public func _layoutSubviews() {
func _layoutSubviews() {
if mathList != nil {
displayList = MTTypesetter.createLineForMathList(mathList, font: font, style: currentStyle)
displayList?.textColor = textColor

View File

@@ -86,11 +86,3 @@ extension Character {
var isGreekSymbol : Bool { self.greekSymbolOrder != nil }
}
extension String {
var unicodeLength:Int {
self.lengthOfBytes(using: .utf32) / 4
}
}