Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pie-framework/mathml-to-latex",
"version": "1.3.3",
"version": "1.4.0",
"description": "A JavaScript tool to convert mathml string to LaTeX string. This is a forked repo.",
"main": "dist/bundle.min.js",
"types": "dist/index.d.ts",
Expand Down
16 changes: 13 additions & 3 deletions src/data/usecases/mathml-to-latex-convertion/converters/mi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { ToLaTeXConverter } from '../../../../domain/usecases/to-latex-converter';
import { MathMLElement } from '../../../protocols/mathml-element';
import { normalizeWhiteSpaces } from '../../../helpers';
import { allMathSymbolsByChar, allMathSymbolsByGlyph, mathNumberByGlyph } from '../../../../syntax';
import {
allMathSymbolsByChar,
allMathSymbolsByGlyph,
allMathSymbolsByGlyphSpecial,
mathNumberByGlyph,
mathNumberByGlyphSpecial,
} from '../../../../syntax';
import { UTF8ToLtXConverter } from 'data/protocols';
import { HashUTF8ToLtXConverter } from '../../../../syntax/utf8-converter';

Expand Down Expand Up @@ -91,10 +97,14 @@ class Character {
}

private _findByGlyph(): string | undefined {
return allMathSymbolsByGlyph[this._value];
const mathOperator = allMathSymbolsByGlyphSpecial[`"${this._value}"`];

return mathOperator || allMathSymbolsByGlyph[this._value];
}

private _findByNumber(): string | undefined {
return mathNumberByGlyph[this._value];
const mathOperator = mathNumberByGlyphSpecial[`"${this._value}"`];

return mathOperator || mathNumberByGlyph[this._value];
}
}
5 changes: 3 additions & 2 deletions src/data/usecases/mathml-to-latex-convertion/converters/mn.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ToLaTeXConverter } from '../../../../domain/usecases/to-latex-converter';
import { MathMLElement } from '../../../protocols/mathml-element';
import { normalizeWhiteSpaces } from '../../../helpers';
import { mathNumberByGlyph } from '../../../../syntax';
import { mathNumberByGlyph, mathNumberByGlyphSpecial } from '../../../../syntax';

