From 83dc5829460d3275309a3f610eb76c956d927d88 Mon Sep 17 00:00:00 2001 From: Alexandre Nunes Date: Sat, 19 Sep 2020 14:13:58 -0300 Subject: [PATCH] feat: add especial symbols to mi tag implementation --- .../mathml-tag-to-latex/mathml-tags/MI.ts | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/converters/mathml-interfaces-to-latex/mathml-tag-to-latex/mathml-tags/MI.ts b/src/converters/mathml-interfaces-to-latex/mathml-tag-to-latex/mathml-tags/MI.ts index 2f93a86..c9f4740 100755 --- a/src/converters/mathml-interfaces-to-latex/mathml-tag-to-latex/mathml-tags/MI.ts +++ b/src/converters/mathml-interfaces-to-latex/mathml-tag-to-latex/mathml-tags/MI.ts @@ -1,4 +1,6 @@ import { MathMLTag } from './MathMLTag'; +import { allMathSymbolsByChar } from '../../../../syntax/allMathSymbolsByChar'; +import { allMathSymbolsByGlyph } from '../../../../syntax/allMathSymbolsByGlyph'; export class MI extends MathMLTag { constructor(value: string, attributes: Record, children: MathMLTag[]) { @@ -7,6 +9,33 @@ export class MI extends MathMLTag { convert(): string { const normalizedValue = this._normalizeWhiteSpaces(this._value); - return normalizedValue.trim(); + if (normalizedValue === ' ') return Character.apply(normalizedValue); + + const trimmedValue = normalizedValue.trim(); + return Character.apply(trimmedValue); + } +} + +class Character { + private _value: string; + + constructor(value: string) { + this._value = value; + } + + static apply(value: string): string { + return new Character(value)._apply(); + } + + private _apply(): string { + return this._findByCharacter() || this._findByGlyph() || this._value; + } + + private _findByCharacter(): string | undefined { + return allMathSymbolsByChar[this._value]; + } + + private _findByGlyph(): string | undefined { + return allMathSymbolsByGlyph[this._value]; } }