Skip to content

Commit

Permalink
Merge pull request #29 from asnunes/fix/mmultiscripts
Browse files Browse the repository at this point in the history
Fix/mmultiscripts
  • Loading branch information
asnunes authored Nov 2, 2024
2 parents d4eb63d + b5b2229 commit b0a56d8
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 3 deletions.
16 changes: 16 additions & 0 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1222,4 +1222,20 @@ describe('#convert', () => {

expect(result).toBe(expectedLatex);
});

it('should correctly convert mmultiscripts with empty mprescripts', () => {
const mathml = `
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mmultiscripts>
<mi mathvariant="normal">U</mi>
<mprescripts></mprescripts>
<mn>238</mn>
</mmultiscripts>
</math>
`;

const result = MathMLToLaTeX.convert(mathml);

expect(result).toBe('\\_{238}^{}U');
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mathml-to-latex",
"version": "1.4.2",
"version": "1.4.3",
"description": "A JavaScript tool to convert mathml string to LaTeX string",
"main": "dist/bundle.min.js",
"types": "dist/index.d.ts",
Expand Down
7 changes: 7 additions & 0 deletions src/data/protocols/mathml-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ export interface MathMLElement {
readonly children: MathMLElement[];
attributes: Record<string, string>;
}

export class VoidMathMLElement implements MathMLElement {
readonly name = 'void';
readonly value = '';
readonly children = [];
attributes = {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export { MTable } from './mtable';
export { MTr } from './mtr';
export { GenericSpacingWrapper } from './generic-spacing-wrapper';
export { GenericUnderOver } from './generic-under-over';
export { Void } from './void';
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ToLaTeXConverter } from 'domain/usecases/to-latex-converter';

export class Void implements ToLaTeXConverter {
constructor(private readonly _mathmlElement: MathMLElement) {}

convert(): string {
return '';
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as ToLatexConverters from './converters';
import { MathMLElement } from '../../../data/protocols/mathml-element';
import { MathMLElement, VoidMathMLElement } from '../../../data/protocols/mathml-element';
import { ToLaTeXConverter, ToLaTeXConverterClass } from '../../../domain/usecases/to-latex-converter';

export class MathMLElementToLatexConverterAdapter {
private readonly _mathMLElement: MathMLElement;

constructor(mathMLElement: MathMLElement) {
this._mathMLElement = mathMLElement;
this._mathMLElement = mathMLElement ?? new VoidMathMLElement();
}

toLatexConverter(): ToLaTeXConverter {
Expand Down Expand Up @@ -42,4 +42,5 @@ const fromMathMLElementToLatexConverter: Record<string, ToLaTeXConverterClass> =
munder: ToLatexConverters.GenericUnderOver,
mrow: ToLatexConverters.GenericSpacingWrapper,
mpadded: ToLatexConverters.GenericSpacingWrapper,
void: ToLatexConverters.Void,
};

0 comments on commit b0a56d8

Please sign in to comment.