Added new command \lbar to show \u{019B} or lambda bar.
Made displayErrorInline and error visible. Code clean up.
This commit is contained in:
@@ -351,6 +351,7 @@ public class MTMathAtomFactory {
|
|||||||
"ldots" : MTMathAtom(type: .ordinary, value: "\u{2026}"),
|
"ldots" : MTMathAtom(type: .ordinary, value: "\u{2026}"),
|
||||||
"prime" : MTMathAtom(type: .ordinary, value: "\u{2032}"),
|
"prime" : MTMathAtom(type: .ordinary, value: "\u{2032}"),
|
||||||
"hbar" : MTMathAtom(type: .ordinary, value: "\u{210F}"),
|
"hbar" : MTMathAtom(type: .ordinary, value: "\u{210F}"),
|
||||||
|
"lbar" : MTMathAtom(type: .ordinary, value: "\u{019B}"), // NEW ƛ
|
||||||
"Im" : MTMathAtom(type: .ordinary, value: "\u{2111}"),
|
"Im" : MTMathAtom(type: .ordinary, value: "\u{2111}"),
|
||||||
"ell" : MTMathAtom(type: .ordinary, value: "\u{2113}"),
|
"ell" : MTMathAtom(type: .ordinary, value: "\u{2113}"),
|
||||||
"wp" : MTMathAtom(type: .ordinary, value: "\u{2118}"),
|
"wp" : MTMathAtom(type: .ordinary, value: "\u{2118}"),
|
||||||
@@ -468,48 +469,41 @@ public class MTMathAtomFactory {
|
|||||||
|
|
||||||
// Return an atom for times sign \times or *
|
// Return an atom for times sign \times or *
|
||||||
public static func times() -> MTMathAtom {
|
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 /
|
// Return an atom for division sign \div or /
|
||||||
public static func divide() -> MTMathAtom {
|
public static func divide() -> MTMathAtom {
|
||||||
return MTMathAtom(type: .binaryOperator, value: UnicodeSymbol.division)
|
MTMathAtom(type: .binaryOperator, value: UnicodeSymbol.division)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return an atom aka placeholder square
|
// Return an atom aka placeholder square
|
||||||
public static func placeholder() -> MTMathAtom {
|
public static func placeholder() -> MTMathAtom {
|
||||||
return MTMathAtom(type: .placeholder, value: UnicodeSymbol.whiteSquare)
|
MTMathAtom(type: .placeholder, value: UnicodeSymbol.whiteSquare)
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func placeholderFraction() -> MTFraction {
|
public static func placeholderFraction() -> MTFraction {
|
||||||
let frac = MTFraction()
|
let frac = MTFraction()
|
||||||
|
|
||||||
frac.numerator = MTMathList()
|
frac.numerator = MTMathList()
|
||||||
frac.numerator?.add(placeholder())
|
frac.numerator?.add(placeholder())
|
||||||
frac.denominator = MTMathList()
|
frac.denominator = MTMathList()
|
||||||
frac.denominator?.add(placeholder())
|
frac.denominator?.add(placeholder())
|
||||||
|
|
||||||
return frac
|
return frac
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func placeholderSquareRoot() -> MTRadical {
|
public static func placeholderSquareRoot() -> MTRadical {
|
||||||
let rad = MTRadical()
|
let rad = MTRadical()
|
||||||
|
|
||||||
rad.radicand = MTMathList()
|
rad.radicand = MTMathList()
|
||||||
rad.radicand?.add(placeholder())
|
rad.radicand?.add(placeholder())
|
||||||
|
|
||||||
return rad
|
return rad
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func placeholderRadical() -> MTRadical {
|
public static func placeholderRadical() -> MTRadical {
|
||||||
let rad = MTRadical()
|
let rad = MTRadical()
|
||||||
|
|
||||||
rad.radicand = MTMathList()
|
rad.radicand = MTMathList()
|
||||||
rad.degree = MTMathList()
|
rad.degree = MTMathList()
|
||||||
|
|
||||||
rad.radicand?.add(placeholder())
|
rad.radicand?.add(placeholder())
|
||||||
rad.degree?.add(placeholder())
|
rad.degree?.add(placeholder())
|
||||||
|
|
||||||
return rad
|
return rad
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -564,13 +558,11 @@ public class MTMathAtomFactory {
|
|||||||
convert the characters to atoms. Any character that cannot be converted is ignored. */
|
convert the characters to atoms. Any character that cannot be converted is ignored. */
|
||||||
public static func atomList(for string: String) -> MTMathList {
|
public static func atomList(for string: String) -> MTMathList {
|
||||||
let list = MTMathList()
|
let list = MTMathList()
|
||||||
|
|
||||||
for character in string {
|
for character in string {
|
||||||
if let newAtom = atom(forCharacter: character) {
|
if let newAtom = atom(forCharacter: character) {
|
||||||
list.add(newAtom)
|
list.add(newAtom)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -579,15 +571,12 @@ public class MTMathAtomFactory {
|
|||||||
*/
|
*/
|
||||||
public static func atom(forLatexSymbol name: String) -> MTMathAtom? {
|
public static func atom(forLatexSymbol name: String) -> MTMathAtom? {
|
||||||
var name = name
|
var name = name
|
||||||
|
|
||||||
if let canonicalName = aliases[name] {
|
if let canonicalName = aliases[name] {
|
||||||
name = canonicalName
|
name = canonicalName
|
||||||
}
|
}
|
||||||
|
|
||||||
if let atom = supportedLatexSymbols[name] {
|
if let atom = supportedLatexSymbols[name] {
|
||||||
return atom.copy()
|
return atom.copy()
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -603,7 +592,6 @@ public class MTMathAtomFactory {
|
|||||||
if atom.nucleus.count == 0 {
|
if atom.nucleus.count == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return sharedInstance.textToLatexSymbolName[atom.nucleus]
|
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
|
/** Returns a large opertor for the given name. If limits is true, limits are set up on
|
||||||
the operator and displayed differently. */
|
the operator and displayed differently. */
|
||||||
public static func operatorWithName(_ name: String, limits: Bool) -> MTLargeOperator {
|
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
|
/** 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
|
/** Returns the accent name for the given accent. This is the reverse of the above
|
||||||
function. */
|
function. */
|
||||||
public static func accentName(_ accent: MTAccent) -> String? {
|
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
|
/** 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)
|
table.set(alignment: .left, forColumn: 1)
|
||||||
|
|
||||||
let style = MTMathStyle(style: .text)
|
let style = MTMathStyle(style: .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)
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class MTMathUILabel : MTView {
|
|||||||
set {
|
set {
|
||||||
_mathList = newValue
|
_mathList = newValue
|
||||||
error = nil
|
error = nil
|
||||||
_latex = MTMathListBuilder.mathListToString(mathList)
|
_latex = MTMathListBuilder.mathListToString(newValue)
|
||||||
self.invalidateIntrinsicContentSize()
|
self.invalidateIntrinsicContentSize()
|
||||||
self.setNeedsLayout()
|
self.setNeedsLayout()
|
||||||
}
|
}
|
||||||
@@ -80,7 +80,7 @@ public class MTMathUILabel : MTView {
|
|||||||
_latex = newValue
|
_latex = newValue
|
||||||
self.error = nil
|
self.error = nil
|
||||||
var error : NSError? = nil
|
var error : NSError? = nil
|
||||||
_mathList = MTMathListBuilder.build(fromString: latex, error: &error)
|
_mathList = MTMathListBuilder.build(fromString: newValue, error: &error)
|
||||||
if error != nil {
|
if error != nil {
|
||||||
_mathList = nil
|
_mathList = nil
|
||||||
self.error = error
|
self.error = error
|
||||||
@@ -97,10 +97,10 @@ public class MTMathUILabel : MTView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** This contains any error that occurred when parsing the latex. */
|
/** 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. */
|
/** 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. */
|
/** The MTFont to use for rendering. */
|
||||||
var font = MTFontManager.fontManager.defaultFont {
|
var font = MTFontManager.fontManager.defaultFont {
|
||||||
@@ -220,7 +220,7 @@ public class MTMathUILabel : MTView {
|
|||||||
override public func layoutSubviews() { _layoutSubviews() }
|
override public func layoutSubviews() { _layoutSubviews() }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public func _layoutSubviews() {
|
func _layoutSubviews() {
|
||||||
if mathList != nil {
|
if mathList != nil {
|
||||||
displayList = MTTypesetter.createLineForMathList(mathList, font: font, style: currentStyle)
|
displayList = MTTypesetter.createLineForMathList(mathList, font: font, style: currentStyle)
|
||||||
displayList?.textColor = textColor
|
displayList?.textColor = textColor
|
||||||
|
|||||||
@@ -86,11 +86,3 @@ extension Character {
|
|||||||
|
|
||||||
var isGreekSymbol : Bool { self.greekSymbolOrder != nil }
|
var isGreekSymbol : Bool { self.greekSymbolOrder != nil }
|
||||||
}
|
}
|
||||||
|
|
||||||
extension String {
|
|
||||||
|
|
||||||
var unicodeLength:Int {
|
|
||||||
self.lengthOfBytes(using: .utf32) / 4
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user