feat: add mfenced and mtable as bmatrix
This commit is contained in:
parent
6921b8869f
commit
187cd3bf00
@ -17,6 +17,8 @@ import {
|
||||
MSubsup,
|
||||
MText,
|
||||
MUnderover,
|
||||
MTable,
|
||||
MTr,
|
||||
GenericContentWrapperTag,
|
||||
GenericUnderOverTag,
|
||||
} from './mathml-tags';
|
||||
@ -70,6 +72,10 @@ export class Dispatcher {
|
||||
return new MText(this._value, this._attributes, this._children);
|
||||
case 'munderover':
|
||||
return new MUnderover(this._value, this._attributes, this._children);
|
||||
case 'mtable':
|
||||
return new MTable(this._value, this._attributes, this._children);
|
||||
case 'mtr':
|
||||
return new MTr(this._value, this._attributes, this._children);
|
||||
case 'mover':
|
||||
case 'munder':
|
||||
return new GenericUnderOverTag(this._name, this._value, this._attributes, this._children);
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { MathMLTag } from './MathMLTag';
|
||||
import { GenericWrapper } from '../../../../utils/wrappers';
|
||||
import { JoinWithManySeparators } from '../../../../utils';
|
||||
import { MTable } from './MTable';
|
||||
|
||||
export class MFenced extends MathMLTag {
|
||||
private readonly _open: string;
|
||||
@ -16,8 +17,14 @@ export class MFenced extends MathMLTag {
|
||||
}
|
||||
|
||||
convert(): string {
|
||||
if (this._isMatrix()) return new Matrix(this._open).apply(this._mapChildrenToLaTeX().join());
|
||||
|
||||
return new Vector(this._open, this._close, this._separators).apply(this._mapChildrenToLaTeX());
|
||||
}
|
||||
|
||||
private _isMatrix(): boolean {
|
||||
return this._children.some((child) => child instanceof MTable);
|
||||
}
|
||||
}
|
||||
|
||||
class Vector {
|
||||
@ -37,3 +44,15 @@ class Vector {
|
||||
return new GenericWrapper(this._open, this._close).wrap(contentWithoutWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
class Matrix {
|
||||
private readonly _open: string;
|
||||
|
||||
constructor(open: string) {
|
||||
this._open = open;
|
||||
}
|
||||
|
||||
apply(latex: string): string {
|
||||
return '\\begin{bmatrix}\n' + latex + '\n\\end{bmatrix}';
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
import { MathMLTag } from './MathMLTag';
|
||||
|
||||
export class MTable extends MathMLTag {
|
||||
constructor(value: string, attributes: Record<string, string>, children: MathMLTag[]) {
|
||||
super('mtable', value, attributes, children);
|
||||
}
|
||||
|
||||
convert(): string {
|
||||
return this._mapChildrenToLaTeX().join(' \\\\\n');
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
import { MathMLTag } from './MathMLTag';
|
||||
|
||||
export class MTr extends MathMLTag {
|
||||
constructor(value: string, attributes: Record<string, string>, children: MathMLTag[]) {
|
||||
super('mtr', value, attributes, children);
|
||||
}
|
||||
|
||||
convert(): string {
|
||||
return this._mapChildrenToLaTeX().join(' & ');
|
||||
}
|
||||
}
|
@ -16,5 +16,7 @@ export { MSub } from './MSub';
|
||||
export { MSubsup } from './MSubsup';
|
||||
export { MText } from './MText';
|
||||
export { MUnderover } from './MUnderover';
|
||||
export { MTable } from './MTable';
|
||||
export { MTr } from './MTr';
|
||||
export { GenericContentWrapperTag } from './GenericContentWrapperTag';
|
||||
export { GenericUnderOverTag } from './GenericUnderOverTag';
|
||||
|
Loading…
Reference in New Issue
Block a user