export class MN implements ToLaTeXConverter {
private readonly _mathmlElement: MathMLElement;
Expand All @@ -12,7 +12,8 @@ export class MN implements ToLaTeXConverter {

convert(): string {
const normalizedValue = normalizeWhiteSpaces(this._mathmlElement.value).trim();
const convertedValue = mathNumberByGlyph[normalizedValue];
const mathOperator = mathNumberByGlyphSpecial[`"${normalizedValue}"`];
const convertedValue = mathOperator || mathNumberByGlyph[normalizedValue];

return convertedValue || normalizedValue;
}
Expand Down
10 changes: 7 additions & 3 deletions src/data/usecases/mathml-to-latex-convertion/converters/mo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
HashUTF8ToLtXConverter,
allMathOperatorsByChar,
allMathOperatorsByGlyph,
mathNumberByGlyph,
mathNumberByGlyph, allMathOperatorsByGlyphSpecial, mathNumberByGlyphSpecial,
} from '../../../../syntax';

export class MO implements ToLaTeXConverter {
Expand Down Expand Up @@ -48,10 +48,14 @@ class Operator {
}

private _findByGlyph(): string | undefined {
return allMathOperatorsByGlyph[this._value];
const mathOperator = allMathOperatorsByGlyphSpecial[`"${this._value}"`];

return mathOperator || allMathOperatorsByGlyph[this._value];
}

private _findByNumber(): string | undefined {
return mathNumberByGlyph[this._value];
const mathOperator = mathNumberByGlyphSpecial[`"${this._value}"`];

return mathOperator || mathNumberByGlyph[this._value];
}
}
159 changes: 81 additions & 78 deletions src/syntax/all-math-operators-by-glyph.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,84 @@
export const allMathOperatorsByGlyphSpecial: Record<string, string> = {
'"ˍ"': '\\_',
'"ˋ"': 'ˋ',
'"ˊ"': 'ˊ',
'"ˉ"': 'ˉ',
'"ˇ"': '',
'"ˆ"': '\\hat',
'"º"': 'o',
'"ª"': 'a',
'"ⅆ"': 'd',
'"ⅅ"': '\\mathbb{D}',
'"土"': '\\pm',
'"十"': '+',
'"α"': '\\alpha',
'"β"': '\\beta',
'"γ"': '\\gamma',
'"Γ"': '\\Gamma',
'"δ"': '\\delta',
'"Δ"': '\\Delta',
'"ϵ"': '\\epsilon',
'"ζ"': '\\zeta',
'"η"': '\\eta',
'"θ"': '\\theta',
'"Θ"': '\\Theta',
'"ι"': '\\iota',
'"κ"': '\\kappa',
'"λ"': '\\lambda',
'"ν"': '\\nu',
'"ο"': '\\omicron',
'"π"': '\\pi',
'"Π"': '\\Pi',
'"ρ"': '\\rho',
'"σ"': '\\sigma',
'"Σ"': '\\Sigma',
'"τ"': '\\tau',
'"υ"': '\\upsilon',
'"Υ"': '\\Upsilon',
'"ϕ"': '\\phi',
'"Φ"': '\\Phi',
'"χ"': '\\chi',
'"ψ"': '\\psi',
'"Ψ"': '\\Psi',
'"ω"': '\\omega',
'"Ω"': '\\Omega',
'"Ω"': '\\Omega',
'"ℏ"': '\\hbar',
'"ℜ"': '\\mathfrak{R}',
'"Ѳ"': '\\theta',
'"Ø"': '\\emptyset',
'"ϱ"': '\\varrho',
'"ф"': '\\phi',
'"ℇ"': '\\varepsilon',
'"Ρ"': 'P',
'"ᐁ"': '\\nabla',
'"ƞ"': '\\eta',
'"μ"': '\\mu',
'"Ө"': '\\theta',
'"ⅇ"': '\\text{e}',
'"ɼ"': 'r',
'"ἱ"': 'i',
'"ϒ"': '\\Upsilon',
'"ѳ"': '\\theta',
'"ⁿ"': '^{n}',
'"เ"': '\\prime',
'"П"': '\\prod',
'"о"': 'o',
'"ђ"': '\\hbar',
'"Ʌ"': '\\Lambda',
'"ῡ"': '\\bar{u}',
'"φ"': '\\varphi',
'"ȼ"': 'c',
'"Χ"': '\\mathsf{X}',
'"ₙ"': '_{n}',
'"ħ"': '\\hbar',
'"T"': 'T',
'"$"': '\\$',
'"𝛿"': '\\delta',
'"𝜙"': '\\phi',
'"𝞮"': '\\epsilon',
};

export const allMathOperatorsByGlyph: Record<string, string> = {
_: '\\underline',
'⏡': '\\underbrace',
Expand Down Expand Up @@ -29,21 +110,13 @@ export const allMathOperatorsByGlyph: Record<string, string> = {
'˚': '\\degree',
'˙': '\\cdot',
'˘': ' ',
ˍ: '\\_',
ˋ: 'ˋ',
ˊ: 'ˊ',
ˉ: 'ˉ',
ˇ: '',
ˆ: '\\hat',
º: 'o',
'¹': '1',
'¸': ',',
'´': '´',
'³': '3',
'²': '2',
'°': '\\degree',
'¯': '\\overline',
ª: 'a',
'↛': '\\nrightarrow',
'¨': '\\cdot\\cdot',
'~': '\\sim',
Expand All @@ -54,8 +127,6 @@ export const allMathOperatorsByGlyph: Record<string, string> = {
'∜': '\\sqrt[4]{}',
'∛': '\\sqrt[3]{}',
'√': '\\sqrt{}',
ⅆ: 'd',
ⅅ: '\\mathbb{D}',
'?': '?',
'@': '@',
'//': '//',
Expand Down Expand Up @@ -783,8 +854,6 @@ export const allMathOperatorsByGlyph: Record<string, string> = {
'⊼': '\\overline{\\land}',
'⊻': '\\underline{\\lor}',
'⊺': '\\top',
土: '\\pm',
十: '+',
'⊹': '',
'⊷': '\\circ\\multimap',
'⊶': '\\circ\\multimap',
Expand Down Expand Up @@ -1083,63 +1152,18 @@ export const allMathOperatorsByGlyph: Record<string, string> = {
'“': '\\text{``}',
'’': "'",
'‘': '`',
α: '\\alpha',
β: '\\beta',
γ: '\\gamma',
Γ: '\\Gamma',
δ: '\\delta',
Δ: '\\Delta',
ϵ: '\\epsilon',
ζ: '\\zeta',
η: '\\eta',
θ: '\\theta',
Θ: '\\Theta',
ι: '\\iota',
κ: '\\kappa',
λ: '\\lambda',
ν: '\\nu',
ο: '\\omicron',
π: '\\pi',
Π: '\\Pi',
ρ: '\\rho',
σ: '\\sigma',
Σ: '\\Sigma',
τ: '\\tau',
υ: '\\upsilon',
Υ: '\\Upsilon',
ϕ: '\\phi',
Φ: '\\Phi',
χ: '\\chi',
ψ: '\\psi',
Ψ: '\\Psi',
ω: '\\omega',
Ω: '\\Omega',
Ω: '\\Omega',
'∅': '\\emptyset',
'⟲': '\\circlearrowleft',
'⟳': '\\circlearrowright',
'×': '\\times',
'½': '\\dfrac{1}{2}',
μ: '\\mu',
Ө: '\\theta',
'✓': '\\checkmark',
'⟩': '\\rangle',
'⟨': '\\langle',
'¼': '\\dfrac{1}{4}',
'…': '\\ldots',
ℏ: '\\hbar',
ℜ: '\\mathfrak{R}',
Ѳ: '\\theta',
Ø: '\\emptyset',
ϱ: '\\varrho',
ф: '\\phi',
ℇ: '\\varepsilon',
T: 'T',
'∙': '\\cdot',
Ρ: 'P',
'∞': '\\infty',
ᐁ: '\\nabla',
ƞ: '\\eta',
'⁺': '^{+}',
'⁻': '^{-}',
'⁼': '^{=}',
Expand All @@ -1160,44 +1184,23 @@ export const allMathOperatorsByGlyph: Record<string, string> = {
'⎼': '-',
'⎜': '\\mid',
'⎥': '\\mid',
ħ: '\\hbar',
'⮕': '\\rightarrow',
'・': '\\cdot',
'¦': '\\mid',
'£': '\\pounds',
'¥': '\\yen',
'✗': '\\times',
'✔': '\\checkmark',
ⁿ: '^{n}',
'«': '\\ll',
เ: '\\prime',
'†': '\\dagger',
'│': '\\mid',
$: '\\$',
'#': '\\#',
'℃': '\\text{\\textdegree C}',
'℉': '\\text{\\textdegree F}',
'█': '\\blacksquare',
'℧': '\\mho',
ⅇ: '\\text{e}',
ɼ: 'r',
'‡': '\\ddagger',
ἱ: 'i',
ϒ: '\\Upsilon',
'𝛿': '\\delta',
'˳': '\\cdot',
ѳ: '\\theta',
'𝜙': '\\phi',
П: '\\prod',
о: 'o',
ђ: '\\hbar',
Ʌ: '\\Lambda',
'।': '\\mid',
'€': '\\euro',
ῡ: '\\bar{u}',
φ: '\\varphi',
ȼ: 'c',
'𝞮': '\\epsilon',
Χ: '\\mathsf{X}',
ₙ: '_{n}',
};
Loading