Skip to content

Commit

Permalink
started on orderedpair parse
Browse files Browse the repository at this point in the history
  • Loading branch information
mathipalm committed Apr 15, 2019
1 parent b85a4de commit de2b829
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 2 deletions.
22 changes: 21 additions & 1 deletion iosMath/lib/MTMathList.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ typedef NS_ENUM(NSUInteger, MTMathAtomType)
kMTMathAtomOverline,
/// An accented atom - Accent in TeX
kMTMathAtomAccent,

kMTMathAtomOrderedPair,
// Atoms after this point do not support subscripts or superscripts

/// A left atom - Left & Right in TeX. We don't need two since we track boundaries separately.
Expand Down Expand Up @@ -194,6 +194,26 @@ typedef NS_ENUM(NSUInteger, MTFontStyle)

@end

@interface MTOrderedPair : MTMathAtom

/// Creates an empty orderedPair

- (instancetype)init NS_DESIGNATED_INITIALIZER;

/// Left operand pair
@property (nonatomic) MTMathList* leftOperand;

/// Right operand pair
@property (nonatomic) MTMathList* rightOperand;

/** An optional delimiter for a pair on the left. */
@property (nonatomic, nullable) NSString* open;

/** An optional delimiter for a pair on the right. */
@property (nonatomic, nullable) NSString* close;

@end

/** An atom of type radical (square root). */
@interface MTRadical : MTMathAtom

Expand Down
53 changes: 53 additions & 0 deletions iosMath/lib/MTMathList.m
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,59 @@ - (instancetype)finalized

@end

#pragma mark - MTOrderedPair

@implementation MTOrderedPair

- (instancetype)init
{
// radicals have no nucleus
self = [super initWithType:kMTMathAtomOrderedPair value:@""];
return self;
}

- (instancetype)initWithType:(MTMathAtomType)type value:(NSString *)value
{
if (type == kMTMathAtomOrderedPair) {
return [self init];
}
@throw [NSException exceptionWithName:@"InvalidMethod"
reason:@"[MTOrderedPair initWithType:value:] cannot be called. Use [MTOrdreredPair init] instead."
userInfo:nil];
}

- (NSString *)stringValue
{
NSMutableString* str = [[NSMutableString alloc] init];
[str appendFormat:@"(%@,%@)", self.leftOperand.stringValue, self.rightOperand.stringValue];
//Below line can be uncommented for scaling up in ordered pair
// [str appendFormat:@"\\left(%@,%@\\right)", self.leftOperand.stringValue, self.rightOperand.stringValue];

return str;
}

- (id)copyWithZone:(NSZone *)zone
{
MTOrderedPair* pair = [super copyWithZone:zone];
pair.leftOperand = [self.leftOperand copyWithZone:zone];
pair.rightOperand = [self.rightOperand copyWithZone:zone];
pair.open = [self.open copyWithZone:zone];
pair.close = [self.close copyWithZone:zone];
return pair;

}

- (instancetype)finalized
{
MTOrderedPair* newPair = [super finalized];
newPair.leftOperand = newPair.leftOperand.finalized;
newPair.rightOperand = newPair.rightOperand.finalized;
return newPair;
}

@end


#pragma mark - MTRadical

@implementation MTRadical
Expand Down
5 changes: 5 additions & 0 deletions iosMath/lib/MTMathListBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,11 @@ + (NSString *)mathListToString:(MTMathList *)ml
} else if ([atom.nucleus isEqualToString:@"\u2212"]) {
// math minus
[str appendString:@"-"];
} else if (atom.type == kMTMathAtomOrderedPair) {
MTOrderedPair* pair = (MTOrderedPair*) atom;
[str appendFormat:@"(%@,%@)", [self mathListToString:pair.leftOperand ], [self mathListToString:pair.rightOperand]];
//Below line can be uncommented for ordered pair
// [str appendFormat:@"\\left(%@,%@\\right)", [self mathListToString:pair.leftOperand ], [self mathListToString:pair.rightOperand]];
} else {
NSString* command = [MTMathAtomFactory latexSymbolNameForAtom:atom];
if (command) {
Expand Down
4 changes: 3 additions & 1 deletion iosMath/lib/MTMathListIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ typedef NS_ENUM(unsigned int, MTMathListSubIndexType) {
/// The subindex indexes into the radicand (only valid for radicals)
kMTSubIndexTypeRadicand,
/// The subindex indexes into the degree (only valid for radicals)
kMTSubIndexTypeDegree
kMTSubIndexTypeDegree,
kMTSubIndexTypeLeftOperand,
kMTSubIndexTypeRightOperand
};


Expand Down

0 comments on commit de2b829

Please sign in to comment.